diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/nvim/api/vim.c | 18 | ||||
-rw-r--r-- | src/nvim/ex_cmds2.c | 279 | ||||
-rw-r--r-- | src/nvim/os/env.c | 2 | ||||
-rw-r--r-- | src/nvim/tui/tui.c | 12 |
4 files changed, 195 insertions, 116 deletions
diff --git a/src/nvim/api/vim.c b/src/nvim/api/vim.c index 4da61a30ef..ecfff1ea8f 100644 --- a/src/nvim/api/vim.c +++ b/src/nvim/api/vim.c @@ -905,17 +905,17 @@ void nvim_set_current_tabpage(Tabpage tabpage, Error *err) } } -/// create a new namespace, or get one with an exisiting name +/// Creates a new namespace, or gets an existing one /// -/// Namespaces are currently used for buffer highlighting and virtual text, see -/// |nvim_buf_add_highlight| and |nvim_buf_set_virtual_text|. +/// Namespaces are used for buffer highlights and virtual text, see +/// |nvim_buf_add_highlight()| and |nvim_buf_set_virtual_text()|. /// -/// Namespaces can have a name of be anonymous. If `name` is a non-empty string, -/// and a namespace already exists with that name,the existing namespace id is -/// returned. If an empty string is used, a new anonymous namespace is returned. +/// Namespaces can be named or anonymous. If `name` matches an existing +/// namespace, the associated id is returned. If `name` is an empty string +/// a new, anonymous namespace is created. /// -/// @param name Name of the namespace or empty string -/// @return the namespace id +/// @param name Namespace name or empty string +/// @return Namespace id Integer nvim_create_namespace(String name) FUNC_API_SINCE(5) { @@ -931,7 +931,7 @@ Integer nvim_create_namespace(String name) return (Integer)id; } -/// Get existing named namespaces +/// Gets existing, non-anonymous namespaces /// /// @return dict that maps from names to namespace ids. Dictionary nvim_get_namespaces(void) diff --git a/src/nvim/ex_cmds2.c b/src/nvim/ex_cmds2.c index c9b6d19aaa..1ffcf67ef7 100644 --- a/src/nvim/ex_cmds2.c +++ b/src/nvim/ex_cmds2.c @@ -2536,48 +2536,50 @@ static void source_all_matches(char_u *pat) } } -// used for "cookie" of add_pack_plugin() -static int APP_ADD_DIR; -static int APP_LOAD; -static int APP_BOTH; - -static void add_pack_plugin(char_u *fname, void *cookie) +/// Add the package directory to 'runtimepath' +static int add_pack_dir_to_rtp(char_u *fname) { char_u *p4, *p3, *p2, *p1, *p; char_u *buf = NULL; + char *afterdir = NULL; + int retval = FAIL; + p4 = p3 = p2 = p1 = get_past_head(fname); + for (p = p1; *p; MB_PTR_ADV(p)) { + if (vim_ispathsep_nocolon(*p)) { + p4 = p3; p3 = p2; p2 = p1; p1 = p; + } + } + + // now we have: + // rtp/pack/name/start/name + // p4 p3 p2 p1 + // + // find the part up to "pack" in 'runtimepath' + p4++; // append pathsep in order to expand symlink + char_u c = *p4; + *p4 = NUL; char *const ffname = fix_fname((char *)fname); + *p4 = c; if (ffname == NULL) { - return; + return FAIL; } - if (cookie != &APP_LOAD && strstr((char *)p_rtp, ffname) == NULL) { - // directory is not yet in 'runtimepath', add it - p4 = p3 = p2 = p1 = get_past_head((char_u *)ffname); - for (p = p1; *p; MB_PTR_ADV(p)) { - if (vim_ispathsep_nocolon(*p)) { - p4 = p3; p3 = p2; p2 = p1; p1 = p; - } - } - - // now we have: - // rtp/pack/name/start/name - // p4 p3 p2 p1 - // - // find the part up to "pack" in 'runtimepath' - char_u c = *p4; - *p4 = NUL; + // Find "ffname" in "p_rtp", ignoring '/' vs '\' differences + // Also stop at the first "after" directory + size_t fname_len = strlen(ffname); + buf = try_malloc(MAXPATHL); + if (buf == NULL) { + goto theend; + } + const char *insp = NULL; + const char *after_insp = NULL; + for (const char *entry = (const char *)p_rtp; *entry != NUL; ) { + const char *cur_entry = entry; - // Find "ffname" in "p_rtp", ignoring '/' vs '\' differences - size_t fname_len = strlen(ffname); - const char *insp = (const char *)p_rtp; - buf = try_malloc(MAXPATHL); - if (buf == NULL) { - goto theend; - } - while (*insp != NUL) { - copy_option_part((char_u **)&insp, buf, MAXPATHL, ","); + copy_option_part((char_u **)&entry, buf, MAXPATHL, ","); + if (insp == NULL) { add_pathsep((char *)buf); char *const rtp_ffname = fix_fname((char *)buf); if (rtp_ffname == NULL) { @@ -2586,87 +2588,164 @@ static void add_pack_plugin(char_u *fname, void *cookie) bool match = path_fnamencmp(rtp_ffname, ffname, fname_len) == 0; xfree(rtp_ffname); if (match) { - break; + // Insert "ffname" after this entry (and comma). + insp = entry; } } - if (*insp == NUL) { - // not found, append at the end - insp = (const char *)p_rtp + STRLEN(p_rtp); - } else { - // append after the matching directory. - insp--; - } - *p4 = c; - - // check if rtp/pack/name/start/name/after exists - char *afterdir = concat_fnames(ffname, "after", true); - size_t afterlen = 0; - if (os_isdir((char_u *)afterdir)) { - afterlen = strlen(afterdir) + 1; // add one for comma - } - - const size_t oldlen = STRLEN(p_rtp); - const size_t addlen = strlen(ffname) + 1; // add one for comma - const size_t new_rtp_len = oldlen + addlen + afterlen + 1; - // add one for NUL -------------------------------------^ - char *const new_rtp = try_malloc(new_rtp_len); - if (new_rtp == NULL) { - goto theend; - } - const size_t keep = (size_t)(insp - (const char *)p_rtp); - size_t new_rtp_fill = 0; - memmove(new_rtp, p_rtp, keep); - new_rtp_fill += keep; - new_rtp[new_rtp_fill++] = ','; - memmove(new_rtp + new_rtp_fill, ffname, addlen); - new_rtp_fill += addlen - 1; - assert(new_rtp[new_rtp_fill] == NUL || new_rtp[new_rtp_fill] == ','); - if (p_rtp[keep] != NUL) { - memmove(new_rtp + new_rtp_fill, p_rtp + keep, oldlen - keep + 1); - new_rtp_fill += oldlen - keep; - } - if (afterlen > 0) { - assert(new_rtp[new_rtp_fill] == NUL); - new_rtp[new_rtp_fill++] = ','; - memmove(new_rtp + new_rtp_fill, afterdir, afterlen - 1); - new_rtp_fill += afterlen - 1; - } - new_rtp[new_rtp_fill] = NUL; - set_option_value("rtp", 0L, new_rtp, 0); - xfree(new_rtp); - xfree(afterdir); + if ((p = (char_u *)strstr((char *)buf, "after")) != NULL + && p > buf + && vim_ispathsep(p[-1]) + && (vim_ispathsep(p[5]) || p[5] == NUL || p[5] == ',')) { + if (insp == NULL) { + // Did not find "ffname" before the first "after" directory, + // insert it before this entry. + insp = cur_entry; + } + after_insp = cur_entry; + break; + } } - if (cookie != &APP_ADD_DIR) { - static const char *plugpat = "%s/plugin/**/*.vim"; // NOLINT - static const char *ftpat = "%s/ftdetect/*.vim"; // NOLINT + if (insp == NULL) { + // Both "fname" and "after" not found, append at the end. + insp = (const char *)p_rtp + STRLEN(p_rtp); + } - size_t len = strlen(ffname) + STRLEN(ftpat); - char_u *pat = try_malloc(len + 1); - if (pat == NULL) { - goto theend; - } - vim_snprintf((char *)pat, len, plugpat, ffname); - source_all_matches(pat); + // check if rtp/pack/name/start/name/after exists + afterdir = concat_fnames((char *)fname, "after", true); + size_t afterlen = 0; + if (os_isdir((char_u *)afterdir)) { + afterlen = strlen(afterdir) + 1; // add one for comma + } - char_u *cmd = vim_strsave((char_u *)"g:did_load_filetypes"); + const size_t oldlen = STRLEN(p_rtp); + const size_t addlen = STRLEN(fname) + 1; // add one for comma + const size_t new_rtp_capacity = oldlen + addlen + afterlen + 1; + // add one for NUL ------------------------------------------^ + char *const new_rtp = try_malloc(new_rtp_capacity); + if (new_rtp == NULL) { + goto theend; + } - // If runtime/filetype.vim wasn't loaded yet, the scripts will be - // found when it loads. - if (eval_to_number(cmd) > 0) { - do_cmdline_cmd("augroup filetypedetect"); - vim_snprintf((char *)pat, len, ftpat, ffname); - source_all_matches(pat); - do_cmdline_cmd("augroup END"); - } - xfree(cmd); - xfree(pat); + // We now have 'rtp' parts: {keep}{keep_after}{rest}. + // Create new_rtp, first: {keep},{fname} + size_t keep = (size_t)(insp - (const char *)p_rtp); + memmove(new_rtp, p_rtp, keep); + size_t new_rtp_len = keep; + if (*insp == NUL) { + new_rtp[new_rtp_len++] = ','; // add comma before + } + memmove(new_rtp + new_rtp_len, fname, addlen - 1); + new_rtp_len += addlen - 1; + if (*insp != NUL) { + new_rtp[new_rtp_len++] = ','; // add comma after + } + + if (afterlen > 0 && after_insp != NULL) { + size_t keep_after = (size_t)(after_insp - (const char *)p_rtp); + + // Add to new_rtp: {keep},{fname}{keep_after},{afterdir} + memmove(new_rtp + new_rtp_len, p_rtp + keep, keep_after - keep); + new_rtp_len += keep_after - keep; + memmove(new_rtp + new_rtp_len, afterdir, afterlen - 1); + new_rtp_len += afterlen - 1; + new_rtp[new_rtp_len++] = ','; + keep = keep_after; + } + + if (p_rtp[keep] != NUL) { + // Append rest: {keep},{fname}{keep_after},{afterdir}{rest} + memmove(new_rtp + new_rtp_len, p_rtp + keep, oldlen - keep + 1); + } else { + new_rtp[new_rtp_len] = NUL; + } + + if (afterlen > 0 && after_insp == NULL) { + // Append afterdir when "after" was not found: + // {keep},{fname}{rest},{afterdir} + xstrlcat(new_rtp, ",", new_rtp_capacity); + xstrlcat(new_rtp, afterdir, new_rtp_capacity); } + set_option_value("rtp", 0L, new_rtp, 0); + xfree(new_rtp); + retval = OK; + theend: xfree(buf); xfree(ffname); + xfree(afterdir); + return retval; +} + +/// Load scripts in "plugin" and "ftdetect" directories of the package. +static int load_pack_plugin(char_u *fname) +{ + static const char *plugpat = "%s/plugin/**/*.vim"; // NOLINT + static const char *ftpat = "%s/ftdetect/*.vim"; // NOLINT + + int retval = FAIL; + char *const ffname = fix_fname((char *)fname); + size_t len = strlen(ffname) + STRLEN(ftpat); + char_u *pat = try_malloc(len + 1); + if (pat == NULL) { + goto theend; + } + vim_snprintf((char *)pat, len, plugpat, ffname); + source_all_matches(pat); + + char_u *cmd = vim_strsave((char_u *)"g:did_load_filetypes"); + + // If runtime/filetype.vim wasn't loaded yet, the scripts will be + // found when it loads. + if (eval_to_number(cmd) > 0) { + do_cmdline_cmd("augroup filetypedetect"); + vim_snprintf((char *)pat, len, ftpat, ffname); + source_all_matches(pat); + do_cmdline_cmd("augroup END"); + } + xfree(cmd); + xfree(pat); + retval = OK; + +theend: + xfree(ffname); + + return retval; +} + +// used for "cookie" of add_pack_plugin() +static int APP_ADD_DIR; +static int APP_LOAD; +static int APP_BOTH; + +static void add_pack_plugin(char_u *fname, void *cookie) +{ + if (cookie != &APP_LOAD) { + char *buf = xmalloc(MAXPATHL); + bool found = false; + + const char *p = (const char *)p_rtp; + while (*p != NUL) { + copy_option_part((char_u **)&p, (char_u *)buf, MAXPATHL, ","); + if (path_fnamecmp(buf, (char *)fname) == 0) { + found = true; + break; + } + } + xfree(buf); + if (!found) { + // directory is not yet in 'runtimepath', add it + if (add_pack_dir_to_rtp(fname) == FAIL) { + return; + } + } + } + + if (cookie != &APP_ADD_DIR) { + load_pack_plugin(fname); + } } /// Add all packages in the "start" directory to 'runtimepath'. diff --git a/src/nvim/os/env.c b/src/nvim/os/env.c index fe01787f9e..c6794e4be5 100644 --- a/src/nvim/os/env.c +++ b/src/nvim/os/env.c @@ -779,7 +779,7 @@ size_t home_replace(const buf_T *const buf, const char_u *src, char *homedir_env_mod = (char *)homedir_env; bool must_free = false; - if (homedir_env_mod != NULL && strchr(homedir_env_mod, '~') != NULL) { + if (homedir_env_mod != NULL && *homedir_env_mod == '~') { must_free = true; size_t usedlen = 0; size_t flen = strlen(homedir_env_mod); diff --git a/src/nvim/tui/tui.c b/src/nvim/tui/tui.c index 426605b785..d1e456f185 100644 --- a/src/nvim/tui/tui.c +++ b/src/nvim/tui/tui.c @@ -1589,9 +1589,9 @@ static void patch_terminfo_bugs(TUIData *data, const char *term, unibi_set_if_empty(ut, unibi_exit_italics_mode, "\x1b[23m"); unibi_set_if_empty(ut, unibi_to_status_line, "\x1b]2"); unibi_set_if_empty(ut, unibi_from_status_line, "\x07"); - // 2017-04 terminfo.src has older control sequences. - unibi_set_str(ut, unibi_enter_ca_mode, "\x1b[?1049h"); - unibi_set_str(ut, unibi_exit_ca_mode, "\x1b[?1049l"); + // Enter/exit alternate screen with "title stacking". #4063 + unibi_set_str(ut, unibi_enter_ca_mode, "\x1b[?1049h\x1b[22;0;0t"); + unibi_set_str(ut, unibi_exit_ca_mode, "\x1b[?1049l\x1b[23;0;0t"); } else if (screen) { // per the screen manual; 2017-04 terminfo.src lacks these. unibi_set_if_empty(ut, unibi_to_status_line, "\x1b_"); @@ -1611,9 +1611,9 @@ static void patch_terminfo_bugs(TUIData *data, const char *term, } else if (putty) { // No bugs in the vanilla terminfo for our purposes. } else if (iterm) { - // 2017-04 terminfo.src has older control sequences. - unibi_set_str(ut, unibi_enter_ca_mode, "\x1b[?1049h"); - unibi_set_str(ut, unibi_exit_ca_mode, "\x1b[?1049l"); + // Enter/exit alternate screen with "title stacking". #4063 + unibi_set_str(ut, unibi_enter_ca_mode, "\x1b[?1049h\x1b[22;0;0t"); + unibi_set_str(ut, unibi_exit_ca_mode, "\x1b[?1049l\x1b[23;0;0t"); // 2017-04 terminfo.src lacks these. unibi_set_if_empty(ut, unibi_set_tb_margin, "\x1b[%i%p1%d;%p2%dr"); unibi_set_if_empty(ut, unibi_orig_pair, "\x1b[39;49m"); |