mirror of
https://github.com/neovim/neovim.git
synced 2025-09-25 12:38:33 +00:00
refactor: collapse statements in single assignments
Problem: Variables are often assigned multiple places in common patterns. Solution: Replace these common patterns with different patterns that reduce the number of assignments. Use `MAX` and `MIN`: ```c if (x < y) { x = y; } // --> x = MAX(x, y); ``` ```c if (x > y) { x = y; } // --> x = MIN(x, y); ``` Use ternary: ```c int a; if (cond) { a = b; } els { a = c; } // --> int a = cond ? b : c; ```
This commit is contained in:

committed by
Lewis Russell

parent
1b5a394ffd
commit
d1bd3d643e
@@ -346,12 +346,7 @@ static void alist_add_list(int count, char **files, int after, bool will_edit)
|
|||||||
int old_argcount = ARGCOUNT;
|
int old_argcount = ARGCOUNT;
|
||||||
ga_grow(&ALIST(curwin)->al_ga, count);
|
ga_grow(&ALIST(curwin)->al_ga, count);
|
||||||
if (check_arglist_locked() != FAIL) {
|
if (check_arglist_locked() != FAIL) {
|
||||||
if (after < 0) {
|
after = MIN(MAX(after, 0), ARGCOUNT);
|
||||||
after = 0;
|
|
||||||
}
|
|
||||||
if (after > ARGCOUNT) {
|
|
||||||
after = ARGCOUNT;
|
|
||||||
}
|
|
||||||
if (after < ARGCOUNT) {
|
if (after < ARGCOUNT) {
|
||||||
memmove(&(ARGLIST[after + count]), &(ARGLIST[after]),
|
memmove(&(ARGLIST[after + count]), &(ARGLIST[after]),
|
||||||
(size_t)(ARGCOUNT - after) * sizeof(aentry_T));
|
(size_t)(ARGCOUNT - after) * sizeof(aentry_T));
|
||||||
|
@@ -1262,17 +1262,8 @@ static int do_buffer_ext(int action, int start, int dir, int count, int flags)
|
|||||||
if (bp == NULL) {
|
if (bp == NULL) {
|
||||||
bp = buf;
|
bp = buf;
|
||||||
}
|
}
|
||||||
if (dir == FORWARD) {
|
buf = dir == FORWARD ? (buf->b_next != NULL ? buf->b_next : firstbuf)
|
||||||
buf = buf->b_next;
|
: (buf->b_prev != NULL ? buf->b_prev : lastbuf);
|
||||||
if (buf == NULL) {
|
|
||||||
buf = firstbuf;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
buf = buf->b_prev;
|
|
||||||
if (buf == NULL) {
|
|
||||||
buf = lastbuf;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// Don't count unlisted buffers.
|
// Don't count unlisted buffers.
|
||||||
// Avoid non-help buffers if the starting point was a non-help buffer and
|
// Avoid non-help buffers if the starting point was a non-help buffer and
|
||||||
// vice-versa.
|
// vice-versa.
|
||||||
@@ -1505,11 +1496,7 @@ static int do_buffer_ext(int action, int start, int dir, int count, int flags)
|
|||||||
bp = buf;
|
bp = buf;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (forward) {
|
buf = forward ? buf->b_next : buf->b_prev;
|
||||||
buf = buf->b_next;
|
|
||||||
} else {
|
|
||||||
buf = buf->b_prev;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (buf == NULL) { // No loaded buffer, use unloaded one
|
if (buf == NULL) { // No loaded buffer, use unloaded one
|
||||||
@@ -1524,11 +1511,7 @@ static int do_buffer_ext(int action, int start, int dir, int count, int flags)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (buf == NULL) { // Still no buffer, just take one
|
if (buf == NULL) { // Still no buffer, just take one
|
||||||
if (curbuf->b_next != NULL) {
|
buf = curbuf->b_next != NULL ? curbuf->b_next : curbuf->b_prev;
|
||||||
buf = curbuf->b_next;
|
|
||||||
} else {
|
|
||||||
buf = curbuf->b_prev;
|
|
||||||
}
|
|
||||||
if (bt_quickfix(buf)) {
|
if (bt_quickfix(buf)) {
|
||||||
buf = NULL;
|
buf = NULL;
|
||||||
}
|
}
|
||||||
@@ -1679,11 +1662,7 @@ void set_curbuf(buf_T *buf, int action, bool update_jumplist)
|
|||||||
}
|
}
|
||||||
// If the buffer is not valid but curwin->w_buffer is NULL we must
|
// If the buffer is not valid but curwin->w_buffer is NULL we must
|
||||||
// enter some buffer. Using the last one is hopefully OK.
|
// enter some buffer. Using the last one is hopefully OK.
|
||||||
if (!valid) {
|
enter_buffer(valid ? buf : lastbuf);
|
||||||
enter_buffer(lastbuf);
|
|
||||||
} else {
|
|
||||||
enter_buffer(buf);
|
|
||||||
}
|
|
||||||
if (old_tw != curbuf->b_p_tw) {
|
if (old_tw != curbuf->b_p_tw) {
|
||||||
check_colorcolumn(curwin);
|
check_colorcolumn(curwin);
|
||||||
}
|
}
|
||||||
@@ -2135,7 +2114,6 @@ int buflist_getfile(int n, linenr_T lnum, int options, int forceit)
|
|||||||
{
|
{
|
||||||
win_T *wp = NULL;
|
win_T *wp = NULL;
|
||||||
fmark_T *fm = NULL;
|
fmark_T *fm = NULL;
|
||||||
colnr_T col;
|
|
||||||
|
|
||||||
buf_T *buf = buflist_findnr(n);
|
buf_T *buf = buflist_findnr(n);
|
||||||
if (buf == NULL) {
|
if (buf == NULL) {
|
||||||
@@ -2156,6 +2134,7 @@ int buflist_getfile(int n, linenr_T lnum, int options, int forceit)
|
|||||||
return FAIL;
|
return FAIL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
colnr_T col;
|
||||||
bool restore_view = false;
|
bool restore_view = false;
|
||||||
// altfpos may be changed by getfile(), get it now
|
// altfpos may be changed by getfile(), get it now
|
||||||
if (lnum == 0) {
|
if (lnum == 0) {
|
||||||
@@ -2291,11 +2270,7 @@ int buflist_findpat(const char *pattern, const char *pattern_end, bool unlisted,
|
|||||||
int match = -1;
|
int match = -1;
|
||||||
|
|
||||||
if (pattern_end == pattern + 1 && (*pattern == '%' || *pattern == '#')) {
|
if (pattern_end == pattern + 1 && (*pattern == '%' || *pattern == '#')) {
|
||||||
if (*pattern == '%') {
|
match = *pattern == '%' ? curbuf->b_fnum : curwin->w_alt_fnum;
|
||||||
match = curbuf->b_fnum;
|
|
||||||
} else {
|
|
||||||
match = curwin->w_alt_fnum;
|
|
||||||
}
|
|
||||||
buf_T *found_buf = buflist_findnr(match);
|
buf_T *found_buf = buflist_findnr(match);
|
||||||
if (diffmode && !(found_buf && diff_mode_buf(found_buf))) {
|
if (diffmode && !(found_buf && diff_mode_buf(found_buf))) {
|
||||||
match = -1;
|
match = -1;
|
||||||
@@ -2906,9 +2881,7 @@ void buflist_list(exarg_T *eap)
|
|||||||
changed_char,
|
changed_char,
|
||||||
NameBuff);
|
NameBuff);
|
||||||
|
|
||||||
if (len > IOSIZE - 20) {
|
len = MIN(len, IOSIZE - 20);
|
||||||
len = IOSIZE - 20;
|
|
||||||
}
|
|
||||||
|
|
||||||
// put "line 999" in column 40 or after the file name
|
// put "line 999" in column 40 or after the file name
|
||||||
int i = 40 - vim_strsize(IObuff);
|
int i = 40 - vim_strsize(IObuff);
|
||||||
@@ -3212,8 +3185,6 @@ static bool buf_same_file_id(buf_T *buf, FileID *file_id)
|
|||||||
/// @param fullname when non-zero print full path
|
/// @param fullname when non-zero print full path
|
||||||
void fileinfo(int fullname, int shorthelp, bool dont_truncate)
|
void fileinfo(int fullname, int shorthelp, bool dont_truncate)
|
||||||
{
|
{
|
||||||
char *name;
|
|
||||||
int n;
|
|
||||||
char *p;
|
char *p;
|
||||||
|
|
||||||
char *buffer = xmalloc(IOSIZE);
|
char *buffer = xmalloc(IOSIZE);
|
||||||
@@ -3229,11 +3200,9 @@ void fileinfo(int fullname, int shorthelp, bool dont_truncate)
|
|||||||
if (buf_spname(curbuf) != NULL) {
|
if (buf_spname(curbuf) != NULL) {
|
||||||
xstrlcpy(p, buf_spname(curbuf), (size_t)(IOSIZE - (p - buffer)));
|
xstrlcpy(p, buf_spname(curbuf), (size_t)(IOSIZE - (p - buffer)));
|
||||||
} else {
|
} else {
|
||||||
if (!fullname && curbuf->b_fname != NULL) {
|
char *name = (!fullname && curbuf->b_fname != NULL)
|
||||||
name = curbuf->b_fname;
|
? curbuf->b_fname
|
||||||
} else {
|
: curbuf->b_ffname;
|
||||||
name = curbuf->b_ffname;
|
|
||||||
}
|
|
||||||
home_replace(shorthelp ? curbuf : NULL, name, p,
|
home_replace(shorthelp ? curbuf : NULL, name, p,
|
||||||
(size_t)(IOSIZE - (p - buffer)), true);
|
(size_t)(IOSIZE - (p - buffer)), true);
|
||||||
}
|
}
|
||||||
@@ -3254,6 +3223,7 @@ void fileinfo(int fullname, int shorthelp, bool dont_truncate)
|
|||||||
|| (curbuf->b_flags & BF_WRITE_MASK)
|
|| (curbuf->b_flags & BF_WRITE_MASK)
|
||||||
|| curbuf->b_p_ro)
|
|| curbuf->b_p_ro)
|
||||||
? " " : "");
|
? " " : "");
|
||||||
|
int n;
|
||||||
// With 32 bit longs and more than 21,474,836 lines multiplying by 100
|
// With 32 bit longs and more than 21,474,836 lines multiplying by 100
|
||||||
// causes an overflow, thus for large numbers divide instead.
|
// causes an overflow, thus for large numbers divide instead.
|
||||||
if (curwin->w_cursor.lnum > 1000000) {
|
if (curwin->w_cursor.lnum > 1000000) {
|
||||||
@@ -3342,10 +3312,7 @@ void maketitle(void)
|
|||||||
|
|
||||||
if (p_title) {
|
if (p_title) {
|
||||||
if (p_titlelen > 0) {
|
if (p_titlelen > 0) {
|
||||||
maxlen = (int)(p_titlelen * Columns / 100);
|
maxlen = MAX((int)(p_titlelen * Columns / 100), 10);
|
||||||
if (maxlen < 10) {
|
|
||||||
maxlen = 10;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (*p_titlestring != NUL) {
|
if (*p_titlestring != NUL) {
|
||||||
@@ -3461,12 +3428,9 @@ void maketitle(void)
|
|||||||
icon_str = p_iconstring;
|
icon_str = p_iconstring;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
char *buf_p;
|
char *buf_p = buf_spname(curbuf) != NULL
|
||||||
if (buf_spname(curbuf) != NULL) {
|
? buf_spname(curbuf)
|
||||||
buf_p = buf_spname(curbuf);
|
: path_tail(curbuf->b_ffname); // use file name only in icon
|
||||||
} else { // use file name only in icon
|
|
||||||
buf_p = path_tail(curbuf->b_ffname);
|
|
||||||
}
|
|
||||||
*icon_str = NUL;
|
*icon_str = NUL;
|
||||||
// Truncate name at 100 bytes.
|
// Truncate name at 100 bytes.
|
||||||
int len = (int)strlen(buf_p);
|
int len = (int)strlen(buf_p);
|
||||||
@@ -3631,23 +3595,18 @@ bool bt_prompt(buf_T *buf)
|
|||||||
/// Open a window for a number of buffers.
|
/// Open a window for a number of buffers.
|
||||||
void ex_buffer_all(exarg_T *eap)
|
void ex_buffer_all(exarg_T *eap)
|
||||||
{
|
{
|
||||||
win_T *wp, *wpnext;
|
win_T *wpnext;
|
||||||
int split_ret = OK;
|
int split_ret = OK;
|
||||||
int open_wins = 0;
|
int open_wins = 0;
|
||||||
linenr_T count; // Maximum number of windows to open.
|
|
||||||
int all; // When true also load inactive buffers.
|
|
||||||
int had_tab = cmdmod.cmod_tab;
|
int had_tab = cmdmod.cmod_tab;
|
||||||
|
|
||||||
if (eap->addr_count == 0) { // make as many windows as possible
|
// Maximum number of windows to open.
|
||||||
count = 9999;
|
linenr_T count = eap->addr_count == 0
|
||||||
} else {
|
? 9999 // make as many windows as possible
|
||||||
count = eap->line2; // make as many windows as specified
|
: eap->line2; // make as many windows as specified
|
||||||
}
|
|
||||||
if (eap->cmdidx == CMD_unhide || eap->cmdidx == CMD_sunhide) {
|
// When true also load inactive buffers.
|
||||||
all = false;
|
int all = eap->cmdidx != CMD_unhide && eap->cmdidx != CMD_sunhide;
|
||||||
} else {
|
|
||||||
all = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Stop Visual mode, the cursor and "VIsual" may very well be invalid after
|
// Stop Visual mode, the cursor and "VIsual" may very well be invalid after
|
||||||
// switching to another buffer.
|
// switching to another buffer.
|
||||||
@@ -3663,7 +3622,7 @@ void ex_buffer_all(exarg_T *eap)
|
|||||||
while (true) {
|
while (true) {
|
||||||
tabpage_T *tpnext = curtab->tp_next;
|
tabpage_T *tpnext = curtab->tp_next;
|
||||||
// Try to close floating windows first
|
// Try to close floating windows first
|
||||||
for (wp = lastwin->w_floating ? lastwin : firstwin; wp != NULL; wp = wpnext) {
|
for (win_T *wp = lastwin->w_floating ? lastwin : firstwin; wp != NULL; wp = wpnext) {
|
||||||
wpnext = wp->w_floating
|
wpnext = wp->w_floating
|
||||||
? wp->w_prev->w_floating ? wp->w_prev : firstwin
|
? wp->w_prev->w_floating ? wp->w_prev : firstwin
|
||||||
: (wp->w_next == NULL || wp->w_next->w_floating) ? NULL : wp->w_next;
|
: (wp->w_next == NULL || wp->w_next->w_floating) ? NULL : wp->w_next;
|
||||||
@@ -3712,13 +3671,12 @@ void ex_buffer_all(exarg_T *eap)
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
win_T *wp;
|
||||||
if (had_tab != 0) {
|
if (had_tab != 0) {
|
||||||
// With the ":tab" modifier don't move the window.
|
// With the ":tab" modifier don't move the window.
|
||||||
if (buf->b_nwindows > 0) {
|
wp = buf->b_nwindows > 0
|
||||||
wp = lastwin; // buffer has a window, skip it
|
? lastwin // buffer has a window, skip it
|
||||||
} else {
|
: NULL;
|
||||||
wp = NULL;
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
// Check if this buffer already has a window
|
// Check if this buffer already has a window
|
||||||
for (wp = firstwin; wp != NULL; wp = wp->w_next) {
|
for (wp = firstwin; wp != NULL; wp = wp->w_next) {
|
||||||
@@ -3794,7 +3752,7 @@ void ex_buffer_all(exarg_T *eap)
|
|||||||
autocmd_no_leave--;
|
autocmd_no_leave--;
|
||||||
|
|
||||||
// Close superfluous windows.
|
// Close superfluous windows.
|
||||||
for (wp = lastwin; open_wins > count;) {
|
for (win_T *wp = lastwin; open_wins > count;) {
|
||||||
bool r = (buf_hide(wp->w_buffer) || !bufIsChanged(wp->w_buffer)
|
bool r = (buf_hide(wp->w_buffer) || !bufIsChanged(wp->w_buffer)
|
||||||
|| autowrite(wp->w_buffer, false) == OK) && !is_aucmd_win(wp);
|
|| autowrite(wp->w_buffer, false) == OK) && !is_aucmd_win(wp);
|
||||||
if (!win_valid(wp)) {
|
if (!win_valid(wp)) {
|
||||||
@@ -3862,7 +3820,6 @@ static int chk_modeline(linenr_T lnum, int flags)
|
|||||||
{
|
{
|
||||||
char *s;
|
char *s;
|
||||||
char *e;
|
char *e;
|
||||||
char *linecopy; // local copy of any modeline found
|
|
||||||
intmax_t vers;
|
intmax_t vers;
|
||||||
int retval = OK;
|
int retval = OK;
|
||||||
|
|
||||||
@@ -3907,6 +3864,7 @@ static int chk_modeline(linenr_T lnum, int flags)
|
|||||||
s++;
|
s++;
|
||||||
} while (s[-1] != ':');
|
} while (s[-1] != ':');
|
||||||
|
|
||||||
|
char *linecopy; // local copy of any modeline found
|
||||||
s = linecopy = xstrdup(s); // copy the line, it will change
|
s = linecopy = xstrdup(s); // copy the line, it will change
|
||||||
|
|
||||||
// prepare for emsg()
|
// prepare for emsg()
|
||||||
|
@@ -261,11 +261,8 @@ static int buf_write_convert(struct bw_info *ip, char **bufp, int *lenp)
|
|||||||
ip->bw_restlen += *lenp;
|
ip->bw_restlen += *lenp;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (n > 1) {
|
c = (n > 1) ? (unsigned)utf_ptr2char((char *)ip->bw_rest)
|
||||||
c = (unsigned)utf_ptr2char((char *)ip->bw_rest);
|
: ip->bw_rest[0];
|
||||||
} else {
|
|
||||||
c = ip->bw_rest[0];
|
|
||||||
}
|
|
||||||
if (n >= ip->bw_restlen) {
|
if (n >= ip->bw_restlen) {
|
||||||
n -= ip->bw_restlen;
|
n -= ip->bw_restlen;
|
||||||
ip->bw_restlen = 0;
|
ip->bw_restlen = 0;
|
||||||
@@ -289,11 +286,8 @@ static int buf_write_convert(struct bw_info *ip, char **bufp, int *lenp)
|
|||||||
(size_t)ip->bw_restlen);
|
(size_t)ip->bw_restlen);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (n > 1) {
|
c = n > 1 ? (unsigned)utf_ptr2char(*bufp + wlen)
|
||||||
c = (unsigned)utf_ptr2char(*bufp + wlen);
|
: (uint8_t)(*bufp)[wlen];
|
||||||
} else {
|
|
||||||
c = (uint8_t)(*bufp)[wlen];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ucs2bytes(c, &p, flags) && !ip->bw_conv_error) {
|
if (ucs2bytes(c, &p, flags) && !ip->bw_conv_error) {
|
||||||
@@ -876,9 +870,7 @@ static int buf_write_make_backup(char *fname, bool append, FileInfo *file_info_o
|
|||||||
// Change one character, just before the extension.
|
// Change one character, just before the extension.
|
||||||
//
|
//
|
||||||
char *wp = *backupp + strlen(*backupp) - 1 - strlen(backup_ext);
|
char *wp = *backupp + strlen(*backupp) - 1 - strlen(backup_ext);
|
||||||
if (wp < *backupp) { // empty file name ???
|
wp = MAX(wp, *backupp); // empty file name ???
|
||||||
wp = *backupp;
|
|
||||||
}
|
|
||||||
*wp = 'z';
|
*wp = 'z';
|
||||||
while (*wp > 'a' && os_fileinfo(*backupp, &file_info_new)) {
|
while (*wp > 'a' && os_fileinfo(*backupp, &file_info_new)) {
|
||||||
(*wp)--;
|
(*wp)--;
|
||||||
@@ -993,9 +985,7 @@ nobackup:
|
|||||||
// Change one character, just before the extension.
|
// Change one character, just before the extension.
|
||||||
if (!p_bk && os_path_exists(*backupp)) {
|
if (!p_bk && os_path_exists(*backupp)) {
|
||||||
p = *backupp + strlen(*backupp) - 1 - strlen(backup_ext);
|
p = *backupp + strlen(*backupp) - 1 - strlen(backup_ext);
|
||||||
if (p < *backupp) { // empty file name ???
|
p = MAX(p, *backupp); // empty file name ???
|
||||||
p = *backupp;
|
|
||||||
}
|
|
||||||
*p = 'z';
|
*p = 'z';
|
||||||
while (*p > 'a' && os_path_exists(*backupp)) {
|
while (*p > 'a' && os_path_exists(*backupp)) {
|
||||||
(*p)--;
|
(*p)--;
|
||||||
@@ -1255,9 +1245,7 @@ int buf_write(buf_T *buf, char *fname, char *sfname, linenr_T start, linenr_T en
|
|||||||
status_redraw_all(); // redraw status lines later
|
status_redraw_all(); // redraw status lines later
|
||||||
}
|
}
|
||||||
|
|
||||||
if (end > buf->b_ml.ml_line_count) {
|
end = MIN(end, buf->b_ml.ml_line_count);
|
||||||
end = buf->b_ml.ml_line_count;
|
|
||||||
}
|
|
||||||
if (buf->b_ml.ml_flags & ML_EMPTY) {
|
if (buf->b_ml.ml_flags & ML_EMPTY) {
|
||||||
start = end + 1;
|
start = end + 1;
|
||||||
}
|
}
|
||||||
|
@@ -523,19 +523,13 @@ void changed_lines_redraw_buf(buf_T *buf, linenr_T lnum, linenr_T lnume, linenr_
|
|||||||
{
|
{
|
||||||
if (buf->b_mod_set) {
|
if (buf->b_mod_set) {
|
||||||
// find the maximum area that must be redisplayed
|
// find the maximum area that must be redisplayed
|
||||||
if (lnum < buf->b_mod_top) {
|
buf->b_mod_top = MIN(buf->b_mod_top, lnum);
|
||||||
buf->b_mod_top = lnum;
|
|
||||||
}
|
|
||||||
if (lnum < buf->b_mod_bot) {
|
if (lnum < buf->b_mod_bot) {
|
||||||
// adjust old bot position for xtra lines
|
// adjust old bot position for xtra lines
|
||||||
buf->b_mod_bot += xtra;
|
buf->b_mod_bot += xtra;
|
||||||
if (buf->b_mod_bot < lnum) {
|
buf->b_mod_bot = MAX(buf->b_mod_bot, lnum);
|
||||||
buf->b_mod_bot = lnum;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (lnume + xtra > buf->b_mod_bot) {
|
|
||||||
buf->b_mod_bot = lnume + xtra;
|
|
||||||
}
|
}
|
||||||
|
buf->b_mod_bot = MAX(buf->b_mod_bot, lnume + xtra);
|
||||||
buf->b_mod_xlines += xtra;
|
buf->b_mod_xlines += xtra;
|
||||||
} else {
|
} else {
|
||||||
// set the area that must be redisplayed
|
// set the area that must be redisplayed
|
||||||
@@ -2262,9 +2256,7 @@ int get_last_leader_offset(char *line, char **flags)
|
|||||||
for (int off = (len2 > i ? i : len2); off > 0 && off + len1 > len2;) {
|
for (int off = (len2 > i ? i : len2); off > 0 && off + len1 > len2;) {
|
||||||
off--;
|
off--;
|
||||||
if (!strncmp(string + off, com_leader, (size_t)(len2 - off))) {
|
if (!strncmp(string + off, com_leader, (size_t)(len2 - off))) {
|
||||||
if (i - off < lower_check_bound) {
|
lower_check_bound = MIN(lower_check_bound, i - off);
|
||||||
lower_check_bound = i - off;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -670,10 +670,7 @@ static char *get_next_or_prev_match(int mode, expand_T *xp)
|
|||||||
ht -= 2;
|
ht -= 2;
|
||||||
}
|
}
|
||||||
findex -= ht;
|
findex -= ht;
|
||||||
if (findex < 0) {
|
findex = MAX(findex, 0); // few entries left, select the first entry
|
||||||
// few entries left, select the first entry
|
|
||||||
findex = 0;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else if (mode == WILD_PAGEDOWN) {
|
} else if (mode == WILD_PAGEDOWN) {
|
||||||
if (findex == xp->xp_numfiles - 1) {
|
if (findex == xp->xp_numfiles - 1) {
|
||||||
@@ -701,18 +698,10 @@ static char *get_next_or_prev_match(int mode, expand_T *xp)
|
|||||||
|
|
||||||
// When wrapping around, return the original string, set findex to -1.
|
// When wrapping around, return the original string, set findex to -1.
|
||||||
if (findex < 0) {
|
if (findex < 0) {
|
||||||
if (xp->xp_orig == NULL) {
|
findex = xp->xp_orig == NULL ? xp->xp_numfiles - 1 : -1;
|
||||||
findex = xp->xp_numfiles - 1;
|
|
||||||
} else {
|
|
||||||
findex = -1;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (findex >= xp->xp_numfiles) {
|
if (findex >= xp->xp_numfiles) {
|
||||||
if (xp->xp_orig == NULL) {
|
findex = xp->xp_orig == NULL ? 0 : -1;
|
||||||
findex = 0;
|
|
||||||
} else {
|
|
||||||
findex = -1;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (compl_match_array) {
|
if (compl_match_array) {
|
||||||
compl_selected = findex;
|
compl_selected = findex;
|
||||||
@@ -1112,9 +1101,7 @@ int showmatches(expand_T *xp, bool wildmenu)
|
|||||||
} else {
|
} else {
|
||||||
j = vim_strsize(SHOW_MATCH(i));
|
j = vim_strsize(SHOW_MATCH(i));
|
||||||
}
|
}
|
||||||
if (j > maxlen) {
|
maxlen = MAX(maxlen, j);
|
||||||
maxlen = j;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (xp->xp_context == EXPAND_TAGS_LISTFILES) {
|
if (xp->xp_context == EXPAND_TAGS_LISTFILES) {
|
||||||
|
@@ -216,12 +216,7 @@ static int coladvance2(win_T *wp, pos_T *pos, bool addspaces, bool finetune, col
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (idx < 0) {
|
pos->col = MAX(idx, 0);
|
||||||
pos->col = 0;
|
|
||||||
} else {
|
|
||||||
pos->col = idx;
|
|
||||||
}
|
|
||||||
|
|
||||||
pos->coladd = 0;
|
pos->coladd = 0;
|
||||||
|
|
||||||
if (finetune) {
|
if (finetune) {
|
||||||
@@ -310,15 +305,9 @@ linenr_T get_cursor_rel_lnum(win_T *wp, linenr_T lnum)
|
|||||||
/// This allows for the col to be on the NUL byte.
|
/// This allows for the col to be on the NUL byte.
|
||||||
void check_pos(buf_T *buf, pos_T *pos)
|
void check_pos(buf_T *buf, pos_T *pos)
|
||||||
{
|
{
|
||||||
if (pos->lnum > buf->b_ml.ml_line_count) {
|
pos->lnum = MIN(pos->lnum, buf->b_ml.ml_line_count);
|
||||||
pos->lnum = buf->b_ml.ml_line_count;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (pos->col > 0) {
|
if (pos->col > 0) {
|
||||||
colnr_T len = ml_get_buf_len(buf, pos->lnum);
|
pos->col = MIN(pos->col, ml_get_buf_len(buf, pos->lnum));
|
||||||
if (pos->col > len) {
|
|
||||||
pos->col = len;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -385,9 +374,7 @@ void check_cursor_col(win_T *win)
|
|||||||
int cs, ce;
|
int cs, ce;
|
||||||
|
|
||||||
getvcol(win, &win->w_cursor, &cs, NULL, &ce);
|
getvcol(win, &win->w_cursor, &cs, NULL, &ce);
|
||||||
if (win->w_cursor.coladd > ce - cs) {
|
win->w_cursor.coladd = MIN(win->w_cursor.coladd, ce - cs);
|
||||||
win->w_cursor.coladd = ce - cs;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// avoid weird number when there is a miscalculation or overflow
|
// avoid weird number when there is a miscalculation or overflow
|
||||||
|
@@ -694,7 +694,7 @@ void diff_redraw(bool dofold)
|
|||||||
|
|
||||||
if (((wp != curwin) && (wp->w_topfill > 0)) || (n > 0)) {
|
if (((wp != curwin) && (wp->w_topfill > 0)) || (n > 0)) {
|
||||||
if (wp->w_topfill > n) {
|
if (wp->w_topfill > n) {
|
||||||
wp->w_topfill = (n < 0 ? 0 : n);
|
wp->w_topfill = MAX(n, 0);
|
||||||
} else if ((n > 0) && (n > wp->w_topfill)) {
|
} else if ((n > 0) && (n > wp->w_topfill)) {
|
||||||
wp->w_topfill = n;
|
wp->w_topfill = n;
|
||||||
if (wp == curwin) {
|
if (wp == curwin) {
|
||||||
@@ -2679,9 +2679,7 @@ bool diff_find_change(win_T *wp, linenr_T lnum, int *startp, int *endp)
|
|||||||
si_org -= utf_head_off(line_org, line_org + si_org);
|
si_org -= utf_head_off(line_org, line_org + si_org);
|
||||||
si_new -= utf_head_off(line_new, line_new + si_new);
|
si_new -= utf_head_off(line_new, line_new + si_new);
|
||||||
|
|
||||||
if (*startp > si_org) {
|
*startp = MIN(*startp, si_org);
|
||||||
*startp = si_org;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Search for end of difference, if any.
|
// Search for end of difference, if any.
|
||||||
if ((line_org[si_org] != NUL) || (line_new[si_new] != NUL)) {
|
if ((line_org[si_org] != NUL) || (line_new[si_new] != NUL)) {
|
||||||
@@ -2721,9 +2719,7 @@ bool diff_find_change(win_T *wp, linenr_T lnum, int *startp, int *endp)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (*endp < ei_org) {
|
*endp = MAX(*endp, ei_org);
|
||||||
*endp = ei_org;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -3051,19 +3047,11 @@ static void diffgetput(const int addr_count, const int idx_cur, const int idx_fr
|
|||||||
// range ends above end of current/from diff block
|
// range ends above end of current/from diff block
|
||||||
if (idx_cur == idx_from) {
|
if (idx_cur == idx_from) {
|
||||||
// :diffput
|
// :diffput
|
||||||
int i = dp->df_count[idx_cur] - start_skip - end_skip;
|
count = MIN(count, dp->df_count[idx_cur] - start_skip - end_skip);
|
||||||
|
|
||||||
if (count > i) {
|
|
||||||
count = i;
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
// :diffget
|
// :diffget
|
||||||
count -= end_skip;
|
count -= end_skip;
|
||||||
end_skip = dp->df_count[idx_from] - start_skip - count;
|
end_skip = MAX(dp->df_count[idx_from] - start_skip - count, 0);
|
||||||
|
|
||||||
if (end_skip < 0) {
|
|
||||||
end_skip = 0;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
end_skip = 0;
|
end_skip = 0;
|
||||||
@@ -3249,9 +3237,7 @@ int diff_move_to(int dir, int count)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// don't end up past the end of the file
|
// don't end up past the end of the file
|
||||||
if (lnum > curbuf->b_ml.ml_line_count) {
|
lnum = MIN(lnum, curbuf->b_ml.ml_line_count);
|
||||||
lnum = curbuf->b_ml.ml_line_count;
|
|
||||||
}
|
|
||||||
|
|
||||||
// When the cursor didn't move at all we fail.
|
// When the cursor didn't move at all we fail.
|
||||||
if (lnum == curwin->w_cursor.lnum) {
|
if (lnum == curwin->w_cursor.lnum) {
|
||||||
@@ -3297,10 +3283,7 @@ static linenr_T diff_get_corresponding_line_int(buf_T *buf1, linenr_T lnum1)
|
|||||||
if ((dp->df_lnum[idx1] + dp->df_count[idx1]) > lnum1) {
|
if ((dp->df_lnum[idx1] + dp->df_count[idx1]) > lnum1) {
|
||||||
// Inside the diffblock
|
// Inside the diffblock
|
||||||
baseline = lnum1 - dp->df_lnum[idx1];
|
baseline = lnum1 - dp->df_lnum[idx1];
|
||||||
|
baseline = MIN(baseline, dp->df_count[idx2]);
|
||||||
if (baseline > dp->df_count[idx2]) {
|
|
||||||
baseline = dp->df_count[idx2];
|
|
||||||
}
|
|
||||||
|
|
||||||
return dp->df_lnum[idx2] + baseline;
|
return dp->df_lnum[idx2] + baseline;
|
||||||
}
|
}
|
||||||
@@ -3335,10 +3318,7 @@ linenr_T diff_get_corresponding_line(buf_T *buf1, linenr_T lnum1)
|
|||||||
linenr_T lnum = diff_get_corresponding_line_int(buf1, lnum1);
|
linenr_T lnum = diff_get_corresponding_line_int(buf1, lnum1);
|
||||||
|
|
||||||
// don't end up past the end of the file
|
// don't end up past the end of the file
|
||||||
if (lnum > curbuf->b_ml.ml_line_count) {
|
return MIN(lnum, curbuf->b_ml.ml_line_count);
|
||||||
return curbuf->b_ml.ml_line_count;
|
|
||||||
}
|
|
||||||
return lnum;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// For line "lnum" in the current window find the equivalent lnum in window
|
/// For line "lnum" in the current window find the equivalent lnum in window
|
||||||
@@ -3381,10 +3361,7 @@ linenr_T diff_lnum_win(linenr_T lnum, win_T *wp)
|
|||||||
}
|
}
|
||||||
|
|
||||||
linenr_T n = lnum + (dp->df_lnum[i] - dp->df_lnum[idx]);
|
linenr_T n = lnum + (dp->df_lnum[i] - dp->df_lnum[idx]);
|
||||||
if (n > dp->df_lnum[i] + dp->df_count[i]) {
|
return MIN(n, dp->df_lnum[i] + dp->df_count[i]);
|
||||||
n = dp->df_lnum[i] + dp->df_count[i];
|
|
||||||
}
|
|
||||||
return n;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Handle an ED style diff line.
|
/// Handle an ED style diff line.
|
||||||
|
@@ -886,9 +886,7 @@ static int get_rightmost_vcol(win_T *wp, const int *color_cols)
|
|||||||
if (color_cols) {
|
if (color_cols) {
|
||||||
// determine rightmost colorcolumn to possibly draw
|
// determine rightmost colorcolumn to possibly draw
|
||||||
for (int i = 0; color_cols[i] >= 0; i++) {
|
for (int i = 0; color_cols[i] >= 0; i++) {
|
||||||
if (ret < color_cols[i]) {
|
ret = MAX(ret, color_cols[i]);
|
||||||
ret = color_cols[i];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2560,9 +2558,7 @@ int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow, int col_rows, s
|
|||||||
// Highlight 'cursorcolumn' & 'colorcolumn' past end of the line.
|
// Highlight 'cursorcolumn' & 'colorcolumn' past end of the line.
|
||||||
|
|
||||||
// check if line ends before left margin
|
// check if line ends before left margin
|
||||||
if (wlv.vcol < start_col + wlv.col - win_col_off(wp)) {
|
wlv.vcol = MAX(wlv.vcol, start_col + wlv.col - win_col_off(wp));
|
||||||
wlv.vcol = start_col + wlv.col - win_col_off(wp);
|
|
||||||
}
|
|
||||||
// Get rid of the boguscols now, we want to draw until the right
|
// Get rid of the boguscols now, we want to draw until the right
|
||||||
// edge for 'cursorcolumn'.
|
// edge for 'cursorcolumn'.
|
||||||
wlv.col -= wlv.boguscols;
|
wlv.col -= wlv.boguscols;
|
||||||
|
@@ -395,18 +395,9 @@ void screen_resize(int width, int height)
|
|||||||
void check_screensize(void)
|
void check_screensize(void)
|
||||||
{
|
{
|
||||||
// Limit Rows and Columns to avoid an overflow in Rows * Columns.
|
// Limit Rows and Columns to avoid an overflow in Rows * Columns.
|
||||||
if (Rows < min_rows()) {
|
// need room for one window and command line
|
||||||
// need room for one window and command line
|
Rows = MIN(MAX(Rows, min_rows()), 1000);
|
||||||
Rows = min_rows();
|
Columns = MIN(MAX(Columns, MIN_COLUMNS), 10000);
|
||||||
} else if (Rows > 1000) {
|
|
||||||
Rows = 1000;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Columns < MIN_COLUMNS) {
|
|
||||||
Columns = MIN_COLUMNS;
|
|
||||||
} else if (Columns > 10000) {
|
|
||||||
Columns = 10000;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Return true if redrawing should currently be done.
|
/// Return true if redrawing should currently be done.
|
||||||
@@ -996,12 +987,9 @@ int showmode(void)
|
|||||||
}
|
}
|
||||||
if (edit_submode_extra != NULL) {
|
if (edit_submode_extra != NULL) {
|
||||||
msg_puts_attr(" ", attr); // Add a space in between.
|
msg_puts_attr(" ", attr); // Add a space in between.
|
||||||
int sub_attr;
|
int sub_attr = edit_submode_highl < HLF_COUNT
|
||||||
if (edit_submode_highl < HLF_COUNT) {
|
? win_hl_attr(curwin, (int)edit_submode_highl)
|
||||||
sub_attr = win_hl_attr(curwin, (int)edit_submode_highl);
|
: attr;
|
||||||
} else {
|
|
||||||
sub_attr = attr;
|
|
||||||
}
|
|
||||||
msg_puts_attr(edit_submode_extra, sub_attr);
|
msg_puts_attr(edit_submode_extra, sub_attr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1564,9 +1552,7 @@ static void win_update(win_T *wp)
|
|||||||
// in a pattern match.
|
// in a pattern match.
|
||||||
if (syntax_present(wp)) {
|
if (syntax_present(wp)) {
|
||||||
mod_top -= buf->b_s.b_syn_sync_linebreaks;
|
mod_top -= buf->b_s.b_syn_sync_linebreaks;
|
||||||
if (mod_top < 1) {
|
mod_top = MAX(mod_top, 1);
|
||||||
mod_top = 1;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (mod_bot == 0 || mod_bot < buf->b_mod_bot) {
|
if (mod_bot == 0 || mod_bot < buf->b_mod_bot) {
|
||||||
@@ -1635,17 +1621,13 @@ static void win_update(win_T *wp)
|
|||||||
}
|
}
|
||||||
|
|
||||||
hasFolding(wp, mod_top, &mod_top, NULL);
|
hasFolding(wp, mod_top, &mod_top, NULL);
|
||||||
if (mod_top > lnumt) {
|
mod_top = MIN(mod_top, lnumt);
|
||||||
mod_top = lnumt;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Now do the same for the bottom line (one above mod_bot).
|
// Now do the same for the bottom line (one above mod_bot).
|
||||||
mod_bot--;
|
mod_bot--;
|
||||||
hasFolding(wp, mod_bot, NULL, &mod_bot);
|
hasFolding(wp, mod_bot, NULL, &mod_bot);
|
||||||
mod_bot++;
|
mod_bot++;
|
||||||
if (mod_bot < lnumb) {
|
mod_bot = MAX(mod_bot, lnumb);
|
||||||
mod_bot = lnumb;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// When a change starts above w_topline and the end is below
|
// When a change starts above w_topline and the end is below
|
||||||
@@ -1865,18 +1847,8 @@ static void win_update(win_T *wp)
|
|||||||
to = curwin->w_cursor.lnum;
|
to = curwin->w_cursor.lnum;
|
||||||
}
|
}
|
||||||
// redraw more when the cursor moved as well
|
// redraw more when the cursor moved as well
|
||||||
if (wp->w_old_cursor_lnum < from) {
|
from = MIN(MIN(from, wp->w_old_cursor_lnum), wp->w_old_visual_lnum);
|
||||||
from = wp->w_old_cursor_lnum;
|
to = MAX(MAX(to, wp->w_old_cursor_lnum), wp->w_old_visual_lnum);
|
||||||
}
|
|
||||||
if (wp->w_old_cursor_lnum > to) {
|
|
||||||
to = wp->w_old_cursor_lnum;
|
|
||||||
}
|
|
||||||
if (wp->w_old_visual_lnum < from) {
|
|
||||||
from = wp->w_old_visual_lnum;
|
|
||||||
}
|
|
||||||
if (wp->w_old_visual_lnum > to) {
|
|
||||||
to = wp->w_old_visual_lnum;
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
// Find the line numbers that need to be updated: The lines
|
// Find the line numbers that need to be updated: The lines
|
||||||
// between the old cursor position and the current cursor
|
// between the old cursor position and the current cursor
|
||||||
@@ -1898,15 +1870,8 @@ static void win_update(win_T *wp)
|
|||||||
&& wp->w_old_visual_lnum != 0) {
|
&& wp->w_old_visual_lnum != 0) {
|
||||||
from = wp->w_old_visual_lnum;
|
from = wp->w_old_visual_lnum;
|
||||||
}
|
}
|
||||||
if (wp->w_old_visual_lnum > to) {
|
to = MAX(MAX(to, wp->w_old_visual_lnum), VIsual.lnum);
|
||||||
to = wp->w_old_visual_lnum;
|
from = MIN(from, VIsual.lnum);
|
||||||
}
|
|
||||||
if (VIsual.lnum < from) {
|
|
||||||
from = VIsual.lnum;
|
|
||||||
}
|
|
||||||
if (VIsual.lnum > to) {
|
|
||||||
to = VIsual.lnum;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1941,9 +1906,7 @@ static void win_update(win_T *wp)
|
|||||||
|
|
||||||
pos.col = (colnr_T)strlen(ml_get_buf(wp->w_buffer, pos.lnum));
|
pos.col = (colnr_T)strlen(ml_get_buf(wp->w_buffer, pos.lnum));
|
||||||
getvvcol(wp, &pos, NULL, NULL, &t);
|
getvvcol(wp, &pos, NULL, NULL, &t);
|
||||||
if (toc < t) {
|
toc = MAX(toc, t);
|
||||||
toc = t;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
toc++;
|
toc++;
|
||||||
} else {
|
} else {
|
||||||
@@ -1953,12 +1916,8 @@ static void win_update(win_T *wp)
|
|||||||
|
|
||||||
if (fromc != wp->w_old_cursor_fcol
|
if (fromc != wp->w_old_cursor_fcol
|
||||||
|| toc != wp->w_old_cursor_lcol) {
|
|| toc != wp->w_old_cursor_lcol) {
|
||||||
if (from > VIsual.lnum) {
|
from = MIN(from, VIsual.lnum);
|
||||||
from = VIsual.lnum;
|
to = MAX(to, VIsual.lnum);
|
||||||
}
|
|
||||||
if (to < VIsual.lnum) {
|
|
||||||
to = VIsual.lnum;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
wp->w_old_cursor_fcol = fromc;
|
wp->w_old_cursor_fcol = fromc;
|
||||||
wp->w_old_cursor_lcol = toc;
|
wp->w_old_cursor_lcol = toc;
|
||||||
@@ -1975,19 +1934,13 @@ static void win_update(win_T *wp)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// There is no need to update lines above the top of the window.
|
// There is no need to update lines above the top of the window.
|
||||||
if (from < wp->w_topline) {
|
from = MAX(from, wp->w_topline);
|
||||||
from = wp->w_topline;
|
|
||||||
}
|
|
||||||
|
|
||||||
// If we know the value of w_botline, use it to restrict the update to
|
// If we know the value of w_botline, use it to restrict the update to
|
||||||
// the lines that are visible in the window.
|
// the lines that are visible in the window.
|
||||||
if (wp->w_valid & VALID_BOTLINE) {
|
if (wp->w_valid & VALID_BOTLINE) {
|
||||||
if (from >= wp->w_botline) {
|
from = MIN(from, wp->w_botline - 1);
|
||||||
from = wp->w_botline - 1;
|
to = MIN(to, wp->w_botline - 1);
|
||||||
}
|
|
||||||
if (to >= wp->w_botline) {
|
|
||||||
to = wp->w_botline - 1;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Find the minimal part to be updated.
|
// Find the minimal part to be updated.
|
||||||
@@ -2175,11 +2128,9 @@ static void win_update(win_T *wp)
|
|||||||
if (hasFolding(wp, l, NULL, &l)) {
|
if (hasFolding(wp, l, NULL, &l)) {
|
||||||
new_rows++;
|
new_rows++;
|
||||||
} else if (l == wp->w_topline) {
|
} else if (l == wp->w_topline) {
|
||||||
int n = plines_win_nofill(wp, l, false) + wp->w_topfill;
|
int n = plines_win_nofill(wp, l, false) + wp->w_topfill
|
||||||
n -= adjust_plines_for_skipcol(wp);
|
- adjust_plines_for_skipcol(wp);
|
||||||
if (n > wp->w_height_inner) {
|
n = MIN(n, wp->w_height_inner);
|
||||||
n = wp->w_height_inner;
|
|
||||||
}
|
|
||||||
new_rows += n;
|
new_rows += n;
|
||||||
} else {
|
} else {
|
||||||
new_rows += plines_win(wp, l, true);
|
new_rows += plines_win(wp, l, true);
|
||||||
@@ -2244,16 +2195,12 @@ static void win_update(win_T *wp)
|
|||||||
x += wp->w_lines[j++].wl_size;
|
x += wp->w_lines[j++].wl_size;
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
if (bot_start > x) {
|
bot_start = MIN(bot_start, x);
|
||||||
bot_start = x;
|
|
||||||
}
|
|
||||||
} else { // j > i
|
} else { // j > i
|
||||||
// move entries in w_lines[] downwards
|
// move entries in w_lines[] downwards
|
||||||
j -= i;
|
j -= i;
|
||||||
wp->w_lines_valid += (linenr_T)j;
|
wp->w_lines_valid += (linenr_T)j;
|
||||||
if (wp->w_lines_valid > wp->w_grid.rows) {
|
wp->w_lines_valid = MIN(wp->w_lines_valid, wp->w_grid.rows);
|
||||||
wp->w_lines_valid = wp->w_grid.rows;
|
|
||||||
}
|
|
||||||
for (i = wp->w_lines_valid; i - j >= idx; i--) {
|
for (i = wp->w_lines_valid; i - j >= idx; i--) {
|
||||||
wp->w_lines[i] = wp->w_lines[i - j];
|
wp->w_lines[i] = wp->w_lines[i - j];
|
||||||
}
|
}
|
||||||
@@ -2385,9 +2332,7 @@ redr_statuscol:
|
|||||||
|
|
||||||
wp->w_last_cursor_lnum_rnu = wp->w_p_rnu ? wp->w_cursor.lnum : 0;
|
wp->w_last_cursor_lnum_rnu = wp->w_p_rnu ? wp->w_cursor.lnum : 0;
|
||||||
|
|
||||||
if (idx > wp->w_lines_valid) {
|
wp->w_lines_valid = MAX(wp->w_lines_valid, idx);
|
||||||
wp->w_lines_valid = idx;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Let the syntax stuff know we stop parsing here.
|
// Let the syntax stuff know we stop parsing here.
|
||||||
if (syntax_last_parsed != 0 && syntax_present(wp)) {
|
if (syntax_last_parsed != 0 && syntax_present(wp)) {
|
||||||
@@ -2602,10 +2547,7 @@ int compute_foldcolumn(win_T *wp, int col)
|
|||||||
int wmw = wp == curwin && p_wmw == 0 ? 1 : (int)p_wmw;
|
int wmw = wp == curwin && p_wmw == 0 ? 1 : (int)p_wmw;
|
||||||
int wwidth = wp->w_grid.cols;
|
int wwidth = wp->w_grid.cols;
|
||||||
|
|
||||||
if (fdc > wwidth - (col + wmw)) {
|
return MIN(fdc, wwidth - (col + wmw));
|
||||||
fdc = wwidth - (col + wmw);
|
|
||||||
}
|
|
||||||
return fdc;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Return the width of the 'number' and 'relativenumber' column.
|
/// Return the width of the 'number' and 'relativenumber' column.
|
||||||
@@ -2642,9 +2584,7 @@ int number_width(win_T *wp)
|
|||||||
} while (lnum > 0);
|
} while (lnum > 0);
|
||||||
|
|
||||||
// 'numberwidth' gives the minimal width plus one
|
// 'numberwidth' gives the minimal width plus one
|
||||||
if (n < wp->w_p_nuw - 1) {
|
n = MAX(n, (int)wp->w_p_nuw - 1);
|
||||||
n = (int)wp->w_p_nuw - 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
// If 'signcolumn' is set to 'number' and there is a sign to display, then
|
// If 'signcolumn' is set to 'number' and there is a sign to display, then
|
||||||
// the minimal width for the number column is 2.
|
// the minimal width for the number column is 2.
|
||||||
@@ -2669,9 +2609,7 @@ void redraw_later(win_T *wp, int type)
|
|||||||
if (type >= UPD_NOT_VALID) {
|
if (type >= UPD_NOT_VALID) {
|
||||||
wp->w_lines_valid = 0;
|
wp->w_lines_valid = 0;
|
||||||
}
|
}
|
||||||
if (must_redraw < type) { // must_redraw is the maximum of all windows
|
must_redraw = MAX(must_redraw, type); // must_redraw is the maximum of all windows
|
||||||
must_redraw = type;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2689,8 +2627,8 @@ void redraw_all_later(int type)
|
|||||||
/// or it is currently not allowed.
|
/// or it is currently not allowed.
|
||||||
void set_must_redraw(int type)
|
void set_must_redraw(int type)
|
||||||
{
|
{
|
||||||
if (!redraw_not_allowed && must_redraw < type) {
|
if (!redraw_not_allowed) {
|
||||||
must_redraw = type;
|
must_redraw = MAX(must_redraw, type);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -271,11 +271,7 @@ static void insert_enter(InsertState *s)
|
|||||||
if (restart_edit != 0 && stuff_empty()) {
|
if (restart_edit != 0 && stuff_empty()) {
|
||||||
// After a paste we consider text typed to be part of the insert for
|
// After a paste we consider text typed to be part of the insert for
|
||||||
// the pasted text. You can backspace over the pasted text too.
|
// the pasted text. You can backspace over the pasted text too.
|
||||||
if (where_paste_started.lnum) {
|
arrow_used = where_paste_started.lnum == 0;
|
||||||
arrow_used = false;
|
|
||||||
} else {
|
|
||||||
arrow_used = true;
|
|
||||||
}
|
|
||||||
restart_edit = 0;
|
restart_edit = 0;
|
||||||
|
|
||||||
// If the cursor was after the end-of-line before the CTRL-O and it is
|
// If the cursor was after the end-of-line before the CTRL-O and it is
|
||||||
@@ -1541,9 +1537,7 @@ static void init_prompt(int cmdchar_todo)
|
|||||||
if (cmdchar_todo == 'A') {
|
if (cmdchar_todo == 'A') {
|
||||||
coladvance(curwin, MAXCOL);
|
coladvance(curwin, MAXCOL);
|
||||||
}
|
}
|
||||||
if (curwin->w_cursor.col < (colnr_T)strlen(prompt)) {
|
curwin->w_cursor.col = MAX(curwin->w_cursor.col, (colnr_T)strlen(prompt));
|
||||||
curwin->w_cursor.col = (colnr_T)strlen(prompt);
|
|
||||||
}
|
|
||||||
// Make sure the cursor is in a valid position.
|
// Make sure the cursor is in a valid position.
|
||||||
check_cursor(curwin);
|
check_cursor(curwin);
|
||||||
}
|
}
|
||||||
@@ -1578,7 +1572,7 @@ void edit_unputchar(void)
|
|||||||
/// text. Only works when cursor is in the line that changes.
|
/// text. Only works when cursor is in the line that changes.
|
||||||
void display_dollar(colnr_T col_arg)
|
void display_dollar(colnr_T col_arg)
|
||||||
{
|
{
|
||||||
colnr_T col = col_arg < 0 ? 0 : col_arg;
|
colnr_T col = MAX(col_arg, 0);
|
||||||
|
|
||||||
if (!redrawing()) {
|
if (!redrawing()) {
|
||||||
return;
|
return;
|
||||||
@@ -1736,12 +1730,7 @@ void change_indent(int type, int amount, int round, int replaced, bool call_chan
|
|||||||
}
|
}
|
||||||
|
|
||||||
curwin->w_p_list = save_p_list;
|
curwin->w_p_list = save_p_list;
|
||||||
|
curwin->w_cursor.col = MAX(0, (colnr_T)new_cursor_col);
|
||||||
if (new_cursor_col <= 0) {
|
|
||||||
curwin->w_cursor.col = 0;
|
|
||||||
} else {
|
|
||||||
curwin->w_cursor.col = (colnr_T)new_cursor_col;
|
|
||||||
}
|
|
||||||
curwin->w_set_curswant = true;
|
curwin->w_set_curswant = true;
|
||||||
changed_cline_bef_curs(curwin);
|
changed_cline_bef_curs(curwin);
|
||||||
|
|
||||||
@@ -2607,9 +2596,7 @@ void cursor_up_inner(win_T *wp, linenr_T n)
|
|||||||
hasFolding(wp, lnum, &lnum, NULL);
|
hasFolding(wp, lnum, &lnum, NULL);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (lnum < 1) {
|
lnum = MAX(lnum, 1);
|
||||||
lnum = 1;
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
lnum -= n;
|
lnum -= n;
|
||||||
}
|
}
|
||||||
@@ -2659,9 +2646,7 @@ void cursor_down_inner(win_T *wp, int n)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (lnum > line_count) {
|
lnum = MIN(lnum, line_count);
|
||||||
lnum = line_count;
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
lnum += (linenr_T)n;
|
lnum += (linenr_T)n;
|
||||||
}
|
}
|
||||||
@@ -4726,9 +4711,7 @@ static void ins_try_si(int c)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Adjust ai_col, the char at this position can be deleted.
|
// Adjust ai_col, the char at this position can be deleted.
|
||||||
if (ai_col > curwin->w_cursor.col) {
|
ai_col = MIN(ai_col, curwin->w_cursor.col);
|
||||||
ai_col = curwin->w_cursor.col;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get the value that w_virtcol would have when 'list' is off.
|
// Get the value that w_virtcol would have when 'list' is off.
|
||||||
|
@@ -311,9 +311,7 @@ void ex_align(exarg_T *eap)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (new_indent < 0) {
|
new_indent = MAX(new_indent, 0);
|
||||||
new_indent = 0;
|
|
||||||
}
|
|
||||||
set_indent(new_indent, 0); // set indent
|
set_indent(new_indent, 0); // set indent
|
||||||
}
|
}
|
||||||
changed_lines(curbuf, eap->line1, 0, eap->line2 + 1, 0, true);
|
changed_lines(curbuf, eap->line1, 0, eap->line2 + 1, 0, true);
|
||||||
@@ -543,9 +541,7 @@ void ex_sort(exarg_T *eap)
|
|||||||
for (linenr_T lnum = eap->line1; lnum <= eap->line2; lnum++) {
|
for (linenr_T lnum = eap->line1; lnum <= eap->line2; lnum++) {
|
||||||
char *s = ml_get(lnum);
|
char *s = ml_get(lnum);
|
||||||
int len = ml_get_len(lnum);
|
int len = ml_get_len(lnum);
|
||||||
if (maxlen < len) {
|
maxlen = MAX(maxlen, len);
|
||||||
maxlen = len;
|
|
||||||
}
|
|
||||||
|
|
||||||
colnr_T start_col = 0;
|
colnr_T start_col = 0;
|
||||||
colnr_T end_col = len;
|
colnr_T end_col = len;
|
||||||
@@ -705,11 +701,6 @@ sortend:
|
|||||||
/// @return FAIL for failure, OK otherwise
|
/// @return FAIL for failure, OK otherwise
|
||||||
int do_move(linenr_T line1, linenr_T line2, linenr_T dest)
|
int do_move(linenr_T line1, linenr_T line2, linenr_T dest)
|
||||||
{
|
{
|
||||||
linenr_T l;
|
|
||||||
linenr_T extra; // Num lines added before line1
|
|
||||||
linenr_T num_lines; // Num lines moved
|
|
||||||
linenr_T last_line; // Last line in file after adding new text
|
|
||||||
|
|
||||||
if (dest >= line1 && dest < line2) {
|
if (dest >= line1 && dest < line2) {
|
||||||
emsg(_("E134: Cannot move a range of lines into itself"));
|
emsg(_("E134: Cannot move a range of lines into itself"));
|
||||||
return FAIL;
|
return FAIL;
|
||||||
@@ -720,11 +711,9 @@ int do_move(linenr_T line1, linenr_T line2, linenr_T dest)
|
|||||||
if (dest == line1 - 1 || dest == line2) {
|
if (dest == line1 - 1 || dest == line2) {
|
||||||
// Move the cursor as if lines were moved (see below) to be backwards
|
// Move the cursor as if lines were moved (see below) to be backwards
|
||||||
// compatible.
|
// compatible.
|
||||||
if (dest >= line1) {
|
curwin->w_cursor.lnum = dest >= line1
|
||||||
curwin->w_cursor.lnum = dest;
|
? dest
|
||||||
} else {
|
: dest + (line2 - line1) + 1;
|
||||||
curwin->w_cursor.lnum = dest + (line2 - line1) + 1;
|
|
||||||
}
|
|
||||||
return OK;
|
return OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -733,13 +722,16 @@ int do_move(linenr_T line1, linenr_T line2, linenr_T dest)
|
|||||||
bcount_t extent_byte = end_byte - start_byte;
|
bcount_t extent_byte = end_byte - start_byte;
|
||||||
bcount_t dest_byte = ml_find_line_or_offset(curbuf, dest + 1, NULL, true);
|
bcount_t dest_byte = ml_find_line_or_offset(curbuf, dest + 1, NULL, true);
|
||||||
|
|
||||||
num_lines = line2 - line1 + 1;
|
linenr_T num_lines = line2 - line1 + 1; // Num lines moved
|
||||||
|
|
||||||
// First we copy the old text to its new location -- webb
|
// First we copy the old text to its new location -- webb
|
||||||
// Also copy the flag that ":global" command uses.
|
// Also copy the flag that ":global" command uses.
|
||||||
if (u_save(dest, dest + 1) == FAIL) {
|
if (u_save(dest, dest + 1) == FAIL) {
|
||||||
return FAIL;
|
return FAIL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
linenr_T l;
|
||||||
|
linenr_T extra; // Num lines added before line1
|
||||||
for (extra = 0, l = line1; l <= line2; l++) {
|
for (extra = 0, l = line1; l <= line2; l++) {
|
||||||
char *str = xstrnsave(ml_get(l + extra), (size_t)ml_get_len(l + extra));
|
char *str = xstrnsave(ml_get(l + extra), (size_t)ml_get_len(l + extra));
|
||||||
ml_append(dest + l - line1, str, 0, false);
|
ml_append(dest + l - line1, str, 0, false);
|
||||||
@@ -762,7 +754,7 @@ int do_move(linenr_T line1, linenr_T line2, linenr_T dest)
|
|||||||
//
|
//
|
||||||
// And Finally we adjust the marks we put at the end of the file back to
|
// And Finally we adjust the marks we put at the end of the file back to
|
||||||
// their final destination at the new text position -- webb
|
// their final destination at the new text position -- webb
|
||||||
last_line = curbuf->b_ml.ml_line_count;
|
linenr_T last_line = curbuf->b_ml.ml_line_count; // Last line in file after adding new text
|
||||||
mark_adjust_nofold(line1, line2, last_line - line2, 0, kExtmarkNOOP);
|
mark_adjust_nofold(line1, line2, last_line - line2, 0, kExtmarkNOOP);
|
||||||
|
|
||||||
disable_fold_update++;
|
disable_fold_update++;
|
||||||
@@ -838,9 +830,7 @@ int do_move(linenr_T line1, linenr_T line2, linenr_T dest)
|
|||||||
if (line1 < dest) {
|
if (line1 < dest) {
|
||||||
dest += num_lines + 1;
|
dest += num_lines + 1;
|
||||||
last_line = curbuf->b_ml.ml_line_count;
|
last_line = curbuf->b_ml.ml_line_count;
|
||||||
if (dest > last_line + 1) {
|
dest = MIN(dest, last_line + 1);
|
||||||
dest = last_line + 1;
|
|
||||||
}
|
|
||||||
changed_lines(curbuf, line1, 0, dest, 0, false);
|
changed_lines(curbuf, line1, 0, dest, 0, false);
|
||||||
} else {
|
} else {
|
||||||
changed_lines(curbuf, dest + 1, 0, line1 + num_lines, 0, false);
|
changed_lines(curbuf, dest + 1, 0, line1 + num_lines, 0, false);
|
||||||
@@ -2931,9 +2921,7 @@ void ex_z(exarg_T *eap)
|
|||||||
} else {
|
} else {
|
||||||
bigness = curwin->w_height_inner - 3;
|
bigness = curwin->w_height_inner - 3;
|
||||||
}
|
}
|
||||||
if (bigness < 1) {
|
bigness = MAX(bigness, 1);
|
||||||
bigness = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
char *x = eap->arg;
|
char *x = eap->arg;
|
||||||
char *kind = x;
|
char *kind = x;
|
||||||
@@ -3006,19 +2994,9 @@ void ex_z(exarg_T *eap)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (start < 1) {
|
start = MAX(start, 1);
|
||||||
start = 1;
|
end = MIN(end, curbuf->b_ml.ml_line_count);
|
||||||
}
|
curs = MIN(MAX(curs, 1), curbuf->b_ml.ml_line_count);
|
||||||
|
|
||||||
if (end > curbuf->b_ml.ml_line_count) {
|
|
||||||
end = curbuf->b_ml.ml_line_count;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (curs > curbuf->b_ml.ml_line_count) {
|
|
||||||
curs = curbuf->b_ml.ml_line_count;
|
|
||||||
} else if (curs < 1) {
|
|
||||||
curs = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (linenr_T i = start; i <= end; i++) {
|
for (linenr_T i = start; i <= end; i++) {
|
||||||
if (minus && i == lnum) {
|
if (minus && i == lnum) {
|
||||||
@@ -3459,9 +3437,7 @@ static int do_sub(exarg_T *eap, const proftime_T timeout, const int cmdpreview_n
|
|||||||
}
|
}
|
||||||
eap->line1 = eap->line2;
|
eap->line1 = eap->line2;
|
||||||
eap->line2 += (linenr_T)i - 1;
|
eap->line2 += (linenr_T)i - 1;
|
||||||
if (eap->line2 > curbuf->b_ml.ml_line_count) {
|
eap->line2 = MIN(eap->line2, curbuf->b_ml.ml_line_count);
|
||||||
eap->line2 = curbuf->b_ml.ml_line_count;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// check for trailing command or garbage
|
// check for trailing command or garbage
|
||||||
@@ -3725,10 +3701,8 @@ static int do_sub(exarg_T *eap, const proftime_T timeout, const int cmdpreview_n
|
|||||||
print_line_no_prefix(lnum, subflags.do_number, subflags.do_list);
|
print_line_no_prefix(lnum, subflags.do_number, subflags.do_list);
|
||||||
|
|
||||||
getvcol(curwin, &curwin->w_cursor, &sc, NULL, NULL);
|
getvcol(curwin, &curwin->w_cursor, &sc, NULL, NULL);
|
||||||
curwin->w_cursor.col = regmatch.endpos[0].col - 1;
|
curwin->w_cursor.col = MAX(regmatch.endpos[0].col - 1, 0);
|
||||||
if (curwin->w_cursor.col < 0) {
|
|
||||||
curwin->w_cursor.col = 0;
|
|
||||||
}
|
|
||||||
getvcol(curwin, &curwin->w_cursor, NULL, NULL, &ec);
|
getvcol(curwin, &curwin->w_cursor, NULL, NULL, &ec);
|
||||||
curwin->w_cursor.col = regmatch.startpos[0].col;
|
curwin->w_cursor.col = regmatch.startpos[0].col;
|
||||||
if (subflags.do_number || curwin->w_p_nu) {
|
if (subflags.do_number || curwin->w_p_nu) {
|
||||||
|
@@ -1079,7 +1079,6 @@ void *getline_cookie(LineGetter fgetline, void *cookie)
|
|||||||
/// @return the buffer number.
|
/// @return the buffer number.
|
||||||
static int compute_buffer_local_count(cmd_addr_T addr_type, linenr_T lnum, int offset)
|
static int compute_buffer_local_count(cmd_addr_T addr_type, linenr_T lnum, int offset)
|
||||||
{
|
{
|
||||||
buf_T *nextbuf;
|
|
||||||
int count = offset;
|
int count = offset;
|
||||||
|
|
||||||
buf_T *buf = firstbuf;
|
buf_T *buf = firstbuf;
|
||||||
@@ -1088,7 +1087,7 @@ static int compute_buffer_local_count(cmd_addr_T addr_type, linenr_T lnum, int o
|
|||||||
}
|
}
|
||||||
while (count != 0) {
|
while (count != 0) {
|
||||||
count += (count < 0) ? 1 : -1;
|
count += (count < 0) ? 1 : -1;
|
||||||
nextbuf = (offset < 0) ? buf->b_prev : buf->b_next;
|
buf_T *nextbuf = (offset < 0) ? buf->b_prev : buf->b_next;
|
||||||
if (nextbuf == NULL) {
|
if (nextbuf == NULL) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -1107,7 +1106,7 @@ static int compute_buffer_local_count(cmd_addr_T addr_type, linenr_T lnum, int o
|
|||||||
// we might have gone too far, last buffer is not loaded
|
// we might have gone too far, last buffer is not loaded
|
||||||
if (addr_type == ADDR_LOADED_BUFFERS) {
|
if (addr_type == ADDR_LOADED_BUFFERS) {
|
||||||
while (buf->b_ml.ml_mfp == NULL) {
|
while (buf->b_ml.ml_mfp == NULL) {
|
||||||
nextbuf = (offset >= 0) ? buf->b_prev : buf->b_next;
|
buf_T *nextbuf = (offset >= 0) ? buf->b_prev : buf->b_next;
|
||||||
if (nextbuf == NULL) {
|
if (nextbuf == NULL) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -1696,9 +1695,7 @@ static int execute_cmd0(int *retv, exarg_T *eap, const char **errormsg, bool pre
|
|||||||
// ":silent! try" was used, it should only apply to :try itself.
|
// ":silent! try" was used, it should only apply to :try itself.
|
||||||
if (eap->cmdidx == CMD_try && cmdmod.cmod_did_esilent > 0) {
|
if (eap->cmdidx == CMD_try && cmdmod.cmod_did_esilent > 0) {
|
||||||
emsg_silent -= cmdmod.cmod_did_esilent;
|
emsg_silent -= cmdmod.cmod_did_esilent;
|
||||||
if (emsg_silent < 0) {
|
emsg_silent = MAX(emsg_silent, 0);
|
||||||
emsg_silent = 0;
|
|
||||||
}
|
|
||||||
cmdmod.cmod_did_esilent = 0;
|
cmdmod.cmod_did_esilent = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2444,9 +2441,7 @@ static char *ex_range_without_command(exarg_T *eap)
|
|||||||
ex_print(eap);
|
ex_print(eap);
|
||||||
}
|
}
|
||||||
} else if (eap->addr_count != 0) {
|
} else if (eap->addr_count != 0) {
|
||||||
if (eap->line2 > curbuf->b_ml.ml_line_count) {
|
eap->line2 = MIN(eap->line2, curbuf->b_ml.ml_line_count);
|
||||||
eap->line2 = curbuf->b_ml.ml_line_count;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (eap->line2 < 0) {
|
if (eap->line2 < 0) {
|
||||||
errormsg = _(e_invrange);
|
errormsg = _(e_invrange);
|
||||||
@@ -2785,9 +2780,7 @@ void undo_cmdmod(cmdmod_T *cmod)
|
|||||||
msg_silent = cmod->cmod_save_msg_silent - 1;
|
msg_silent = cmod->cmod_save_msg_silent - 1;
|
||||||
}
|
}
|
||||||
emsg_silent -= cmod->cmod_did_esilent;
|
emsg_silent -= cmod->cmod_did_esilent;
|
||||||
if (emsg_silent < 0) {
|
emsg_silent = MAX(emsg_silent, 0);
|
||||||
emsg_silent = 0;
|
|
||||||
}
|
|
||||||
// Restore msg_scroll, it's set by file I/O commands, even when no
|
// Restore msg_scroll, it's set by file I/O commands, even when no
|
||||||
// message is actually displayed.
|
// message is actually displayed.
|
||||||
msg_scroll = cmod->cmod_save_msg_scroll;
|
msg_scroll = cmod->cmod_save_msg_scroll;
|
||||||
@@ -3520,11 +3513,7 @@ static linenr_T get_address(exarg_T *eap, char **ptr, cmd_addr_T addr_type, bool
|
|||||||
// This makes sure we never match in the current
|
// This makes sure we never match in the current
|
||||||
// line, and can match anywhere in the
|
// line, and can match anywhere in the
|
||||||
// next/previous line.
|
// next/previous line.
|
||||||
if (c == '/' && curwin->w_cursor.lnum > 0) {
|
curwin->w_cursor.col = (c == '/' && curwin->w_cursor.lnum > 0) ? MAXCOL : 0;
|
||||||
curwin->w_cursor.col = MAXCOL;
|
|
||||||
} else {
|
|
||||||
curwin->w_cursor.col = 0;
|
|
||||||
}
|
|
||||||
searchcmdlen = 0;
|
searchcmdlen = 0;
|
||||||
flags = silent ? 0 : SEARCH_HIS | SEARCH_MSG;
|
flags = silent ? 0 : SEARCH_HIS | SEARCH_MSG;
|
||||||
if (!do_search(NULL, c, c, cmd, strlen(cmd), 1, flags, NULL)) {
|
if (!do_search(NULL, c, c, cmd, strlen(cmd), 1, flags, NULL)) {
|
||||||
@@ -4793,11 +4782,9 @@ static void ex_cquit(exarg_T *eap)
|
|||||||
int before_quit_all(exarg_T *eap)
|
int before_quit_all(exarg_T *eap)
|
||||||
{
|
{
|
||||||
if (cmdwin_type != 0) {
|
if (cmdwin_type != 0) {
|
||||||
if (eap->forceit) {
|
cmdwin_result = eap->forceit
|
||||||
cmdwin_result = K_XF1; // open_cmdwin() takes care of this
|
? K_XF1 // open_cmdwin() takes care of this
|
||||||
} else {
|
: K_XF2;
|
||||||
cmdwin_result = K_XF2;
|
|
||||||
}
|
|
||||||
return FAIL;
|
return FAIL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -5594,7 +5581,6 @@ static void ex_swapname(exarg_T *eap)
|
|||||||
static void ex_syncbind(exarg_T *eap)
|
static void ex_syncbind(exarg_T *eap)
|
||||||
{
|
{
|
||||||
linenr_T topline;
|
linenr_T topline;
|
||||||
int y;
|
|
||||||
linenr_T old_linenr = curwin->w_cursor.lnum;
|
linenr_T old_linenr = curwin->w_cursor.lnum;
|
||||||
|
|
||||||
setpcmark();
|
setpcmark();
|
||||||
@@ -5604,15 +5590,10 @@ static void ex_syncbind(exarg_T *eap)
|
|||||||
topline = curwin->w_topline;
|
topline = curwin->w_topline;
|
||||||
FOR_ALL_WINDOWS_IN_TAB(wp, curtab) {
|
FOR_ALL_WINDOWS_IN_TAB(wp, curtab) {
|
||||||
if (wp->w_p_scb && wp->w_buffer) {
|
if (wp->w_p_scb && wp->w_buffer) {
|
||||||
y = wp->w_buffer->b_ml.ml_line_count - get_scrolloff_value(curwin);
|
topline = MIN(topline, wp->w_buffer->b_ml.ml_line_count - get_scrolloff_value(curwin));
|
||||||
if (topline > y) {
|
|
||||||
topline = y;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (topline < 1) {
|
topline = MAX(topline, 1);
|
||||||
topline = 1;
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
topline = 1;
|
topline = 1;
|
||||||
}
|
}
|
||||||
@@ -5620,7 +5601,7 @@ static void ex_syncbind(exarg_T *eap)
|
|||||||
// Set all scrollbind windows to the same topline.
|
// Set all scrollbind windows to the same topline.
|
||||||
FOR_ALL_WINDOWS_IN_TAB(wp, curtab) {
|
FOR_ALL_WINDOWS_IN_TAB(wp, curtab) {
|
||||||
if (wp->w_p_scb) {
|
if (wp->w_p_scb) {
|
||||||
y = topline - wp->w_topline;
|
int y = topline - wp->w_topline;
|
||||||
if (y > 0) {
|
if (y > 0) {
|
||||||
scrollup(wp, y, true);
|
scrollup(wp, y, true);
|
||||||
} else {
|
} else {
|
||||||
|
@@ -390,13 +390,8 @@ static bool do_incsearch_highlighting(int firstc, int *search_delim, incsearch_s
|
|||||||
parse_cmd_address(&ea, &dummy, true);
|
parse_cmd_address(&ea, &dummy, true);
|
||||||
if (ea.addr_count > 0) {
|
if (ea.addr_count > 0) {
|
||||||
// Allow for reverse match.
|
// Allow for reverse match.
|
||||||
if (ea.line2 < ea.line1) {
|
search_first_line = MIN(ea.line1, ea.line1);
|
||||||
search_first_line = ea.line2;
|
search_last_line = MAX(ea.line2, ea.line1);
|
||||||
search_last_line = ea.line1;
|
|
||||||
} else {
|
|
||||||
search_first_line = ea.line1;
|
|
||||||
search_last_line = ea.line2;
|
|
||||||
}
|
|
||||||
} else if (cmd[0] == 's' && cmd[1] != 'o') {
|
} else if (cmd[0] == 's' && cmd[1] != 'o') {
|
||||||
// :s defaults to the current line
|
// :s defaults to the current line
|
||||||
search_first_line = curwin->w_cursor.lnum;
|
search_first_line = curwin->w_cursor.lnum;
|
||||||
@@ -1034,11 +1029,7 @@ static int command_line_handle_ctrl_bsl(CommandLineState *s)
|
|||||||
|
|
||||||
// Restore the cursor or use the position set with
|
// Restore the cursor or use the position set with
|
||||||
// set_cmdline_pos().
|
// set_cmdline_pos().
|
||||||
if (new_cmdpos > ccline.cmdlen) {
|
ccline.cmdpos = MIN(ccline.cmdlen, new_cmdpos);
|
||||||
ccline.cmdpos = ccline.cmdlen;
|
|
||||||
} else {
|
|
||||||
ccline.cmdpos = new_cmdpos;
|
|
||||||
}
|
|
||||||
|
|
||||||
KeyTyped = false; // Don't do p_wc completion.
|
KeyTyped = false; // Don't do p_wc completion.
|
||||||
redrawcmd();
|
redrawcmd();
|
||||||
@@ -1658,11 +1649,7 @@ static int command_line_insert_reg(CommandLineState *s)
|
|||||||
KeyTyped = false; // Don't do p_wc completion.
|
KeyTyped = false; // Don't do p_wc completion.
|
||||||
if (new_cmdpos >= 0) {
|
if (new_cmdpos >= 0) {
|
||||||
// set_cmdline_pos() was used
|
// set_cmdline_pos() was used
|
||||||
if (new_cmdpos > ccline.cmdlen) {
|
ccline.cmdpos = MIN(ccline.cmdlen, new_cmdpos);
|
||||||
ccline.cmdpos = ccline.cmdlen;
|
|
||||||
} else {
|
|
||||||
ccline.cmdpos = new_cmdpos;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
new_cmdpos = save_new_cmdpos;
|
new_cmdpos = save_new_cmdpos;
|
||||||
@@ -3546,10 +3533,6 @@ void unputcmdline(void)
|
|||||||
// called afterwards.
|
// called afterwards.
|
||||||
void put_on_cmdline(const char *str, int len, bool redraw)
|
void put_on_cmdline(const char *str, int len, bool redraw)
|
||||||
{
|
{
|
||||||
int i;
|
|
||||||
int m;
|
|
||||||
int c;
|
|
||||||
|
|
||||||
if (len < 0) {
|
if (len < 0) {
|
||||||
len = (int)strlen(str);
|
len = (int)strlen(str);
|
||||||
}
|
}
|
||||||
@@ -3563,7 +3546,8 @@ void put_on_cmdline(const char *str, int len, bool redraw)
|
|||||||
ccline.cmdlen += len;
|
ccline.cmdlen += len;
|
||||||
} else {
|
} else {
|
||||||
// Count nr of characters in the new string.
|
// Count nr of characters in the new string.
|
||||||
m = 0;
|
int m = 0;
|
||||||
|
int i;
|
||||||
for (i = 0; i < len; i += utfc_ptr2len(str + i)) {
|
for (i = 0; i < len; i += utfc_ptr2len(str + i)) {
|
||||||
m++;
|
m++;
|
||||||
}
|
}
|
||||||
@@ -3587,8 +3571,8 @@ void put_on_cmdline(const char *str, int len, bool redraw)
|
|||||||
{
|
{
|
||||||
// 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;
|
int i = 0;
|
||||||
c = utf_ptr2char(ccline.cmdbuff + ccline.cmdpos);
|
int c = utf_ptr2char(ccline.cmdbuff + ccline.cmdpos);
|
||||||
while (ccline.cmdpos > 0 && utf_iscomposing(c)) {
|
while (ccline.cmdpos > 0 && utf_iscomposing(c)) {
|
||||||
i = utf_head_off(ccline.cmdbuff, ccline.cmdbuff + ccline.cmdpos - 1) + 1;
|
i = utf_head_off(ccline.cmdbuff, ccline.cmdbuff + ccline.cmdpos - 1) + 1;
|
||||||
ccline.cmdpos -= i;
|
ccline.cmdpos -= i;
|
||||||
@@ -3619,7 +3603,7 @@ void put_on_cmdline(const char *str, int len, bool redraw)
|
|||||||
|
|
||||||
if (redraw && !cmd_silent) {
|
if (redraw && !cmd_silent) {
|
||||||
msg_no_more = true;
|
msg_no_more = true;
|
||||||
i = cmdline_row;
|
int i = cmdline_row;
|
||||||
cursorcmd();
|
cursorcmd();
|
||||||
draw_cmdline(ccline.cmdpos, ccline.cmdlen - ccline.cmdpos);
|
draw_cmdline(ccline.cmdpos, ccline.cmdlen - ccline.cmdpos);
|
||||||
// Avoid clearing the rest of the line too often.
|
// Avoid clearing the rest of the line too often.
|
||||||
@@ -3628,6 +3612,7 @@ void put_on_cmdline(const char *str, int len, bool redraw)
|
|||||||
}
|
}
|
||||||
msg_no_more = false;
|
msg_no_more = false;
|
||||||
}
|
}
|
||||||
|
int m;
|
||||||
if (KeyTyped) {
|
if (KeyTyped) {
|
||||||
m = Columns * Rows;
|
m = Columns * Rows;
|
||||||
if (m < 0) { // overflow, Columns or Rows at weird value
|
if (m < 0) { // overflow, Columns or Rows at weird value
|
||||||
@@ -3636,8 +3621,8 @@ void put_on_cmdline(const char *str, int len, bool redraw)
|
|||||||
} else {
|
} else {
|
||||||
m = MAXCOL;
|
m = MAXCOL;
|
||||||
}
|
}
|
||||||
for (i = 0; i < len; i++) {
|
for (int i = 0; i < len; i++) {
|
||||||
c = cmdline_charsize(ccline.cmdpos);
|
int 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.
|
||||||
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
|
||||||
@@ -3647,9 +3632,7 @@ void put_on_cmdline(const char *str, int len, bool redraw)
|
|||||||
ccline.cmdspos += c;
|
ccline.cmdspos += c;
|
||||||
}
|
}
|
||||||
c = utfc_ptr2len(ccline.cmdbuff + ccline.cmdpos) - 1;
|
c = utfc_ptr2len(ccline.cmdbuff + ccline.cmdpos) - 1;
|
||||||
if (c > len - i - 1) {
|
c = MIN(c, len - i - 1);
|
||||||
c = len - i - 1;
|
|
||||||
}
|
|
||||||
ccline.cmdpos += c;
|
ccline.cmdpos += c;
|
||||||
i += c;
|
i += c;
|
||||||
ccline.cmdpos++;
|
ccline.cmdpos++;
|
||||||
@@ -3886,17 +3869,13 @@ void cursorcmd(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (ui_has(kUICmdline)) {
|
if (ui_has(kUICmdline)) {
|
||||||
if (ccline.redraw_state < kCmdRedrawPos) {
|
ccline.redraw_state = MAX(ccline.redraw_state, kCmdRedrawPos);
|
||||||
ccline.redraw_state = kCmdRedrawPos;
|
|
||||||
}
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
msg_row = cmdline_row + (ccline.cmdspos / Columns);
|
msg_row = cmdline_row + (ccline.cmdspos / Columns);
|
||||||
msg_col = ccline.cmdspos % Columns;
|
msg_col = ccline.cmdspos % Columns;
|
||||||
if (msg_row >= Rows) {
|
msg_row = MIN(msg_row, Rows - 1);
|
||||||
msg_row = Rows - 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
msg_cursor_goto(msg_row, msg_col);
|
msg_cursor_goto(msg_row, msg_col);
|
||||||
}
|
}
|
||||||
@@ -4192,11 +4171,7 @@ static int set_cmdline_pos(int pos)
|
|||||||
|
|
||||||
// The position is not set directly but after CTRL-\ e or CTRL-R = has
|
// The position is not set directly but after CTRL-\ e or CTRL-R = has
|
||||||
// changed the command line.
|
// changed the command line.
|
||||||
if (pos < 0) {
|
new_cmdpos = MAX(0, pos);
|
||||||
new_cmdpos = 0;
|
|
||||||
} else {
|
|
||||||
new_cmdpos = pos;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@@ -888,10 +888,7 @@ retry:
|
|||||||
// Use buffer >= 64K. Add linerest to double the size if the
|
// Use buffer >= 64K. Add linerest to double the size if the
|
||||||
// line gets very long, to avoid a lot of copying. But don't
|
// line gets very long, to avoid a lot of copying. But don't
|
||||||
// read more than 1 Mbyte at a time, so we can be interrupted.
|
// read more than 1 Mbyte at a time, so we can be interrupted.
|
||||||
size = 0x10000 + linerest;
|
size = MIN(0x10000 + linerest, 0x100000);
|
||||||
if (size > 0x100000) {
|
|
||||||
size = 0x100000;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Protect against the argument of lalloc() going negative.
|
// Protect against the argument of lalloc() going negative.
|
||||||
@@ -2800,9 +2797,7 @@ int check_timestamps(int focus)
|
|||||||
bufref_T bufref;
|
bufref_T bufref;
|
||||||
set_bufref(&bufref, buf);
|
set_bufref(&bufref, buf);
|
||||||
const int n = buf_check_timestamp(buf);
|
const int n = buf_check_timestamp(buf);
|
||||||
if (didit < n) {
|
didit = MAX(didit, n);
|
||||||
didit = n;
|
|
||||||
}
|
|
||||||
if (n > 0 && !bufref_valid(&bufref)) {
|
if (n > 0 && !bufref_valid(&bufref)) {
|
||||||
// Autocommands have removed the buffer, start at the first one again.
|
// Autocommands have removed the buffer, start at the first one again.
|
||||||
buf = firstbuf;
|
buf = firstbuf;
|
||||||
@@ -3192,11 +3187,7 @@ void buf_reload(buf_T *buf, int orig_mode, bool reload_options)
|
|||||||
|
|
||||||
// Restore the topline and cursor position and check it (lines may
|
// Restore the topline and cursor position and check it (lines may
|
||||||
// have been removed).
|
// have been removed).
|
||||||
if (old_topline > curbuf->b_ml.ml_line_count) {
|
curwin->w_topline = MIN(old_topline, curbuf->b_ml.ml_line_count);
|
||||||
curwin->w_topline = curbuf->b_ml.ml_line_count;
|
|
||||||
} else {
|
|
||||||
curwin->w_topline = old_topline;
|
|
||||||
}
|
|
||||||
curwin->w_cursor = old_cursor;
|
curwin->w_cursor = old_cursor;
|
||||||
check_cursor(curwin);
|
check_cursor(curwin);
|
||||||
update_topline(curwin);
|
update_topline(curwin);
|
||||||
|
130
src/nvim/fold.c
130
src/nvim/fold.c
@@ -248,9 +248,7 @@ bool hasFoldingWin(win_T *const win, const linenr_T lnum, linenr_T *const firstp
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (last > win->w_buffer->b_ml.ml_line_count) {
|
last = MIN(last, win->w_buffer->b_ml.ml_line_count);
|
||||||
last = win->w_buffer->b_ml.ml_line_count;
|
|
||||||
}
|
|
||||||
if (lastp != NULL) {
|
if (lastp != NULL) {
|
||||||
*lastp = last;
|
*lastp = last;
|
||||||
}
|
}
|
||||||
@@ -618,15 +616,11 @@ void foldCreate(win_T *wp, pos_T start, pos_T end)
|
|||||||
ga_grow(&fold_ga, cont);
|
ga_grow(&fold_ga, cont);
|
||||||
// If the first fold starts before the new fold, let the new fold
|
// If the first fold starts before the new fold, let the new fold
|
||||||
// start there. Otherwise the existing fold would change.
|
// start there. Otherwise the existing fold would change.
|
||||||
if (start_rel.lnum > fp->fd_top) {
|
start_rel.lnum = MIN(start_rel.lnum, fp->fd_top);
|
||||||
start_rel.lnum = fp->fd_top;
|
|
||||||
}
|
|
||||||
|
|
||||||
// When last contained fold isn't completely contained, adjust end
|
// When last contained fold isn't completely contained, adjust end
|
||||||
// of new fold.
|
// of new fold.
|
||||||
if (end_rel.lnum < fp[cont - 1].fd_top + fp[cont - 1].fd_len - 1) {
|
end_rel.lnum = MAX(end_rel.lnum, fp[cont - 1].fd_top + fp[cont - 1].fd_len - 1);
|
||||||
end_rel.lnum = fp[cont - 1].fd_top + fp[cont - 1].fd_len - 1;
|
|
||||||
}
|
|
||||||
// Move contained folds to inside new fold
|
// Move contained folds to inside new fold
|
||||||
memmove(fold_ga.ga_data, fp, sizeof(fold_T) * (size_t)cont);
|
memmove(fold_ga.ga_data, fp, sizeof(fold_T) * (size_t)cont);
|
||||||
fold_ga.ga_len += cont;
|
fold_ga.ga_len += cont;
|
||||||
@@ -722,12 +716,8 @@ void deleteFold(win_T *const wp, const linenr_T start, const linenr_T end, const
|
|||||||
(int)(found_fp - (fold_T *)found_ga->ga_data),
|
(int)(found_fp - (fold_T *)found_ga->ga_data),
|
||||||
recursive);
|
recursive);
|
||||||
} else {
|
} else {
|
||||||
if (first_lnum > found_fp->fd_top + found_off) {
|
first_lnum = MIN(first_lnum, found_fp->fd_top + found_off);
|
||||||
first_lnum = found_fp->fd_top + found_off;
|
last_lnum = MAX(last_lnum, lnum);
|
||||||
}
|
|
||||||
if (last_lnum < lnum) {
|
|
||||||
last_lnum = lnum;
|
|
||||||
}
|
|
||||||
if (!did_one) {
|
if (!did_one) {
|
||||||
parseMarker(wp);
|
parseMarker(wp);
|
||||||
}
|
}
|
||||||
@@ -788,14 +778,10 @@ void foldUpdate(win_T *wp, linenr_T top, linenr_T bot)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (wp->w_folds.ga_len > 0) {
|
if (wp->w_folds.ga_len > 0) {
|
||||||
linenr_T maybe_small_start = top;
|
|
||||||
linenr_T maybe_small_end = bot;
|
|
||||||
|
|
||||||
// Mark all folds from top to bot (or bot to top) as maybe-small.
|
// Mark all folds from top to bot (or bot to top) as maybe-small.
|
||||||
if (top > bot) {
|
linenr_T maybe_small_start = MIN(top, bot);
|
||||||
maybe_small_start = bot;
|
linenr_T maybe_small_end = MAX(top, bot);
|
||||||
maybe_small_end = top;
|
|
||||||
}
|
|
||||||
fold_T *fp;
|
fold_T *fp;
|
||||||
foldFind(&wp->w_folds, maybe_small_start, &fp);
|
foldFind(&wp->w_folds, maybe_small_start, &fp);
|
||||||
while (fp < (fold_T *)wp->w_folds.ga_data + wp->w_folds.ga_len
|
while (fp < (fold_T *)wp->w_folds.ga_data + wp->w_folds.ga_len
|
||||||
@@ -1225,11 +1211,7 @@ static linenr_T setManualFoldWin(win_T *wp, linenr_T lnum, bool opening, bool re
|
|||||||
// Change from level-dependent folding to manual.
|
// Change from level-dependent folding to manual.
|
||||||
if (use_level || fp->fd_flags == FD_LEVEL) {
|
if (use_level || fp->fd_flags == FD_LEVEL) {
|
||||||
use_level = true;
|
use_level = true;
|
||||||
if (level >= wp->w_p_fdl) {
|
fp->fd_flags = level >= wp->w_p_fdl ? FD_CLOSED : FD_OPEN;
|
||||||
fp->fd_flags = FD_CLOSED;
|
|
||||||
} else {
|
|
||||||
fp->fd_flags = FD_OPEN;
|
|
||||||
}
|
|
||||||
fp2 = (fold_T *)fp->fd_nested.ga_data;
|
fp2 = (fold_T *)fp->fd_nested.ga_data;
|
||||||
for (int j = 0; j < fp->fd_nested.ga_len; j++) {
|
for (int j = 0; j < fp->fd_nested.ga_len; j++) {
|
||||||
fp2[j].fd_flags = FD_LEVEL;
|
fp2[j].fd_flags = FD_LEVEL;
|
||||||
@@ -1378,15 +1360,11 @@ static void foldMarkAdjustRecurse(win_T *wp, garray_T *gap, linenr_T line1, line
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
linenr_T top;
|
|
||||||
|
|
||||||
// In Insert mode an inserted line at the top of a fold is considered part
|
// In Insert mode an inserted line at the top of a fold is considered part
|
||||||
// of the fold, otherwise it isn't.
|
// of the fold, otherwise it isn't.
|
||||||
if ((State & MODE_INSERT) && amount == 1 && line2 == MAXLNUM) {
|
linenr_T top = ((State & MODE_INSERT) && amount == 1 && line2 == MAXLNUM)
|
||||||
top = line1 + 1;
|
? line1 + 1
|
||||||
} else {
|
: line1;
|
||||||
top = line1;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Find the fold containing or just below "line1".
|
// Find the fold containing or just below "line1".
|
||||||
fold_T *fp;
|
fold_T *fp;
|
||||||
@@ -1480,9 +1458,7 @@ static int getDeepestNestingRecurse(garray_T *gap)
|
|||||||
fold_T *fp = (fold_T *)gap->ga_data;
|
fold_T *fp = (fold_T *)gap->ga_data;
|
||||||
for (int i = 0; i < gap->ga_len; i++) {
|
for (int i = 0; i < gap->ga_len; i++) {
|
||||||
int level = getDeepestNestingRecurse(&fp[i].fd_nested) + 1;
|
int level = getDeepestNestingRecurse(&fp[i].fd_nested) + 1;
|
||||||
if (level > maxlevel) {
|
maxlevel = MAX(maxlevel, level);
|
||||||
maxlevel = level;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return maxlevel;
|
return maxlevel;
|
||||||
@@ -1598,7 +1574,6 @@ static void foldCreateMarkers(win_T *wp, pos_T start, pos_T end)
|
|||||||
static void foldAddMarker(buf_T *buf, pos_T pos, const char *marker, size_t markerlen)
|
static void foldAddMarker(buf_T *buf, pos_T pos, const char *marker, size_t markerlen)
|
||||||
{
|
{
|
||||||
char *cms = buf->b_p_cms;
|
char *cms = buf->b_p_cms;
|
||||||
char *newline;
|
|
||||||
char *p = strstr(buf->b_p_cms, "%s");
|
char *p = strstr(buf->b_p_cms, "%s");
|
||||||
bool line_is_comment = false;
|
bool line_is_comment = false;
|
||||||
linenr_T lnum = pos.lnum;
|
linenr_T lnum = pos.lnum;
|
||||||
@@ -1614,7 +1589,7 @@ static void foldAddMarker(buf_T *buf, pos_T pos, const char *marker, size_t mark
|
|||||||
|
|
||||||
// Check if the line ends with an unclosed comment
|
// Check if the line ends with an unclosed comment
|
||||||
skip_comment(line, false, false, &line_is_comment);
|
skip_comment(line, false, false, &line_is_comment);
|
||||||
newline = xmalloc(line_len + markerlen + strlen(cms) + 1);
|
char *newline = xmalloc(line_len + markerlen + strlen(cms) + 1);
|
||||||
STRCPY(newline, line);
|
STRCPY(newline, line);
|
||||||
// Append the marker to the end of the line
|
// Append the marker to the end of the line
|
||||||
if (p == NULL || line_is_comment) {
|
if (p == NULL || line_is_comment) {
|
||||||
@@ -1737,10 +1712,7 @@ char *get_foldtext(win_T *wp, linenr_T lnum, linenr_T lnume, foldinfo_T foldinfo
|
|||||||
|
|
||||||
// Set "v:folddashes" to a string of "level" dashes.
|
// Set "v:folddashes" to a string of "level" dashes.
|
||||||
// Set "v:foldlevel" to "level".
|
// Set "v:foldlevel" to "level".
|
||||||
int level = foldinfo.fi_level;
|
int level = MIN(foldinfo.fi_level, (int)sizeof(dashes) - 1);
|
||||||
if (level > (int)sizeof(dashes) - 1) {
|
|
||||||
level = (int)sizeof(dashes) - 1;
|
|
||||||
}
|
|
||||||
memset(dashes, '-', (size_t)level);
|
memset(dashes, '-', (size_t)level);
|
||||||
dashes[level] = NUL;
|
dashes[level] = NUL;
|
||||||
set_vim_var_string(VV_FOLDDASHES, dashes, -1);
|
set_vim_var_string(VV_FOLDDASHES, dashes, -1);
|
||||||
@@ -1937,9 +1909,7 @@ static void foldUpdateIEMS(win_T *const wp, linenr_T top, linenr_T bot)
|
|||||||
|
|
||||||
// When deleting lines at the end of the buffer "top" can be past the end
|
// When deleting lines at the end of the buffer "top" can be past the end
|
||||||
// of the buffer.
|
// of the buffer.
|
||||||
if (top > wp->w_buffer->b_ml.ml_line_count) {
|
top = MIN(top, wp->w_buffer->b_ml.ml_line_count);
|
||||||
top = wp->w_buffer->b_ml.ml_line_count;
|
|
||||||
}
|
|
||||||
|
|
||||||
fline_T fline;
|
fline_T fline;
|
||||||
|
|
||||||
@@ -2047,9 +2017,7 @@ static void foldUpdateIEMS(win_T *const wp, linenr_T top, linenr_T bot)
|
|||||||
if (fpn != NULL && current_fdl == fline.lvl) {
|
if (fpn != NULL && current_fdl == fline.lvl) {
|
||||||
linenr_T fold_end_lnum = fold_start_lnum + fpn->fd_len;
|
linenr_T fold_end_lnum = fold_start_lnum + fpn->fd_len;
|
||||||
|
|
||||||
if (fold_end_lnum > bot) {
|
bot = MAX(bot, fold_end_lnum);
|
||||||
bot = fold_end_lnum;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2127,9 +2095,7 @@ static void foldUpdateIEMS(win_T *const wp, linenr_T top, linenr_T bot)
|
|||||||
if (wp->w_redraw_top == 0 || wp->w_redraw_top > top) {
|
if (wp->w_redraw_top == 0 || wp->w_redraw_top > top) {
|
||||||
wp->w_redraw_top = top;
|
wp->w_redraw_top = top;
|
||||||
}
|
}
|
||||||
if (wp->w_redraw_bot < end) {
|
wp->w_redraw_bot = MAX(wp->w_redraw_bot, end);
|
||||||
wp->w_redraw_bot = end;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
invalid_top = 0;
|
invalid_top = 0;
|
||||||
@@ -2205,10 +2171,7 @@ static linenr_T foldUpdateIEMSRecurse(garray_T *const gap, const int level,
|
|||||||
// and after the first line of the fold, set the level to zero to
|
// and after the first line of the fold, set the level to zero to
|
||||||
// force the fold to end. Do the same when had_end is set: Previous
|
// force the fold to end. Do the same when had_end is set: Previous
|
||||||
// line was marked as end of a fold.
|
// line was marked as end of a fold.
|
||||||
lvl = flp->lvl;
|
lvl = MIN(flp->lvl, MAX_LEVEL);
|
||||||
if (lvl > MAX_LEVEL) {
|
|
||||||
lvl = MAX_LEVEL;
|
|
||||||
}
|
|
||||||
if (flp->lnum > firstlnum
|
if (flp->lnum > firstlnum
|
||||||
&& (level > lvl - flp->start || level >= flp->had_end)) {
|
&& (level > lvl - flp->start || level >= flp->had_end)) {
|
||||||
lvl = 0;
|
lvl = 0;
|
||||||
@@ -2263,12 +2226,7 @@ static linenr_T foldUpdateIEMSRecurse(garray_T *const gap, const int level,
|
|||||||
while (!got_int) {
|
while (!got_int) {
|
||||||
// set concat to 1 if it's allowed to concatenate this fold
|
// set concat to 1 if it's allowed to concatenate this fold
|
||||||
// with a previous one that touches it.
|
// with a previous one that touches it.
|
||||||
int concat;
|
int concat = (flp->start != 0 || flp->had_end <= MAX_LEVEL) ? 0 : 1;
|
||||||
if (flp->start != 0 || flp->had_end <= MAX_LEVEL) {
|
|
||||||
concat = 0;
|
|
||||||
} else {
|
|
||||||
concat = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Find an existing fold to re-use. Preferably one that
|
// Find an existing fold to re-use. Preferably one that
|
||||||
// includes startlnum, otherwise one that ends just before
|
// includes startlnum, otherwise one that ends just before
|
||||||
@@ -2424,9 +2382,7 @@ static linenr_T foldUpdateIEMSRecurse(garray_T *const gap, const int level,
|
|||||||
if (lvl > level && fp != NULL) {
|
if (lvl > level && fp != NULL) {
|
||||||
// There is a nested fold, handle it recursively.
|
// There is a nested fold, handle it recursively.
|
||||||
// At least do one line (can happen when finish is true).
|
// At least do one line (can happen when finish is true).
|
||||||
if (bot < flp->lnum) {
|
bot = MAX(bot, flp->lnum);
|
||||||
bot = flp->lnum;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Line numbers in the nested fold are relative to the start of
|
// Line numbers in the nested fold are relative to the start of
|
||||||
// this fold.
|
// this fold.
|
||||||
@@ -2556,9 +2512,7 @@ static linenr_T foldUpdateIEMSRecurse(garray_T *const gap, const int level,
|
|||||||
|
|
||||||
// Need to redraw the lines we inspected, which might be further down than
|
// Need to redraw the lines we inspected, which might be further down than
|
||||||
// was asked for.
|
// was asked for.
|
||||||
if (bot < flp->lnum - 1) {
|
bot = MAX(bot, flp->lnum - 1);
|
||||||
bot = flp->lnum - 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
return bot;
|
return bot;
|
||||||
}
|
}
|
||||||
@@ -2898,17 +2852,11 @@ static void foldlevelIndent(fline_T *flp)
|
|||||||
// depends on surrounding lines
|
// depends on surrounding lines
|
||||||
if (*s == NUL || vim_strchr(flp->wp->w_p_fdi, (uint8_t)(*s)) != NULL) {
|
if (*s == NUL || vim_strchr(flp->wp->w_p_fdi, (uint8_t)(*s)) != NULL) {
|
||||||
// first and last line can't be undefined, use level 0
|
// first and last line can't be undefined, use level 0
|
||||||
if (lnum == 1 || lnum == buf->b_ml.ml_line_count) {
|
flp->lvl = (lnum == 1 || lnum == buf->b_ml.ml_line_count) ? 0 : -1;
|
||||||
flp->lvl = 0;
|
|
||||||
} else {
|
|
||||||
flp->lvl = -1;
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
flp->lvl = get_indent_buf(buf, lnum) / get_sw_value(buf);
|
flp->lvl = get_indent_buf(buf, lnum) / get_sw_value(buf);
|
||||||
}
|
}
|
||||||
if (flp->lvl > flp->wp->w_p_fdn) {
|
flp->lvl = MIN(flp->lvl, (int)MAX(0, flp->wp->w_p_fdn));
|
||||||
flp->lvl = (int)MAX(0, flp->wp->w_p_fdn);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// foldlevelDiff() {{{2
|
// foldlevelDiff() {{{2
|
||||||
@@ -2916,11 +2864,7 @@ static void foldlevelIndent(fline_T *flp)
|
|||||||
/// Doesn't use any caching.
|
/// Doesn't use any caching.
|
||||||
static void foldlevelDiff(fline_T *flp)
|
static void foldlevelDiff(fline_T *flp)
|
||||||
{
|
{
|
||||||
if (diff_infold(flp->wp, flp->lnum + flp->off)) {
|
flp->lvl = (diff_infold(flp->wp, flp->lnum + flp->off)) ? 1 : 0;
|
||||||
flp->lvl = 1;
|
|
||||||
} else {
|
|
||||||
flp->lvl = 0;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// foldlevelExpr() {{{2
|
// foldlevelExpr() {{{2
|
||||||
@@ -3067,11 +3011,7 @@ static void foldlevelMarker(fline_T *flp)
|
|||||||
if (n > 0) {
|
if (n > 0) {
|
||||||
flp->lvl = n;
|
flp->lvl = n;
|
||||||
flp->lvl_next = n;
|
flp->lvl_next = n;
|
||||||
if (n <= start_lvl) {
|
flp->start = MAX(n - start_lvl, 1);
|
||||||
flp->start = 1;
|
|
||||||
} else {
|
|
||||||
flp->start = n - start_lvl;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
flp->lvl++;
|
flp->lvl++;
|
||||||
@@ -3088,9 +3028,7 @@ static void foldlevelMarker(fline_T *flp)
|
|||||||
flp->lvl = n;
|
flp->lvl = n;
|
||||||
flp->lvl_next = n - 1;
|
flp->lvl_next = n - 1;
|
||||||
// never start a fold with an end marker
|
// never start a fold with an end marker
|
||||||
if (flp->lvl_next > start_lvl) {
|
flp->lvl_next = MIN(flp->lvl_next, start_lvl);
|
||||||
flp->lvl_next = start_lvl;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
flp->lvl_next--;
|
flp->lvl_next--;
|
||||||
@@ -3101,9 +3039,7 @@ static void foldlevelMarker(fline_T *flp)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// The level can't go negative, must be missing a start marker.
|
// The level can't go negative, must be missing a start marker.
|
||||||
if (flp->lvl_next < 0) {
|
flp->lvl_next = MAX(flp->lvl_next, 0);
|
||||||
flp->lvl_next = 0;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// foldlevelSyntax() {{{2
|
// foldlevelSyntax() {{{2
|
||||||
@@ -3244,11 +3180,7 @@ static void foldclosed_both(typval_T *argvars, typval_T *rettv, bool end)
|
|||||||
linenr_T first;
|
linenr_T first;
|
||||||
linenr_T last;
|
linenr_T last;
|
||||||
if (hasFoldingWin(curwin, lnum, &first, &last, false, NULL)) {
|
if (hasFoldingWin(curwin, lnum, &first, &last, false, NULL)) {
|
||||||
if (end) {
|
rettv->vval.v_number = (varnumber_T)(end ? last : first);
|
||||||
rettv->vval.v_number = (varnumber_T)last;
|
|
||||||
} else {
|
|
||||||
rettv->vval.v_number = (varnumber_T)first;
|
|
||||||
}
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -3336,9 +3268,7 @@ void f_foldtextresult(typval_T *argvars, typval_T *rettv, EvalFuncData fptr)
|
|||||||
entered = true;
|
entered = true;
|
||||||
linenr_T lnum = tv_get_lnum(argvars);
|
linenr_T lnum = tv_get_lnum(argvars);
|
||||||
// Treat illegal types and illegal string values for {lnum} the same.
|
// Treat illegal types and illegal string values for {lnum} the same.
|
||||||
if (lnum < 0) {
|
lnum = MAX(lnum, 0);
|
||||||
lnum = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
foldinfo_T info = fold_info(curwin, lnum);
|
foldinfo_T info = fold_info(curwin, lnum);
|
||||||
if (info.fi_lines > 0) {
|
if (info.fi_lines > 0) {
|
||||||
|
@@ -78,16 +78,12 @@ void ga_grow(garray_T *gap, int n)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// the garray grows by at least growsize
|
// the garray grows by at least growsize
|
||||||
if (n < gap->ga_growsize) {
|
n = MAX(n, gap->ga_growsize);
|
||||||
n = gap->ga_growsize;
|
|
||||||
}
|
|
||||||
|
|
||||||
// A linear growth is very inefficient when the array grows big. This
|
// A linear growth is very inefficient when the array grows big. This
|
||||||
// is a compromise between allocating memory that won't be used and too
|
// is a compromise between allocating memory that won't be used and too
|
||||||
// many copy operations. A factor of 1.5 seems reasonable.
|
// many copy operations. A factor of 1.5 seems reasonable.
|
||||||
if (n < gap->ga_len / 2) {
|
n = MAX(n, gap->ga_len / 2);
|
||||||
n = gap->ga_len / 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
int new_maxlen = gap->ga_len + n;
|
int new_maxlen = gap->ga_len + n;
|
||||||
|
|
||||||
|
@@ -268,17 +268,12 @@ static void add_buff(buffheader_T *const buf, const char *const s, ptrdiff_t sle
|
|||||||
}
|
}
|
||||||
buf->bh_index = 0;
|
buf->bh_index = 0;
|
||||||
|
|
||||||
size_t len;
|
|
||||||
if (buf->bh_space >= (size_t)slen) {
|
if (buf->bh_space >= (size_t)slen) {
|
||||||
len = strlen(buf->bh_curr->b_str);
|
size_t len = strlen(buf->bh_curr->b_str);
|
||||||
xmemcpyz(buf->bh_curr->b_str + len, s, (size_t)slen);
|
xmemcpyz(buf->bh_curr->b_str + len, s, (size_t)slen);
|
||||||
buf->bh_space -= (size_t)slen;
|
buf->bh_space -= (size_t)slen;
|
||||||
} else {
|
} else {
|
||||||
if (slen < MINIMAL_SIZE) {
|
size_t len = MAX(MINIMAL_SIZE, (size_t)slen);
|
||||||
len = MINIMAL_SIZE;
|
|
||||||
} else {
|
|
||||||
len = (size_t)slen;
|
|
||||||
}
|
|
||||||
buffblock_T *p = xmalloc(offsetof(buffblock_T, b_str) + len + 1);
|
buffblock_T *p = xmalloc(offsetof(buffblock_T, b_str) + len + 1);
|
||||||
buf->bh_space = len - (size_t)slen;
|
buf->bh_space = len - (size_t)slen;
|
||||||
xmemcpyz(p->b_str, s, (size_t)slen);
|
xmemcpyz(p->b_str, s, (size_t)slen);
|
||||||
@@ -2238,9 +2233,7 @@ static int handle_mapping(int *keylenp, const bool *timedout, int *mapdepth)
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// No match; may have to check for termcode at next character.
|
// No match; may have to check for termcode at next character.
|
||||||
if (max_mlen < mlen) {
|
max_mlen = MAX(max_mlen, mlen);
|
||||||
max_mlen = mlen;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2372,9 +2365,7 @@ static int handle_mapping(int *keylenp, const bool *timedout, int *mapdepth)
|
|||||||
if (State & MODE_CMDLINE) {
|
if (State & MODE_CMDLINE) {
|
||||||
// redraw the command below the error
|
// redraw the command below the error
|
||||||
msg_didout = true;
|
msg_didout = true;
|
||||||
if (msg_row < cmdline_row) {
|
msg_row = MAX(msg_row, cmdline_row);
|
||||||
msg_row = cmdline_row;
|
|
||||||
}
|
|
||||||
redrawcmd();
|
redrawcmd();
|
||||||
}
|
}
|
||||||
} else if (State & (MODE_NORMAL | MODE_INSERT)) {
|
} else if (State & (MODE_NORMAL | MODE_INSERT)) {
|
||||||
@@ -2738,11 +2729,7 @@ static int vgetorpeek(bool advance)
|
|||||||
// For the cmdline window: Alternate between ESC and
|
// For the cmdline window: Alternate between ESC and
|
||||||
// CTRL-C: ESC for most situations and CTRL-C to close the
|
// CTRL-C: ESC for most situations and CTRL-C to close the
|
||||||
// cmdline window.
|
// cmdline window.
|
||||||
if ((State & MODE_CMDLINE) || (cmdwin_type > 0 && tc == ESC)) {
|
c = ((State & MODE_CMDLINE) || (cmdwin_type > 0 && tc == ESC)) ? Ctrl_C : ESC;
|
||||||
c = Ctrl_C;
|
|
||||||
} else {
|
|
||||||
c = ESC;
|
|
||||||
}
|
|
||||||
tc = c;
|
tc = c;
|
||||||
|
|
||||||
// set a flag to indicate this wasn't a normal char
|
// set a flag to indicate this wasn't a normal char
|
||||||
|
@@ -316,10 +316,7 @@ static void hash_may_resize(hashtab_T *ht, size_t minitems)
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Use specified size.
|
// Use specified size.
|
||||||
if (minitems < ht->ht_used) {
|
minitems = MAX(minitems, ht->ht_used);
|
||||||
// just in case...
|
|
||||||
minitems = ht->ht_used;
|
|
||||||
}
|
|
||||||
// array is up to 2/3 full
|
// array is up to 2/3 full
|
||||||
minsize = minitems * 3 / 2;
|
minsize = minitems * 3 / 2;
|
||||||
}
|
}
|
||||||
|
@@ -905,12 +905,9 @@ void ml_recover(bool checkext)
|
|||||||
msg_end();
|
msg_end();
|
||||||
goto theend;
|
goto theend;
|
||||||
}
|
}
|
||||||
off_T size;
|
off_T size = vim_lseek(mfp->mf_fd, 0, SEEK_END);
|
||||||
if ((size = vim_lseek(mfp->mf_fd, 0, SEEK_END)) <= 0) {
|
// 0 means no file or empty file
|
||||||
mfp->mf_blocknr_max = 0; // no file or empty file
|
mfp->mf_blocknr_max = size <= 0 ? 0 : size / mfp->mf_page_size;
|
||||||
} else {
|
|
||||||
mfp->mf_blocknr_max = size / mfp->mf_page_size;
|
|
||||||
}
|
|
||||||
mfp->mf_infile_count = mfp->mf_blocknr_max;
|
mfp->mf_infile_count = mfp->mf_blocknr_max;
|
||||||
|
|
||||||
// need to reallocate the memory used to store the data
|
// need to reallocate the memory used to store the data
|
||||||
@@ -1898,9 +1895,7 @@ errorret:
|
|||||||
buf->b_ml.ml_line_lnum = lnum;
|
buf->b_ml.ml_line_lnum = lnum;
|
||||||
return questions;
|
return questions;
|
||||||
}
|
}
|
||||||
if (lnum <= 0) { // pretend line 0 is line 1
|
lnum = MAX(lnum, 1); // pretend line 0 is line 1
|
||||||
lnum = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (buf->b_ml.ml_mfp == NULL) { // there are no lines
|
if (buf->b_ml.ml_mfp == NULL) { // there are no lines
|
||||||
buf->b_ml.ml_line_len = 1;
|
buf->b_ml.ml_line_len = 1;
|
||||||
@@ -2111,12 +2106,8 @@ static int ml_append_int(buf_T *buf, linenr_T lnum, char *line, colnr_T len, boo
|
|||||||
if (line_count > db_idx + 1) { // if there are following lines
|
if (line_count > db_idx + 1) { // if there are following lines
|
||||||
// Offset is the start of the previous line.
|
// Offset is the start of the previous line.
|
||||||
// This will become the character just after the new line.
|
// This will become the character just after the new line.
|
||||||
int offset;
|
int offset = db_idx < 0 ? (int)dp->db_txt_end
|
||||||
if (db_idx < 0) {
|
: (int)((dp->db_index[db_idx]) & DB_INDEX_MASK);
|
||||||
offset = (int)dp->db_txt_end;
|
|
||||||
} else {
|
|
||||||
offset = ((dp->db_index[db_idx]) & DB_INDEX_MASK);
|
|
||||||
}
|
|
||||||
memmove((char *)dp + dp->db_txt_start,
|
memmove((char *)dp + dp->db_txt_start,
|
||||||
(char *)dp + dp->db_txt_start + len,
|
(char *)dp + dp->db_txt_start + len,
|
||||||
(size_t)offset - (dp->db_txt_start + (size_t)len));
|
(size_t)offset - (dp->db_txt_start + (size_t)len));
|
||||||
|
@@ -1384,11 +1384,7 @@ void msgmore(int n)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (n > 0) {
|
pn = abs(n);
|
||||||
pn = n;
|
|
||||||
} else {
|
|
||||||
pn = -n;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (pn > p_report) {
|
if (pn > p_report) {
|
||||||
if (n > 0) {
|
if (n > 0) {
|
||||||
@@ -1426,9 +1422,7 @@ void msg_start(void)
|
|||||||
{
|
{
|
||||||
bool did_return = false;
|
bool did_return = false;
|
||||||
|
|
||||||
if (msg_row < cmdline_row) {
|
msg_row = MAX(msg_row, cmdline_row);
|
||||||
msg_row = cmdline_row;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!msg_silent) {
|
if (!msg_silent) {
|
||||||
XFREE_CLEAR(keep_msg); // don't display old message now
|
XFREE_CLEAR(keep_msg); // don't display old message now
|
||||||
@@ -3382,9 +3376,7 @@ void msg_advance(int col)
|
|||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (col >= Columns) { // not enough room
|
col = MIN(col, Columns - 1); // not enough room
|
||||||
col = Columns - 1;
|
|
||||||
}
|
|
||||||
while (msg_col < col) {
|
while (msg_col < col) {
|
||||||
msg_putchar(' ');
|
msg_putchar(' ');
|
||||||
}
|
}
|
||||||
|
@@ -1050,9 +1050,7 @@ void do_mousescroll(cmdarg_T *cap)
|
|||||||
// Horizontal scrolling
|
// Horizontal scrolling
|
||||||
int step = shift_or_ctrl ? curwin->w_width_inner : (int)p_mousescroll_hor;
|
int step = shift_or_ctrl ? curwin->w_width_inner : (int)p_mousescroll_hor;
|
||||||
colnr_T leftcol = curwin->w_leftcol + (cap->arg == MSCR_RIGHT ? -step : +step);
|
colnr_T leftcol = curwin->w_leftcol + (cap->arg == MSCR_RIGHT ? -step : +step);
|
||||||
if (leftcol < 0) {
|
leftcol = MAX(leftcol, 0);
|
||||||
leftcol = 0;
|
|
||||||
}
|
|
||||||
do_mousescroll_horiz(leftcol);
|
do_mousescroll_horiz(leftcol);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1619,11 +1617,8 @@ bool mouse_comp_pos(win_T *win, int *rowp, int *colp, linenr_T *lnump)
|
|||||||
while (row > 0) {
|
while (row > 0) {
|
||||||
// Don't include filler lines in "count"
|
// Don't include filler lines in "count"
|
||||||
if (win_may_fill(win)) {
|
if (win_may_fill(win)) {
|
||||||
if (lnum == win->w_topline) {
|
row -= lnum == win->w_topline ? win->w_topfill
|
||||||
row -= win->w_topfill;
|
: win_get_fill(win, lnum);
|
||||||
} else {
|
|
||||||
row -= win_get_fill(win, lnum);
|
|
||||||
}
|
|
||||||
count = plines_win_nofill(win, lnum, false);
|
count = plines_win_nofill(win, lnum, false);
|
||||||
} else {
|
} else {
|
||||||
count = plines_win(win, lnum, false);
|
count = plines_win(win, lnum, false);
|
||||||
@@ -1664,9 +1659,7 @@ bool mouse_comp_pos(win_T *win, int *rowp, int *colp, linenr_T *lnump)
|
|||||||
if (!retval) {
|
if (!retval) {
|
||||||
// Compute the column without wrapping.
|
// Compute the column without wrapping.
|
||||||
int off = win_col_off(win) - win_col_off2(win);
|
int off = win_col_off(win) - win_col_off2(win);
|
||||||
if (col < off) {
|
col = MAX(col, off);
|
||||||
col = off;
|
|
||||||
}
|
|
||||||
col += row * (win->w_width_inner - off);
|
col += row * (win->w_width_inner - off);
|
||||||
|
|
||||||
// Add skip column for the topline.
|
// Add skip column for the topline.
|
||||||
@@ -1681,9 +1674,7 @@ bool mouse_comp_pos(win_T *win, int *rowp, int *colp, linenr_T *lnump)
|
|||||||
|
|
||||||
// skip line number and fold column in front of the line
|
// skip line number and fold column in front of the line
|
||||||
col -= win_col_off(win);
|
col -= win_col_off(win);
|
||||||
if (col <= 0) {
|
col = MAX(col, 0);
|
||||||
col = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
*colp = col;
|
*colp = col;
|
||||||
*rowp = row;
|
*rowp = row;
|
||||||
|
@@ -894,9 +894,7 @@ void curs_columns(win_T *wp, int may_scroll)
|
|||||||
new_leftcol = wp->w_leftcol + diff;
|
new_leftcol = wp->w_leftcol + diff;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (new_leftcol < 0) {
|
new_leftcol = MAX(new_leftcol, 0);
|
||||||
new_leftcol = 0;
|
|
||||||
}
|
|
||||||
if (new_leftcol != (int)wp->w_leftcol) {
|
if (new_leftcol != (int)wp->w_leftcol) {
|
||||||
wp->w_leftcol = new_leftcol;
|
wp->w_leftcol = new_leftcol;
|
||||||
win_check_anchored_floats(wp);
|
win_check_anchored_floats(wp);
|
||||||
@@ -969,11 +967,8 @@ void curs_columns(win_T *wp, int may_scroll)
|
|||||||
if (n > plines - wp->w_height_inner + 1) {
|
if (n > plines - wp->w_height_inner + 1) {
|
||||||
n = plines - wp->w_height_inner + 1;
|
n = plines - wp->w_height_inner + 1;
|
||||||
}
|
}
|
||||||
if (n > 0) {
|
wp->w_skipcol = n > 0 ? width1 + (n - 1) * width2
|
||||||
wp->w_skipcol = width1 + (n - 1) * width2;
|
: 0;
|
||||||
} else {
|
|
||||||
wp->w_skipcol = 0;
|
|
||||||
}
|
|
||||||
} else if (extra == 1) {
|
} else if (extra == 1) {
|
||||||
// less than 'scrolloff' lines above, decrease skipcol
|
// less than 'scrolloff' lines above, decrease skipcol
|
||||||
assert(so <= INT_MAX);
|
assert(so <= INT_MAX);
|
||||||
@@ -990,9 +985,7 @@ void curs_columns(win_T *wp, int may_scroll)
|
|||||||
while (endcol > wp->w_virtcol) {
|
while (endcol > wp->w_virtcol) {
|
||||||
endcol -= width2;
|
endcol -= width2;
|
||||||
}
|
}
|
||||||
if (endcol > wp->w_skipcol) {
|
wp->w_skipcol = MAX(wp->w_skipcol, endcol);
|
||||||
wp->w_skipcol = endcol;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// adjust w_wrow for the changed w_skipcol
|
// adjust w_wrow for the changed w_skipcol
|
||||||
@@ -1129,9 +1122,7 @@ void f_screenpos(typval_T *argvars, typval_T *rettv, EvalFuncData fptr)
|
|||||||
semsg(_(e_invalid_line_number_nr), pos.lnum);
|
semsg(_(e_invalid_line_number_nr), pos.lnum);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (pos.col < 0) {
|
pos.col = MAX(pos.col, 0);
|
||||||
pos.col = 0;
|
|
||||||
}
|
|
||||||
int row = 0;
|
int row = 0;
|
||||||
int scol = 0;
|
int scol = 0;
|
||||||
int ccol = 0;
|
int ccol = 0;
|
||||||
@@ -1423,9 +1414,7 @@ bool scrolldown(win_T *wp, linenr_T line_count, int byfold)
|
|||||||
foldAdjustCursor(wp);
|
foldAdjustCursor(wp);
|
||||||
coladvance(wp, wp->w_curswant);
|
coladvance(wp, wp->w_curswant);
|
||||||
}
|
}
|
||||||
if (wp->w_cursor.lnum < wp->w_topline) {
|
wp->w_cursor.lnum = MAX(wp->w_cursor.lnum, wp->w_topline);
|
||||||
wp->w_cursor.lnum = wp->w_topline;
|
|
||||||
}
|
|
||||||
|
|
||||||
return moved;
|
return moved;
|
||||||
}
|
}
|
||||||
@@ -1506,12 +1495,8 @@ bool scrollup(win_T *wp, linenr_T line_count, bool byfold)
|
|||||||
wp->w_botline += line_count; // approximate w_botline
|
wp->w_botline += line_count; // approximate w_botline
|
||||||
}
|
}
|
||||||
|
|
||||||
if (wp->w_topline > wp->w_buffer->b_ml.ml_line_count) {
|
wp->w_topline = MIN(wp->w_topline, wp->w_buffer->b_ml.ml_line_count);
|
||||||
wp->w_topline = wp->w_buffer->b_ml.ml_line_count;
|
wp->w_botline = MIN(wp->w_botline, wp->w_buffer->b_ml.ml_line_count + 1);
|
||||||
}
|
|
||||||
if (wp->w_botline > wp->w_buffer->b_ml.ml_line_count + 1) {
|
|
||||||
wp->w_botline = wp->w_buffer->b_ml.ml_line_count + 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
check_topfill(wp, false);
|
check_topfill(wp, false);
|
||||||
|
|
||||||
@@ -1623,9 +1608,7 @@ void check_topfill(win_T *wp, bool down)
|
|||||||
wp->w_topfill = 0;
|
wp->w_topfill = 0;
|
||||||
} else {
|
} else {
|
||||||
wp->w_topfill = wp->w_height_inner - n;
|
wp->w_topfill = wp->w_height_inner - n;
|
||||||
if (wp->w_topfill < 0) {
|
wp->w_topfill = MAX(wp->w_topfill, 0);
|
||||||
wp->w_topfill = 0;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1849,15 +1832,11 @@ void scroll_cursor_top(win_T *wp, int min_scroll, int always)
|
|||||||
if (new_topline < wp->w_topline || always) {
|
if (new_topline < wp->w_topline || always) {
|
||||||
wp->w_topline = new_topline;
|
wp->w_topline = new_topline;
|
||||||
}
|
}
|
||||||
if (wp->w_topline > wp->w_cursor.lnum) {
|
wp->w_topline = MIN(wp->w_topline, wp->w_cursor.lnum);
|
||||||
wp->w_topline = wp->w_cursor.lnum;
|
|
||||||
}
|
|
||||||
wp->w_topfill = win_get_fill(wp, wp->w_topline);
|
wp->w_topfill = win_get_fill(wp, wp->w_topline);
|
||||||
if (wp->w_topfill > 0 && extra > off) {
|
if (wp->w_topfill > 0 && extra > off) {
|
||||||
wp->w_topfill -= extra - off;
|
wp->w_topfill -= extra - off;
|
||||||
if (wp->w_topfill < 0) {
|
wp->w_topfill = MAX(wp->w_topfill, 0);
|
||||||
wp->w_topfill = 0;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
check_topfill(wp, false);
|
check_topfill(wp, false);
|
||||||
if (wp->w_topline != old_topline) {
|
if (wp->w_topline != old_topline) {
|
||||||
@@ -2276,18 +2255,14 @@ void cursor_correct(win_T *wp)
|
|||||||
if (wp->w_topline == 1) {
|
if (wp->w_topline == 1) {
|
||||||
above_wanted = 0;
|
above_wanted = 0;
|
||||||
int max_off = wp->w_height_inner / 2;
|
int max_off = wp->w_height_inner / 2;
|
||||||
if (below_wanted > max_off) {
|
below_wanted = MIN(below_wanted, max_off);
|
||||||
below_wanted = max_off;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
validate_botline(wp);
|
validate_botline(wp);
|
||||||
if (wp->w_botline == wp->w_buffer->b_ml.ml_line_count + 1
|
if (wp->w_botline == wp->w_buffer->b_ml.ml_line_count + 1
|
||||||
&& mouse_dragging == 0) {
|
&& mouse_dragging == 0) {
|
||||||
below_wanted = 0;
|
below_wanted = 0;
|
||||||
int max_off = (wp->w_height_inner - 1) / 2;
|
int max_off = (wp->w_height_inner - 1) / 2;
|
||||||
if (above_wanted > max_off) {
|
above_wanted = MIN(above_wanted, max_off);
|
||||||
above_wanted = max_off;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// If there are sufficient file-lines above and below the cursor, we can
|
// If there are sufficient file-lines above and below the cursor, we can
|
||||||
|
@@ -1685,9 +1685,7 @@ size_t find_ident_at_pos(win_T *wp, linenr_T lnum, colnr_T startcol, char **text
|
|||||||
|
|
||||||
// If we don't want just any old text, or we've found an
|
// If we don't want just any old text, or we've found an
|
||||||
// identifier, stop searching.
|
// identifier, stop searching.
|
||||||
if (this_class > 2) {
|
this_class = MIN(this_class, 2);
|
||||||
this_class = 2;
|
|
||||||
}
|
|
||||||
if (!(find_type & FIND_STRING) || this_class == 2) {
|
if (!(find_type & FIND_STRING) || this_class == 2) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -2011,9 +2009,7 @@ static void del_from_showcmd(int len)
|
|||||||
}
|
}
|
||||||
|
|
||||||
int old_len = (int)strlen(showcmd_buf);
|
int old_len = (int)strlen(showcmd_buf);
|
||||||
if (len > old_len) {
|
len = MIN(len, old_len);
|
||||||
len = old_len;
|
|
||||||
}
|
|
||||||
showcmd_buf[old_len - len] = NUL;
|
showcmd_buf[old_len - len] = NUL;
|
||||||
|
|
||||||
if (!char_avail()) {
|
if (!char_avail()) {
|
||||||
@@ -2515,9 +2511,7 @@ bool nv_screengo(oparg_T *oap, int dir, int dist)
|
|||||||
} else {
|
} else {
|
||||||
n = width1;
|
n = width1;
|
||||||
}
|
}
|
||||||
if (curwin->w_curswant >= n) {
|
curwin->w_curswant = MIN(curwin->w_curswant, n - 1);
|
||||||
curwin->w_curswant = n - 1;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
while (dist--) {
|
while (dist--) {
|
||||||
@@ -2776,11 +2770,7 @@ static void nv_zet(cmdarg_T *cap)
|
|||||||
if (cap->count0 == 0) {
|
if (cap->count0 == 0) {
|
||||||
// No count given: put cursor at the line below screen
|
// No count given: put cursor at the line below screen
|
||||||
validate_botline(curwin); // make sure w_botline is valid
|
validate_botline(curwin); // make sure w_botline is valid
|
||||||
if (curwin->w_botline > curbuf->b_ml.ml_line_count) {
|
curwin->w_cursor.lnum = MIN(curwin->w_botline, curbuf->b_ml.ml_line_count);
|
||||||
curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count;
|
|
||||||
} else {
|
|
||||||
curwin->w_cursor.lnum = curwin->w_botline;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
FALLTHROUGH;
|
FALLTHROUGH;
|
||||||
case NL:
|
case NL:
|
||||||
@@ -3049,9 +3039,7 @@ static void nv_zet(cmdarg_T *cap)
|
|||||||
case 'm':
|
case 'm':
|
||||||
if (curwin->w_p_fdl > 0) {
|
if (curwin->w_p_fdl > 0) {
|
||||||
curwin->w_p_fdl -= cap->count1;
|
curwin->w_p_fdl -= cap->count1;
|
||||||
if (curwin->w_p_fdl < 0) {
|
curwin->w_p_fdl = MAX(curwin->w_p_fdl, 0);
|
||||||
curwin->w_p_fdl = 0;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
old_fdl = -1; // force an update
|
old_fdl = -1; // force an update
|
||||||
curwin->w_p_fen = true;
|
curwin->w_p_fen = true;
|
||||||
@@ -3069,9 +3057,7 @@ static void nv_zet(cmdarg_T *cap)
|
|||||||
curwin->w_p_fdl += cap->count1;
|
curwin->w_p_fdl += cap->count1;
|
||||||
{
|
{
|
||||||
int d = getDeepestNesting(curwin);
|
int d = getDeepestNesting(curwin);
|
||||||
if (curwin->w_p_fdl >= d) {
|
curwin->w_p_fdl = MIN(curwin->w_p_fdl, d);
|
||||||
curwin->w_p_fdl = d;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@@ -3662,10 +3648,7 @@ static void nv_scroll(cmdarg_T *cap)
|
|||||||
n = lnum - curwin->w_topline;
|
n = lnum - curwin->w_topline;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
curwin->w_cursor.lnum = curwin->w_topline + n;
|
curwin->w_cursor.lnum = MIN(curwin->w_topline + n, curbuf->b_ml.ml_line_count);
|
||||||
if (curwin->w_cursor.lnum > curbuf->b_ml.ml_line_count) {
|
|
||||||
curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Correct for 'so', except when an operator is pending.
|
// Correct for 'so', except when an operator is pending.
|
||||||
@@ -4344,12 +4327,8 @@ static void nv_percent(cmdarg_T *cap)
|
|||||||
curwin->w_cursor.lnum = (curbuf->b_ml.ml_line_count *
|
curwin->w_cursor.lnum = (curbuf->b_ml.ml_line_count *
|
||||||
cap->count0 + 99) / 100;
|
cap->count0 + 99) / 100;
|
||||||
}
|
}
|
||||||
if (curwin->w_cursor.lnum < 1) {
|
curwin->w_cursor.lnum = MIN(MAX(curwin->w_cursor.lnum, 1), curbuf->b_ml.ml_line_count);
|
||||||
curwin->w_cursor.lnum = 1;
|
|
||||||
}
|
|
||||||
if (curwin->w_cursor.lnum > curbuf->b_ml.ml_line_count) {
|
|
||||||
curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count;
|
|
||||||
}
|
|
||||||
beginline(BL_SOL | BL_FIX);
|
beginline(BL_SOL | BL_FIX);
|
||||||
}
|
}
|
||||||
} else { // "%" : go to matching paren
|
} else { // "%" : go to matching paren
|
||||||
@@ -6088,11 +6067,7 @@ static void nv_goto(cmdarg_T *cap)
|
|||||||
if (cap->count0 != 0) {
|
if (cap->count0 != 0) {
|
||||||
lnum = cap->count0;
|
lnum = cap->count0;
|
||||||
}
|
}
|
||||||
if (lnum < 1) {
|
lnum = MIN(MAX(lnum, 1), curbuf->b_ml.ml_line_count);
|
||||||
lnum = 1;
|
|
||||||
} else if (lnum > curbuf->b_ml.ml_line_count) {
|
|
||||||
lnum = curbuf->b_ml.ml_line_count;
|
|
||||||
}
|
|
||||||
curwin->w_cursor.lnum = lnum;
|
curwin->w_cursor.lnum = lnum;
|
||||||
beginline(BL_SOL | BL_FIX);
|
beginline(BL_SOL | BL_FIX);
|
||||||
if ((fdo_flags & FDO_JUMP) && KeyTyped && cap->oap->op_type == OP_NOP) {
|
if ((fdo_flags & FDO_JUMP) && KeyTyped && cap->oap->op_type == OP_NOP) {
|
||||||
@@ -6422,9 +6397,8 @@ static void nv_join(cmdarg_T *cap)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cap->count0 <= 1) {
|
cap->count0 = MAX(cap->count0, 2); // default for join is two lines!
|
||||||
cap->count0 = 2; // default for join is two lines!
|
|
||||||
}
|
|
||||||
if (curwin->w_cursor.lnum + cap->count0 - 1 >
|
if (curwin->w_cursor.lnum + cap->count0 - 1 >
|
||||||
curbuf->b_ml.ml_line_count) {
|
curbuf->b_ml.ml_line_count) {
|
||||||
// can't join when on the last line
|
// can't join when on the last line
|
||||||
|
110
src/nvim/ops.c
110
src/nvim/ops.c
@@ -246,12 +246,7 @@ void op_shift(oparg_T *oap, bool curs_top, int amount)
|
|||||||
foldOpenCursor();
|
foldOpenCursor();
|
||||||
|
|
||||||
if (oap->line_count > p_report) {
|
if (oap->line_count > p_report) {
|
||||||
char *op;
|
char *op = oap->op_type == OP_RSHIFT ? ">" : "<";
|
||||||
if (oap->op_type == OP_RSHIFT) {
|
|
||||||
op = ">";
|
|
||||||
} else {
|
|
||||||
op = "<";
|
|
||||||
}
|
|
||||||
|
|
||||||
char *msg_line_single = NGETTEXT("%" PRId64 " line %sed %d time",
|
char *msg_line_single = NGETTEXT("%" PRId64 " line %sed %d time",
|
||||||
"%" PRId64 " line %sed %d times", amount);
|
"%" PRId64 " line %sed %d times", amount);
|
||||||
@@ -295,20 +290,14 @@ void shift_line(bool left, bool round, int amount, int call_changed_bytes)
|
|||||||
amount--;
|
amount--;
|
||||||
}
|
}
|
||||||
if (left) {
|
if (left) {
|
||||||
i -= amount;
|
i = MAX(i - amount, 0);
|
||||||
if (i < 0) {
|
|
||||||
i = 0;
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
i += amount;
|
i += amount;
|
||||||
}
|
}
|
||||||
count = i * sw_val;
|
count = i * sw_val;
|
||||||
} else { // original vi indent
|
} else { // original vi indent
|
||||||
if (left) {
|
if (left) {
|
||||||
count -= sw_val * amount;
|
count = MAX(count - sw_val * amount, 0);
|
||||||
if (count < 0) {
|
|
||||||
count = 0;
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
count += sw_val * amount;
|
count += sw_val * amount;
|
||||||
}
|
}
|
||||||
@@ -445,9 +434,7 @@ static void shift_block(oparg_T *oap, int amount)
|
|||||||
|
|
||||||
const colnr_T block_space_width = non_white_col - oap->start_vcol;
|
const colnr_T block_space_width = non_white_col - oap->start_vcol;
|
||||||
// We will shift by "total" or "block_space_width", whichever is less.
|
// We will shift by "total" or "block_space_width", whichever is less.
|
||||||
const colnr_T shift_amount = block_space_width < total
|
const colnr_T shift_amount = MIN(block_space_width, total);
|
||||||
? block_space_width
|
|
||||||
: total;
|
|
||||||
// The column to which we will shift the text.
|
// The column to which we will shift the text.
|
||||||
const colnr_T destination_col = non_white_col - shift_amount;
|
const colnr_T destination_col = non_white_col - shift_amount;
|
||||||
|
|
||||||
@@ -561,9 +548,7 @@ static void block_insert(oparg_T *oap, const char *s, size_t slen, bool b_insert
|
|||||||
// avoid copying part of a multi-byte character
|
// avoid copying part of a multi-byte character
|
||||||
offset -= utf_head_off(oldp, oldp + offset);
|
offset -= utf_head_off(oldp, oldp + offset);
|
||||||
}
|
}
|
||||||
if (spaces < 0) { // can happen when the cursor was moved
|
spaces = MAX(spaces, 0); // can happen when the cursor was moved
|
||||||
spaces = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
assert(count >= 0);
|
assert(count >= 0);
|
||||||
// Make sure the allocated size matches what is actually copied below.
|
// Make sure the allocated size matches what is actually copied below.
|
||||||
@@ -2369,9 +2354,7 @@ void op_insert(oparg_T *oap, int count1)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (add > len) {
|
add = MIN(add, len); // short line, point to the NUL
|
||||||
add = len; // short line, point to the NUL
|
|
||||||
}
|
|
||||||
firstline += add;
|
firstline += add;
|
||||||
len -= add;
|
len -= add;
|
||||||
int ins_len = len - pre_textlen - offset;
|
int ins_len = len - pre_textlen - offset;
|
||||||
@@ -3041,9 +3024,7 @@ void do_put(int regname, yankreg_T *reg, int dir, int count, int flags)
|
|||||||
|
|
||||||
if (y_type == kMTBlockWise) {
|
if (y_type == kMTBlockWise) {
|
||||||
lnum = curwin->w_cursor.lnum + (linenr_T)y_size + 1;
|
lnum = curwin->w_cursor.lnum + (linenr_T)y_size + 1;
|
||||||
if (lnum > curbuf->b_ml.ml_line_count) {
|
lnum = MIN(lnum, curbuf->b_ml.ml_line_count + 1);
|
||||||
lnum = curbuf->b_ml.ml_line_count + 1;
|
|
||||||
}
|
|
||||||
if (u_save(curwin->w_cursor.lnum - 1, lnum) == FAIL) {
|
if (u_save(curwin->w_cursor.lnum - 1, lnum) == FAIL) {
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
@@ -3204,9 +3185,7 @@ void do_put(int regname, yankreg_T *reg, int dir, int count, int flags)
|
|||||||
spaces -= win_charsize(cstype, 0, ci.ptr, ci.chr.value, &csarg).width;
|
spaces -= win_charsize(cstype, 0, ci.ptr, ci.chr.value, &csarg).width;
|
||||||
ci = utfc_next(ci);
|
ci = utfc_next(ci);
|
||||||
}
|
}
|
||||||
if (spaces < 0) {
|
spaces = MAX(spaces, 0);
|
||||||
spaces = 0;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Insert the new text.
|
// Insert the new text.
|
||||||
@@ -3271,10 +3250,7 @@ void do_put(int regname, yankreg_T *reg, int dir, int count, int flags)
|
|||||||
|
|
||||||
// adjust '] mark
|
// adjust '] mark
|
||||||
curbuf->b_op_end.lnum = curwin->w_cursor.lnum - 1;
|
curbuf->b_op_end.lnum = curwin->w_cursor.lnum - 1;
|
||||||
curbuf->b_op_end.col = bd.textcol + (colnr_T)totlen - 1;
|
curbuf->b_op_end.col = MAX(bd.textcol + (colnr_T)totlen - 1, 0);
|
||||||
if (curbuf->b_op_end.col < 0) {
|
|
||||||
curbuf->b_op_end.col = 0;
|
|
||||||
}
|
|
||||||
curbuf->b_op_end.coladd = 0;
|
curbuf->b_op_end.coladd = 0;
|
||||||
if (flags & PUT_CURSEND) {
|
if (flags & PUT_CURSEND) {
|
||||||
curwin->w_cursor = curbuf->b_op_end;
|
curwin->w_cursor = curbuf->b_op_end;
|
||||||
@@ -3282,9 +3258,7 @@ void do_put(int regname, yankreg_T *reg, int dir, int count, int flags)
|
|||||||
|
|
||||||
// in Insert mode we might be after the NUL, correct for that
|
// in Insert mode we might be after the NUL, correct for that
|
||||||
colnr_T len = get_cursor_line_len();
|
colnr_T len = get_cursor_line_len();
|
||||||
if (curwin->w_cursor.col > len) {
|
curwin->w_cursor.col = MIN(curwin->w_cursor.col, len);
|
||||||
curwin->w_cursor.col = len;
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
curwin->w_cursor.lnum = lnum;
|
curwin->w_cursor.lnum = lnum;
|
||||||
}
|
}
|
||||||
@@ -3317,10 +3291,7 @@ void do_put(int regname, yankreg_T *reg, int dir, int count, int flags)
|
|||||||
int first_byte_off = 0;
|
int first_byte_off = 0;
|
||||||
|
|
||||||
if (VIsual_active) {
|
if (VIsual_active) {
|
||||||
end_lnum = curbuf->b_visual.vi_end.lnum;
|
end_lnum = MAX(curbuf->b_visual.vi_end.lnum, curbuf->b_visual.vi_start.lnum);
|
||||||
if (end_lnum < curbuf->b_visual.vi_start.lnum) {
|
|
||||||
end_lnum = curbuf->b_visual.vi_start.lnum;
|
|
||||||
}
|
|
||||||
if (end_lnum > start_lnum) {
|
if (end_lnum > start_lnum) {
|
||||||
// "col" is valid for the first line, in following lines
|
// "col" is valid for the first line, in following lines
|
||||||
// the virtual column needs to be used. Matters for
|
// the virtual column needs to be used. Matters for
|
||||||
@@ -4259,10 +4230,7 @@ void charwise_block_prep(pos_T start, pos_T end, struct block_def *bdp, linenr_T
|
|||||||
if (ce != cs && start.coladd > 0) {
|
if (ce != cs && start.coladd > 0) {
|
||||||
// Part of a tab selected -- but don't double-count it.
|
// Part of a tab selected -- but don't double-count it.
|
||||||
bdp->start_char_vcols = ce - cs + 1;
|
bdp->start_char_vcols = ce - cs + 1;
|
||||||
bdp->startspaces = bdp->start_char_vcols - start.coladd;
|
bdp->startspaces = MAX(bdp->start_char_vcols - start.coladd, 0);
|
||||||
if (bdp->startspaces < 0) {
|
|
||||||
bdp->startspaces = 0;
|
|
||||||
}
|
|
||||||
startcol++;
|
startcol++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -4362,9 +4330,7 @@ void op_addsub(oparg_T *oap, linenr_T Prenum1, bool g_cmd)
|
|||||||
}
|
}
|
||||||
if (pos.lnum == oap->end.lnum) {
|
if (pos.lnum == oap->end.lnum) {
|
||||||
length = ml_get_len(oap->end.lnum);
|
length = ml_get_len(oap->end.lnum);
|
||||||
if (oap->end.col >= length) {
|
oap->end.col = MIN(oap->end.col, length - 1);
|
||||||
oap->end.col = length - 1;
|
|
||||||
}
|
|
||||||
length = oap->end.col - pos.col + 1;
|
length = oap->end.col - pos.col + 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -4553,21 +4519,13 @@ bool do_addsub(int op_type, pos_T *pos, int length, linenr_T Prenum1)
|
|||||||
// decrement or increment alphabetic character
|
// decrement or increment alphabetic character
|
||||||
if (op_type == OP_NR_SUB) {
|
if (op_type == OP_NR_SUB) {
|
||||||
if (CHAR_ORD(firstdigit) < Prenum1) {
|
if (CHAR_ORD(firstdigit) < Prenum1) {
|
||||||
if (isupper(firstdigit)) {
|
firstdigit = isupper(firstdigit) ? 'A' : 'a';
|
||||||
firstdigit = 'A';
|
|
||||||
} else {
|
|
||||||
firstdigit = 'a';
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
firstdigit -= (int)Prenum1;
|
firstdigit -= (int)Prenum1;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (26 - CHAR_ORD(firstdigit) - 1 < Prenum1) {
|
if (26 - CHAR_ORD(firstdigit) - 1 < Prenum1) {
|
||||||
if (isupper(firstdigit)) {
|
firstdigit = isupper(firstdigit) ? 'Z' : 'z';
|
||||||
firstdigit = 'Z';
|
|
||||||
} else {
|
|
||||||
firstdigit = 'z';
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
firstdigit += (int)Prenum1;
|
firstdigit += (int)Prenum1;
|
||||||
}
|
}
|
||||||
@@ -4678,11 +4636,7 @@ bool do_addsub(int op_type, pos_T *pos, int length, linenr_T Prenum1)
|
|||||||
}
|
}
|
||||||
while (todel-- > 0) {
|
while (todel-- > 0) {
|
||||||
if (c < 0x100 && isalpha(c)) {
|
if (c < 0x100 && isalpha(c)) {
|
||||||
if (isupper(c)) {
|
hexupper = isupper(c);
|
||||||
hexupper = true;
|
|
||||||
} else {
|
|
||||||
hexupper = false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
// del_char() will mark line needing displaying
|
// del_char() will mark line needing displaying
|
||||||
del_char(false);
|
del_char(false);
|
||||||
@@ -5158,9 +5112,7 @@ static void str_to_reg(yankreg_T *y_ptr, MotionType yank_type, const char *str,
|
|||||||
for (char **ss = (char **)str; *ss != NULL; ss++, lnum++) {
|
for (char **ss = (char **)str; *ss != NULL; ss++, lnum++) {
|
||||||
size_t ss_len = strlen(*ss);
|
size_t ss_len = strlen(*ss);
|
||||||
pp[lnum] = xmemdupz(*ss, ss_len);
|
pp[lnum] = xmemdupz(*ss, ss_len);
|
||||||
if (ss_len > maxlen) {
|
maxlen = MAX(maxlen, ss_len);
|
||||||
maxlen = ss_len;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
size_t line_len;
|
size_t line_len;
|
||||||
@@ -5169,9 +5121,7 @@ static void str_to_reg(yankreg_T *y_ptr, MotionType yank_type, const char *str,
|
|||||||
start += line_len + 1, lnum++) {
|
start += line_len + 1, lnum++) {
|
||||||
assert(end - start >= 0);
|
assert(end - start >= 0);
|
||||||
line_len = (size_t)((char *)xmemscan(start, '\n', (size_t)(end - start)) - start);
|
line_len = (size_t)((char *)xmemscan(start, '\n', (size_t)(end - start)) - start);
|
||||||
if (line_len > maxlen) {
|
maxlen = MAX(maxlen, line_len);
|
||||||
maxlen = line_len;
|
|
||||||
}
|
|
||||||
|
|
||||||
// When appending, copy the previous line and free it after.
|
// When appending, copy the previous line and free it after.
|
||||||
size_t extra = append ? strlen(pp[--lnum]) : 0;
|
size_t extra = append ? strlen(pp[--lnum]) : 0;
|
||||||
@@ -5661,9 +5611,7 @@ static void get_op_vcol(oparg_T *oap, colnr_T redo_VIsual_vcol, bool initial)
|
|||||||
if (!redo_VIsual_busy) {
|
if (!redo_VIsual_busy) {
|
||||||
getvvcol(curwin, &(oap->end), &start, NULL, &end);
|
getvvcol(curwin, &(oap->end), &start, NULL, &end);
|
||||||
|
|
||||||
if (start < oap->start_vcol) {
|
oap->start_vcol = MIN(oap->start_vcol, start);
|
||||||
oap->start_vcol = start;
|
|
||||||
}
|
|
||||||
if (end > oap->end_vcol) {
|
if (end > oap->end_vcol) {
|
||||||
if (initial && *p_sel == 'e'
|
if (initial && *p_sel == 'e'
|
||||||
&& start >= 1
|
&& start >= 1
|
||||||
@@ -5682,9 +5630,7 @@ static void get_op_vcol(oparg_T *oap, colnr_T redo_VIsual_vcol, bool initial)
|
|||||||
for (curwin->w_cursor.lnum = oap->start.lnum;
|
for (curwin->w_cursor.lnum = oap->start.lnum;
|
||||||
curwin->w_cursor.lnum <= oap->end.lnum; curwin->w_cursor.lnum++) {
|
curwin->w_cursor.lnum <= oap->end.lnum; curwin->w_cursor.lnum++) {
|
||||||
getvvcol(curwin, &curwin->w_cursor, NULL, NULL, &end);
|
getvvcol(curwin, &curwin->w_cursor, NULL, NULL, &end);
|
||||||
if (end > oap->end_vcol) {
|
oap->end_vcol = MAX(oap->end_vcol, end);
|
||||||
oap->end_vcol = end;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else if (redo_VIsual_busy) {
|
} else if (redo_VIsual_busy) {
|
||||||
oap->end_vcol = oap->start_vcol + redo_VIsual_vcol - 1;
|
oap->end_vcol = oap->start_vcol + redo_VIsual_vcol - 1;
|
||||||
@@ -5818,9 +5764,7 @@ void do_pending_operator(cmdarg_T *cap, int old_col, bool gui_yank)
|
|||||||
// redo_VIsual.rv_line_count and redo_VIsual.rv_vcol.
|
// redo_VIsual.rv_line_count and redo_VIsual.rv_vcol.
|
||||||
oap->start = curwin->w_cursor;
|
oap->start = curwin->w_cursor;
|
||||||
curwin->w_cursor.lnum += redo_VIsual.rv_line_count - 1;
|
curwin->w_cursor.lnum += redo_VIsual.rv_line_count - 1;
|
||||||
if (curwin->w_cursor.lnum > curbuf->b_ml.ml_line_count) {
|
curwin->w_cursor.lnum = MIN(curwin->w_cursor.lnum, curbuf->b_ml.ml_line_count);
|
||||||
curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count;
|
|
||||||
}
|
|
||||||
VIsual_mode = redo_VIsual.rv_mode;
|
VIsual_mode = redo_VIsual.rv_mode;
|
||||||
if (redo_VIsual.rv_vcol == MAXCOL || VIsual_mode == 'v') {
|
if (redo_VIsual.rv_vcol == MAXCOL || VIsual_mode == 'v') {
|
||||||
if (VIsual_mode == 'v') {
|
if (VIsual_mode == 'v') {
|
||||||
@@ -6108,9 +6052,7 @@ void do_pending_operator(cmdarg_T *cap, int old_col, bool gui_yank)
|
|||||||
|
|
||||||
case OP_JOIN_NS:
|
case OP_JOIN_NS:
|
||||||
case OP_JOIN:
|
case OP_JOIN:
|
||||||
if (oap->line_count < 2) {
|
oap->line_count = MAX(oap->line_count, 2);
|
||||||
oap->line_count = 2;
|
|
||||||
}
|
|
||||||
if (curwin->w_cursor.lnum + oap->line_count - 1 >
|
if (curwin->w_cursor.lnum + oap->line_count - 1 >
|
||||||
curbuf->b_ml.ml_line_count) {
|
curbuf->b_ml.ml_line_count) {
|
||||||
beep_flush();
|
beep_flush();
|
||||||
@@ -6509,9 +6451,7 @@ void finish_yankreg_from_object(yankreg_T *reg, bool clipboard_adjust)
|
|||||||
size_t maxlen = 0;
|
size_t maxlen = 0;
|
||||||
for (size_t i = 0; i < reg->y_size; i++) {
|
for (size_t i = 0; i < reg->y_size; i++) {
|
||||||
size_t rowlen = strlen(reg->y_array[i]);
|
size_t rowlen = strlen(reg->y_array[i]);
|
||||||
if (rowlen > maxlen) {
|
maxlen = MAX(maxlen, rowlen);
|
||||||
maxlen = rowlen;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
assert(maxlen <= INT_MAX);
|
assert(maxlen <= INT_MAX);
|
||||||
reg->y_width = MAX(reg->y_width, (int)maxlen - 1);
|
reg->y_width = MAX(reg->y_width, (int)maxlen - 1);
|
||||||
@@ -6615,9 +6555,7 @@ static bool get_clipboard(int name, yankreg_T **target, bool quiet)
|
|||||||
size_t maxlen = 0;
|
size_t maxlen = 0;
|
||||||
for (size_t i = 0; i < reg->y_size; i++) {
|
for (size_t i = 0; i < reg->y_size; i++) {
|
||||||
size_t rowlen = strlen(reg->y_array[i]);
|
size_t rowlen = strlen(reg->y_array[i]);
|
||||||
if (rowlen > maxlen) {
|
maxlen = MAX(maxlen, rowlen);
|
||||||
maxlen = rowlen;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
assert(maxlen <= INT_MAX);
|
assert(maxlen <= INT_MAX);
|
||||||
reg->y_width = (int)maxlen - 1;
|
reg->y_width = (int)maxlen - 1;
|
||||||
|
@@ -382,11 +382,7 @@ static int qf_init_process_nextline(qf_list_T *qfl, efm_T *fmt_first, qfstate_T
|
|||||||
int qf_init(win_T *wp, const char *restrict efile, char *restrict errorformat, int newlist,
|
int qf_init(win_T *wp, const char *restrict efile, char *restrict errorformat, int newlist,
|
||||||
const char *restrict qf_title, char *restrict enc)
|
const char *restrict qf_title, char *restrict enc)
|
||||||
{
|
{
|
||||||
qf_info_T *qi = &ql_info;
|
qf_info_T *qi = wp == NULL ? &ql_info : ll_get_or_alloc_list(wp);
|
||||||
|
|
||||||
if (wp != NULL) {
|
|
||||||
qi = ll_get_or_alloc_list(wp);
|
|
||||||
}
|
|
||||||
|
|
||||||
return qf_init_ext(qi, qi->qf_curlist, efile, curbuf, NULL, errorformat,
|
return qf_init_ext(qi, qi->qf_curlist, efile, curbuf, NULL, errorformat,
|
||||||
newlist, 0, 0, qf_title, enc);
|
newlist, 0, 0, qf_title, enc);
|
||||||
@@ -834,8 +830,7 @@ retry:
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
state->growbufsiz = (2 * state->growbufsiz < LINE_MAXLEN)
|
state->growbufsiz = MIN(2 * state->growbufsiz, LINE_MAXLEN);
|
||||||
? 2 * state->growbufsiz : LINE_MAXLEN;
|
|
||||||
state->growbuf = xrealloc(state->growbuf, state->growbufsiz);
|
state->growbuf = xrealloc(state->growbuf, state->growbufsiz);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -871,8 +866,7 @@ retry:
|
|||||||
xfree(state->growbuf);
|
xfree(state->growbuf);
|
||||||
state->linebuf = line;
|
state->linebuf = line;
|
||||||
state->growbuf = line;
|
state->growbuf = line;
|
||||||
state->growbufsiz = state->linelen < LINE_MAXLEN
|
state->growbufsiz = MIN(state->linelen, LINE_MAXLEN);
|
||||||
? state->linelen : LINE_MAXLEN;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1152,14 +1146,10 @@ static int qf_init_ext(qf_info_T *qi, int qf_idx, const char *restrict efile, bu
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
char *efm;
|
|
||||||
|
|
||||||
// Use the local value of 'errorformat' if it's set.
|
// Use the local value of 'errorformat' if it's set.
|
||||||
if (errorformat == p_efm && tv == NULL && buf && *buf->b_p_efm != NUL) {
|
char *efm = (errorformat == p_efm && tv == NULL && buf && *buf->b_p_efm != NUL)
|
||||||
efm = buf->b_p_efm;
|
? buf->b_p_efm
|
||||||
} else {
|
: errorformat;
|
||||||
efm = errorformat;
|
|
||||||
}
|
|
||||||
|
|
||||||
// If the errorformat didn't change between calls, then reuse the previously
|
// If the errorformat didn't change between calls, then reuse the previously
|
||||||
// parsed values.
|
// parsed values.
|
||||||
@@ -1491,9 +1481,7 @@ static int qf_parse_fmt_s(regmatch_T *rmp, int midx, qffields_T *fields)
|
|||||||
return QF_FAIL;
|
return QF_FAIL;
|
||||||
}
|
}
|
||||||
size_t len = (size_t)(rmp->endp[midx] - rmp->startp[midx]);
|
size_t len = (size_t)(rmp->endp[midx] - rmp->startp[midx]);
|
||||||
if (len > CMDBUFFSIZE - 5) {
|
len = MIN(len, CMDBUFFSIZE - 5);
|
||||||
len = CMDBUFFSIZE - 5;
|
|
||||||
}
|
|
||||||
STRCPY(fields->pattern, "^\\V");
|
STRCPY(fields->pattern, "^\\V");
|
||||||
xstrlcat(fields->pattern, rmp->startp[midx], len + 4);
|
xstrlcat(fields->pattern, rmp->startp[midx], len + 4);
|
||||||
fields->pattern[len + 3] = '\\';
|
fields->pattern[len + 3] = '\\';
|
||||||
@@ -1511,9 +1499,7 @@ static int qf_parse_fmt_o(regmatch_T *rmp, int midx, qffields_T *fields)
|
|||||||
}
|
}
|
||||||
size_t len = (size_t)(rmp->endp[midx] - rmp->startp[midx]);
|
size_t len = (size_t)(rmp->endp[midx] - rmp->startp[midx]);
|
||||||
size_t dsize = strlen(fields->module) + len + 1;
|
size_t dsize = strlen(fields->module) + len + 1;
|
||||||
if (dsize > CMDBUFFSIZE) {
|
dsize = MIN(dsize, CMDBUFFSIZE);
|
||||||
dsize = CMDBUFFSIZE;
|
|
||||||
}
|
|
||||||
xstrlcat(fields->module, rmp->startp[midx], dsize);
|
xstrlcat(fields->module, rmp->startp[midx], dsize);
|
||||||
return QF_OK;
|
return QF_OK;
|
||||||
}
|
}
|
||||||
@@ -2527,13 +2513,7 @@ static void win_set_loclist(win_T *wp, qf_info_T *qi)
|
|||||||
/// window.
|
/// window.
|
||||||
static int jump_to_help_window(qf_info_T *qi, bool newwin, bool *opened_window)
|
static int jump_to_help_window(qf_info_T *qi, bool newwin, bool *opened_window)
|
||||||
{
|
{
|
||||||
win_T *wp = NULL;
|
win_T *wp = (cmdmod.cmod_tab != 0 || newwin) ? NULL : qf_find_help_win();
|
||||||
|
|
||||||
if (cmdmod.cmod_tab != 0 || newwin) {
|
|
||||||
wp = NULL;
|
|
||||||
} else {
|
|
||||||
wp = qf_find_help_win();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (wp != NULL && wp->w_buffer->b_nwindows > 0) {
|
if (wp != NULL && wp->w_buffer->b_nwindows > 0) {
|
||||||
win_enter(wp, true);
|
win_enter(wp, true);
|
||||||
@@ -2882,9 +2862,7 @@ static void qf_jump_goto_line(linenr_T qf_lnum, int qf_col, char qf_viscol, char
|
|||||||
// Go to line with error, unless qf_lnum is 0.
|
// Go to line with error, unless qf_lnum is 0.
|
||||||
linenr_T i = qf_lnum;
|
linenr_T i = qf_lnum;
|
||||||
if (i > 0) {
|
if (i > 0) {
|
||||||
if (i > curbuf->b_ml.ml_line_count) {
|
i = MIN(i, curbuf->b_ml.ml_line_count);
|
||||||
i = curbuf->b_ml.ml_line_count;
|
|
||||||
}
|
|
||||||
curwin->w_cursor.lnum = i;
|
curwin->w_cursor.lnum = i;
|
||||||
}
|
}
|
||||||
if (qf_col > 0) {
|
if (qf_col > 0) {
|
||||||
@@ -3898,13 +3876,8 @@ static bool qf_win_pos_update(qf_info_T *qi, int old_qf_index)
|
|||||||
if (win != NULL
|
if (win != NULL
|
||||||
&& qf_index <= win->w_buffer->b_ml.ml_line_count
|
&& qf_index <= win->w_buffer->b_ml.ml_line_count
|
||||||
&& old_qf_index != qf_index) {
|
&& old_qf_index != qf_index) {
|
||||||
if (qf_index > old_qf_index) {
|
win->w_redraw_top = MIN(old_qf_index, qf_index);
|
||||||
win->w_redraw_top = old_qf_index;
|
win->w_redraw_bot = MAX(old_qf_index, qf_index);
|
||||||
win->w_redraw_bot = qf_index;
|
|
||||||
} else {
|
|
||||||
win->w_redraw_top = qf_index;
|
|
||||||
win->w_redraw_bot = old_qf_index;
|
|
||||||
}
|
|
||||||
qf_win_goto(win, qf_index);
|
qf_win_goto(win, qf_index);
|
||||||
}
|
}
|
||||||
return win != NULL;
|
return win != NULL;
|
||||||
@@ -4220,11 +4193,7 @@ static void qf_fill_buffer(qf_list_T *qfl, buf_T *buf, qfline_T *old_last, int q
|
|||||||
qfp = qfl->qf_start;
|
qfp = qfl->qf_start;
|
||||||
lnum = 0;
|
lnum = 0;
|
||||||
} else {
|
} else {
|
||||||
if (old_last->qf_next != NULL) {
|
qfp = old_last->qf_next != NULL ? old_last->qf_next : old_last;
|
||||||
qfp = old_last->qf_next;
|
|
||||||
} else {
|
|
||||||
qfp = old_last;
|
|
||||||
}
|
|
||||||
lnum = buf->b_ml.ml_line_count;
|
lnum = buf->b_ml.ml_line_count;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -4451,15 +4420,11 @@ void ex_make(exarg_T *eap)
|
|||||||
|
|
||||||
incr_quickfix_busy();
|
incr_quickfix_busy();
|
||||||
|
|
||||||
char *errorformat = p_efm;
|
char *errorformat = (eap->cmdidx != CMD_make && eap->cmdidx != CMD_lmake)
|
||||||
bool newlist = true;
|
? p_gefm
|
||||||
|
: p_efm;
|
||||||
|
|
||||||
if (eap->cmdidx != CMD_make && eap->cmdidx != CMD_lmake) {
|
bool newlist = eap->cmdidx != CMD_grepadd && eap->cmdidx != CMD_lgrepadd;
|
||||||
errorformat = p_gefm;
|
|
||||||
}
|
|
||||||
if (eap->cmdidx == CMD_grepadd || eap->cmdidx == CMD_lgrepadd) {
|
|
||||||
newlist = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
int res = qf_init(wp, fname, errorformat, newlist, qf_cmdtitle(*eap->cmdlinep), enc);
|
int res = qf_init(wp, fname, errorformat, newlist, qf_cmdtitle(*eap->cmdlinep), enc);
|
||||||
|
|
||||||
@@ -5323,9 +5288,7 @@ static bool vgr_match_buflines(qf_list_T *qfl, char *fname, buf_T *buf, char *sp
|
|||||||
{
|
{
|
||||||
bool found_match = false;
|
bool found_match = false;
|
||||||
size_t pat_len = strlen(spat);
|
size_t pat_len = strlen(spat);
|
||||||
if (pat_len > MAX_FUZZY_MATCHES) {
|
pat_len = MIN(pat_len, MAX_FUZZY_MATCHES);
|
||||||
pat_len = MAX_FUZZY_MATCHES;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (linenr_T lnum = 1; lnum <= buf->b_ml.ml_line_count && *tomatch > 0; lnum++) {
|
for (linenr_T lnum = 1; lnum <= buf->b_ml.ml_line_count && *tomatch > 0; lnum++) {
|
||||||
colnr_T col = 0;
|
colnr_T col = 0;
|
||||||
@@ -5467,12 +5430,7 @@ static int vgr_process_args(exarg_T *eap, vgr_args_T *args)
|
|||||||
|
|
||||||
args->regmatch.regprog = NULL;
|
args->regmatch.regprog = NULL;
|
||||||
args->qf_title = xstrdup(qf_cmdtitle(*eap->cmdlinep));
|
args->qf_title = xstrdup(qf_cmdtitle(*eap->cmdlinep));
|
||||||
|
args->tomatch = eap->addr_count > 0 ? eap->line2 : MAXLNUM;
|
||||||
if (eap->addr_count > 0) {
|
|
||||||
args->tomatch = eap->line2;
|
|
||||||
} else {
|
|
||||||
args->tomatch = MAXLNUM;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get the search pattern: either white-separated or enclosed in //
|
// Get the search pattern: either white-separated or enclosed in //
|
||||||
char *p = skip_vimgrep_pat(eap->arg, &args->spat, &args->flags);
|
char *p = skip_vimgrep_pat(eap->arg, &args->spat, &args->flags);
|
||||||
@@ -6702,9 +6660,7 @@ static int qf_setprop_curidx(qf_info_T *qi, qf_list_T *qfl, const dictitem_T *di
|
|||||||
if (newidx < 1) { // sanity check
|
if (newidx < 1) { // sanity check
|
||||||
return FAIL;
|
return FAIL;
|
||||||
}
|
}
|
||||||
if (newidx > qfl->qf_count) {
|
newidx = MIN(newidx, qfl->qf_count);
|
||||||
newidx = qfl->qf_count;
|
|
||||||
}
|
|
||||||
const int old_qfidx = qfl->qf_index;
|
const int old_qfidx = qfl->qf_index;
|
||||||
qfline_T *const qf_ptr = get_nth_entry(qfl, newidx, &newidx);
|
qfline_T *const qf_ptr = get_nth_entry(qfl, newidx, &newidx);
|
||||||
if (qf_ptr == NULL) {
|
if (qf_ptr == NULL) {
|
||||||
@@ -6901,31 +6857,17 @@ static bool mark_quickfix_ctx(qf_info_T *qi, int copyID)
|
|||||||
/// "in use". So that garbage collection doesn't free the context.
|
/// "in use". So that garbage collection doesn't free the context.
|
||||||
bool set_ref_in_quickfix(int copyID)
|
bool set_ref_in_quickfix(int copyID)
|
||||||
{
|
{
|
||||||
bool abort = mark_quickfix_ctx(&ql_info, copyID);
|
if (mark_quickfix_ctx(&ql_info, copyID)
|
||||||
if (abort) {
|
|| mark_quickfix_user_data(&ql_info, copyID)
|
||||||
return abort;
|
|| set_ref_in_callback(&qftf_cb, copyID, NULL, NULL)) {
|
||||||
}
|
return true;
|
||||||
|
|
||||||
abort = mark_quickfix_user_data(&ql_info, copyID);
|
|
||||||
if (abort) {
|
|
||||||
return abort;
|
|
||||||
}
|
|
||||||
|
|
||||||
abort = set_ref_in_callback(&qftf_cb, copyID, NULL, NULL);
|
|
||||||
if (abort) {
|
|
||||||
return abort;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
FOR_ALL_TAB_WINDOWS(tp, win) {
|
FOR_ALL_TAB_WINDOWS(tp, win) {
|
||||||
if (win->w_llist != NULL) {
|
if (win->w_llist != NULL) {
|
||||||
abort = mark_quickfix_ctx(win->w_llist, copyID);
|
if (mark_quickfix_ctx(win->w_llist, copyID)
|
||||||
if (abort) {
|
|| mark_quickfix_user_data(win->w_llist, copyID)) {
|
||||||
return abort;
|
return true;
|
||||||
}
|
|
||||||
|
|
||||||
abort = mark_quickfix_user_data(win->w_llist, copyID);
|
|
||||||
if (abort) {
|
|
||||||
return abort;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -6933,14 +6875,13 @@ bool set_ref_in_quickfix(int copyID)
|
|||||||
// In a location list window and none of the other windows is
|
// In a location list window and none of the other windows is
|
||||||
// referring to this location list. Mark the location list
|
// referring to this location list. Mark the location list
|
||||||
// context as still in use.
|
// context as still in use.
|
||||||
abort = mark_quickfix_ctx(win->w_llist_ref, copyID);
|
if (mark_quickfix_ctx(win->w_llist_ref, copyID)) {
|
||||||
if (abort) {
|
return true;
|
||||||
return abort;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return abort;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Return the autocmd name for the :cbuffer Ex commands
|
/// Return the autocmd name for the :cbuffer Ex commands
|
||||||
|
@@ -947,11 +947,9 @@ int searchit(win_T *win, buf_T *buf, pos_T *pos, pos_T *end_pos, Direction dir,
|
|||||||
// This message is also remembered in keep_msg for when the screen
|
// This message is also remembered in keep_msg for when the screen
|
||||||
// is redrawn. The keep_msg is cleared whenever another message is
|
// is redrawn. The keep_msg is cleared whenever another message is
|
||||||
// written.
|
// written.
|
||||||
if (dir == BACKWARD) { // start second loop at the other end
|
lnum = dir == BACKWARD // start second loop at the other end
|
||||||
lnum = buf->b_ml.ml_line_count;
|
? buf->b_ml.ml_line_count
|
||||||
} else {
|
: 1;
|
||||||
lnum = 1;
|
|
||||||
}
|
|
||||||
if (!shortmess(SHM_SEARCH)
|
if (!shortmess(SHM_SEARCH)
|
||||||
&& shortmess(SHM_SEARCHCOUNT)
|
&& shortmess(SHM_SEARCHCOUNT)
|
||||||
&& (options & SEARCH_MSG)) {
|
&& (options & SEARCH_MSG)) {
|
||||||
@@ -1053,7 +1051,6 @@ static int first_submatch(regmmatch_T *rp)
|
|||||||
int do_search(oparg_T *oap, int dirc, int search_delim, char *pat, size_t patlen, int count,
|
int do_search(oparg_T *oap, int dirc, int search_delim, char *pat, size_t patlen, int count,
|
||||||
int options, searchit_arg_T *sia)
|
int options, searchit_arg_T *sia)
|
||||||
{
|
{
|
||||||
pos_T pos; // position of the last match
|
|
||||||
char *searchstr;
|
char *searchstr;
|
||||||
size_t searchstrlen;
|
size_t searchstrlen;
|
||||||
int retval; // Return value
|
int retval; // Return value
|
||||||
@@ -1078,7 +1075,8 @@ int do_search(oparg_T *oap, int dirc, int search_delim, char *pat, size_t patlen
|
|||||||
// (there is no "if ()" around this because gcc wants them initialized)
|
// (there is no "if ()" around this because gcc wants them initialized)
|
||||||
SearchOffset old_off = spats[0].off;
|
SearchOffset old_off = spats[0].off;
|
||||||
|
|
||||||
pos = curwin->w_cursor; // start searching at the cursor position
|
pos_T pos = curwin->w_cursor; // Position of the last match.
|
||||||
|
// Start searching at the cursor position.
|
||||||
|
|
||||||
// Find out the direction of the search.
|
// Find out the direction of the search.
|
||||||
if (dirc == 0) {
|
if (dirc == 0) {
|
||||||
@@ -1088,11 +1086,7 @@ int do_search(oparg_T *oap, int dirc, int search_delim, char *pat, size_t patlen
|
|||||||
set_vv_searchforward();
|
set_vv_searchforward();
|
||||||
}
|
}
|
||||||
if (options & SEARCH_REV) {
|
if (options & SEARCH_REV) {
|
||||||
if (dirc == '/') {
|
dirc = dirc == '/' ? '?' : '/';
|
||||||
dirc = '?';
|
|
||||||
} else {
|
|
||||||
dirc = '/';
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// If the cursor is in a closed fold, don't find another match in the same
|
// If the cursor is in a closed fold, don't find another match in the same
|
||||||
@@ -1564,11 +1558,9 @@ int searchc(cmdarg_T *cap, bool t_cmd)
|
|||||||
if (*lastc == NUL && lastc_bytelen <= 1) {
|
if (*lastc == NUL && lastc_bytelen <= 1) {
|
||||||
return FAIL;
|
return FAIL;
|
||||||
}
|
}
|
||||||
if (dir) { // repeat in opposite direction
|
dir = dir // repeat in opposite direction
|
||||||
dir = -lastcdir;
|
? -lastcdir
|
||||||
} else {
|
: lastcdir;
|
||||||
dir = lastcdir;
|
|
||||||
}
|
|
||||||
t_cmd = last_t_cmd;
|
t_cmd = last_t_cmd;
|
||||||
c = *lastc;
|
c = *lastc;
|
||||||
// For multi-byte re-use last lastc_bytes[] and lastc_bytelen.
|
// For multi-byte re-use last lastc_bytes[] and lastc_bytelen.
|
||||||
@@ -1581,11 +1573,7 @@ int searchc(cmdarg_T *cap, bool t_cmd)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dir == BACKWARD) {
|
cap->oap->inclusive = dir != BACKWARD;
|
||||||
cap->oap->inclusive = false;
|
|
||||||
} else {
|
|
||||||
cap->oap->inclusive = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
char *p = get_cursor_line_ptr();
|
char *p = get_cursor_line_ptr();
|
||||||
int col = curwin->w_cursor.col;
|
int col = curwin->w_cursor.col;
|
||||||
@@ -2432,17 +2420,13 @@ int current_search(int count, bool forward)
|
|||||||
dec_cursor();
|
dec_cursor();
|
||||||
}
|
}
|
||||||
|
|
||||||
pos_T end_pos; // end position of the pattern match
|
|
||||||
pos_T orig_pos; // position of the cursor at beginning
|
|
||||||
pos_T pos; // position after the pattern
|
|
||||||
int result; // result of various function calls
|
|
||||||
|
|
||||||
// When searching forward and the cursor is at the start of the Visual
|
// When searching forward and the cursor is at the start of the Visual
|
||||||
// area, skip the first search backward, otherwise it doesn't move.
|
// area, skip the first search backward, otherwise it doesn't move.
|
||||||
const bool skip_first_backward = forward && VIsual_active
|
const bool skip_first_backward = forward && VIsual_active
|
||||||
&& lt(curwin->w_cursor, VIsual);
|
&& lt(curwin->w_cursor, VIsual);
|
||||||
|
|
||||||
orig_pos = pos = curwin->w_cursor;
|
pos_T pos = curwin->w_cursor; // position after the pattern
|
||||||
|
pos_T orig_pos = curwin->w_cursor; // position of the cursor at beginning
|
||||||
if (VIsual_active) {
|
if (VIsual_active) {
|
||||||
// Searching further will extend the match.
|
// Searching further will extend the match.
|
||||||
if (forward) {
|
if (forward) {
|
||||||
@@ -2459,6 +2443,9 @@ int current_search(int count, bool forward)
|
|||||||
return FAIL; // pattern not found
|
return FAIL; // pattern not found
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pos_T end_pos; // end position of the pattern match
|
||||||
|
int result; // result of various function calls
|
||||||
|
|
||||||
// The trick is to first search backwards and then search forward again,
|
// The trick is to first search backwards and then search forward again,
|
||||||
// so that a match at the current cursor position will be correctly
|
// so that a match at the current cursor position will be correctly
|
||||||
// captured. When "forward" is false do it the other way around.
|
// captured. When "forward" is false do it the other way around.
|
||||||
@@ -3238,9 +3225,8 @@ static int fuzzy_match_item_compare(const void *const s1, const void *const s2)
|
|||||||
|
|
||||||
if (v1 == v2) {
|
if (v1 == v2) {
|
||||||
return idx1 == idx2 ? 0 : idx1 > idx2 ? 1 : -1;
|
return idx1 == idx2 ? 0 : idx1 > idx2 ? 1 : -1;
|
||||||
} else {
|
|
||||||
return v1 > v2 ? -1 : 1;
|
|
||||||
}
|
}
|
||||||
|
return v1 > v2 ? -1 : 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Fuzzy search the string "str" in a list of "items" and return the matching
|
/// Fuzzy search the string "str" in a list of "items" and return the matching
|
||||||
@@ -3514,9 +3500,8 @@ static int fuzzy_match_func_compare(const void *const s1, const void *const s2)
|
|||||||
}
|
}
|
||||||
if (v1 == v2) {
|
if (v1 == v2) {
|
||||||
return idx1 == idx2 ? 0 : idx1 > idx2 ? 1 : -1;
|
return idx1 == idx2 ? 0 : idx1 > idx2 ? 1 : -1;
|
||||||
} else {
|
|
||||||
return v1 > v2 ? -1 : 1;
|
|
||||||
}
|
}
|
||||||
|
return v1 > v2 ? -1 : 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Sort fuzzy matches of function names by score.
|
/// Sort fuzzy matches of function names by score.
|
||||||
@@ -3704,13 +3689,8 @@ void find_pattern_in_path(char *ptr, Direction dir, size_t len, bool whole, bool
|
|||||||
int old_files = max_path_depth;
|
int old_files = max_path_depth;
|
||||||
int depth = depth_displayed = -1;
|
int depth = depth_displayed = -1;
|
||||||
|
|
||||||
linenr_T lnum = start_lnum;
|
end_lnum = MIN(end_lnum, curbuf->b_ml.ml_line_count);
|
||||||
if (end_lnum > curbuf->b_ml.ml_line_count) {
|
linenr_T lnum = MIN(start_lnum, end_lnum); // do at least one line
|
||||||
end_lnum = curbuf->b_ml.ml_line_count;
|
|
||||||
}
|
|
||||||
if (lnum > end_lnum) { // do at least one line
|
|
||||||
lnum = end_lnum;
|
|
||||||
}
|
|
||||||
char *line = get_line_and_copy(lnum, file_line);
|
char *line = get_line_and_copy(lnum, file_line);
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
@@ -4159,9 +4139,7 @@ exit_matched:
|
|||||||
depth--;
|
depth--;
|
||||||
curr_fname = (depth == -1) ? curbuf->b_fname
|
curr_fname = (depth == -1) ? curbuf->b_fname
|
||||||
: files[depth].name;
|
: files[depth].name;
|
||||||
if (depth < depth_displayed) {
|
depth_displayed = MIN(depth_displayed, depth);
|
||||||
depth_displayed = depth;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (depth >= 0) { // we could read the line
|
if (depth >= 0) { // we could read the line
|
||||||
files[depth].lnum++;
|
files[depth].lnum++;
|
||||||
|
@@ -223,18 +223,15 @@ static uint8_t sha256_padding[SHA256_BUFFER_SIZE] = {
|
|||||||
|
|
||||||
void sha256_finish(context_sha256_T *ctx, uint8_t digest[SHA256_SUM_SIZE])
|
void sha256_finish(context_sha256_T *ctx, uint8_t digest[SHA256_SUM_SIZE])
|
||||||
{
|
{
|
||||||
uint32_t last, padn;
|
uint32_t high = (ctx->total[0] >> 29) | (ctx->total[1] << 3);
|
||||||
uint32_t high, low;
|
uint32_t low = (ctx->total[0] << 3);
|
||||||
|
|
||||||
uint8_t msglen[8];
|
uint8_t msglen[8];
|
||||||
|
|
||||||
high = (ctx->total[0] >> 29) | (ctx->total[1] << 3);
|
|
||||||
low = (ctx->total[0] << 3);
|
|
||||||
|
|
||||||
PUT_UINT32(high, msglen, 0);
|
PUT_UINT32(high, msglen, 0);
|
||||||
PUT_UINT32(low, msglen, 4);
|
PUT_UINT32(low, msglen, 4);
|
||||||
|
|
||||||
last = ctx->total[0] & 0x3F;
|
uint32_t last = ctx->total[0] & 0x3F;
|
||||||
padn = (last < 56) ? (56 - last) : (120 - last);
|
uint32_t padn = (last < 56) ? (56 - last) : (120 - last);
|
||||||
|
|
||||||
sha256_update(ctx, sha256_padding, padn);
|
sha256_update(ctx, sha256_padding, padn);
|
||||||
sha256_update(ctx, msglen, 8);
|
sha256_update(ctx, msglen, 8);
|
||||||
@@ -263,18 +260,18 @@ void sha256_finish(context_sha256_T *ctx, uint8_t digest[SHA256_SUM_SIZE])
|
|||||||
const char *sha256_bytes(const uint8_t *restrict buf, size_t buf_len, const uint8_t *restrict salt,
|
const char *sha256_bytes(const uint8_t *restrict buf, size_t buf_len, const uint8_t *restrict salt,
|
||||||
size_t salt_len)
|
size_t salt_len)
|
||||||
{
|
{
|
||||||
uint8_t sha256sum[SHA256_SUM_SIZE];
|
|
||||||
static char hexit[SHA256_BUFFER_SIZE + 1]; // buf size + NULL
|
static char hexit[SHA256_BUFFER_SIZE + 1]; // buf size + NULL
|
||||||
context_sha256_T ctx;
|
|
||||||
|
|
||||||
sha256_self_test();
|
sha256_self_test();
|
||||||
|
|
||||||
|
context_sha256_T ctx;
|
||||||
sha256_start(&ctx);
|
sha256_start(&ctx);
|
||||||
sha256_update(&ctx, buf, buf_len);
|
sha256_update(&ctx, buf, buf_len);
|
||||||
|
|
||||||
if (salt != NULL) {
|
if (salt != NULL) {
|
||||||
sha256_update(&ctx, salt, salt_len);
|
sha256_update(&ctx, salt, salt_len);
|
||||||
}
|
}
|
||||||
|
uint8_t sha256sum[SHA256_SUM_SIZE];
|
||||||
sha256_finish(&ctx, sha256sum);
|
sha256_finish(&ctx, sha256sum);
|
||||||
|
|
||||||
for (size_t j = 0; j < SHA256_SUM_SIZE; j++) {
|
for (size_t j = 0; j < SHA256_SUM_SIZE; j++) {
|
||||||
|
@@ -276,7 +276,6 @@ static bool can_be_compound(trystate_T *sp, slang_T *slang, uint8_t *compflags,
|
|||||||
static int score_wordcount_adj(slang_T *slang, int score, char *word, bool split)
|
static int score_wordcount_adj(slang_T *slang, int score, char *word, bool split)
|
||||||
{
|
{
|
||||||
int bonus;
|
int bonus;
|
||||||
int newscore;
|
|
||||||
|
|
||||||
hashitem_T *hi = hash_find(&slang->sl_wordcount, word);
|
hashitem_T *hi = hash_find(&slang->sl_wordcount, word);
|
||||||
if (HASHITEM_EMPTY(hi)) {
|
if (HASHITEM_EMPTY(hi)) {
|
||||||
@@ -291,11 +290,8 @@ static int score_wordcount_adj(slang_T *slang, int score, char *word, bool split
|
|||||||
} else {
|
} else {
|
||||||
bonus = SCORE_COMMON3;
|
bonus = SCORE_COMMON3;
|
||||||
}
|
}
|
||||||
if (split) {
|
int newscore = split ? score - bonus / 2
|
||||||
newscore = score - bonus / 2;
|
: score - bonus;
|
||||||
} else {
|
|
||||||
newscore = score - bonus;
|
|
||||||
}
|
|
||||||
if (newscore < 0) {
|
if (newscore < 0) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -449,7 +445,6 @@ void spell_suggest(int count)
|
|||||||
suginfo_T sug;
|
suginfo_T sug;
|
||||||
suggest_T *stp;
|
suggest_T *stp;
|
||||||
bool mouse_used;
|
bool mouse_used;
|
||||||
int limit;
|
|
||||||
int selected = count;
|
int selected = count;
|
||||||
int badlen = 0;
|
int badlen = 0;
|
||||||
int msg_scroll_save = msg_scroll;
|
int msg_scroll_save = msg_scroll;
|
||||||
@@ -481,9 +476,7 @@ void spell_suggest(int count)
|
|||||||
badlen++;
|
badlen++;
|
||||||
end_visual_mode();
|
end_visual_mode();
|
||||||
// make sure we don't include the NUL at the end of the line
|
// make sure we don't include the NUL at the end of the line
|
||||||
if (badlen > get_cursor_line_len() - curwin->w_cursor.col) {
|
badlen = MIN(badlen, get_cursor_line_len() - curwin->w_cursor.col);
|
||||||
badlen = get_cursor_line_len() - curwin->w_cursor.col;
|
|
||||||
}
|
|
||||||
// Find the start of the badly spelled word.
|
// Find the start of the badly spelled word.
|
||||||
} else if (spell_move_to(curwin, FORWARD, SMT_ALL, true, NULL) == 0
|
} else if (spell_move_to(curwin, FORWARD, SMT_ALL, true, NULL) == 0
|
||||||
|| curwin->w_cursor.col > prev_cursor.col) {
|
|| curwin->w_cursor.col > prev_cursor.col) {
|
||||||
@@ -519,11 +512,7 @@ void spell_suggest(int count)
|
|||||||
|
|
||||||
// Get the list of suggestions. Limit to 'lines' - 2 or the number in
|
// Get the list of suggestions. Limit to 'lines' - 2 or the number in
|
||||||
// 'spellsuggest', whatever is smaller.
|
// 'spellsuggest', whatever is smaller.
|
||||||
if (sps_limit > Rows - 2) {
|
int limit = MIN(sps_limit, Rows - 2);
|
||||||
limit = Rows - 2;
|
|
||||||
} else {
|
|
||||||
limit = sps_limit;
|
|
||||||
}
|
|
||||||
spell_find_suggest(line + curwin->w_cursor.col, badlen, &sug, limit,
|
spell_find_suggest(line + curwin->w_cursor.col, badlen, &sug, limit,
|
||||||
true, need_cap, true);
|
true, need_cap, true);
|
||||||
|
|
||||||
@@ -731,10 +720,7 @@ static void spell_find_suggest(char *badptr, int badlen, suginfo_T *su, int maxc
|
|||||||
}
|
}
|
||||||
su->su_maxcount = maxcount;
|
su->su_maxcount = maxcount;
|
||||||
su->su_maxscore = SCORE_MAXINIT;
|
su->su_maxscore = SCORE_MAXINIT;
|
||||||
|
su->su_badlen = MIN(su->su_badlen, MAXWLEN - 1); // just in case
|
||||||
if (su->su_badlen >= MAXWLEN) {
|
|
||||||
su->su_badlen = MAXWLEN - 1; // just in case
|
|
||||||
}
|
|
||||||
xmemcpyz(su->su_badword, su->su_badptr, (size_t)su->su_badlen);
|
xmemcpyz(su->su_badword, su->su_badptr, (size_t)su->su_badlen);
|
||||||
spell_casefold(curwin, su->su_badptr, su->su_badlen, su->su_fbadword,
|
spell_casefold(curwin, su->su_badptr, su->su_badlen, su->su_fbadword,
|
||||||
MAXWLEN);
|
MAXWLEN);
|
||||||
@@ -1145,7 +1131,6 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char *fword, bool soun
|
|||||||
idx_T *idxs, *fidxs, *pidxs;
|
idx_T *idxs, *fidxs, *pidxs;
|
||||||
int c, c2, c3;
|
int c, c2, c3;
|
||||||
int n = 0;
|
int n = 0;
|
||||||
garray_T *gap;
|
|
||||||
idx_T arridx;
|
idx_T arridx;
|
||||||
int fl = 0;
|
int fl = 0;
|
||||||
int tl;
|
int tl;
|
||||||
@@ -1736,11 +1721,8 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char *fword, bool soun
|
|||||||
// Done all bytes at this node, do next state. When still at
|
// Done all bytes at this node, do next state. When still at
|
||||||
// already changed bytes skip the other tricks.
|
// already changed bytes skip the other tricks.
|
||||||
PROF_STORE(sp->ts_state)
|
PROF_STORE(sp->ts_state)
|
||||||
if (sp->ts_fidx >= sp->ts_fidxtry) {
|
sp->ts_state = sp->ts_fidx >= sp->ts_fidxtry ? STATE_DEL
|
||||||
sp->ts_state = STATE_DEL;
|
: STATE_FINAL;
|
||||||
} else {
|
|
||||||
sp->ts_state = STATE_FINAL;
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
arridx += sp->ts_curi++;
|
arridx += sp->ts_curi++;
|
||||||
c = byts[arridx];
|
c = byts[arridx];
|
||||||
@@ -2254,11 +2236,8 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char *fword, bool soun
|
|||||||
// valid.
|
// valid.
|
||||||
p = fword + sp->ts_fidx;
|
p = fword + sp->ts_fidx;
|
||||||
|
|
||||||
if (soundfold) {
|
garray_T *gap = soundfold ? &slang->sl_repsal
|
||||||
gap = &slang->sl_repsal;
|
: &lp->lp_replang->sl_rep;
|
||||||
} else {
|
|
||||||
gap = &lp->lp_replang->sl_rep;
|
|
||||||
}
|
|
||||||
while (sp->ts_curi < gap->ga_len) {
|
while (sp->ts_curi < gap->ga_len) {
|
||||||
fromto_T *ftp = (fromto_T *)gap->ga_data + sp->ts_curi++;
|
fromto_T *ftp = (fromto_T *)gap->ga_data + sp->ts_curi++;
|
||||||
if (*ftp->ft_from != *p) {
|
if (*ftp->ft_from != *p) {
|
||||||
@@ -3126,11 +3105,9 @@ static void add_suggestion(suginfo_T *su, garray_T *gap, const char *goodword, i
|
|||||||
// the best suggestions.
|
// the best suggestions.
|
||||||
if (gap->ga_len > SUG_MAX_COUNT(su)) {
|
if (gap->ga_len > SUG_MAX_COUNT(su)) {
|
||||||
if (maxsf) {
|
if (maxsf) {
|
||||||
su->su_sfmaxscore = cleanup_suggestions(gap,
|
su->su_sfmaxscore = cleanup_suggestions(gap, su->su_sfmaxscore, SUG_CLEAN_COUNT(su));
|
||||||
su->su_sfmaxscore, SUG_CLEAN_COUNT(su));
|
|
||||||
} else {
|
} else {
|
||||||
su->su_maxscore = cleanup_suggestions(gap,
|
su->su_maxscore = cleanup_suggestions(gap, su->su_maxscore, SUG_CLEAN_COUNT(su));
|
||||||
su->su_maxscore, SUG_CLEAN_COUNT(su));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -3276,8 +3253,6 @@ static int soundalike_score(char *goodstart, char *badstart)
|
|||||||
{
|
{
|
||||||
char *goodsound = goodstart;
|
char *goodsound = goodstart;
|
||||||
char *badsound = badstart;
|
char *badsound = badstart;
|
||||||
char *pl, *ps;
|
|
||||||
char *pl2, *ps2;
|
|
||||||
int score = 0;
|
int score = 0;
|
||||||
|
|
||||||
// Adding/inserting "*" at the start (word starts with vowel) shouldn't be
|
// Adding/inserting "*" at the start (word starts with vowel) shouldn't be
|
||||||
@@ -3318,13 +3293,10 @@ static int soundalike_score(char *goodstart, char *badstart)
|
|||||||
return SCORE_MAXMAX;
|
return SCORE_MAXMAX;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (n > 0) {
|
// n > 0 : goodsound is longest
|
||||||
pl = goodsound; // goodsound is longest
|
// n <= 0 : badsound is longest
|
||||||
ps = badsound;
|
char *pl = n > 0 ? goodsound : badsound;
|
||||||
} else {
|
char *ps = n > 0 ? badsound : goodsound;
|
||||||
pl = badsound; // badsound is longest
|
|
||||||
ps = goodsound;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Skip over the identical part.
|
// Skip over the identical part.
|
||||||
while (*pl == *ps && *pl != NUL) {
|
while (*pl == *ps && *pl != NUL) {
|
||||||
@@ -3332,6 +3304,8 @@ static int soundalike_score(char *goodstart, char *badstart)
|
|||||||
ps++;
|
ps++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
char *pl2, *ps2;
|
||||||
|
|
||||||
switch (n) {
|
switch (n) {
|
||||||
case -2:
|
case -2:
|
||||||
case 2:
|
case 2:
|
||||||
@@ -3552,19 +3526,13 @@ static int spell_edit_score(slang_T *slang, const char *badword, const char *goo
|
|||||||
int pgc = wgoodword[j - 2];
|
int pgc = wgoodword[j - 2];
|
||||||
if (bc == pgc && pbc == gc) {
|
if (bc == pgc && pbc == gc) {
|
||||||
int t = SCORE_SWAP + CNT(i - 2, j - 2);
|
int t = SCORE_SWAP + CNT(i - 2, j - 2);
|
||||||
if (t < CNT(i, j)) {
|
CNT(i, j) = MIN(CNT(i, j), t);
|
||||||
CNT(i, j) = t;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
int t = SCORE_DEL + CNT(i - 1, j);
|
int t = SCORE_DEL + CNT(i - 1, j);
|
||||||
if (t < CNT(i, j)) {
|
CNT(i, j) = MIN(CNT(i, j), t);
|
||||||
CNT(i, j) = t;
|
|
||||||
}
|
|
||||||
t = SCORE_INS + CNT(i, j - 1);
|
t = SCORE_INS + CNT(i, j - 1);
|
||||||
if (t < CNT(i, j)) {
|
CNT(i, j) = MIN(CNT(i, j), t);
|
||||||
CNT(i, j) = t;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -123,10 +123,7 @@ void win_redr_status(win_T *wp)
|
|||||||
// len += (int)strlen(p + len); // dead assignment
|
// len += (int)strlen(p + len); // dead assignment
|
||||||
}
|
}
|
||||||
|
|
||||||
int this_ru_col = ru_col - (Columns - stl_width);
|
int this_ru_col = MAX(ru_col - (Columns - stl_width), (stl_width + 1) / 2);
|
||||||
if (this_ru_col < (stl_width + 1) / 2) {
|
|
||||||
this_ru_col = (stl_width + 1) / 2;
|
|
||||||
}
|
|
||||||
if (this_ru_col <= 1) {
|
if (this_ru_col <= 1) {
|
||||||
p = "<"; // No room for file name!
|
p = "<"; // No room for file name!
|
||||||
len = 1;
|
len = 1;
|
||||||
@@ -374,10 +371,7 @@ static void win_redr_custom(win_T *wp, bool draw_winbar, bool draw_ruler)
|
|||||||
stl = p_ruf;
|
stl = p_ruf;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
col = ru_col - (Columns - maxwidth);
|
col = MAX(ru_col - (Columns - maxwidth), (maxwidth + 1) / 2);
|
||||||
if (col < (maxwidth + 1) / 2) {
|
|
||||||
col = (maxwidth + 1) / 2;
|
|
||||||
}
|
|
||||||
maxwidth -= col;
|
maxwidth -= col;
|
||||||
if (!in_status_line) {
|
if (!in_status_line) {
|
||||||
grid = &msg_grid_adj;
|
grid = &msg_grid_adj;
|
||||||
@@ -574,15 +568,9 @@ void win_redr_ruler(win_T *wp)
|
|||||||
if (wp->w_status_height == 0 && !is_stl_global) { // can't use last char of screen
|
if (wp->w_status_height == 0 && !is_stl_global) { // can't use last char of screen
|
||||||
o++;
|
o++;
|
||||||
}
|
}
|
||||||
int this_ru_col = ru_col - (Columns - width);
|
|
||||||
if (this_ru_col < 0) {
|
|
||||||
this_ru_col = 0;
|
|
||||||
}
|
|
||||||
// Never use more than half the window/screen width, leave the other half
|
// Never use more than half the window/screen width, leave the other half
|
||||||
// for the filename.
|
// for the filename.
|
||||||
if (this_ru_col < (width + 1) / 2) {
|
int this_ru_col = MAX(ru_col - (Columns - width), (width + 1) / 2);
|
||||||
this_ru_col = (width + 1) / 2;
|
|
||||||
}
|
|
||||||
if (this_ru_col + o < width) {
|
if (this_ru_col + o < width) {
|
||||||
// Need at least 3 chars left for get_rel_pos() + NUL.
|
// Need at least 3 chars left for get_rel_pos() + NUL.
|
||||||
while (this_ru_col + o < width && RULER_BUF_LEN > i + 4) {
|
while (this_ru_col + o < width && RULER_BUF_LEN > i + 4) {
|
||||||
@@ -726,7 +714,6 @@ void draw_tabline(void)
|
|||||||
win_redr_custom(NULL, false, false);
|
win_redr_custom(NULL, false, false);
|
||||||
} else {
|
} else {
|
||||||
int tabcount = 0;
|
int tabcount = 0;
|
||||||
int tabwidth = 0;
|
|
||||||
int col = 0;
|
int col = 0;
|
||||||
win_T *cwp;
|
win_T *cwp;
|
||||||
int wincount;
|
int wincount;
|
||||||
@@ -735,13 +722,7 @@ void draw_tabline(void)
|
|||||||
tabcount++;
|
tabcount++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tabcount > 0) {
|
int tabwidth = MAX(tabcount > 0 ? (Columns - 1 + tabcount / 2) / tabcount : 0, 6);
|
||||||
tabwidth = (Columns - 1 + tabcount / 2) / tabcount;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (tabwidth < 6) {
|
|
||||||
tabwidth = 6;
|
|
||||||
}
|
|
||||||
|
|
||||||
int attr = attr_nosel;
|
int attr = attr_nosel;
|
||||||
tabcount = 0;
|
tabcount = 0;
|
||||||
@@ -810,9 +791,7 @@ void draw_tabline(void)
|
|||||||
len -= ptr2cells(p);
|
len -= ptr2cells(p);
|
||||||
MB_PTR_ADV(p);
|
MB_PTR_ADV(p);
|
||||||
}
|
}
|
||||||
if (len > Columns - col - 1) {
|
len = MIN(len, Columns - col - 1);
|
||||||
len = Columns - col - 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
grid_line_puts(col, p, -1, attr);
|
grid_line_puts(col, p, -1, attr);
|
||||||
col += len;
|
col += len;
|
||||||
@@ -1193,9 +1172,7 @@ int build_stl_str_hl(win_T *wp, char *out, size_t outlen, char *fmt, OptIndex op
|
|||||||
|
|
||||||
// If the item was partially or completely truncated, set its
|
// If the item was partially or completely truncated, set its
|
||||||
// start to the start of the group
|
// start to the start of the group
|
||||||
if (stl_items[idx].start < t) {
|
stl_items[idx].start = MAX(stl_items[idx].start, t);
|
||||||
stl_items[idx].start = t;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
// If the group is shorter than the minimum width, add padding characters.
|
// If the group is shorter than the minimum width, add padding characters.
|
||||||
} else if (abs(stl_items[stl_groupitems[groupdepth]].minwid) > group_len) {
|
} else if (abs(stl_items[stl_groupitems[groupdepth]].minwid) > group_len) {
|
||||||
|
136
src/nvim/tag.c
136
src/nvim/tag.c
@@ -586,11 +586,7 @@ void do_tag(char *tag, int type, int count, int forceit, bool verbose)
|
|||||||
|| type == DT_LTAG) {
|
|| type == DT_LTAG) {
|
||||||
cur_match = MAXCOL - 1;
|
cur_match = MAXCOL - 1;
|
||||||
}
|
}
|
||||||
if (type == DT_TAG) {
|
max_num_matches = type == DT_TAG ? MAXCOL : cur_match + 1;
|
||||||
max_num_matches = MAXCOL;
|
|
||||||
} else {
|
|
||||||
max_num_matches = cur_match + 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
// when the argument starts with '/', use it as a regexp
|
// when the argument starts with '/', use it as a regexp
|
||||||
if (!no_regexp && *name == '/') {
|
if (!no_regexp && *name == '/') {
|
||||||
@@ -600,12 +596,8 @@ void do_tag(char *tag, int type, int count, int forceit, bool verbose)
|
|||||||
flags = TAG_NOIC;
|
flags = TAG_NOIC;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (verbose) {
|
flags |= verbose ? TAG_VERBOSE : 0;
|
||||||
flags |= TAG_VERBOSE;
|
flags |= !use_tfu ? TAG_NO_TAGFUNC : 0;
|
||||||
}
|
|
||||||
if (!use_tfu) {
|
|
||||||
flags |= TAG_NO_TAGFUNC;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (find_tags(name, &new_num_matches, &new_matches, flags,
|
if (find_tags(name, &new_num_matches, &new_matches, flags,
|
||||||
max_num_matches, buf_ffname) == OK
|
max_num_matches, buf_ffname) == OK
|
||||||
@@ -815,10 +807,7 @@ static void print_tag_list(bool new_tag, bool use_tagstack, int num_matches, cha
|
|||||||
// Assume that the first match indicates how long the tags can
|
// Assume that the first match indicates how long the tags can
|
||||||
// be, and align the file names to that.
|
// be, and align the file names to that.
|
||||||
parse_match(matches[0], &tagp);
|
parse_match(matches[0], &tagp);
|
||||||
int taglen = (int)(tagp.tagname_end - tagp.tagname + 2);
|
int taglen = MAX((int)(tagp.tagname_end - tagp.tagname + 2), 18);
|
||||||
if (taglen < 18) {
|
|
||||||
taglen = 18;
|
|
||||||
}
|
|
||||||
if (taglen > Columns - 25) {
|
if (taglen > Columns - 25) {
|
||||||
taglen = MAXCOL;
|
taglen = MAXCOL;
|
||||||
}
|
}
|
||||||
@@ -999,10 +988,7 @@ static int add_llist_tags(char *tag, int num_matches, char **matches)
|
|||||||
parse_match(matches[i], &tagp);
|
parse_match(matches[i], &tagp);
|
||||||
|
|
||||||
// Save the tag name
|
// Save the tag name
|
||||||
int len = (int)(tagp.tagname_end - tagp.tagname);
|
int len = MIN((int)(tagp.tagname_end - tagp.tagname), 128);
|
||||||
if (len > 128) {
|
|
||||||
len = 128;
|
|
||||||
}
|
|
||||||
xmemcpyz(tag_name, tagp.tagname, (size_t)len);
|
xmemcpyz(tag_name, tagp.tagname, (size_t)len);
|
||||||
tag_name[len] = NUL;
|
tag_name[len] = NUL;
|
||||||
|
|
||||||
@@ -1063,10 +1049,7 @@ static int add_llist_tags(char *tag, int num_matches, char **matches)
|
|||||||
strcat(cmd, "\\V");
|
strcat(cmd, "\\V");
|
||||||
len += 2;
|
len += 2;
|
||||||
|
|
||||||
int cmd_len = (int)(cmd_end - cmd_start + 1);
|
int cmd_len = MIN((int)(cmd_end - cmd_start + 1), CMDBUFFSIZE - 5);
|
||||||
if (cmd_len > (CMDBUFFSIZE - 5)) {
|
|
||||||
cmd_len = CMDBUFFSIZE - 5;
|
|
||||||
}
|
|
||||||
snprintf(cmd + len, (size_t)(CMDBUFFSIZE + 1 - len),
|
snprintf(cmd + len, (size_t)(CMDBUFFSIZE + 1 - len),
|
||||||
"%.*s", cmd_len, cmd_start);
|
"%.*s", cmd_len, cmd_start);
|
||||||
len += cmd_len;
|
len += cmd_len;
|
||||||
@@ -1820,11 +1803,9 @@ static tagmatch_status_T findtags_parse_line(findtags_state_T *st, tagptrs_T *ta
|
|||||||
} else if (st->state == TS_STEP_FORWARD) {
|
} else if (st->state == TS_STEP_FORWARD) {
|
||||||
assert(cmplen >= 0);
|
assert(cmplen >= 0);
|
||||||
if (mb_strnicmp(tagpp->tagname, st->orgpat->head, (size_t)cmplen) != 0) {
|
if (mb_strnicmp(tagpp->tagname, st->orgpat->head, (size_t)cmplen) != 0) {
|
||||||
if ((off_T)vim_ftell(st->fp) > sinfo_p->match_offset) {
|
return ((off_T)vim_ftell(st->fp) > sinfo_p->match_offset)
|
||||||
return TAG_MATCH_STOP; // past last match
|
? TAG_MATCH_STOP // past last match
|
||||||
} else {
|
: TAG_MATCH_NEXT; // before first match
|
||||||
return TAG_MATCH_NEXT; // before first match
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// skip this match if it can't match
|
// skip this match if it can't match
|
||||||
@@ -1847,11 +1828,9 @@ static tagmatch_status_T findtags_parse_line(findtags_state_T *st, tagptrs_T *ta
|
|||||||
status = parse_tag_line(st->lbuf, tagpp);
|
status = parse_tag_line(st->lbuf, tagpp);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (status == FAIL) {
|
return status == FAIL
|
||||||
return TAG_MATCH_FAIL;
|
? TAG_MATCH_FAIL
|
||||||
}
|
: TAG_MATCH_SUCCESS;
|
||||||
|
|
||||||
return TAG_MATCH_SUCCESS;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Initialize the structure used for tag matching.
|
/// Initialize the structure used for tag matching.
|
||||||
@@ -1944,32 +1923,22 @@ static void findtags_add_match(findtags_state_T *st, tagptrs_T *tagpp, findtags_
|
|||||||
char *buf_ffname, hash_T *hash)
|
char *buf_ffname, hash_T *hash)
|
||||||
{
|
{
|
||||||
const bool name_only = (st->flags & TAG_NAMES);
|
const bool name_only = (st->flags & TAG_NAMES);
|
||||||
int mtt;
|
|
||||||
size_t len = 0;
|
size_t len = 0;
|
||||||
size_t mfp_size = 0;
|
size_t mfp_size = 0;
|
||||||
bool is_current; // file name matches
|
|
||||||
bool is_static; // current tag line is static
|
|
||||||
char *mfp;
|
char *mfp;
|
||||||
|
|
||||||
// Decide in which array to store this match.
|
// Decide in which array to store this match.
|
||||||
is_current = test_for_current(tagpp->fname, tagpp->fname_end,
|
bool is_current = test_for_current(tagpp->fname, tagpp->fname_end,
|
||||||
st->tag_fname, buf_ffname);
|
st->tag_fname, buf_ffname);
|
||||||
is_static = test_for_static(tagpp);
|
|
||||||
|
// current tag line is static
|
||||||
|
bool is_static = test_for_static(tagpp);
|
||||||
|
|
||||||
// Decide in which of the sixteen tables to store this match.
|
// Decide in which of the sixteen tables to store this match.
|
||||||
if (is_static) {
|
int mtt = is_static
|
||||||
if (is_current) {
|
? is_current ? MT_ST_CUR : MT_ST_OTH
|
||||||
mtt = MT_ST_CUR;
|
: is_current ? MT_GL_CUR : MT_GL_OTH;
|
||||||
} else {
|
|
||||||
mtt = MT_ST_OTH;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (is_current) {
|
|
||||||
mtt = MT_GL_CUR;
|
|
||||||
} else {
|
|
||||||
mtt = MT_GL_OTH;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (st->orgpat->regmatch.rm_ic && !margs->match_no_ic) {
|
if (st->orgpat->regmatch.rm_ic && !margs->match_no_ic) {
|
||||||
mtt += MT_IC_OFF;
|
mtt += MT_IC_OFF;
|
||||||
}
|
}
|
||||||
@@ -2237,13 +2206,11 @@ static void findtags_in_file(findtags_state_T *st, int flags, char *buf_ffname)
|
|||||||
static int findtags_copy_matches(findtags_state_T *st, char ***matchesp)
|
static int findtags_copy_matches(findtags_state_T *st, char ***matchesp)
|
||||||
{
|
{
|
||||||
const bool name_only = (st->flags & TAG_NAMES);
|
const bool name_only = (st->flags & TAG_NAMES);
|
||||||
char **matches;
|
|
||||||
|
|
||||||
if (st->match_count > 0) {
|
char **matches = st->match_count > 0
|
||||||
matches = xmalloc((size_t)st->match_count * sizeof(char *));
|
? xmalloc((size_t)st->match_count * sizeof(char *))
|
||||||
} else {
|
: NULL;
|
||||||
matches = NULL;
|
|
||||||
}
|
|
||||||
st->match_count = 0;
|
st->match_count = 0;
|
||||||
for (int mtt = 0; mtt < MT_COUNT; mtt++) {
|
for (int mtt = 0; mtt < MT_COUNT; mtt++) {
|
||||||
for (int i = 0; i < st->ga_match[mtt].ga_len; i++) {
|
for (int i = 0; i < st->ga_match[mtt].ga_len; i++) {
|
||||||
@@ -2956,13 +2923,13 @@ static int jumpto_tag(const char *lbuf_arg, int forceit, bool keep_help)
|
|||||||
p_ic = false; // don't ignore case now
|
p_ic = false; // don't ignore case now
|
||||||
p_scs = false;
|
p_scs = false;
|
||||||
linenr_T save_lnum = curwin->w_cursor.lnum;
|
linenr_T save_lnum = curwin->w_cursor.lnum;
|
||||||
if (tagp.tagline > 0) {
|
|
||||||
// start search before line from "line:" field
|
curwin->w_cursor.lnum = tagp.tagline > 0
|
||||||
curwin->w_cursor.lnum = tagp.tagline - 1;
|
// start search before line from "line:" field
|
||||||
} else {
|
? tagp.tagline - 1
|
||||||
// start search before first line
|
// start search before first line
|
||||||
curwin->w_cursor.lnum = 0;
|
: 0;
|
||||||
}
|
|
||||||
if (do_search(NULL, pbuf[0], pbuf[0], pbuf + 1, pbuflen - 1, 1,
|
if (do_search(NULL, pbuf[0], pbuf[0], pbuf + 1, pbuflen - 1, 1,
|
||||||
search_options, NULL)) {
|
search_options, NULL)) {
|
||||||
retval = OK;
|
retval = OK;
|
||||||
@@ -3197,18 +3164,12 @@ void tagstack_clear_entry(taggy_T *item)
|
|||||||
/// @param tagnames expand tag names
|
/// @param tagnames expand tag names
|
||||||
int expand_tags(bool tagnames, char *pat, int *num_file, char ***file)
|
int expand_tags(bool tagnames, char *pat, int *num_file, char ***file)
|
||||||
{
|
{
|
||||||
int extra_flag;
|
|
||||||
size_t name_buf_size = 100;
|
size_t name_buf_size = 100;
|
||||||
tagptrs_T t_p;
|
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
char *name_buf = xmalloc(name_buf_size);
|
char *name_buf = xmalloc(name_buf_size);
|
||||||
|
|
||||||
if (tagnames) {
|
int extra_flag = tagnames ? TAG_NAMES : 0;
|
||||||
extra_flag = TAG_NAMES;
|
|
||||||
} else {
|
|
||||||
extra_flag = 0;
|
|
||||||
}
|
|
||||||
if (pat[0] == '/') {
|
if (pat[0] == '/') {
|
||||||
ret = find_tags(pat + 1, num_file, file,
|
ret = find_tags(pat + 1, num_file, file,
|
||||||
TAG_REGEXP | extra_flag | TAG_VERBOSE | TAG_NO_TAGFUNC,
|
TAG_REGEXP | extra_flag | TAG_VERBOSE | TAG_NO_TAGFUNC,
|
||||||
@@ -3222,10 +3183,9 @@ int expand_tags(bool tagnames, char *pat, int *num_file, char ***file)
|
|||||||
// Reorganize the tags for display and matching as strings of:
|
// Reorganize the tags for display and matching as strings of:
|
||||||
// "<tagname>\0<kind>\0<filename>\0"
|
// "<tagname>\0<kind>\0<filename>\0"
|
||||||
for (int i = 0; i < *num_file; i++) {
|
for (int i = 0; i < *num_file; i++) {
|
||||||
size_t len;
|
tagptrs_T t_p;
|
||||||
|
|
||||||
parse_match((*file)[i], &t_p);
|
parse_match((*file)[i], &t_p);
|
||||||
len = (size_t)(t_p.tagname_end - t_p.tagname);
|
size_t len = (size_t)(t_p.tagname_end - t_p.tagname);
|
||||||
if (len > name_buf_size - 3) {
|
if (len > name_buf_size - 3) {
|
||||||
name_buf_size = len + 3;
|
name_buf_size = len + 3;
|
||||||
char *buf = xrealloc(name_buf, name_buf_size);
|
char *buf = xrealloc(name_buf, name_buf_size);
|
||||||
@@ -3254,8 +3214,6 @@ int expand_tags(bool tagnames, char *pat, int *num_file, char ***file)
|
|||||||
static int add_tag_field(dict_T *dict, const char *field_name, const char *start, const char *end)
|
static int add_tag_field(dict_T *dict, const char *field_name, const char *start, const char *end)
|
||||||
FUNC_ATTR_NONNULL_ARG(1, 2)
|
FUNC_ATTR_NONNULL_ARG(1, 2)
|
||||||
{
|
{
|
||||||
int len = 0;
|
|
||||||
|
|
||||||
// Check that the field name doesn't exist yet.
|
// Check that the field name doesn't exist yet.
|
||||||
if (tv_dict_find(dict, field_name, -1) != NULL) {
|
if (tv_dict_find(dict, field_name, -1) != NULL) {
|
||||||
if (p_verbose > 0) {
|
if (p_verbose > 0) {
|
||||||
@@ -3265,6 +3223,7 @@ static int add_tag_field(dict_T *dict, const char *field_name, const char *start
|
|||||||
}
|
}
|
||||||
return FAIL;
|
return FAIL;
|
||||||
}
|
}
|
||||||
|
int len = 0;
|
||||||
char *buf = xmalloc(MAXPATHL);
|
char *buf = xmalloc(MAXPATHL);
|
||||||
if (start != NULL) {
|
if (start != NULL) {
|
||||||
if (end == NULL) {
|
if (end == NULL) {
|
||||||
@@ -3273,10 +3232,7 @@ static int add_tag_field(dict_T *dict, const char *field_name, const char *start
|
|||||||
end--;
|
end--;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
len = (int)(end - start);
|
len = MIN((int)(end - start), MAXPATHL - 1);
|
||||||
if (len > MAXPATHL - 1) {
|
|
||||||
len = MAXPATHL - 1;
|
|
||||||
}
|
|
||||||
xmemcpyz(buf, start, (size_t)len);
|
xmemcpyz(buf, start, (size_t)len);
|
||||||
}
|
}
|
||||||
buf[len] = NUL;
|
buf[len] = NUL;
|
||||||
@@ -3455,9 +3411,7 @@ static void tagstack_push_item(win_T *wp, char *tagname, int cur_fnum, int cur_m
|
|||||||
tagstack[idx].tagname = tagname;
|
tagstack[idx].tagname = tagname;
|
||||||
tagstack[idx].cur_fnum = cur_fnum;
|
tagstack[idx].cur_fnum = cur_fnum;
|
||||||
tagstack[idx].cur_match = cur_match;
|
tagstack[idx].cur_match = cur_match;
|
||||||
if (tagstack[idx].cur_match < 0) {
|
tagstack[idx].cur_match = MAX(tagstack[idx].cur_match, 0);
|
||||||
tagstack[idx].cur_match = 0;
|
|
||||||
}
|
|
||||||
tagstack[idx].fmark.mark = mark;
|
tagstack[idx].fmark.mark = mark;
|
||||||
tagstack[idx].fmark.fnum = fnum;
|
tagstack[idx].fmark.fnum = fnum;
|
||||||
tagstack[idx].user_data = user_data;
|
tagstack[idx].user_data = user_data;
|
||||||
@@ -3507,12 +3461,8 @@ static void tagstack_push_items(win_T *wp, list_T *l)
|
|||||||
static void tagstack_set_curidx(win_T *wp, int curidx)
|
static void tagstack_set_curidx(win_T *wp, int curidx)
|
||||||
{
|
{
|
||||||
wp->w_tagstackidx = curidx;
|
wp->w_tagstackidx = curidx;
|
||||||
if (wp->w_tagstackidx < 0) { // sanity check
|
// sanity check
|
||||||
wp->w_tagstackidx = 0;
|
wp->w_tagstackidx = MIN(MAX(wp->w_tagstackidx, 0), wp->w_tagstacklen);
|
||||||
}
|
|
||||||
if (wp->w_tagstackidx > wp->w_tagstacklen) {
|
|
||||||
wp->w_tagstackidx = wp->w_tagstacklen;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set the tag stack entries of the specified window.
|
// Set the tag stack entries of the specified window.
|
||||||
@@ -3523,15 +3473,15 @@ static void tagstack_set_curidx(win_T *wp, int curidx)
|
|||||||
int set_tagstack(win_T *wp, const dict_T *d, int action)
|
int set_tagstack(win_T *wp, const dict_T *d, int action)
|
||||||
FUNC_ATTR_NONNULL_ARG(1)
|
FUNC_ATTR_NONNULL_ARG(1)
|
||||||
{
|
{
|
||||||
dictitem_T *di;
|
|
||||||
list_T *l = NULL;
|
|
||||||
|
|
||||||
// not allowed to alter the tag stack entries from inside tagfunc
|
// not allowed to alter the tag stack entries from inside tagfunc
|
||||||
if (tfu_in_use) {
|
if (tfu_in_use) {
|
||||||
emsg(_(e_cannot_modify_tag_stack_within_tagfunc));
|
emsg(_(e_cannot_modify_tag_stack_within_tagfunc));
|
||||||
return FAIL;
|
return FAIL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
dictitem_T *di;
|
||||||
|
list_T *l = NULL;
|
||||||
|
|
||||||
if ((di = tv_dict_find(d, "items", -1)) != NULL) {
|
if ((di = tv_dict_find(d, "items", -1)) != NULL) {
|
||||||
if (di->di_tv.v_type != VAR_LIST) {
|
if (di->di_tv.v_type != VAR_LIST) {
|
||||||
emsg(_(e_listreq));
|
emsg(_(e_listreq));
|
||||||
|
@@ -1191,10 +1191,7 @@ static int term_sb_pop(int cols, VTermScreenCell *cells, void *data)
|
|||||||
memmove(term->sb_buffer, term->sb_buffer + 1,
|
memmove(term->sb_buffer, term->sb_buffer + 1,
|
||||||
sizeof(term->sb_buffer[0]) * (term->sb_current));
|
sizeof(term->sb_buffer[0]) * (term->sb_current));
|
||||||
|
|
||||||
size_t cols_to_copy = (size_t)cols;
|
size_t cols_to_copy = MIN((size_t)cols, sbrow->cols);
|
||||||
if (cols_to_copy > sbrow->cols) {
|
|
||||||
cols_to_copy = sbrow->cols;
|
|
||||||
}
|
|
||||||
|
|
||||||
// copy to vterm state
|
// copy to vterm state
|
||||||
memcpy(cells, sbrow->cells, sizeof(cells[0]) * cols_to_copy);
|
memcpy(cells, sbrow->cells, sizeof(cells[0]) * cols_to_copy);
|
||||||
|
@@ -348,9 +348,7 @@ void internal_format(int textwidth, int second_indent, int flags, bool format_on
|
|||||||
inc_cursor();
|
inc_cursor();
|
||||||
}
|
}
|
||||||
startcol -= curwin->w_cursor.col;
|
startcol -= curwin->w_cursor.col;
|
||||||
if (startcol < 0) {
|
startcol = MAX(startcol, 0);
|
||||||
startcol = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (State & VREPLACE_FLAG) {
|
if (State & VREPLACE_FLAG) {
|
||||||
// In MODE_VREPLACE state, we will backspace over the text to be
|
// In MODE_VREPLACE state, we will backspace over the text to be
|
||||||
@@ -433,9 +431,7 @@ void internal_format(int textwidth, int second_indent, int flags, bool format_on
|
|||||||
// may have added or removed indent.
|
// may have added or removed indent.
|
||||||
curwin->w_cursor.col += startcol;
|
curwin->w_cursor.col += startcol;
|
||||||
colnr_T len = get_cursor_line_len();
|
colnr_T len = get_cursor_line_len();
|
||||||
if (curwin->w_cursor.col > len) {
|
curwin->w_cursor.col = MIN(curwin->w_cursor.col, len);
|
||||||
curwin->w_cursor.col = len;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
haveto_redraw = true;
|
haveto_redraw = true;
|
||||||
@@ -758,14 +754,9 @@ int comp_textwidth(bool ff)
|
|||||||
textwidth -= 8;
|
textwidth -= 8;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (textwidth < 0) {
|
textwidth = MAX(textwidth, 0);
|
||||||
textwidth = 0;
|
|
||||||
}
|
|
||||||
if (ff && textwidth == 0) {
|
if (ff && textwidth == 0) {
|
||||||
textwidth = curwin->w_width_inner - 1;
|
textwidth = MIN(curwin->w_width_inner - 1, 79);
|
||||||
if (textwidth > 79) {
|
|
||||||
textwidth = 79;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return textwidth;
|
return textwidth;
|
||||||
}
|
}
|
||||||
@@ -1105,11 +1096,7 @@ void format_lines(linenr_T line_count, bool avoid_fex)
|
|||||||
}
|
}
|
||||||
first_par_line = false;
|
first_par_line = false;
|
||||||
// If the line is getting long, format it next time
|
// If the line is getting long, format it next time
|
||||||
if (get_cursor_line_len() > max_len) {
|
force_format = get_cursor_line_len() > max_len;
|
||||||
force_format = true;
|
|
||||||
} else {
|
|
||||||
force_format = false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
line_breakcheck();
|
line_breakcheck();
|
||||||
|
@@ -1269,11 +1269,7 @@ int current_par(oparg_T *oap, int count, bool include, int type)
|
|||||||
// When visual area is more than one line: extend it.
|
// When visual area is more than one line: extend it.
|
||||||
if (VIsual_active && start_lnum != VIsual.lnum) {
|
if (VIsual_active && start_lnum != VIsual.lnum) {
|
||||||
extend:
|
extend:
|
||||||
if (start_lnum < VIsual.lnum) {
|
dir = start_lnum < VIsual.lnum ? BACKWARD : FORWARD;
|
||||||
dir = BACKWARD;
|
|
||||||
} else {
|
|
||||||
dir = FORWARD;
|
|
||||||
}
|
|
||||||
for (int i = count; --i >= 0;) {
|
for (int i = count; --i >= 0;) {
|
||||||
if (start_lnum ==
|
if (start_lnum ==
|
||||||
(dir == BACKWARD ? 1 : curbuf->b_ml.ml_line_count)) {
|
(dir == BACKWARD ? 1 : curbuf->b_ml.ml_line_count)) {
|
||||||
|
@@ -1132,17 +1132,11 @@ static void serialize_pos(bufinfo_T *bi, pos_T pos)
|
|||||||
static void unserialize_pos(bufinfo_T *bi, pos_T *pos)
|
static void unserialize_pos(bufinfo_T *bi, pos_T *pos)
|
||||||
{
|
{
|
||||||
pos->lnum = undo_read_4c(bi);
|
pos->lnum = undo_read_4c(bi);
|
||||||
if (pos->lnum < 0) {
|
pos->lnum = MAX(pos->lnum, 0);
|
||||||
pos->lnum = 0;
|
|
||||||
}
|
|
||||||
pos->col = undo_read_4c(bi);
|
pos->col = undo_read_4c(bi);
|
||||||
if (pos->col < 0) {
|
pos->col = MAX(pos->col, 0);
|
||||||
pos->col = 0;
|
|
||||||
}
|
|
||||||
pos->coladd = undo_read_4c(bi);
|
pos->coladd = undo_read_4c(bi);
|
||||||
if (pos->coladd < 0) {
|
pos->coladd = MAX(pos->coladd, 0);
|
||||||
pos->coladd = 0;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Serializes "info".
|
/// Serializes "info".
|
||||||
@@ -1209,14 +1203,12 @@ void u_write_undo(const char *const name, const bool forceit, buf_T *const buf,
|
|||||||
// Strip any sticky and executable bits.
|
// Strip any sticky and executable bits.
|
||||||
perm = perm & 0666;
|
perm = perm & 0666;
|
||||||
|
|
||||||
int fd;
|
|
||||||
|
|
||||||
// If the undo file already exists, verify that it actually is an undo
|
// If the undo file already exists, verify that it actually is an undo
|
||||||
// file, and delete it.
|
// file, and delete it.
|
||||||
if (os_path_exists(file_name)) {
|
if (os_path_exists(file_name)) {
|
||||||
if (name == NULL || !forceit) {
|
if (name == NULL || !forceit) {
|
||||||
// Check we can read it and it's an undo file.
|
// Check we can read it and it's an undo file.
|
||||||
fd = os_open(file_name, O_RDONLY, 0);
|
int fd = os_open(file_name, O_RDONLY, 0);
|
||||||
if (fd < 0) {
|
if (fd < 0) {
|
||||||
if (name != NULL || p_verbose > 0) {
|
if (name != NULL || p_verbose > 0) {
|
||||||
if (name == NULL) {
|
if (name == NULL) {
|
||||||
@@ -1261,7 +1253,7 @@ void u_write_undo(const char *const name, const bool forceit, buf_T *const buf,
|
|||||||
goto theend;
|
goto theend;
|
||||||
}
|
}
|
||||||
|
|
||||||
fd = os_open(file_name, O_CREAT|O_WRONLY|O_EXCL|O_NOFOLLOW, perm);
|
int fd = os_open(file_name, O_CREAT|O_WRONLY|O_EXCL|O_NOFOLLOW, perm);
|
||||||
if (fd < 0) {
|
if (fd < 0) {
|
||||||
semsg(_(e_not_open), file_name);
|
semsg(_(e_not_open), file_name);
|
||||||
goto theend;
|
goto theend;
|
||||||
@@ -2001,9 +1993,7 @@ void undo_time(int step, bool sec, bool file, bool absolute)
|
|||||||
target = curbuf->b_u_seq_cur + step;
|
target = curbuf->b_u_seq_cur + step;
|
||||||
}
|
}
|
||||||
if (step < 0) {
|
if (step < 0) {
|
||||||
if (target < 0) {
|
target = MAX(target, 0);
|
||||||
target = 0;
|
|
||||||
}
|
|
||||||
closest = -1;
|
closest = -1;
|
||||||
} else {
|
} else {
|
||||||
if (dosec) {
|
if (dosec) {
|
||||||
@@ -2396,9 +2386,7 @@ static void u_undoredo(bool undo, bool do_buf_event)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Set the '[ mark.
|
// Set the '[ mark.
|
||||||
if (top + 1 < curbuf->b_op_start.lnum) {
|
curbuf->b_op_start.lnum = MIN(curbuf->b_op_start.lnum, top + 1);
|
||||||
curbuf->b_op_start.lnum = top + 1;
|
|
||||||
}
|
|
||||||
// Set the '] mark.
|
// Set the '] mark.
|
||||||
if (newsize == 0 && top + 1 > curbuf->b_op_end.lnum) {
|
if (newsize == 0 && top + 1 > curbuf->b_op_end.lnum) {
|
||||||
curbuf->b_op_end.lnum = top + 1;
|
curbuf->b_op_end.lnum = top + 1;
|
||||||
@@ -2419,12 +2407,8 @@ static void u_undoredo(bool undo, bool do_buf_event)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Ensure the '[ and '] marks are within bounds.
|
// Ensure the '[ and '] marks are within bounds.
|
||||||
if (curbuf->b_op_start.lnum > curbuf->b_ml.ml_line_count) {
|
curbuf->b_op_start.lnum = MIN(curbuf->b_op_start.lnum, curbuf->b_ml.ml_line_count);
|
||||||
curbuf->b_op_start.lnum = curbuf->b_ml.ml_line_count;
|
curbuf->b_op_end.lnum = MIN(curbuf->b_op_end.lnum, curbuf->b_ml.ml_line_count);
|
||||||
}
|
|
||||||
if (curbuf->b_op_end.lnum > curbuf->b_ml.ml_line_count) {
|
|
||||||
curbuf->b_op_end.lnum = curbuf->b_ml.ml_line_count;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Adjust Extmarks
|
// Adjust Extmarks
|
||||||
if (undo) {
|
if (undo) {
|
||||||
|
@@ -805,9 +805,7 @@ invalid_count:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (*def < 0) {
|
*def = MAX(*def, 0);
|
||||||
*def = 0;
|
|
||||||
}
|
|
||||||
} else if (STRNICMP(attr, "complete", attrlen) == 0) {
|
} else if (STRNICMP(attr, "complete", attrlen) == 0) {
|
||||||
if (val == NULL) {
|
if (val == NULL) {
|
||||||
semsg(_(e_argument_required_for_str), "-complete");
|
semsg(_(e_argument_required_for_str), "-complete");
|
||||||
|
@@ -1112,12 +1112,7 @@ win_T *win_split_ins(int size, int flags, win_T *new_wp, int dir, frame_T *to_fl
|
|||||||
if (new_size == 0) {
|
if (new_size == 0) {
|
||||||
new_size = oldwin->w_width / 2;
|
new_size = oldwin->w_width / 2;
|
||||||
}
|
}
|
||||||
if (new_size > available - minwidth - 1) {
|
new_size = MAX(MIN(new_size, available - minwidth - 1), wmw1);
|
||||||
new_size = available - minwidth - 1;
|
|
||||||
}
|
|
||||||
if (new_size < wmw1) {
|
|
||||||
new_size = wmw1;
|
|
||||||
}
|
|
||||||
|
|
||||||
// if it doesn't fit in the current window, need win_equal()
|
// if it doesn't fit in the current window, need win_equal()
|
||||||
if (oldwin->w_width - new_size - 1 < p_wmw) {
|
if (oldwin->w_width - new_size - 1 < p_wmw) {
|
||||||
@@ -1198,12 +1193,7 @@ win_T *win_split_ins(int size, int flags, win_T *new_wp, int dir, frame_T *to_fl
|
|||||||
new_size = oldwin_height / 2;
|
new_size = oldwin_height / 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (new_size > available - minheight - STATUS_HEIGHT) {
|
new_size = MAX(MIN(new_size, available - minheight - STATUS_HEIGHT), wmh1);
|
||||||
new_size = available - minheight - STATUS_HEIGHT;
|
|
||||||
}
|
|
||||||
if (new_size < wmh1) {
|
|
||||||
new_size = wmh1;
|
|
||||||
}
|
|
||||||
|
|
||||||
// if it doesn't fit in the current window, need win_equal()
|
// if it doesn't fit in the current window, need win_equal()
|
||||||
if (oldwin_height - new_size - STATUS_HEIGHT < p_wmh) {
|
if (oldwin_height - new_size - STATUS_HEIGHT < p_wmh) {
|
||||||
@@ -1730,12 +1720,8 @@ int make_windows(int count, bool vertical)
|
|||||||
- (p_wh - p_wmh)) / ((int)p_wmh + STATUS_HEIGHT + global_winbar_height());
|
- (p_wh - p_wmh)) / ((int)p_wmh + STATUS_HEIGHT + global_winbar_height());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (maxcount < 2) {
|
maxcount = MAX(maxcount, 2);
|
||||||
maxcount = 2;
|
count = MIN(count, maxcount);
|
||||||
}
|
|
||||||
if (count > maxcount) {
|
|
||||||
count = maxcount;
|
|
||||||
}
|
|
||||||
|
|
||||||
// add status line now, otherwise first window will be too big
|
// add status line now, otherwise first window will be too big
|
||||||
if (count > 1) {
|
if (count > 1) {
|
||||||
@@ -2189,9 +2175,7 @@ static void win_equal_rec(win_T *next_curwin, bool current, frame_T *topfr, int
|
|||||||
if (frame_has_win(fr, next_curwin)) {
|
if (frame_has_win(fr, next_curwin)) {
|
||||||
room += (int)p_wiw - (int)p_wmw;
|
room += (int)p_wiw - (int)p_wmw;
|
||||||
next_curwin_size = 0;
|
next_curwin_size = 0;
|
||||||
if (new_size < p_wiw) {
|
new_size = MAX(new_size, (int)p_wiw);
|
||||||
new_size = (int)p_wiw;
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
// These windows don't use up room.
|
// These windows don't use up room.
|
||||||
totwincount -= (n + (fr->fr_next == NULL ? extra_sep : 0)) / ((int)p_wmw + 1);
|
totwincount -= (n + (fr->fr_next == NULL ? extra_sep : 0)) / ((int)p_wmw + 1);
|
||||||
@@ -2254,9 +2238,7 @@ static void win_equal_rec(win_T *next_curwin, bool current, frame_T *topfr, int
|
|||||||
}
|
}
|
||||||
if (hnc) { // add next_curwin size
|
if (hnc) { // add next_curwin size
|
||||||
next_curwin_size -= (int)p_wiw - (m - n);
|
next_curwin_size -= (int)p_wiw - (m - n);
|
||||||
if (next_curwin_size < 0) {
|
next_curwin_size = MAX(next_curwin_size, 0);
|
||||||
next_curwin_size = 0;
|
|
||||||
}
|
|
||||||
new_size += next_curwin_size;
|
new_size += next_curwin_size;
|
||||||
room -= new_size - next_curwin_size;
|
room -= new_size - next_curwin_size;
|
||||||
} else {
|
} else {
|
||||||
@@ -2319,9 +2301,7 @@ static void win_equal_rec(win_T *next_curwin, bool current, frame_T *topfr, int
|
|||||||
if (frame_has_win(fr, next_curwin)) {
|
if (frame_has_win(fr, next_curwin)) {
|
||||||
room += (int)p_wh - (int)p_wmh;
|
room += (int)p_wh - (int)p_wmh;
|
||||||
next_curwin_size = 0;
|
next_curwin_size = 0;
|
||||||
if (new_size < p_wh) {
|
new_size = MAX(new_size, (int)p_wh);
|
||||||
new_size = (int)p_wh;
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
// These windows don't use up room.
|
// These windows don't use up room.
|
||||||
totwincount -= get_maximum_wincount(fr, (n + (fr->fr_next == NULL ? extra_sep : 0)));
|
totwincount -= get_maximum_wincount(fr, (n + (fr->fr_next == NULL ? extra_sep : 0)));
|
||||||
@@ -3931,9 +3911,7 @@ static int frame_minwidth(frame_T *topfrp, win_T *next_curwin)
|
|||||||
frame_T *frp;
|
frame_T *frp;
|
||||||
FOR_ALL_FRAMES(frp, topfrp->fr_child) {
|
FOR_ALL_FRAMES(frp, topfrp->fr_child) {
|
||||||
int n = frame_minwidth(frp, next_curwin);
|
int n = frame_minwidth(frp, next_curwin);
|
||||||
if (n > m) {
|
m = MAX(m, n);
|
||||||
m = n;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Add up the minimal widths for all frames in this row.
|
// Add up the minimal widths for all frames in this row.
|
||||||
@@ -4266,9 +4244,7 @@ int make_tabpages(int maxcount)
|
|||||||
int count = maxcount;
|
int count = maxcount;
|
||||||
|
|
||||||
// Limit to 'tabpagemax' tabs.
|
// Limit to 'tabpagemax' tabs.
|
||||||
if (count > p_tpm) {
|
count = MIN(count, (int)p_tpm);
|
||||||
count = (int)p_tpm;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Don't execute autocommands while creating the tab pages. Must do that
|
// Don't execute autocommands while creating the tab pages. Must do that
|
||||||
// when putting the buffers in the windows.
|
// when putting the buffers in the windows.
|
||||||
@@ -5428,14 +5404,10 @@ void win_new_screensize(void)
|
|||||||
/// This only does the current tab page, others must be done when made active.
|
/// This only does the current tab page, others must be done when made active.
|
||||||
void win_new_screen_rows(void)
|
void win_new_screen_rows(void)
|
||||||
{
|
{
|
||||||
int h = (int)ROWS_AVAIL;
|
|
||||||
|
|
||||||
if (firstwin == NULL) { // not initialized yet
|
if (firstwin == NULL) { // not initialized yet
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (h < frame_minheight(topframe, NULL)) {
|
int h = MAX((int)ROWS_AVAIL, frame_minheight(topframe, NULL));
|
||||||
h = frame_minheight(topframe, NULL);
|
|
||||||
}
|
|
||||||
|
|
||||||
// First try setting the heights of windows with 'winfixheight'. If
|
// First try setting the heights of windows with 'winfixheight'. If
|
||||||
// that doesn't result in the right height, forget about that option.
|
// that doesn't result in the right height, forget about that option.
|
||||||
@@ -5932,9 +5904,7 @@ static void frame_setheight(frame_T *curfrp, int height)
|
|||||||
// Row of frames: Also need to resize frames left and right of this
|
// Row of frames: Also need to resize frames left and right of this
|
||||||
// one. First check for the minimal height of these.
|
// one. First check for the minimal height of these.
|
||||||
int h = frame_minheight(curfrp->fr_parent, NULL);
|
int h = frame_minheight(curfrp->fr_parent, NULL);
|
||||||
if (height < h) {
|
height = MAX(height, h);
|
||||||
height = h;
|
|
||||||
}
|
|
||||||
frame_setheight(curfrp->fr_parent, height);
|
frame_setheight(curfrp->fr_parent, height);
|
||||||
} else {
|
} else {
|
||||||
// Column of frames: try to change only frames in this column.
|
// Column of frames: try to change only frames in this column.
|
||||||
@@ -5969,9 +5939,7 @@ static void frame_setheight(frame_T *curfrp, int height)
|
|||||||
win_T *wp = lastwin_nofloating();
|
win_T *wp = lastwin_nofloating();
|
||||||
room_cmdline = Rows - (int)p_ch - global_stl_height()
|
room_cmdline = Rows - (int)p_ch - global_stl_height()
|
||||||
- (wp->w_winrow + wp->w_height + wp->w_hsep_height + wp->w_status_height);
|
- (wp->w_winrow + wp->w_height + wp->w_hsep_height + wp->w_status_height);
|
||||||
if (room_cmdline < 0) {
|
room_cmdline = MAX(room_cmdline, 0);
|
||||||
room_cmdline = 0;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (height <= room + room_cmdline) {
|
if (height <= room + room_cmdline) {
|
||||||
@@ -6003,9 +5971,7 @@ static void frame_setheight(frame_T *curfrp, int height)
|
|||||||
|
|
||||||
if (take > 0 && room_cmdline > 0) {
|
if (take > 0 && room_cmdline > 0) {
|
||||||
// use lines from cmdline first
|
// use lines from cmdline first
|
||||||
if (take < room_cmdline) {
|
room_cmdline = MIN(room_cmdline, take),
|
||||||
room_cmdline = take;
|
|
||||||
}
|
|
||||||
take -= room_cmdline;
|
take -= room_cmdline;
|
||||||
topframe->fr_height += room_cmdline;
|
topframe->fr_height += room_cmdline;
|
||||||
}
|
}
|
||||||
@@ -6067,12 +6033,7 @@ void win_setwidth_win(int width, win_T *wp)
|
|||||||
// Always keep current window at least one column wide, even when
|
// Always keep current window at least one column wide, even when
|
||||||
// 'winminwidth' is zero.
|
// 'winminwidth' is zero.
|
||||||
if (wp == curwin) {
|
if (wp == curwin) {
|
||||||
if (width < p_wmw) {
|
width = MAX(MAX(width, (int)p_wmw), 1);
|
||||||
width = (int)p_wmw;
|
|
||||||
}
|
|
||||||
if (width == 0) {
|
|
||||||
width = 1;
|
|
||||||
}
|
|
||||||
} else if (width < 0) {
|
} else if (width < 0) {
|
||||||
width = 0;
|
width = 0;
|
||||||
}
|
}
|
||||||
@@ -6110,9 +6071,7 @@ static void frame_setwidth(frame_T *curfrp, int width)
|
|||||||
// Column of frames: Also need to resize frames above and below of
|
// Column of frames: Also need to resize frames above and below of
|
||||||
// this one. First check for the minimal width of these.
|
// this one. First check for the minimal width of these.
|
||||||
int w = frame_minwidth(curfrp->fr_parent, NULL);
|
int w = frame_minwidth(curfrp->fr_parent, NULL);
|
||||||
if (width < w) {
|
width = MAX(width, w);
|
||||||
width = w;
|
|
||||||
}
|
|
||||||
frame_setwidth(curfrp->fr_parent, width);
|
frame_setwidth(curfrp->fr_parent, width);
|
||||||
} else {
|
} else {
|
||||||
// Row of frames: try to change only frames in this row.
|
// Row of frames: try to change only frames in this row.
|
||||||
@@ -6309,9 +6268,7 @@ void win_drag_status_line(win_T *dragwin, int offset)
|
|||||||
} else if (!p_ch_was_zero) {
|
} else if (!p_ch_was_zero) {
|
||||||
room--;
|
room--;
|
||||||
}
|
}
|
||||||
if (room < 0) {
|
room = MAX(room, 0);
|
||||||
room = 0;
|
|
||||||
}
|
|
||||||
// sum up the room of frames below of the current one
|
// sum up the room of frames below of the current one
|
||||||
FOR_ALL_FRAMES(fr, curfr->fr_next) {
|
FOR_ALL_FRAMES(fr, curfr->fr_next) {
|
||||||
room += fr->fr_height - frame_minheight(fr, NULL);
|
room += fr->fr_height - frame_minheight(fr, NULL);
|
||||||
@@ -6319,9 +6276,8 @@ void win_drag_status_line(win_T *dragwin, int offset)
|
|||||||
fr = curfr; // put fr at window that grows
|
fr = curfr; // put fr at window that grows
|
||||||
}
|
}
|
||||||
|
|
||||||
if (room < offset) { // Not enough room
|
// If not enough room then move as far as we can
|
||||||
offset = room; // Move as far as we can
|
offset = MIN(offset, room);
|
||||||
}
|
|
||||||
if (offset <= 0) {
|
if (offset <= 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -6423,10 +6379,8 @@ void win_drag_vsep_line(win_T *dragwin, int offset)
|
|||||||
fr = curfr; // put fr at window that grows
|
fr = curfr; // put fr at window that grows
|
||||||
}
|
}
|
||||||
|
|
||||||
// Not enough room
|
// If not enough room thn move as far as we can
|
||||||
if (room < offset) {
|
offset = MIN(offset, room);
|
||||||
offset = room; // Move as far as we can
|
|
||||||
}
|
|
||||||
|
|
||||||
// No room at all, quit.
|
// No room at all, quit.
|
||||||
if (offset <= 0) {
|
if (offset <= 0) {
|
||||||
@@ -6597,9 +6551,7 @@ void win_new_height(win_T *wp, int height)
|
|||||||
{
|
{
|
||||||
// Don't want a negative height. Happens when splitting a tiny window.
|
// Don't want a negative height. Happens when splitting a tiny window.
|
||||||
// Will equalize heights soon to fix it.
|
// Will equalize heights soon to fix it.
|
||||||
if (height < 0) {
|
height = MAX(height, 0);
|
||||||
height = 0;
|
|
||||||
}
|
|
||||||
if (wp->w_height == height) {
|
if (wp->w_height == height) {
|
||||||
return; // nothing to do
|
return; // nothing to do
|
||||||
}
|
}
|
||||||
@@ -6625,9 +6577,8 @@ void scroll_to_fraction(win_T *wp, int prev_height)
|
|||||||
// Find a value for w_topline that shows the cursor at the same
|
// Find a value for w_topline that shows the cursor at the same
|
||||||
// relative position in the window as before (more or less).
|
// relative position in the window as before (more or less).
|
||||||
linenr_T lnum = wp->w_cursor.lnum;
|
linenr_T lnum = wp->w_cursor.lnum;
|
||||||
if (lnum < 1) { // can happen when starting up
|
// can happen when starting up
|
||||||
lnum = 1;
|
lnum = MAX(lnum, 1);
|
||||||
}
|
|
||||||
wp->w_wrow = (wp->w_fraction * height - 1) / FRACTION_MULT;
|
wp->w_wrow = (wp->w_fraction * height - 1) / FRACTION_MULT;
|
||||||
int line_size = plines_win_col(wp, lnum, wp->w_cursor.col) - 1;
|
int line_size = plines_win_col(wp, lnum, wp->w_cursor.col) - 1;
|
||||||
int sline = wp->w_wrow - line_size;
|
int sline = wp->w_wrow - line_size;
|
||||||
@@ -6843,9 +6794,7 @@ void command_height(void)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
int h = frp->fr_height - frame_minheight(frp, NULL);
|
int h = frp->fr_height - frame_minheight(frp, NULL);
|
||||||
if (h > p_ch - old_p_ch) {
|
h = MIN(h, (int)p_ch - old_p_ch);
|
||||||
h = (int)p_ch - old_p_ch;
|
|
||||||
}
|
|
||||||
old_p_ch += h;
|
old_p_ch += h;
|
||||||
frame_add_height(frp, -h);
|
frame_add_height(frp, -h);
|
||||||
frp = frp->fr_prev;
|
frp = frp->fr_prev;
|
||||||
@@ -6863,9 +6812,7 @@ void command_height(void)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (msg_row < cmdline_row) {
|
msg_row = MAX(msg_row, cmdline_row);
|
||||||
msg_row = cmdline_row;
|
|
||||||
}
|
|
||||||
redraw_cmdline = true;
|
redraw_cmdline = true;
|
||||||
}
|
}
|
||||||
frame_add_height(frp, (int)(old_p_ch - p_ch));
|
frame_add_height(frp, (int)(old_p_ch - p_ch));
|
||||||
@@ -7251,9 +7198,7 @@ int min_rows(void)
|
|||||||
int total = 0;
|
int total = 0;
|
||||||
FOR_ALL_TABS(tp) {
|
FOR_ALL_TABS(tp) {
|
||||||
int n = frame_minheight(tp->tp_topframe, NULL);
|
int n = frame_minheight(tp->tp_topframe, NULL);
|
||||||
if (total < n) {
|
total = MAX(total, n);
|
||||||
total = n;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
total += tabline_height() + global_stl_height();
|
total += tabline_height() + global_stl_height();
|
||||||
if (p_ch > 0) {
|
if (p_ch > 0) {
|
||||||
@@ -7548,13 +7493,7 @@ static int int_cmp(const void *pa, const void *pb)
|
|||||||
{
|
{
|
||||||
const int a = *(const int *)pa;
|
const int a = *(const int *)pa;
|
||||||
const int b = *(const int *)pb;
|
const int b = *(const int *)pb;
|
||||||
if (a > b) {
|
return a == b ? 0 : a < b ? -1 : 1;
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
if (a < b) {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Handle setting 'colorcolumn' or 'textwidth' in window "wp".
|
/// Handle setting 'colorcolumn' or 'textwidth' in window "wp".
|
||||||
|
Reference in New Issue
Block a user