mirror of
https://github.com/neovim/neovim.git
synced 2025-09-08 04:18:18 +00:00
vim-patch:partial:9.0.1237: code is indented more than necessary (#21971)
Problem: Code is indented more than necessary.
Solution: Use an early return where it makes sense. (Yegappan Lakshmanan,
closes vim/vim#11858)
6ec6666047
Co-authored-by: Yegappan Lakshmanan <yegappan@yahoo.com>
This commit is contained in:
@@ -126,12 +126,14 @@ static char *provider_err = NULL;
|
|||||||
void conceal_check_cursor_line(void)
|
void conceal_check_cursor_line(void)
|
||||||
{
|
{
|
||||||
bool should_conceal = conceal_cursor_line(curwin);
|
bool should_conceal = conceal_cursor_line(curwin);
|
||||||
if (curwin->w_p_cole > 0 && (conceal_cursor_used != should_conceal)) {
|
if (curwin->w_p_cole <= 0 || conceal_cursor_used == should_conceal) {
|
||||||
redrawWinline(curwin, curwin->w_cursor.lnum);
|
return;
|
||||||
// Need to recompute cursor column, e.g., when starting Visual mode
|
|
||||||
// without concealing.
|
|
||||||
curs_columns(curwin, true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
redrawWinline(curwin, curwin->w_cursor.lnum);
|
||||||
|
// Need to recompute cursor column, e.g., when starting Visual mode
|
||||||
|
// without concealing.
|
||||||
|
curs_columns(curwin, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Resize default_grid to Rows and Columns.
|
/// Resize default_grid to Rows and Columns.
|
||||||
@@ -837,25 +839,29 @@ static bool vsep_connected(win_T *wp, WindowCorner corner)
|
|||||||
/// Draw the vertical separator right of window "wp"
|
/// Draw the vertical separator right of window "wp"
|
||||||
static void draw_vsep_win(win_T *wp)
|
static void draw_vsep_win(win_T *wp)
|
||||||
{
|
{
|
||||||
if (wp->w_vsep_width) {
|
if (!wp->w_vsep_width) {
|
||||||
// draw the vertical separator right of this window
|
return;
|
||||||
int hl;
|
|
||||||
int c = fillchar_vsep(wp, &hl);
|
|
||||||
grid_fill(&default_grid, wp->w_winrow, W_ENDROW(wp),
|
|
||||||
W_ENDCOL(wp), W_ENDCOL(wp) + 1, c, ' ', hl);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// draw the vertical separator right of this window
|
||||||
|
int hl;
|
||||||
|
int c = fillchar_vsep(wp, &hl);
|
||||||
|
grid_fill(&default_grid, wp->w_winrow, W_ENDROW(wp),
|
||||||
|
W_ENDCOL(wp), W_ENDCOL(wp) + 1, c, ' ', hl);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Draw the horizontal separator below window "wp"
|
/// Draw the horizontal separator below window "wp"
|
||||||
static void draw_hsep_win(win_T *wp)
|
static void draw_hsep_win(win_T *wp)
|
||||||
{
|
{
|
||||||
if (wp->w_hsep_height) {
|
if (!wp->w_hsep_height) {
|
||||||
// draw the horizontal separator below this window
|
return;
|
||||||
int hl;
|
|
||||||
int c = fillchar_hsep(wp, &hl);
|
|
||||||
grid_fill(&default_grid, W_ENDROW(wp), W_ENDROW(wp) + 1,
|
|
||||||
wp->w_wincol, W_ENDCOL(wp), c, c, hl);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// draw the horizontal separator below this window
|
||||||
|
int hl;
|
||||||
|
int c = fillchar_hsep(wp, &hl);
|
||||||
|
grid_fill(&default_grid, W_ENDROW(wp), W_ENDROW(wp) + 1,
|
||||||
|
wp->w_wincol, W_ENDCOL(wp), c, c, hl);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get the separator connector for specified window corner of window "wp"
|
/// Get the separator connector for specified window corner of window "wp"
|
||||||
|
@@ -112,40 +112,43 @@ static int ses_win_rec(FILE *fd, frame_T *fr)
|
|||||||
frame_T *frc;
|
frame_T *frc;
|
||||||
int count = 0;
|
int count = 0;
|
||||||
|
|
||||||
if (fr->fr_layout != FR_LEAF) {
|
if (fr->fr_layout == FR_LEAF) {
|
||||||
// Find first frame that's not skipped and then create a window for
|
return OK;
|
||||||
// each following one (first frame is already there).
|
}
|
||||||
frc = ses_skipframe(fr->fr_child);
|
|
||||||
if (frc != NULL) {
|
|
||||||
while ((frc = ses_skipframe(frc->fr_next)) != NULL) {
|
|
||||||
// Make window as big as possible so that we have lots of room
|
|
||||||
// to split.
|
|
||||||
if (fprintf(fd, "%s%s",
|
|
||||||
"wincmd _ | wincmd |\n",
|
|
||||||
(fr->fr_layout == FR_COL ? "split\n" : "vsplit\n")) < 0) {
|
|
||||||
return FAIL;
|
|
||||||
}
|
|
||||||
count++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Go back to the first window.
|
// Find first frame that's not skipped and then create a window for
|
||||||
if (count > 0 && (fprintf(fd, fr->fr_layout == FR_COL
|
// each following one (first frame is already there).
|
||||||
? "%dwincmd k\n" : "%dwincmd h\n", count) < 0)) {
|
frc = ses_skipframe(fr->fr_child);
|
||||||
return FAIL;
|
if (frc != NULL) {
|
||||||
}
|
while ((frc = ses_skipframe(frc->fr_next)) != NULL) {
|
||||||
|
// Make window as big as possible so that we have lots of room
|
||||||
// Recursively create frames/windows in each window of this column or row.
|
// to split.
|
||||||
frc = ses_skipframe(fr->fr_child);
|
if (fprintf(fd, "%s%s",
|
||||||
while (frc != NULL) {
|
"wincmd _ | wincmd |\n",
|
||||||
ses_win_rec(fd, frc);
|
(fr->fr_layout == FR_COL ? "split\n" : "vsplit\n")) < 0) {
|
||||||
frc = ses_skipframe(frc->fr_next);
|
|
||||||
// Go to next window.
|
|
||||||
if (frc != NULL && put_line(fd, "wincmd w") == FAIL) {
|
|
||||||
return FAIL;
|
return FAIL;
|
||||||
}
|
}
|
||||||
|
count++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Go back to the first window.
|
||||||
|
if (count > 0 && (fprintf(fd, fr->fr_layout == FR_COL
|
||||||
|
? "%dwincmd k\n" : "%dwincmd h\n", count) < 0)) {
|
||||||
|
return FAIL;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Recursively create frames/windows in each window of this column or row.
|
||||||
|
frc = ses_skipframe(fr->fr_child);
|
||||||
|
while (frc != NULL) {
|
||||||
|
ses_win_rec(fd, frc);
|
||||||
|
frc = ses_skipframe(frc->fr_next);
|
||||||
|
// Go to next window.
|
||||||
|
if (frc != NULL && put_line(fd, "wincmd w") == FAIL) {
|
||||||
|
return FAIL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return OK;
|
return OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -906,12 +909,14 @@ static int makeopens(FILE *fd, char *dirnow)
|
|||||||
void ex_loadview(exarg_T *eap)
|
void ex_loadview(exarg_T *eap)
|
||||||
{
|
{
|
||||||
char *fname = get_view_file(*eap->arg);
|
char *fname = get_view_file(*eap->arg);
|
||||||
if (fname != NULL) {
|
if (fname == NULL) {
|
||||||
if (do_source(fname, false, DOSO_NONE) == FAIL) {
|
return;
|
||||||
semsg(_(e_notopen), fname);
|
|
||||||
}
|
|
||||||
xfree(fname);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (do_source(fname, false, DOSO_NONE) == FAIL) {
|
||||||
|
semsg(_(e_notopen), fname);
|
||||||
|
}
|
||||||
|
xfree(fname);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// ":mkexrc", ":mkvimrc", ":mkview", ":mksession".
|
/// ":mkexrc", ":mkvimrc", ":mkview", ":mksession".
|
||||||
|
@@ -142,16 +142,16 @@ void grid_putchar(ScreenGrid *grid, int c, int row, int col, int attr)
|
|||||||
/// Also return its attribute in *attrp;
|
/// Also return its attribute in *attrp;
|
||||||
void grid_getbytes(ScreenGrid *grid, int row, int col, char *bytes, int *attrp)
|
void grid_getbytes(ScreenGrid *grid, int row, int col, char *bytes, int *attrp)
|
||||||
{
|
{
|
||||||
size_t off;
|
|
||||||
|
|
||||||
grid_adjust(&grid, &row, &col);
|
grid_adjust(&grid, &row, &col);
|
||||||
|
|
||||||
// safety check
|
// safety check
|
||||||
if (grid->chars != NULL && row < grid->rows && col < grid->cols) {
|
if (grid->chars == NULL || row >= grid->rows || col >= grid->cols) {
|
||||||
off = grid->line_offset[row] + (size_t)col;
|
return;
|
||||||
*attrp = grid->attrs[off];
|
|
||||||
schar_copy(bytes, grid->chars[off]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
size_t off = grid->line_offset[row] + (size_t)col;
|
||||||
|
*attrp = grid->attrs[off];
|
||||||
|
schar_copy(bytes, grid->chars[off]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// put string '*text' on the window grid at position 'row' and 'col', with
|
/// put string '*text' on the window grid at position 'row' and 'col', with
|
||||||
|
@@ -821,12 +821,14 @@ static void source_all_matches(char *pat)
|
|||||||
int num_files;
|
int num_files;
|
||||||
char **files;
|
char **files;
|
||||||
|
|
||||||
if (gen_expand_wildcards(1, &pat, &num_files, &files, EW_FILE) == OK) {
|
if (gen_expand_wildcards(1, &pat, &num_files, &files, EW_FILE) != OK) {
|
||||||
for (int i = 0; i < num_files; i++) {
|
return;
|
||||||
(void)do_source(files[i], false, DOSO_NONE);
|
|
||||||
}
|
|
||||||
FreeWild(num_files, files);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i < num_files; i++) {
|
||||||
|
(void)do_source(files[i], false, DOSO_NONE);
|
||||||
|
}
|
||||||
|
FreeWild(num_files, files);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Add the package directory to 'runtimepath'
|
/// Add the package directory to 'runtimepath'
|
||||||
|
@@ -295,52 +295,54 @@ bool get_keymap_str(win_T *wp, char *fmt, char *buf, int len)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
buf_T *old_curbuf = curbuf;
|
||||||
buf_T *old_curbuf = curbuf;
|
win_T *old_curwin = curwin;
|
||||||
win_T *old_curwin = curwin;
|
char *s;
|
||||||
char *s;
|
|
||||||
|
|
||||||
curbuf = wp->w_buffer;
|
curbuf = wp->w_buffer;
|
||||||
curwin = wp;
|
curwin = wp;
|
||||||
STRCPY(buf, "b:keymap_name"); // must be writable
|
STRCPY(buf, "b:keymap_name"); // must be writable
|
||||||
emsg_skip++;
|
emsg_skip++;
|
||||||
s = p = eval_to_string(buf, NULL, false);
|
s = p = eval_to_string(buf, NULL, false);
|
||||||
emsg_skip--;
|
emsg_skip--;
|
||||||
curbuf = old_curbuf;
|
curbuf = old_curbuf;
|
||||||
curwin = old_curwin;
|
curwin = old_curwin;
|
||||||
if (p == NULL || *p == NUL) {
|
if (p == NULL || *p == NUL) {
|
||||||
if (wp->w_buffer->b_kmap_state & KEYMAP_LOADED) {
|
if (wp->w_buffer->b_kmap_state & KEYMAP_LOADED) {
|
||||||
p = wp->w_buffer->b_p_keymap;
|
p = wp->w_buffer->b_p_keymap;
|
||||||
} else {
|
} else {
|
||||||
p = "lang";
|
p = "lang";
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (vim_snprintf(buf, (size_t)len, fmt, p) > len - 1) {
|
|
||||||
buf[0] = NUL;
|
|
||||||
}
|
|
||||||
xfree(s);
|
|
||||||
}
|
}
|
||||||
|
if (vim_snprintf(buf, (size_t)len, fmt, p) > len - 1) {
|
||||||
|
buf[0] = NUL;
|
||||||
|
}
|
||||||
|
xfree(s);
|
||||||
return buf[0] != NUL;
|
return buf[0] != NUL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Prepare for 'hlsearch' highlighting.
|
/// Prepare for 'hlsearch' highlighting.
|
||||||
void start_search_hl(void)
|
void start_search_hl(void)
|
||||||
{
|
{
|
||||||
if (p_hls && !no_hlsearch) {
|
if (!p_hls || no_hlsearch) {
|
||||||
end_search_hl(); // just in case it wasn't called before
|
return;
|
||||||
last_pat_prog(&screen_search_hl.rm);
|
|
||||||
// Set the time limit to 'redrawtime'.
|
|
||||||
screen_search_hl.tm = profile_setlimit(p_rdt);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
end_search_hl(); // just in case it wasn't called before
|
||||||
|
last_pat_prog(&screen_search_hl.rm);
|
||||||
|
// Set the time limit to 'redrawtime'.
|
||||||
|
screen_search_hl.tm = profile_setlimit(p_rdt);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Clean up for 'hlsearch' highlighting.
|
/// Clean up for 'hlsearch' highlighting.
|
||||||
void end_search_hl(void)
|
void end_search_hl(void)
|
||||||
{
|
{
|
||||||
if (screen_search_hl.rm.regprog != NULL) {
|
if (screen_search_hl.rm.regprog == NULL) {
|
||||||
vim_regfree(screen_search_hl.rm.regprog);
|
return;
|
||||||
screen_search_hl.rm.regprog = NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
vim_regfree(screen_search_hl.rm.regprog);
|
||||||
|
screen_search_hl.rm.regprog = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Check if there should be a delay. Used before clearing or redrawing the
|
/// Check if there should be a delay. Used before clearing or redrawing the
|
||||||
@@ -671,11 +673,13 @@ void clearmode(void)
|
|||||||
static void recording_mode(int attr)
|
static void recording_mode(int attr)
|
||||||
{
|
{
|
||||||
msg_puts_attr(_("recording"), attr);
|
msg_puts_attr(_("recording"), attr);
|
||||||
if (!shortmess(SHM_RECORDING)) {
|
if (shortmess(SHM_RECORDING)) {
|
||||||
char s[4];
|
return;
|
||||||
snprintf(s, ARRAY_SIZE(s), " @%c", reg_recording);
|
|
||||||
msg_puts_attr(s, attr);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
char s[4];
|
||||||
|
snprintf(s, ARRAY_SIZE(s), " @%c", reg_recording);
|
||||||
|
msg_puts_attr(s, attr);
|
||||||
}
|
}
|
||||||
|
|
||||||
void get_trans_bufname(buf_T *buf)
|
void get_trans_bufname(buf_T *buf)
|
||||||
|
@@ -206,20 +206,22 @@ char *get_search_pat(void)
|
|||||||
|
|
||||||
void save_re_pat(int idx, char *pat, int magic)
|
void save_re_pat(int idx, char *pat, int magic)
|
||||||
{
|
{
|
||||||
if (spats[idx].pat != pat) {
|
if (spats[idx].pat == pat) {
|
||||||
free_spat(&spats[idx]);
|
return;
|
||||||
spats[idx].pat = xstrdup(pat);
|
|
||||||
spats[idx].magic = magic;
|
|
||||||
spats[idx].no_scs = no_smartcase;
|
|
||||||
spats[idx].timestamp = os_time();
|
|
||||||
spats[idx].additional_data = NULL;
|
|
||||||
last_idx = idx;
|
|
||||||
// If 'hlsearch' set and search pat changed: need redraw.
|
|
||||||
if (p_hls) {
|
|
||||||
redraw_all_later(UPD_SOME_VALID);
|
|
||||||
}
|
|
||||||
set_no_hlsearch(false);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
free_spat(&spats[idx]);
|
||||||
|
spats[idx].pat = xstrdup(pat);
|
||||||
|
spats[idx].magic = magic;
|
||||||
|
spats[idx].no_scs = no_smartcase;
|
||||||
|
spats[idx].timestamp = os_time();
|
||||||
|
spats[idx].additional_data = NULL;
|
||||||
|
last_idx = idx;
|
||||||
|
// If 'hlsearch' set and search pat changed: need redraw.
|
||||||
|
if (p_hls) {
|
||||||
|
redraw_all_later(UPD_SOME_VALID);
|
||||||
|
}
|
||||||
|
set_no_hlsearch(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Save the search patterns, so they can be restored later.
|
// Save the search patterns, so they can be restored later.
|
||||||
@@ -228,38 +230,42 @@ static int save_level = 0;
|
|||||||
|
|
||||||
void save_search_patterns(void)
|
void save_search_patterns(void)
|
||||||
{
|
{
|
||||||
if (save_level++ == 0) {
|
if (save_level++ != 0) {
|
||||||
saved_spats[0] = spats[0];
|
return;
|
||||||
if (spats[0].pat != NULL) {
|
|
||||||
saved_spats[0].pat = xstrdup(spats[0].pat);
|
|
||||||
}
|
|
||||||
saved_spats[1] = spats[1];
|
|
||||||
if (spats[1].pat != NULL) {
|
|
||||||
saved_spats[1].pat = xstrdup(spats[1].pat);
|
|
||||||
}
|
|
||||||
if (mr_pattern == NULL) {
|
|
||||||
saved_mr_pattern = NULL;
|
|
||||||
} else {
|
|
||||||
saved_mr_pattern = xstrdup(mr_pattern);
|
|
||||||
}
|
|
||||||
saved_spats_last_idx = last_idx;
|
|
||||||
saved_spats_no_hlsearch = no_hlsearch;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
saved_spats[0] = spats[0];
|
||||||
|
if (spats[0].pat != NULL) {
|
||||||
|
saved_spats[0].pat = xstrdup(spats[0].pat);
|
||||||
|
}
|
||||||
|
saved_spats[1] = spats[1];
|
||||||
|
if (spats[1].pat != NULL) {
|
||||||
|
saved_spats[1].pat = xstrdup(spats[1].pat);
|
||||||
|
}
|
||||||
|
if (mr_pattern == NULL) {
|
||||||
|
saved_mr_pattern = NULL;
|
||||||
|
} else {
|
||||||
|
saved_mr_pattern = xstrdup(mr_pattern);
|
||||||
|
}
|
||||||
|
saved_spats_last_idx = last_idx;
|
||||||
|
saved_spats_no_hlsearch = no_hlsearch;
|
||||||
}
|
}
|
||||||
|
|
||||||
void restore_search_patterns(void)
|
void restore_search_patterns(void)
|
||||||
{
|
{
|
||||||
if (--save_level == 0) {
|
if (--save_level != 0) {
|
||||||
free_spat(&spats[0]);
|
return;
|
||||||
spats[0] = saved_spats[0];
|
|
||||||
set_vv_searchforward();
|
|
||||||
free_spat(&spats[1]);
|
|
||||||
spats[1] = saved_spats[1];
|
|
||||||
xfree(mr_pattern);
|
|
||||||
mr_pattern = saved_mr_pattern;
|
|
||||||
last_idx = saved_spats_last_idx;
|
|
||||||
set_no_hlsearch(saved_spats_no_hlsearch);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
free_spat(&spats[0]);
|
||||||
|
spats[0] = saved_spats[0];
|
||||||
|
set_vv_searchforward();
|
||||||
|
free_spat(&spats[1]);
|
||||||
|
spats[1] = saved_spats[1];
|
||||||
|
xfree(mr_pattern);
|
||||||
|
mr_pattern = saved_mr_pattern;
|
||||||
|
last_idx = saved_spats_last_idx;
|
||||||
|
set_no_hlsearch(saved_spats_no_hlsearch);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void free_spat(struct spat *const spat)
|
static inline void free_spat(struct spat *const spat)
|
||||||
@@ -2321,55 +2327,63 @@ void showmatch(int c)
|
|||||||
|
|
||||||
if ((lpos = findmatch(NULL, NUL)) == NULL) { // no match, so beep
|
if ((lpos = findmatch(NULL, NUL)) == NULL) { // no match, so beep
|
||||||
vim_beep(BO_MATCH);
|
vim_beep(BO_MATCH);
|
||||||
} else if (lpos->lnum >= curwin->w_topline
|
return;
|
||||||
&& lpos->lnum < curwin->w_botline) {
|
|
||||||
if (!curwin->w_p_wrap) {
|
|
||||||
getvcol(curwin, lpos, NULL, &vcol, NULL);
|
|
||||||
}
|
|
||||||
if (curwin->w_p_wrap
|
|
||||||
|| (vcol >= curwin->w_leftcol
|
|
||||||
&& vcol < curwin->w_leftcol + curwin->w_width_inner)) {
|
|
||||||
mpos = *lpos; // save the pos, update_screen() may change it
|
|
||||||
save_cursor = curwin->w_cursor;
|
|
||||||
save_so = *so;
|
|
||||||
save_siso = *siso;
|
|
||||||
// Handle "$" in 'cpo': If the ')' is typed on top of the "$",
|
|
||||||
// stop displaying the "$".
|
|
||||||
if (dollar_vcol >= 0 && dollar_vcol == curwin->w_virtcol) {
|
|
||||||
dollar_vcol = -1;
|
|
||||||
}
|
|
||||||
curwin->w_virtcol++; // do display ')' just before "$"
|
|
||||||
update_screen(); // show the new char first
|
|
||||||
|
|
||||||
save_dollar_vcol = dollar_vcol;
|
|
||||||
save_state = State;
|
|
||||||
State = MODE_SHOWMATCH;
|
|
||||||
ui_cursor_shape(); // may show different cursor shape
|
|
||||||
curwin->w_cursor = mpos; // move to matching char
|
|
||||||
*so = 0; // don't use 'scrolloff' here
|
|
||||||
*siso = 0; // don't use 'sidescrolloff' here
|
|
||||||
show_cursor_info(false);
|
|
||||||
setcursor();
|
|
||||||
ui_flush();
|
|
||||||
// Restore dollar_vcol(), because setcursor() may call curs_rows()
|
|
||||||
// which resets it if the matching position is in a previous line
|
|
||||||
// and has a higher column number.
|
|
||||||
dollar_vcol = save_dollar_vcol;
|
|
||||||
|
|
||||||
// brief pause, unless 'm' is present in 'cpo' and a character is
|
|
||||||
// available.
|
|
||||||
if (vim_strchr(p_cpo, CPO_SHOWMATCH) != NULL) {
|
|
||||||
os_delay((uint64_t)p_mat * 100L + 8, true);
|
|
||||||
} else if (!char_avail()) {
|
|
||||||
os_delay((uint64_t)p_mat * 100L + 9, false);
|
|
||||||
}
|
|
||||||
curwin->w_cursor = save_cursor; // restore cursor position
|
|
||||||
*so = save_so;
|
|
||||||
*siso = save_siso;
|
|
||||||
State = save_state;
|
|
||||||
ui_cursor_shape(); // may show different cursor shape
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (lpos->lnum < curwin->w_topline || lpos->lnum >= curwin->w_botline) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!curwin->w_p_wrap) {
|
||||||
|
getvcol(curwin, lpos, NULL, &vcol, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool col_visible = curwin->w_p_wrap
|
||||||
|
|| (vcol >= curwin->w_leftcol
|
||||||
|
&& vcol < curwin->w_leftcol + curwin->w_width_inner);
|
||||||
|
if (!col_visible) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
mpos = *lpos; // save the pos, update_screen() may change it
|
||||||
|
save_cursor = curwin->w_cursor;
|
||||||
|
save_so = *so;
|
||||||
|
save_siso = *siso;
|
||||||
|
// Handle "$" in 'cpo': If the ')' is typed on top of the "$",
|
||||||
|
// stop displaying the "$".
|
||||||
|
if (dollar_vcol >= 0 && dollar_vcol == curwin->w_virtcol) {
|
||||||
|
dollar_vcol = -1;
|
||||||
|
}
|
||||||
|
curwin->w_virtcol++; // do display ')' just before "$"
|
||||||
|
update_screen(); // show the new char first
|
||||||
|
|
||||||
|
save_dollar_vcol = dollar_vcol;
|
||||||
|
save_state = State;
|
||||||
|
State = MODE_SHOWMATCH;
|
||||||
|
ui_cursor_shape(); // may show different cursor shape
|
||||||
|
curwin->w_cursor = mpos; // move to matching char
|
||||||
|
*so = 0; // don't use 'scrolloff' here
|
||||||
|
*siso = 0; // don't use 'sidescrolloff' here
|
||||||
|
show_cursor_info(false);
|
||||||
|
setcursor();
|
||||||
|
ui_flush();
|
||||||
|
// Restore dollar_vcol(), because setcursor() may call curs_rows()
|
||||||
|
// which resets it if the matching position is in a previous line
|
||||||
|
// and has a higher column number.
|
||||||
|
dollar_vcol = save_dollar_vcol;
|
||||||
|
|
||||||
|
// brief pause, unless 'm' is present in 'cpo' and a character is
|
||||||
|
// available.
|
||||||
|
if (vim_strchr(p_cpo, CPO_SHOWMATCH) != NULL) {
|
||||||
|
os_delay((uint64_t)p_mat * 100L + 8, true);
|
||||||
|
} else if (!char_avail()) {
|
||||||
|
os_delay((uint64_t)p_mat * 100L + 9, false);
|
||||||
|
}
|
||||||
|
curwin->w_cursor = save_cursor; // restore cursor position
|
||||||
|
*so = save_so;
|
||||||
|
*siso = save_siso;
|
||||||
|
State = save_state;
|
||||||
|
ui_cursor_shape(); // may show different cursor shape
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Find next search match under cursor, cursor at end.
|
/// Find next search match under cursor, cursor at end.
|
||||||
@@ -2588,56 +2602,58 @@ static void cmdline_search_stat(int dirc, pos_T *pos, pos_T *cursor_pos, bool sh
|
|||||||
|
|
||||||
update_search_stat(dirc, pos, cursor_pos, &stat, recompute, maxcount,
|
update_search_stat(dirc, pos, cursor_pos, &stat, recompute, maxcount,
|
||||||
timeout);
|
timeout);
|
||||||
if (stat.cur > 0) {
|
if (stat.cur <= 0) {
|
||||||
char t[SEARCH_STAT_BUF_LEN];
|
return;
|
||||||
|
|
||||||
if (curwin->w_p_rl && *curwin->w_p_rlc == 's') {
|
|
||||||
if (stat.incomplete == 1) {
|
|
||||||
vim_snprintf(t, SEARCH_STAT_BUF_LEN, "[?/??]");
|
|
||||||
} else if (stat.cnt > maxcount && stat.cur > maxcount) {
|
|
||||||
vim_snprintf(t, SEARCH_STAT_BUF_LEN, "[>%d/>%d]",
|
|
||||||
maxcount, maxcount);
|
|
||||||
} else if (stat.cnt > maxcount) {
|
|
||||||
vim_snprintf(t, SEARCH_STAT_BUF_LEN, "[>%d/%d]",
|
|
||||||
maxcount, stat.cur);
|
|
||||||
} else {
|
|
||||||
vim_snprintf(t, SEARCH_STAT_BUF_LEN, "[%d/%d]",
|
|
||||||
stat.cnt, stat.cur);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (stat.incomplete == 1) {
|
|
||||||
vim_snprintf(t, SEARCH_STAT_BUF_LEN, "[?/??]");
|
|
||||||
} else if (stat.cnt > maxcount && stat.cur > maxcount) {
|
|
||||||
vim_snprintf(t, SEARCH_STAT_BUF_LEN, "[>%d/>%d]",
|
|
||||||
maxcount, maxcount);
|
|
||||||
} else if (stat.cnt > maxcount) {
|
|
||||||
vim_snprintf(t, SEARCH_STAT_BUF_LEN, "[%d/>%d]",
|
|
||||||
stat.cur, maxcount);
|
|
||||||
} else {
|
|
||||||
vim_snprintf(t, SEARCH_STAT_BUF_LEN, "[%d/%d]",
|
|
||||||
stat.cur, stat.cnt);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
size_t len = strlen(t);
|
|
||||||
if (show_top_bot_msg && len + 2 < SEARCH_STAT_BUF_LEN) {
|
|
||||||
memmove(t + 2, t, len);
|
|
||||||
t[0] = 'W';
|
|
||||||
t[1] = ' ';
|
|
||||||
len += 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
memmove(msgbuf + strlen(msgbuf) - len, t, len);
|
|
||||||
if (dirc == '?' && stat.cur == maxcount + 1) {
|
|
||||||
stat.cur = -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
// keep the message even after redraw, but don't put in history
|
|
||||||
msg_hist_off = true;
|
|
||||||
msg_ext_set_kind("search_count");
|
|
||||||
give_warning(msgbuf, false);
|
|
||||||
msg_hist_off = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
char t[SEARCH_STAT_BUF_LEN];
|
||||||
|
|
||||||
|
if (curwin->w_p_rl && *curwin->w_p_rlc == 's') {
|
||||||
|
if (stat.incomplete == 1) {
|
||||||
|
vim_snprintf(t, SEARCH_STAT_BUF_LEN, "[?/??]");
|
||||||
|
} else if (stat.cnt > maxcount && stat.cur > maxcount) {
|
||||||
|
vim_snprintf(t, SEARCH_STAT_BUF_LEN, "[>%d/>%d]",
|
||||||
|
maxcount, maxcount);
|
||||||
|
} else if (stat.cnt > maxcount) {
|
||||||
|
vim_snprintf(t, SEARCH_STAT_BUF_LEN, "[>%d/%d]",
|
||||||
|
maxcount, stat.cur);
|
||||||
|
} else {
|
||||||
|
vim_snprintf(t, SEARCH_STAT_BUF_LEN, "[%d/%d]",
|
||||||
|
stat.cnt, stat.cur);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (stat.incomplete == 1) {
|
||||||
|
vim_snprintf(t, SEARCH_STAT_BUF_LEN, "[?/??]");
|
||||||
|
} else if (stat.cnt > maxcount && stat.cur > maxcount) {
|
||||||
|
vim_snprintf(t, SEARCH_STAT_BUF_LEN, "[>%d/>%d]",
|
||||||
|
maxcount, maxcount);
|
||||||
|
} else if (stat.cnt > maxcount) {
|
||||||
|
vim_snprintf(t, SEARCH_STAT_BUF_LEN, "[%d/>%d]",
|
||||||
|
stat.cur, maxcount);
|
||||||
|
} else {
|
||||||
|
vim_snprintf(t, SEARCH_STAT_BUF_LEN, "[%d/%d]",
|
||||||
|
stat.cur, stat.cnt);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t len = strlen(t);
|
||||||
|
if (show_top_bot_msg && len + 2 < SEARCH_STAT_BUF_LEN) {
|
||||||
|
memmove(t + 2, t, len);
|
||||||
|
t[0] = 'W';
|
||||||
|
t[1] = ' ';
|
||||||
|
len += 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
memmove(msgbuf + strlen(msgbuf) - len, t, len);
|
||||||
|
if (dirc == '?' && stat.cur == maxcount + 1) {
|
||||||
|
stat.cur = -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// keep the message even after redraw, but don't put in history
|
||||||
|
msg_hist_off = true;
|
||||||
|
msg_ext_set_kind("search_count");
|
||||||
|
give_warning(msgbuf, false);
|
||||||
|
msg_hist_off = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add the search count information to "stat".
|
// Add the search count information to "stat".
|
||||||
|
@@ -122,17 +122,17 @@ static signgroup_T *sign_group_ref(const char *groupname)
|
|||||||
/// removed, then remove the group.
|
/// removed, then remove the group.
|
||||||
static void sign_group_unref(char *groupname)
|
static void sign_group_unref(char *groupname)
|
||||||
{
|
{
|
||||||
signgroup_T *group;
|
|
||||||
|
|
||||||
hashitem_T *hi = hash_find(&sg_table, groupname);
|
hashitem_T *hi = hash_find(&sg_table, groupname);
|
||||||
if (!HASHITEM_EMPTY(hi)) {
|
if (HASHITEM_EMPTY(hi)) {
|
||||||
group = HI2SG(hi);
|
return;
|
||||||
group->sg_refcount--;
|
}
|
||||||
if (group->sg_refcount == 0) {
|
|
||||||
// All the signs in this group are removed
|
signgroup_T *group = HI2SG(hi);
|
||||||
hash_remove(&sg_table, hi);
|
group->sg_refcount--;
|
||||||
xfree(group);
|
if (group->sg_refcount == 0) {
|
||||||
}
|
// All the signs in this group are removed
|
||||||
|
hash_remove(&sg_table, hi);
|
||||||
|
xfree(group);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -1488,14 +1488,16 @@ void spell_cat_line(char *buf, char *line, int maxlen)
|
|||||||
p = (char_u *)skipwhite((char *)p + 1);
|
p = (char_u *)skipwhite((char *)p + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (*p != NUL) {
|
if (*p == NUL) {
|
||||||
// Only worth concatenating if there is something else than spaces to
|
return;
|
||||||
// concatenate.
|
}
|
||||||
int n = (int)(p - (char_u *)line) + 1;
|
|
||||||
if (n < maxlen - 1) {
|
// Only worth concatenating if there is something else than spaces to
|
||||||
memset(buf, ' ', (size_t)n);
|
// concatenate.
|
||||||
xstrlcpy(buf + n, (char *)p, (size_t)(maxlen - n));
|
int n = (int)(p - (char_u *)line) + 1;
|
||||||
}
|
if (n < maxlen - 1) {
|
||||||
|
memset(buf, ' ', (size_t)n);
|
||||||
|
xstrlcpy(buf + n, (char *)p, (size_t)(maxlen - n));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1702,17 +1704,19 @@ static void spell_load_cb(char *fname, void *cookie)
|
|||||||
{
|
{
|
||||||
spelload_T *slp = (spelload_T *)cookie;
|
spelload_T *slp = (spelload_T *)cookie;
|
||||||
slang_T *slang = spell_load_file(fname, slp->sl_lang, NULL, false);
|
slang_T *slang = spell_load_file(fname, slp->sl_lang, NULL, false);
|
||||||
if (slang != NULL) {
|
if (slang == NULL) {
|
||||||
// When a previously loaded file has NOBREAK also use it for the
|
return;
|
||||||
// ".add" files.
|
|
||||||
if (slp->sl_nobreak && slang->sl_add) {
|
|
||||||
slang->sl_nobreak = true;
|
|
||||||
} else if (slang->sl_nobreak) {
|
|
||||||
slp->sl_nobreak = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
slp->sl_slang = slang;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// When a previously loaded file has NOBREAK also use it for the
|
||||||
|
// ".add" files.
|
||||||
|
if (slp->sl_nobreak && slang->sl_add) {
|
||||||
|
slang->sl_nobreak = true;
|
||||||
|
} else if (slang->sl_nobreak) {
|
||||||
|
slp->sl_nobreak = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
slp->sl_slang = slang;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Add a word to the hashtable of common words.
|
/// Add a word to the hashtable of common words.
|
||||||
@@ -2258,13 +2262,15 @@ int captype(char *word, const char *end)
|
|||||||
// Delete the internal wordlist and its .spl file.
|
// Delete the internal wordlist and its .spl file.
|
||||||
void spell_delete_wordlist(void)
|
void spell_delete_wordlist(void)
|
||||||
{
|
{
|
||||||
if (int_wordlist != NULL) {
|
if (int_wordlist == NULL) {
|
||||||
char fname[MAXPATHL] = { 0 };
|
return;
|
||||||
os_remove(int_wordlist);
|
|
||||||
int_wordlist_spl(fname);
|
|
||||||
os_remove(fname);
|
|
||||||
XFREE_CLEAR(int_wordlist);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
char fname[MAXPATHL] = { 0 };
|
||||||
|
os_remove(int_wordlist);
|
||||||
|
int_wordlist_spl(fname);
|
||||||
|
os_remove(fname);
|
||||||
|
XFREE_CLEAR(int_wordlist);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Free all languages.
|
// Free all languages.
|
||||||
@@ -2332,10 +2338,12 @@ buf_T *open_spellbuf(void)
|
|||||||
// Close the buffer used for spell info.
|
// Close the buffer used for spell info.
|
||||||
void close_spellbuf(buf_T *buf)
|
void close_spellbuf(buf_T *buf)
|
||||||
{
|
{
|
||||||
if (buf != NULL) {
|
if (buf == NULL) {
|
||||||
ml_close(buf, true);
|
return;
|
||||||
xfree(buf);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ml_close(buf, true);
|
||||||
|
xfree(buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Init the chartab used for spelling for ASCII.
|
// Init the chartab used for spelling for ASCII.
|
||||||
@@ -3624,15 +3632,16 @@ char *did_set_spell_option(bool is_spellfile)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (errmsg == NULL) {
|
if (errmsg != NULL) {
|
||||||
FOR_ALL_WINDOWS_IN_TAB(wp, curtab) {
|
return errmsg;
|
||||||
if (wp->w_buffer == curbuf && wp->w_p_spell) {
|
|
||||||
errmsg = did_set_spelllang(wp);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
FOR_ALL_WINDOWS_IN_TAB(wp, curtab) {
|
||||||
|
if (wp->w_buffer == curbuf && wp->w_p_spell) {
|
||||||
|
errmsg = did_set_spelllang(wp);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
return errmsg;
|
return errmsg;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -1695,23 +1695,25 @@ static int spell_read_tree(FILE *fd, char **bytsp, long *bytsp_len, idx_T **idxs
|
|||||||
// Invalid length, multiply with sizeof(int) would overflow.
|
// Invalid length, multiply with sizeof(int) would overflow.
|
||||||
return SP_FORMERROR;
|
return SP_FORMERROR;
|
||||||
}
|
}
|
||||||
if (len > 0) {
|
if (len <= 0) {
|
||||||
// Allocate the byte array.
|
return 0;
|
||||||
bp = xmalloc((size_t)len);
|
}
|
||||||
*bytsp = bp;
|
|
||||||
if (bytsp_len != NULL) {
|
|
||||||
*bytsp_len = len;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Allocate the index array.
|
// Allocate the byte array.
|
||||||
ip = xcalloc((size_t)len, sizeof(*ip));
|
bp = xmalloc((size_t)len);
|
||||||
*idxsp = ip;
|
*bytsp = bp;
|
||||||
|
if (bytsp_len != NULL) {
|
||||||
|
*bytsp_len = len;
|
||||||
|
}
|
||||||
|
|
||||||
// Recursively read the tree and store it in the array.
|
// Allocate the index array.
|
||||||
idx = read_tree_node(fd, (char_u *)bp, ip, (int)len, 0, prefixtree, prefixcnt);
|
ip = xcalloc((size_t)len, sizeof(*ip));
|
||||||
if (idx < 0) {
|
*idxsp = ip;
|
||||||
return idx;
|
|
||||||
}
|
// Recursively read the tree and store it in the array.
|
||||||
|
idx = read_tree_node(fd, (char_u *)bp, ip, (int)len, 0, prefixtree, prefixcnt);
|
||||||
|
if (idx < 0) {
|
||||||
|
return idx;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -2003,14 +2005,15 @@ static void spell_print_node(wordnode_T *node, int depth)
|
|||||||
|
|
||||||
static void spell_print_tree(wordnode_T *root)
|
static void spell_print_tree(wordnode_T *root)
|
||||||
{
|
{
|
||||||
if (root != NULL) {
|
if (root == NULL) {
|
||||||
// Clear the "wn_u1.index" fields, used to remember what has been
|
return;
|
||||||
// done.
|
|
||||||
spell_clear_flags(root);
|
|
||||||
|
|
||||||
// Recursively print the tree.
|
|
||||||
spell_print_node(root, 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Clear the "wn_u1.index" fields, used to remember what has been done.
|
||||||
|
spell_clear_flags(root);
|
||||||
|
|
||||||
|
// Recursively print the tree.
|
||||||
|
spell_print_node(root, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // SPELL_PRINTTREE
|
#endif // SPELL_PRINTTREE
|
||||||
@@ -4197,31 +4200,33 @@ static void wordtree_compress(spellinfo_T *spin, wordnode_T *root, const char *n
|
|||||||
|
|
||||||
// Skip the root itself, it's not actually used. The first sibling is the
|
// Skip the root itself, it's not actually used. The first sibling is the
|
||||||
// start of the tree.
|
// start of the tree.
|
||||||
if (root->wn_sibling != NULL) {
|
if (root->wn_sibling == NULL) {
|
||||||
hash_init(&ht);
|
return;
|
||||||
const long n = node_compress(spin, root->wn_sibling, &ht, &tot);
|
}
|
||||||
|
|
||||||
|
hash_init(&ht);
|
||||||
|
const long n = node_compress(spin, root->wn_sibling, &ht, &tot);
|
||||||
|
|
||||||
#ifndef SPELL_PRINTTREE
|
#ifndef SPELL_PRINTTREE
|
||||||
if (spin->si_verbose || p_verbose > 2)
|
if (spin->si_verbose || p_verbose > 2)
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
if (tot > 1000000) {
|
if (tot > 1000000) {
|
||||||
perc = (tot - n) / (tot / 100);
|
perc = (tot - n) / (tot / 100);
|
||||||
} else if (tot == 0) {
|
} else if (tot == 0) {
|
||||||
perc = 0;
|
perc = 0;
|
||||||
} else {
|
} else {
|
||||||
perc = (tot - n) * 100 / tot;
|
perc = (tot - n) * 100 / tot;
|
||||||
}
|
|
||||||
vim_snprintf(IObuff, IOSIZE,
|
|
||||||
_("Compressed %s of %ld nodes; %ld (%ld%%) remaining"),
|
|
||||||
name, tot, tot - n, perc);
|
|
||||||
spell_message(spin, IObuff);
|
|
||||||
}
|
}
|
||||||
#ifdef SPELL_PRINTTREE
|
vim_snprintf(IObuff, IOSIZE,
|
||||||
spell_print_tree(root->wn_sibling);
|
_("Compressed %s of %ld nodes; %ld (%ld%%) remaining"),
|
||||||
#endif
|
name, tot, tot - n, perc);
|
||||||
hash_clear(&ht);
|
spell_message(spin, IObuff);
|
||||||
}
|
}
|
||||||
|
#ifdef SPELL_PRINTTREE
|
||||||
|
spell_print_tree(root->wn_sibling);
|
||||||
|
#endif
|
||||||
|
hash_clear(&ht);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Compress a node, its siblings and its children, depth first.
|
/// Compress a node, its siblings and its children, depth first.
|
||||||
@@ -4887,10 +4892,12 @@ void ex_mkspell(exarg_T *eap)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Expand all the remaining arguments (e.g., $VIMRUNTIME).
|
// Expand all the remaining arguments (e.g., $VIMRUNTIME).
|
||||||
if (get_arglist_exp(arg, &fcount, &fnames, false) == OK) {
|
if (get_arglist_exp(arg, &fcount, &fnames, false) != OK) {
|
||||||
mkspell(fcount, fnames, ascii, eap->forceit, false);
|
return;
|
||||||
FreeWild(fcount, fnames);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mkspell(fcount, fnames, ascii, eap->forceit, false);
|
||||||
|
FreeWild(fcount, fnames);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create the .sug file.
|
// Create the .sug file.
|
||||||
@@ -5681,64 +5688,66 @@ static void init_spellfile(void)
|
|||||||
bool aspath = false;
|
bool aspath = false;
|
||||||
char *lstart = curbuf->b_s.b_p_spl;
|
char *lstart = curbuf->b_s.b_p_spl;
|
||||||
|
|
||||||
if (*curwin->w_s->b_p_spl != NUL && !GA_EMPTY(&curwin->w_s->b_langp)) {
|
if (*curwin->w_s->b_p_spl == NUL || GA_EMPTY(&curwin->w_s->b_langp)) {
|
||||||
buf = xmalloc(MAXPATHL);
|
return;
|
||||||
|
|
||||||
// Find the end of the language name. Exclude the region. If there
|
|
||||||
// is a path separator remember the start of the tail.
|
|
||||||
for (lend = curwin->w_s->b_p_spl; *lend != NUL
|
|
||||||
&& vim_strchr(",._", (uint8_t)(*lend)) == NULL; lend++) {
|
|
||||||
if (vim_ispathsep(*lend)) {
|
|
||||||
aspath = true;
|
|
||||||
lstart = lend + 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Loop over all entries in 'runtimepath'. Use the first one where we
|
|
||||||
// are allowed to write.
|
|
||||||
rtp = p_rtp;
|
|
||||||
while (*rtp != NUL) {
|
|
||||||
if (aspath) {
|
|
||||||
// Use directory of an entry with path, e.g., for
|
|
||||||
// "/dir/lg.utf-8.spl" use "/dir".
|
|
||||||
xstrlcpy(buf, curbuf->b_s.b_p_spl, (size_t)(lstart - curbuf->b_s.b_p_spl));
|
|
||||||
} else {
|
|
||||||
// Copy the path from 'runtimepath' to buf[].
|
|
||||||
copy_option_part(&rtp, buf, MAXPATHL, ",");
|
|
||||||
}
|
|
||||||
if (os_file_is_writable(buf) == 2) {
|
|
||||||
// Use the first language name from 'spelllang' and the
|
|
||||||
// encoding used in the first loaded .spl file.
|
|
||||||
if (aspath) {
|
|
||||||
xstrlcpy(buf, curbuf->b_s.b_p_spl, (size_t)(lend - curbuf->b_s.b_p_spl + 1));
|
|
||||||
} else {
|
|
||||||
// Create the "spell" directory if it doesn't exist yet.
|
|
||||||
l = (int)strlen(buf);
|
|
||||||
vim_snprintf(buf + l, MAXPATHL - (size_t)l, "/spell");
|
|
||||||
if (os_file_is_writable(buf) != 2) {
|
|
||||||
os_mkdir(buf, 0755);
|
|
||||||
}
|
|
||||||
|
|
||||||
l = (int)strlen(buf);
|
|
||||||
vim_snprintf(buf + l, MAXPATHL - (size_t)l,
|
|
||||||
"/%.*s", (int)(lend - lstart), lstart);
|
|
||||||
}
|
|
||||||
l = (int)strlen(buf);
|
|
||||||
fname = LANGP_ENTRY(curwin->w_s->b_langp, 0)
|
|
||||||
->lp_slang->sl_fname;
|
|
||||||
vim_snprintf(buf + l, MAXPATHL - (size_t)l, ".%s.add",
|
|
||||||
((fname != NULL
|
|
||||||
&& strstr(path_tail(fname), ".ascii.") != NULL)
|
|
||||||
? "ascii"
|
|
||||||
: (const char *)spell_enc()));
|
|
||||||
set_option_value_give_err("spellfile", 0L, buf, OPT_LOCAL);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
aspath = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
xfree(buf);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
buf = xmalloc(MAXPATHL);
|
||||||
|
|
||||||
|
// Find the end of the language name. Exclude the region. If there
|
||||||
|
// is a path separator remember the start of the tail.
|
||||||
|
for (lend = curwin->w_s->b_p_spl; *lend != NUL
|
||||||
|
&& vim_strchr(",._", (uint8_t)(*lend)) == NULL; lend++) {
|
||||||
|
if (vim_ispathsep(*lend)) {
|
||||||
|
aspath = true;
|
||||||
|
lstart = lend + 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Loop over all entries in 'runtimepath'. Use the first one where we
|
||||||
|
// are allowed to write.
|
||||||
|
rtp = p_rtp;
|
||||||
|
while (*rtp != NUL) {
|
||||||
|
if (aspath) {
|
||||||
|
// Use directory of an entry with path, e.g., for
|
||||||
|
// "/dir/lg.utf-8.spl" use "/dir".
|
||||||
|
xstrlcpy(buf, curbuf->b_s.b_p_spl, (size_t)(lstart - curbuf->b_s.b_p_spl));
|
||||||
|
} else {
|
||||||
|
// Copy the path from 'runtimepath' to buf[].
|
||||||
|
copy_option_part(&rtp, buf, MAXPATHL, ",");
|
||||||
|
}
|
||||||
|
if (os_file_is_writable(buf) == 2) {
|
||||||
|
// Use the first language name from 'spelllang' and the
|
||||||
|
// encoding used in the first loaded .spl file.
|
||||||
|
if (aspath) {
|
||||||
|
xstrlcpy(buf, curbuf->b_s.b_p_spl, (size_t)(lend - curbuf->b_s.b_p_spl + 1));
|
||||||
|
} else {
|
||||||
|
// Create the "spell" directory if it doesn't exist yet.
|
||||||
|
l = (int)strlen(buf);
|
||||||
|
vim_snprintf(buf + l, MAXPATHL - (size_t)l, "/spell");
|
||||||
|
if (os_file_is_writable(buf) != 2) {
|
||||||
|
os_mkdir(buf, 0755);
|
||||||
|
}
|
||||||
|
|
||||||
|
l = (int)strlen(buf);
|
||||||
|
vim_snprintf(buf + l, MAXPATHL - (size_t)l,
|
||||||
|
"/%.*s", (int)(lend - lstart), lstart);
|
||||||
|
}
|
||||||
|
l = (int)strlen(buf);
|
||||||
|
fname = LANGP_ENTRY(curwin->w_s->b_langp, 0)
|
||||||
|
->lp_slang->sl_fname;
|
||||||
|
vim_snprintf(buf + l, MAXPATHL - (size_t)l, ".%s.add",
|
||||||
|
((fname != NULL
|
||||||
|
&& strstr(path_tail(fname), ".ascii.") != NULL)
|
||||||
|
? "ascii"
|
||||||
|
: (const char *)spell_enc()));
|
||||||
|
set_option_value_give_err("spellfile", 0L, buf, OPT_LOCAL);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
aspath = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
xfree(buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Set the spell character tables from strings in the .spl file.
|
/// Set the spell character tables from strings in the .spl file.
|
||||||
|
@@ -276,26 +276,27 @@ static int score_wordcount_adj(slang_T *slang, int score, char_u *word, bool spl
|
|||||||
int newscore;
|
int newscore;
|
||||||
|
|
||||||
hashitem_T *hi = hash_find(&slang->sl_wordcount, (char *)word);
|
hashitem_T *hi = hash_find(&slang->sl_wordcount, (char *)word);
|
||||||
if (!HASHITEM_EMPTY(hi)) {
|
if (HASHITEM_EMPTY(hi)) {
|
||||||
wc = HI2WC(hi);
|
return score;
|
||||||
if (wc->wc_count < SCORE_THRES2) {
|
|
||||||
bonus = SCORE_COMMON1;
|
|
||||||
} else if (wc->wc_count < SCORE_THRES3) {
|
|
||||||
bonus = SCORE_COMMON2;
|
|
||||||
} else {
|
|
||||||
bonus = SCORE_COMMON3;
|
|
||||||
}
|
|
||||||
if (split) {
|
|
||||||
newscore = score - bonus / 2;
|
|
||||||
} else {
|
|
||||||
newscore = score - bonus;
|
|
||||||
}
|
|
||||||
if (newscore < 0) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
return newscore;
|
|
||||||
}
|
}
|
||||||
return score;
|
|
||||||
|
wc = HI2WC(hi);
|
||||||
|
if (wc->wc_count < SCORE_THRES2) {
|
||||||
|
bonus = SCORE_COMMON1;
|
||||||
|
} else if (wc->wc_count < SCORE_THRES3) {
|
||||||
|
bonus = SCORE_COMMON2;
|
||||||
|
} else {
|
||||||
|
bonus = SCORE_COMMON3;
|
||||||
|
}
|
||||||
|
if (split) {
|
||||||
|
newscore = score - bonus / 2;
|
||||||
|
} else {
|
||||||
|
newscore = score - bonus;
|
||||||
|
}
|
||||||
|
if (newscore < 0) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
return newscore;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Like captype() but for a KEEPCAP word add ONECAP if the word starts with a
|
/// Like captype() but for a KEEPCAP word add ONECAP if the word starts with a
|
||||||
@@ -310,36 +311,39 @@ static int badword_captype(char_u *word, char_u *end)
|
|||||||
bool first;
|
bool first;
|
||||||
char_u *p;
|
char_u *p;
|
||||||
|
|
||||||
if (flags & WF_KEEPCAP) {
|
if (!(flags & WF_KEEPCAP)) {
|
||||||
// Count the number of UPPER and lower case letters.
|
return flags;
|
||||||
l = u = 0;
|
}
|
||||||
first = false;
|
|
||||||
for (p = word; p < end; MB_PTR_ADV(p)) {
|
// Count the number of UPPER and lower case letters.
|
||||||
c = utf_ptr2char((char *)p);
|
l = u = 0;
|
||||||
if (SPELL_ISUPPER(c)) {
|
first = false;
|
||||||
u++;
|
for (p = word; p < end; MB_PTR_ADV(p)) {
|
||||||
if (p == word) {
|
c = utf_ptr2char((char *)p);
|
||||||
first = true;
|
if (SPELL_ISUPPER(c)) {
|
||||||
}
|
u++;
|
||||||
} else {
|
if (p == word) {
|
||||||
l++;
|
first = true;
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
|
l++;
|
||||||
// If there are more UPPER than lower case letters suggest an
|
|
||||||
// ALLCAP word. Otherwise, if the first letter is UPPER then
|
|
||||||
// suggest ONECAP. Exception: "ALl" most likely should be "All",
|
|
||||||
// require three upper case letters.
|
|
||||||
if (u > l && u > 2) {
|
|
||||||
flags |= WF_ALLCAP;
|
|
||||||
} else if (first) {
|
|
||||||
flags |= WF_ONECAP;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (u >= 2 && l >= 2) { // maCARONI maCAroni
|
|
||||||
flags |= WF_MIXCAP;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If there are more UPPER than lower case letters suggest an
|
||||||
|
// ALLCAP word. Otherwise, if the first letter is UPPER then
|
||||||
|
// suggest ONECAP. Exception: "ALl" most likely should be "All",
|
||||||
|
// require three upper case letters.
|
||||||
|
if (u > l && u > 2) {
|
||||||
|
flags |= WF_ALLCAP;
|
||||||
|
} else if (first) {
|
||||||
|
flags |= WF_ONECAP;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (u >= 2 && l >= 2) { // maCARONI maCAroni
|
||||||
|
flags |= WF_MIXCAP;
|
||||||
|
}
|
||||||
|
|
||||||
return flags;
|
return flags;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -3247,10 +3251,11 @@ static void add_banned(suginfo_T *su, char *word)
|
|||||||
hash = hash_hash(word);
|
hash = hash_hash(word);
|
||||||
const size_t word_len = strlen(word);
|
const size_t word_len = strlen(word);
|
||||||
hi = hash_lookup(&su->su_banned, word, word_len, hash);
|
hi = hash_lookup(&su->su_banned, word, word_len, hash);
|
||||||
if (HASHITEM_EMPTY(hi)) {
|
if (!HASHITEM_EMPTY(hi)) { // already present
|
||||||
s = xmemdupz(word, word_len);
|
return;
|
||||||
hash_add_item(&su->su_banned, hi, (char *)s, hash);
|
|
||||||
}
|
}
|
||||||
|
s = xmemdupz(word, word_len);
|
||||||
|
hash_add_item(&su->su_banned, hi, (char *)s, hash);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Recompute the score for all suggestions if sound-folding is possible. This
|
/// Recompute the score for all suggestions if sound-folding is possible. This
|
||||||
@@ -3317,21 +3322,23 @@ static int sug_compare(const void *s1, const void *s2)
|
|||||||
static int cleanup_suggestions(garray_T *gap, int maxscore, int keep)
|
static int cleanup_suggestions(garray_T *gap, int maxscore, int keep)
|
||||||
FUNC_ATTR_NONNULL_ALL
|
FUNC_ATTR_NONNULL_ALL
|
||||||
{
|
{
|
||||||
if (gap->ga_len > 0) {
|
if (gap->ga_len <= 0) {
|
||||||
// Sort the list.
|
return maxscore;
|
||||||
qsort(gap->ga_data, (size_t)gap->ga_len, sizeof(suggest_T), sug_compare);
|
}
|
||||||
|
|
||||||
// Truncate the list to the number of suggestions that will be displayed.
|
// Sort the list.
|
||||||
if (gap->ga_len > keep) {
|
qsort(gap->ga_data, (size_t)gap->ga_len, sizeof(suggest_T), sug_compare);
|
||||||
suggest_T *const stp = &SUG(*gap, 0);
|
|
||||||
|
|
||||||
for (int i = keep; i < gap->ga_len; i++) {
|
// Truncate the list to the number of suggestions that will be displayed.
|
||||||
xfree(stp[i].st_word);
|
if (gap->ga_len > keep) {
|
||||||
}
|
suggest_T *const stp = &SUG(*gap, 0);
|
||||||
gap->ga_len = keep;
|
|
||||||
if (keep >= 1) {
|
for (int i = keep; i < gap->ga_len; i++) {
|
||||||
return stp[keep - 1].st_score;
|
xfree(stp[i].st_word);
|
||||||
}
|
}
|
||||||
|
gap->ga_len = keep;
|
||||||
|
if (keep >= 1) {
|
||||||
|
return stp[keep - 1].st_score;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return maxscore;
|
return maxscore;
|
||||||
|
@@ -721,10 +721,12 @@ static void syn_sync(win_T *wp, linenr_T start_lnum, synstate_T *last_valid)
|
|||||||
|
|
||||||
static void save_chartab(char *chartab)
|
static void save_chartab(char *chartab)
|
||||||
{
|
{
|
||||||
if (syn_block->b_syn_isk != empty_option) {
|
if (syn_block->b_syn_isk == empty_option) {
|
||||||
memmove(chartab, syn_buf->b_chartab, (size_t)32);
|
return;
|
||||||
memmove(syn_buf->b_chartab, syn_win->w_s->b_syn_chartab, (size_t)32);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
memmove(chartab, syn_buf->b_chartab, (size_t)32);
|
||||||
|
memmove(syn_buf->b_chartab, syn_win->w_s->b_syn_chartab, (size_t)32);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void restore_chartab(char *chartab)
|
static void restore_chartab(char *chartab)
|
||||||
@@ -737,22 +739,23 @@ static void restore_chartab(char *chartab)
|
|||||||
/// Return true if the line-continuation pattern matches in line "lnum".
|
/// Return true if the line-continuation pattern matches in line "lnum".
|
||||||
static int syn_match_linecont(linenr_T lnum)
|
static int syn_match_linecont(linenr_T lnum)
|
||||||
{
|
{
|
||||||
if (syn_block->b_syn_linecont_prog != NULL) {
|
if (syn_block->b_syn_linecont_prog == NULL) {
|
||||||
regmmatch_T regmatch;
|
return false;
|
||||||
// chartab array for syn iskeyword
|
|
||||||
char buf_chartab[32];
|
|
||||||
save_chartab(buf_chartab);
|
|
||||||
|
|
||||||
regmatch.rmm_ic = syn_block->b_syn_linecont_ic;
|
|
||||||
regmatch.regprog = syn_block->b_syn_linecont_prog;
|
|
||||||
int r = syn_regexec(®match, lnum, (colnr_T)0,
|
|
||||||
IF_SYN_TIME(&syn_block->b_syn_linecont_time));
|
|
||||||
syn_block->b_syn_linecont_prog = regmatch.regprog;
|
|
||||||
|
|
||||||
restore_chartab(buf_chartab);
|
|
||||||
return r;
|
|
||||||
}
|
}
|
||||||
return false;
|
|
||||||
|
regmmatch_T regmatch;
|
||||||
|
// chartab array for syn iskeyword
|
||||||
|
char buf_chartab[32];
|
||||||
|
save_chartab(buf_chartab);
|
||||||
|
|
||||||
|
regmatch.rmm_ic = syn_block->b_syn_linecont_ic;
|
||||||
|
regmatch.regprog = syn_block->b_syn_linecont_prog;
|
||||||
|
int r = syn_regexec(®match, lnum, (colnr_T)0,
|
||||||
|
IF_SYN_TIME(&syn_block->b_syn_linecont_time));
|
||||||
|
syn_block->b_syn_linecont_prog = regmatch.regprog;
|
||||||
|
|
||||||
|
restore_chartab(buf_chartab);
|
||||||
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Prepare the current state for the start of a line.
|
// Prepare the current state for the start of a line.
|
||||||
@@ -873,14 +876,16 @@ static void syn_stack_free_block(synblock_T *block)
|
|||||||
{
|
{
|
||||||
synstate_T *p;
|
synstate_T *p;
|
||||||
|
|
||||||
if (block->b_sst_array != NULL) {
|
if (block->b_sst_array == NULL) {
|
||||||
for (p = block->b_sst_first; p != NULL; p = p->sst_next) {
|
return;
|
||||||
clear_syn_state(p);
|
|
||||||
}
|
|
||||||
XFREE_CLEAR(block->b_sst_array);
|
|
||||||
block->b_sst_first = NULL;
|
|
||||||
block->b_sst_len = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (p = block->b_sst_first; p != NULL; p = p->sst_next) {
|
||||||
|
clear_syn_state(p);
|
||||||
|
}
|
||||||
|
XFREE_CLEAR(block->b_sst_array);
|
||||||
|
block->b_sst_first = NULL;
|
||||||
|
block->b_sst_len = 0;
|
||||||
}
|
}
|
||||||
// Free b_sst_array[] for buffer "buf".
|
// Free b_sst_array[] for buffer "buf".
|
||||||
// Used when syntax items changed to force resyncing everywhere.
|
// Used when syntax items changed to force resyncing everywhere.
|
||||||
@@ -5369,34 +5374,39 @@ void set_context_in_syntax_cmd(expand_T *xp, const char *arg)
|
|||||||
include_link = 0;
|
include_link = 0;
|
||||||
include_default = 0;
|
include_default = 0;
|
||||||
|
|
||||||
|
if (*arg == NUL) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// (part of) subcommand already typed
|
// (part of) subcommand already typed
|
||||||
if (*arg != NUL) {
|
const char *p = (const char *)skiptowhite(arg);
|
||||||
const char *p = (const char *)skiptowhite(arg);
|
if (*p == NUL) {
|
||||||
if (*p != NUL) { // Past first word.
|
return;
|
||||||
xp->xp_pattern = skipwhite(p);
|
}
|
||||||
if (*skiptowhite(xp->xp_pattern) != NUL) {
|
|
||||||
xp->xp_context = EXPAND_NOTHING;
|
// past first world
|
||||||
} else if (STRNICMP(arg, "case", p - arg) == 0) {
|
xp->xp_pattern = skipwhite(p);
|
||||||
expand_what = EXP_CASE;
|
if (*skiptowhite(xp->xp_pattern) != NUL) {
|
||||||
} else if (STRNICMP(arg, "spell", p - arg) == 0) {
|
xp->xp_context = EXPAND_NOTHING;
|
||||||
expand_what = EXP_SPELL;
|
} else if (STRNICMP(arg, "case", p - arg) == 0) {
|
||||||
} else if (STRNICMP(arg, "sync", p - arg) == 0) {
|
expand_what = EXP_CASE;
|
||||||
expand_what = EXP_SYNC;
|
} else if (STRNICMP(arg, "spell", p - arg) == 0) {
|
||||||
} else if (STRNICMP(arg, "list", p - arg) == 0) {
|
expand_what = EXP_SPELL;
|
||||||
p = skipwhite(p);
|
} else if (STRNICMP(arg, "sync", p - arg) == 0) {
|
||||||
if (*p == '@') {
|
expand_what = EXP_SYNC;
|
||||||
expand_what = EXP_CLUSTER;
|
} else if (STRNICMP(arg, "list", p - arg) == 0) {
|
||||||
} else {
|
p = skipwhite(p);
|
||||||
xp->xp_context = EXPAND_HIGHLIGHT;
|
if (*p == '@') {
|
||||||
}
|
expand_what = EXP_CLUSTER;
|
||||||
} else if (STRNICMP(arg, "keyword", p - arg) == 0
|
} else {
|
||||||
|| STRNICMP(arg, "region", p - arg) == 0
|
xp->xp_context = EXPAND_HIGHLIGHT;
|
||||||
|| STRNICMP(arg, "match", p - arg) == 0) {
|
|
||||||
xp->xp_context = EXPAND_HIGHLIGHT;
|
|
||||||
} else {
|
|
||||||
xp->xp_context = EXPAND_NOTHING;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
} else if (STRNICMP(arg, "keyword", p - arg) == 0
|
||||||
|
|| STRNICMP(arg, "region", p - arg) == 0
|
||||||
|
|| STRNICMP(arg, "match", p - arg) == 0) {
|
||||||
|
xp->xp_context = EXPAND_HIGHLIGHT;
|
||||||
|
} else {
|
||||||
|
xp->xp_context = EXPAND_NOTHING;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user