diff options
| author | Justin M. Keyes <justinkz@gmail.com> | 2014-12-14 13:42:10 -0500 |
|---|---|---|
| committer | Justin M. Keyes <justinkz@gmail.com> | 2014-12-14 13:42:10 -0500 |
| commit | ec6afbf4e621bfcfde903d15744dc0c61f80097d (patch) | |
| tree | 94fd08577b5eed003b6f7eb3a7bcafcac7f20a66 /src | |
| parent | 64a32d55c59188f1e922ca438fdb2d65caa06665 (diff) | |
| parent | 0bc40e660c0a74776ace86ad5e393755523c3803 (diff) | |
| download | rneovim-ec6afbf4e621bfcfde903d15744dc0c61f80097d.tar.gz rneovim-ec6afbf4e621bfcfde903d15744dc0c61f80097d.tar.bz2 rneovim-ec6afbf4e621bfcfde903d15744dc0c61f80097d.zip | |
Merge pull request #1661 from philix/early_exit
Reduce indentation level by early returning or continuing loop
Diffstat (limited to 'src')
| -rw-r--r-- | src/nvim/buffer.c | 149 | ||||
| -rw-r--r-- | src/nvim/diff.c | 31 | ||||
| -rw-r--r-- | src/nvim/edit.c | 199 | ||||
| -rw-r--r-- | src/nvim/eval.c | 39 | ||||
| -rw-r--r-- | src/nvim/ex_cmds.c | 216 | ||||
| -rw-r--r-- | src/nvim/ex_docmd.c | 31 | ||||
| -rw-r--r-- | src/nvim/ex_eval.c | 40 | ||||
| -rw-r--r-- | src/nvim/fileio.c | 167 | ||||
| -rw-r--r-- | src/nvim/fold.c | 53 | ||||
| -rw-r--r-- | src/nvim/getchar.c | 53 | ||||
| -rw-r--r-- | src/nvim/hashtab.c | 31 | ||||
| -rw-r--r-- | src/nvim/indent_c.c | 203 | ||||
| -rw-r--r-- | src/nvim/normal.c | 65 | ||||
| -rw-r--r-- | src/nvim/regexp.c | 276 | ||||
| -rw-r--r-- | src/nvim/screen.c | 7 | ||||
| -rw-r--r-- | src/nvim/syntax.c | 339 | ||||
| -rw-r--r-- | src/nvim/window.c | 194 |
17 files changed, 1056 insertions, 1037 deletions
diff --git a/src/nvim/buffer.c b/src/nvim/buffer.c index ec10a826c7..f84e25cdfb 100644 --- a/src/nvim/buffer.c +++ b/src/nvim/buffer.c @@ -238,25 +238,27 @@ open_buffer ( } apply_autocmds_retval(EVENT_BUFENTER, NULL, NULL, FALSE, curbuf, &retval); - if (retval != FAIL) { - /* - * The autocommands may have changed the current buffer. Apply the - * modelines to the correct buffer, if it still exists and is loaded. - */ - if (buf_valid(old_curbuf) && old_curbuf->b_ml.ml_mfp != NULL) { - aco_save_T aco; + if (retval == FAIL) { + return FAIL; + } - /* Go to the buffer that was opened. */ - aucmd_prepbuf(&aco, old_curbuf); - do_modelines(0); - curbuf->b_flags &= ~(BF_CHECK_RO | BF_NEVERLOADED); + /* + * The autocommands may have changed the current buffer. Apply the + * modelines to the correct buffer, if it still exists and is loaded. + */ + if (buf_valid(old_curbuf) && old_curbuf->b_ml.ml_mfp != NULL) { + aco_save_T aco; + + /* Go to the buffer that was opened. */ + aucmd_prepbuf(&aco, old_curbuf); + do_modelines(0); + curbuf->b_flags &= ~(BF_CHECK_RO | BF_NEVERLOADED); - apply_autocmds_retval(EVENT_BUFWINENTER, NULL, NULL, FALSE, curbuf, - &retval); + apply_autocmds_retval(EVENT_BUFWINENTER, NULL, NULL, FALSE, curbuf, + &retval); - /* restore curwin/curbuf and a few other things */ - aucmd_restbuf(&aco); - } + /* restore curwin/curbuf and a few other things */ + aucmd_restbuf(&aco); } return retval; @@ -2103,14 +2105,10 @@ void get_winopts(buf_T *buf) */ pos_T *buflist_findfpos(buf_T *buf) { - wininfo_T *wip; static pos_T no_position = INIT_POS_T(1, 0, 0); - wip = find_wininfo(buf, FALSE); - if (wip != NULL) - return &(wip->wi_fpos); - else - return &no_position; + wininfo_T *wip = find_wininfo(buf, FALSE); + return (wip == NULL) ? &no_position : &(wip->wi_fpos); } /* @@ -4091,66 +4089,69 @@ chk_modeline ( prev = *s; } - if (*s) { - do /* skip over "ex:", "vi:" or "vim:" */ - ++s; - while (s[-1] != ':'); + if (!*s) { + return retval; + } - s = linecopy = vim_strsave(s); /* copy the line, it will change */ + do /* skip over "ex:", "vi:" or "vim:" */ + ++s; + while (s[-1] != ':'); - save_sourcing_lnum = sourcing_lnum; - save_sourcing_name = sourcing_name; - sourcing_lnum = lnum; /* prepare for emsg() */ - sourcing_name = (char_u *)"modelines"; + s = linecopy = vim_strsave(s); /* copy the line, it will change */ - end = FALSE; - while (end == FALSE) { - s = skipwhite(s); - if (*s == NUL) - break; + save_sourcing_lnum = sourcing_lnum; + save_sourcing_name = sourcing_name; + sourcing_lnum = lnum; /* prepare for emsg() */ + sourcing_name = (char_u *)"modelines"; - /* - * Find end of set command: ':' or end of line. - * Skip over "\:", replacing it with ":". - */ - for (e = s; *e != ':' && *e != NUL; ++e) - if (e[0] == '\\' && e[1] == ':') - STRMOVE(e, e + 1); - if (*e == NUL) - end = TRUE; + end = FALSE; + while (end == FALSE) { + s = skipwhite(s); + if (*s == NUL) + break; - /* - * If there is a "set" command, require a terminating ':' and - * ignore the stuff after the ':'. - * "vi:set opt opt opt: foo" -- foo not interpreted - * "vi:opt opt opt: foo" -- foo interpreted - * Accept "se" for compatibility with Elvis. - */ - if (STRNCMP(s, "set ", (size_t)4) == 0 - || STRNCMP(s, "se ", (size_t)3) == 0) { - if (*e != ':') /* no terminating ':'? */ - break; - end = TRUE; - s = vim_strchr(s, ' ') + 1; - } - *e = NUL; /* truncate the set command */ - - if (*s != NUL) { /* skip over an empty "::" */ - save_SID = current_SID; - current_SID = SID_MODELINE; - retval = do_set(s, OPT_MODELINE | OPT_LOCAL | flags); - current_SID = save_SID; - if (retval == FAIL) /* stop if error found */ - break; - } - s = e + 1; /* advance to next part */ + /* + * Find end of set command: ':' or end of line. + * Skip over "\:", replacing it with ":". + */ + for (e = s; *e != ':' && *e != NUL; ++e) + if (e[0] == '\\' && e[1] == ':') + STRMOVE(e, e + 1); + if (*e == NUL) + end = TRUE; + + /* + * If there is a "set" command, require a terminating ':' and + * ignore the stuff after the ':'. + * "vi:set opt opt opt: foo" -- foo not interpreted + * "vi:opt opt opt: foo" -- foo interpreted + * Accept "se" for compatibility with Elvis. + */ + if (STRNCMP(s, "set ", (size_t)4) == 0 + || STRNCMP(s, "se ", (size_t)3) == 0) { + if (*e != ':') /* no terminating ':'? */ + break; + end = TRUE; + s = vim_strchr(s, ' ') + 1; + } + *e = NUL; /* truncate the set command */ + + if (*s != NUL) { /* skip over an empty "::" */ + save_SID = current_SID; + current_SID = SID_MODELINE; + retval = do_set(s, OPT_MODELINE | OPT_LOCAL | flags); + current_SID = save_SID; + if (retval == FAIL) /* stop if error found */ + break; } + s = e + 1; /* advance to next part */ + } - sourcing_lnum = save_sourcing_lnum; - sourcing_name = save_sourcing_name; + sourcing_lnum = save_sourcing_lnum; + sourcing_name = save_sourcing_name; + + free(linecopy); - free(linecopy); - } return retval; } diff --git a/src/nvim/diff.c b/src/nvim/diff.c index b557753bff..3151daf826 100644 --- a/src/nvim/diff.c +++ b/src/nvim/diff.c @@ -579,24 +579,25 @@ static int diff_check_sanity(tabpage_T *tp, diff_T *dp) static void diff_redraw(int dofold) { FOR_ALL_WINDOWS_IN_TAB(wp, curtab) { - if (wp->w_p_diff) { - redraw_win_later(wp, SOME_VALID); - if (dofold && foldmethodIsDiff(wp)) { - foldUpdateAll(wp); - } + if (!wp->w_p_diff) { + continue; + } + redraw_win_later(wp, SOME_VALID); + if (dofold && foldmethodIsDiff(wp)) { + foldUpdateAll(wp); + } - /* A change may have made filler lines invalid, need to take care - * of that for other windows. */ - int n = diff_check(wp, wp->w_topline); + /* A change may have made filler lines invalid, need to take care + * of that for other windows. */ + int n = diff_check(wp, wp->w_topline); - if (((wp != curwin) && (wp->w_topfill > 0)) || (n > 0)) { - if (wp->w_topfill > n) { - wp->w_topfill = (n < 0 ? 0 : n); - } else if ((n > 0) && (n > wp->w_topfill)) { - wp->w_topfill = n; - } - check_topfill(wp, FALSE); + if (((wp != curwin) && (wp->w_topfill > 0)) || (n > 0)) { + if (wp->w_topfill > n) { + wp->w_topfill = (n < 0 ? 0 : n); + } else if ((n > 0) && (n > wp->w_topfill)) { + wp->w_topfill = n; } + check_topfill(wp, FALSE); } } } diff --git a/src/nvim/edit.c b/src/nvim/edit.c index d5ef84ff7b..e1a1fb18fa 100644 --- a/src/nvim/edit.c +++ b/src/nvim/edit.c @@ -2565,75 +2565,76 @@ static void ins_compl_files(int count, char_u **files, int thesaurus, int flags, (void)msg_trunc_attr(IObuff, TRUE, hl_attr(HLF_R)); } - if (fp != NULL) { - /* - * Read dictionary file line by line. - * Check each line for a match. - */ - while (!got_int && !compl_interrupted - && !vim_fgets(buf, LSIZE, fp)) { - ptr = buf; - while (vim_regexec(regmatch, buf, (colnr_T)(ptr - buf))) { - ptr = regmatch->startp[0]; - if (ctrl_x_mode == CTRL_X_WHOLE_LINE) - ptr = find_line_end(ptr); - else - ptr = find_word_end(ptr); - add_r = ins_compl_add_infercase(regmatch->startp[0], - (int)(ptr - regmatch->startp[0]), - p_ic, files[i], *dir, 0); - if (thesaurus) { - char_u *wstart; - - /* - * Add the other matches on the line - */ - ptr = buf; - while (!got_int) { - /* Find start of the next word. Skip white - * space and punctuation. */ - ptr = find_word_start(ptr); - if (*ptr == NUL || *ptr == NL) - break; - wstart = ptr; - - /* Find end of the word. */ - if (has_mbyte) - /* Japanese words may have characters in - * different classes, only separate words - * with single-byte non-word characters. */ - while (*ptr != NUL) { - int l = (*mb_ptr2len)(ptr); - - if (l < 2 && !vim_iswordc(*ptr)) - break; - ptr += l; - } - else - ptr = find_word_end(ptr); + if (fp == NULL) { + continue; + } + /* + * Read dictionary file line by line. + * Check each line for a match. + */ + while (!got_int && !compl_interrupted + && !vim_fgets(buf, LSIZE, fp)) { + ptr = buf; + while (vim_regexec(regmatch, buf, (colnr_T)(ptr - buf))) { + ptr = regmatch->startp[0]; + if (ctrl_x_mode == CTRL_X_WHOLE_LINE) + ptr = find_line_end(ptr); + else + ptr = find_word_end(ptr); + add_r = ins_compl_add_infercase(regmatch->startp[0], + (int)(ptr - regmatch->startp[0]), + p_ic, files[i], *dir, 0); + if (thesaurus) { + char_u *wstart; - /* Add the word. Skip the regexp match. */ - if (wstart != regmatch->startp[0]) - add_r = ins_compl_add_infercase(wstart, - (int)(ptr - wstart), - p_ic, files[i], *dir, 0); - } + /* + * Add the other matches on the line + */ + ptr = buf; + while (!got_int) { + /* Find start of the next word. Skip white + * space and punctuation. */ + ptr = find_word_start(ptr); + if (*ptr == NUL || *ptr == NL) + break; + wstart = ptr; + + /* Find end of the word. */ + if (has_mbyte) + /* Japanese words may have characters in + * different classes, only separate words + * with single-byte non-word characters. */ + while (*ptr != NUL) { + int l = (*mb_ptr2len)(ptr); + + if (l < 2 && !vim_iswordc(*ptr)) + break; + ptr += l; + } + else + ptr = find_word_end(ptr); + + /* Add the word. Skip the regexp match. */ + if (wstart != regmatch->startp[0]) + add_r = ins_compl_add_infercase(wstart, + (int)(ptr - wstart), + p_ic, files[i], *dir, 0); } - if (add_r == OK) - /* if dir was BACKWARD then honor it just once */ - *dir = FORWARD; - else if (add_r == FAIL) - break; - /* avoid expensive call to vim_regexec() when at end - * of line */ - if (*ptr == '\n' || got_int) - break; } - line_breakcheck(); - ins_compl_check_keys(50); + if (add_r == OK) + /* if dir was BACKWARD then honor it just once */ + *dir = FORWARD; + else if (add_r == FAIL) + break; + /* avoid expensive call to vim_regexec() when at end + * of line */ + if (*ptr == '\n' || got_int) + break; } - fclose(fp); + line_breakcheck(); + ins_compl_check_keys(50); } + fclose(fp); } } @@ -7027,41 +7028,43 @@ static void ins_ctrl_(void) */ static int ins_start_select(int c) { - if (km_startsel) - switch (c) { - case K_KHOME: - case K_KEND: - case K_PAGEUP: - case K_KPAGEUP: - case K_PAGEDOWN: - case K_KPAGEDOWN: - if (!(mod_mask & MOD_MASK_SHIFT)) - break; - /* FALLTHROUGH */ - case K_S_LEFT: - case K_S_RIGHT: - case K_S_UP: - case K_S_DOWN: - case K_S_END: - case K_S_HOME: - /* Start selection right away, the cursor can move with - * CTRL-O when beyond the end of the line. */ - start_selection(); - - /* Execute the key in (insert) Select mode. */ - stuffcharReadbuff(Ctrl_O); - if (mod_mask) { - char_u buf[4]; - - buf[0] = K_SPECIAL; - buf[1] = KS_MODIFIER; - buf[2] = mod_mask; - buf[3] = NUL; - stuffReadbuff(buf); - } - stuffcharReadbuff(c); - return TRUE; + if (!km_startsel) { + return FALSE; + } + switch (c) { + case K_KHOME: + case K_KEND: + case K_PAGEUP: + case K_KPAGEUP: + case K_PAGEDOWN: + case K_KPAGEDOWN: + if (!(mod_mask & MOD_MASK_SHIFT)) + break; + /* FALLTHROUGH */ + case K_S_LEFT: + case K_S_RIGHT: + case K_S_UP: + case K_S_DOWN: + case K_S_END: + case K_S_HOME: + /* Start selection right away, the cursor can move with + * CTRL-O when beyond the end of the line. */ + start_selection(); + + /* Execute the key in (insert) Select mode. */ + stuffcharReadbuff(Ctrl_O); + if (mod_mask) { + char_u buf[4]; + + buf[0] = K_SPECIAL; + buf[1] = KS_MODIFIER; + buf[2] = mod_mask; + buf[3] = NUL; + stuffReadbuff(buf); } + stuffcharReadbuff(c); + return TRUE; + } return FALSE; } diff --git a/src/nvim/eval.c b/src/nvim/eval.c index 45ab901398..71cb83e566 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -5987,29 +5987,30 @@ static char_u *dict2string(typval_T *tv, int copyID) todo = (int)d->dv_hashtab.ht_used; for (hi = d->dv_hashtab.ht_array; todo > 0 && !got_int; ++hi) { - if (!HASHITEM_EMPTY(hi)) { - --todo; + if (HASHITEM_EMPTY(hi)) { + continue; + } + --todo; - if (first) - first = FALSE; - else - ga_concat(&ga, (char_u *)", "); + if (first) + first = FALSE; + else + ga_concat(&ga, (char_u *)", "); - tofree = string_quote(hi->hi_key, FALSE); - if (tofree != NULL) { - ga_concat(&ga, tofree); - free(tofree); - } - ga_concat(&ga, (char_u *)": "); - s = tv2string(&HI2DI(hi)->di_tv, &tofree, numbuf, copyID); - if (s != NULL) - ga_concat(&ga, s); + tofree = string_quote(hi->hi_key, FALSE); + if (tofree != NULL) { + ga_concat(&ga, tofree); free(tofree); - if (s == NULL || did_echo_string_emsg) { - break; - } - line_breakcheck(); } + ga_concat(&ga, (char_u *)": "); + s = tv2string(&HI2DI(hi)->di_tv, &tofree, numbuf, copyID); + if (s != NULL) + ga_concat(&ga, s); + free(tofree); + if (s == NULL || did_echo_string_emsg) { + break; + } + line_breakcheck(); } if (todo > 0) { free(ga.ga_data); diff --git a/src/nvim/ex_cmds.c b/src/nvim/ex_cmds.c index 4d9b8feb8a..1c6aa536b3 100644 --- a/src/nvim/ex_cmds.c +++ b/src/nvim/ex_cmds.c @@ -2375,34 +2375,35 @@ void do_wqall(exarg_T *eap) exiting = TRUE; FOR_ALL_BUFFERS(buf) { - if (bufIsChanged(buf)) { - /* - * Check if there is a reason the buffer cannot be written: - * 1. if the 'write' option is set - * 2. if there is no file name (even after browsing) - * 3. if the 'readonly' is set (even after a dialog) - * 4. if overwriting is allowed (even after a dialog) - */ - if (not_writing()) { - ++error; - break; - } - if (buf->b_ffname == NULL) { - EMSGN(_("E141: No file name for buffer %" PRId64), buf->b_fnum); - ++error; - } else if (check_readonly(&eap->forceit, buf) - || check_overwrite(eap, buf, buf->b_fname, buf->b_ffname, - FALSE) == FAIL) { + if (!bufIsChanged(buf)) { + continue; + } + /* + * Check if there is a reason the buffer cannot be written: + * 1. if the 'write' option is set + * 2. if there is no file name (even after browsing) + * 3. if the 'readonly' is set (even after a dialog) + * 4. if overwriting is allowed (even after a dialog) + */ + if (not_writing()) { + ++error; + break; + } + if (buf->b_ffname == NULL) { + EMSGN(_("E141: No file name for buffer %" PRId64), buf->b_fnum); + ++error; + } else if (check_readonly(&eap->forceit, buf) + || check_overwrite(eap, buf, buf->b_fname, buf->b_ffname, + FALSE) == FAIL) { + ++error; + } else { + if (buf_write_all(buf, eap->forceit) == FAIL) ++error; - } else { - if (buf_write_all(buf, eap->forceit) == FAIL) - ++error; - /* an autocommand may have deleted the buffer */ - if (!buf_valid(buf)) - buf = firstbuf; - } - eap->forceit = save_forceit; /* check_overwrite() may set it */ + /* an autocommand may have deleted the buffer */ + if (!buf_valid(buf)) + buf = firstbuf; } + eap->forceit = save_forceit; /* check_overwrite() may set it */ } if (exiting) { if (!error) @@ -3328,12 +3329,11 @@ void ex_z(exarg_T *eap) if (!VIM_ISDIGIT(*x)) { EMSG(_("E144: non-numeric argument to :z")); return; - } else { - bigness = atoi((char *)x); - p_window = bigness; - if (*kind == '=') - bigness += 2; } + bigness = atoi((char *)x); + p_window = bigness; + if (*kind == '=') + bigness += 2; } /* the number of '-' and '+' multiplies the distance */ @@ -5232,61 +5232,62 @@ void fix_help_buffer(void) if (fnames[fi] == NULL) continue; fd = mch_fopen((char *)fnames[fi], "r"); - if (fd != NULL) { - vim_fgets(IObuff, IOSIZE, fd); - if (IObuff[0] == '*' - && (s = vim_strchr(IObuff + 1, '*')) - != NULL) { - int this_utf = MAYBE; - /* Change tag definition to a - * reference and remove <CR>/<NL>. */ - IObuff[0] = '|'; - *s = '|'; - while (*s != NUL) { - if (*s == '\r' || *s == '\n') - *s = NUL; - /* The text is utf-8 when a byte - * above 127 is found and no - * illegal byte sequence is found. - */ - if (*s >= 0x80 && this_utf != FALSE) { - int l; - - this_utf = TRUE; - l = utf_ptr2len(s); - if (l == 1) - this_utf = FALSE; - s += l - 1; - } - ++s; + if (fd == NULL) { + continue; + } + vim_fgets(IObuff, IOSIZE, fd); + if (IObuff[0] == '*' + && (s = vim_strchr(IObuff + 1, '*')) + != NULL) { + int this_utf = MAYBE; + /* Change tag definition to a + * reference and remove <CR>/<NL>. */ + IObuff[0] = '|'; + *s = '|'; + while (*s != NUL) { + if (*s == '\r' || *s == '\n') + *s = NUL; + /* The text is utf-8 when a byte + * above 127 is found and no + * illegal byte sequence is found. + */ + if (*s >= 0x80 && this_utf != FALSE) { + int l; + + this_utf = TRUE; + l = utf_ptr2len(s); + if (l == 1) + this_utf = FALSE; + s += l - 1; } - /* The help file is latin1 or utf-8; - * conversion to the current - * 'encoding' may be required. */ - vc.vc_type = CONV_NONE; - convert_setup(&vc, (char_u *)( - this_utf == TRUE ? "utf-8" - : "latin1"), p_enc); - if (vc.vc_type == CONV_NONE) - /* No conversion needed. */ + ++s; + } + /* The help file is latin1 or utf-8; + * conversion to the current + * 'encoding' may be required. */ + vc.vc_type = CONV_NONE; + convert_setup(&vc, (char_u *)( + this_utf == TRUE ? "utf-8" + : "latin1"), p_enc); + if (vc.vc_type == CONV_NONE) + /* No conversion needed. */ + cp = IObuff; + else { + /* Do the conversion. If it fails + * use the unconverted text. */ + cp = string_convert(&vc, IObuff, + NULL); + if (cp == NULL) cp = IObuff; - else { - /* Do the conversion. If it fails - * use the unconverted text. */ - cp = string_convert(&vc, IObuff, - NULL); - if (cp == NULL) - cp = IObuff; - } - convert_setup(&vc, NULL, NULL); - - ml_append(lnum, cp, (colnr_T)0, FALSE); - if (cp != IObuff) - free(cp); - ++lnum; } - fclose(fd); + convert_setup(&vc, NULL, NULL); + + ml_append(lnum, cp, (colnr_T)0, FALSE); + if (cp != IObuff) + free(cp); + ++lnum; } + fclose(fd); } FreeWild(fcount, fnames); } @@ -5368,32 +5369,33 @@ void ex_helptags(exarg_T *eap) ga_init(&ga, 1, 10); for (int i = 0; i < filecount; ++i) { len = (int)STRLEN(files[i]); - if (len > 4) { - if (STRICMP(files[i] + len - 4, ".txt") == 0) { - /* ".txt" -> language "en" */ - lang[0] = 'e'; - lang[1] = 'n'; - } else if (files[i][len - 4] == '.' - && ASCII_ISALPHA(files[i][len - 3]) - && ASCII_ISALPHA(files[i][len - 2]) - && TOLOWER_ASC(files[i][len - 1]) == 'x') { - /* ".abx" -> language "ab" */ - lang[0] = TOLOWER_ASC(files[i][len - 3]); - lang[1] = TOLOWER_ASC(files[i][len - 2]); - } else - continue; + if (len <= 4) { + continue; + } + if (STRICMP(files[i] + len - 4, ".txt") == 0) { + /* ".txt" -> language "en" */ + lang[0] = 'e'; + lang[1] = 'n'; + } else if (files[i][len - 4] == '.' + && ASCII_ISALPHA(files[i][len - 3]) + && ASCII_ISALPHA(files[i][len - 2]) + && TOLOWER_ASC(files[i][len - 1]) == 'x') { + /* ".abx" -> language "ab" */ + lang[0] = TOLOWER_ASC(files[i][len - 3]); + lang[1] = TOLOWER_ASC(files[i][len - 2]); + } else + continue; - int j; - /* Did we find this language already? */ - for (j = 0; j < ga.ga_len; j += 2) - if (STRNCMP(lang, ((char_u *)ga.ga_data) + j, 2) == 0) - break; - if (j == ga.ga_len) { - /* New language, add it. */ - ga_grow(&ga, 2); - ((char_u *)ga.ga_data)[ga.ga_len++] = lang[0]; - ((char_u *)ga.ga_data)[ga.ga_len++] = lang[1]; - } + int j; + /* Did we find this language already? */ + for (j = 0; j < ga.ga_len; j += 2) + if (STRNCMP(lang, ((char_u *)ga.ga_data) + j, 2) == 0) + break; + if (j == ga.ga_len) { + /* New language, add it. */ + ga_grow(&ga, 2); + ((char_u *)ga.ga_data)[ga.ga_len++] = lang[0]; + ((char_u *)ga.ga_data)[ga.ga_len++] = lang[1]; } } diff --git a/src/nvim/ex_docmd.c b/src/nvim/ex_docmd.c index 2d20ec5025..56c8206d2a 100644 --- a/src/nvim/ex_docmd.c +++ b/src/nvim/ex_docmd.c @@ -7748,24 +7748,25 @@ static char_u *arg_all(void) len = 0; for (idx = 0; idx < ARGCOUNT; ++idx) { p = alist_name(&ARGLIST[idx]); - if (p != NULL) { - if (len > 0) { - /* insert a space in between names */ - if (retval != NULL) - retval[len] = ' '; - ++len; - } - for (; *p != NUL; ++p) { - if (*p == ' ' || *p == '\\') { - /* insert a backslash */ - if (retval != NULL) - retval[len] = '\\'; - ++len; - } + if (p == NULL) { + continue; + } + if (len > 0) { + /* insert a space in between names */ + if (retval != NULL) + retval[len] = ' '; + ++len; + } + for (; *p != NUL; ++p) { + if (*p == ' ' || *p == '\\') { + /* insert a backslash */ if (retval != NULL) - retval[len] = *p; + retval[len] = '\\'; ++len; } + if (retval != NULL) + retval[len] = *p; + ++len; } } diff --git a/src/nvim/ex_eval.c b/src/nvim/ex_eval.c index 196f8e6136..b0c4e14f46 100644 --- a/src/nvim/ex_eval.c +++ b/src/nvim/ex_eval.c @@ -246,28 +246,24 @@ int cause_errthrow(char_u *mesg, int severe, int *ignore) plist = &(*plist)->next; elem = xmalloc(sizeof(struct msglist)); - { - elem->msg = vim_strsave(mesg); - { - elem->next = NULL; - elem->throw_msg = NULL; - *plist = elem; - if (plist == msg_list || severe) { - char_u *tmsg; - - /* Skip the extra "Vim " prefix for message "E458". */ - tmsg = elem->msg; - if (STRNCMP(tmsg, "Vim E", 5) == 0 - && VIM_ISDIGIT(tmsg[5]) - && VIM_ISDIGIT(tmsg[6]) - && VIM_ISDIGIT(tmsg[7]) - && tmsg[8] == ':' - && tmsg[9] == ' ') - (*msg_list)->throw_msg = &tmsg[4]; - else - (*msg_list)->throw_msg = tmsg; - } - } + elem->msg = vim_strsave(mesg); + elem->next = NULL; + elem->throw_msg = NULL; + *plist = elem; + if (plist == msg_list || severe) { + char_u *tmsg; + + /* Skip the extra "Vim " prefix for message "E458". */ + tmsg = elem->msg; + if (STRNCMP(tmsg, "Vim E", 5) == 0 + && VIM_ISDIGIT(tmsg[5]) + && VIM_ISDIGIT(tmsg[6]) + && VIM_ISDIGIT(tmsg[7]) + && tmsg[8] == ':' + && tmsg[9] == ' ') + (*msg_list)->throw_msg = &tmsg[4]; + else + (*msg_list)->throw_msg = tmsg; } } return TRUE; diff --git a/src/nvim/fileio.c b/src/nvim/fileio.c index 021b12208e..9734ac07f9 100644 --- a/src/nvim/fileio.c +++ b/src/nvim/fileio.c @@ -533,63 +533,64 @@ readfile ( curbuf->b_p_ro = TRUE; /* must use "w!" now */ } else #endif - if (newfile) { - if (perm < 0 + if (!newfile) { + return FAIL; + } + if (perm < 0 #ifdef ENOENT - && errno == ENOENT + && errno == ENOENT #endif - ) { - /* - * Set the 'new-file' flag, so that when the file has - * been created by someone else, a ":w" will complain. - */ - curbuf->b_flags |= BF_NEW; - - /* Create a swap file now, so that other Vims are warned - * that we are editing this file. Don't do this for a - * "nofile" or "nowrite" buffer type. */ - if (!bt_dontwrite(curbuf)) { - check_need_swap(newfile); - /* SwapExists autocommand may mess things up */ - if (curbuf != old_curbuf - || (using_b_ffname - && (old_b_ffname != curbuf->b_ffname)) - || (using_b_fname - && (old_b_fname != curbuf->b_fname))) { - EMSG(_(e_auchangedbuf)); - return FAIL; - } - } - if (dir_of_file_exists(fname)) - filemess(curbuf, sfname, (char_u *)_("[New File]"), 0); - else - filemess(curbuf, sfname, - (char_u *)_("[New DIRECTORY]"), 0); - /* Even though this is a new file, it might have been - * edited before and deleted. Get the old marks. */ - check_marks_read(); - /* Set forced 'fileencoding'. */ - if (eap != NULL) - set_forced_fenc(eap); - apply_autocmds_exarg(EVENT_BUFNEWFILE, sfname, sfname, - FALSE, curbuf, eap); - /* remember the current fileformat */ |