diff options
Diffstat (limited to 'src')
-rwxr-xr-x | src/nvim/CMakeLists.txt | 5 | ||||
-rw-r--r-- | src/nvim/api/deprecated.c | 14 | ||||
-rw-r--r-- | src/nvim/api/options.c | 47 | ||||
-rw-r--r-- | src/nvim/autocmd.c | 29 | ||||
-rw-r--r-- | src/nvim/edit.c | 6 | ||||
-rw-r--r-- | src/nvim/option.c | 31 | ||||
-rw-r--r-- | src/nvim/optionstr.c | 35 |
7 files changed, 111 insertions, 56 deletions
diff --git a/src/nvim/CMakeLists.txt b/src/nvim/CMakeLists.txt index d425e819f0..cb688785df 100755 --- a/src/nvim/CMakeLists.txt +++ b/src/nvim/CMakeLists.txt @@ -746,15 +746,12 @@ if(WIN32) "file(MAKE_DIRECTORY \"${PROJECT_BINARY_DIR}/windows_runtime_deps/platforms\")") foreach(DEP_FILE IN ITEMS cat.exe - curl-ca-bundle.crt - curl.exe diff.exe tee.exe win32yank.exe xxd.exe - ${NVIMQT_DEPS} - ) + ${NVIMQT_DEPS}) get_filename_component(DEP_FILE_DIR ${DEP_FILE} DIRECTORY) set(EXTERNAL_BLOBS_SCRIPT "${EXTERNAL_BLOBS_SCRIPT}\n" "file(COPY \"${DEPS_PREFIX}/bin/${DEP_FILE}\" diff --git a/src/nvim/api/deprecated.c b/src/nvim/api/deprecated.c index 6a12cfe2da..5937b2f635 100644 --- a/src/nvim/api/deprecated.c +++ b/src/nvim/api/deprecated.c @@ -20,6 +20,7 @@ #include "nvim/highlight_group.h" #include "nvim/lua/executor.h" #include "nvim/memory.h" +#include "nvim/option.h" #include "nvim/pos.h" #include "nvim/types.h" @@ -508,3 +509,16 @@ static int64_t convert_index(int64_t index) { return index < 0 ? index - 1 : index; } + +/// Gets the option information for one option +/// +/// @deprecated Use @ref nvim_get_option_info2 instead. +/// +/// @param name Option name +/// @param[out] err Error details, if any +/// @return Option Information +Dictionary nvim_get_option_info(String name, Error *err) + FUNC_API_SINCE(7) +{ + return get_vimoption(name, OPT_GLOBAL, curbuf, curwin, err); +} diff --git a/src/nvim/api/options.c b/src/nvim/api/options.c index 7a453c01b4..baeb3e88fb 100644 --- a/src/nvim/api/options.c +++ b/src/nvim/api/options.c @@ -111,15 +111,15 @@ static buf_T *do_ft_buf(char *filetype, aco_save_T *aco, Error *err) // Set curwin/curbuf to buf and save a few things. aucmd_prepbuf(aco, ftbuf); - set_option_value("bufhidden", 0L, "hide", OPT_LOCAL); - set_option_value("buftype", 0L, "nofile", OPT_LOCAL); - set_option_value("swapfile", 0L, NULL, OPT_LOCAL); - set_option_value("modeline", 0L, NULL, OPT_LOCAL); // 'nomodeline' - - ftbuf->b_p_ft = xstrdup(filetype); TRY_WRAP(err, { - apply_autocmds(EVENT_FILETYPE, ftbuf->b_p_ft, ftbuf->b_fname, true, ftbuf); + set_option_value("bufhidden", 0L, "hide", OPT_LOCAL); + set_option_value("buftype", 0L, "nofile", OPT_LOCAL); + set_option_value("swapfile", 0L, NULL, OPT_LOCAL); + set_option_value("modeline", 0L, NULL, OPT_LOCAL); // 'nomodeline' + + ftbuf->b_p_ft = xstrdup(filetype); + do_filetype_autocmd(ftbuf, false); }); return ftbuf; @@ -283,7 +283,7 @@ void nvim_set_option_value(uint64_t channel_id, String name, Object value, Dict( /// Gets the option information for all options. /// /// The dictionary has the full option names as keys and option metadata -/// dictionaries as detailed at |nvim_get_option_info()|. +/// dictionaries as detailed at |nvim_get_option_info2()|. /// /// @return dictionary of all options Dictionary nvim_get_all_options_info(Error *err) @@ -292,7 +292,7 @@ Dictionary nvim_get_all_options_info(Error *err) return get_all_vimoptions(); } -/// Gets the option information for one option +/// Gets the option information for one option from arbitrary buffer or window /// /// Resulting dictionary has keys: /// - name: Name of the option (like 'filetype') @@ -311,15 +311,36 @@ Dictionary nvim_get_all_options_info(Error *err) /// - commalist: List of comma separated values /// - flaglist: List of single char flags /// +/// When {scope} is not provided, the last set information applies to the local +/// value in the current buffer or window if it is available, otherwise the +/// global value information is returned. This behavior can be disabled by +/// explicitly specifying {scope} in the {opts} table. /// -/// @param name Option name +/// @param name Option name +/// @param opts Optional parameters +/// - scope: One of "global" or "local". Analogous to +/// |:setglobal| and |:setlocal|, respectively. +/// - win: |window-ID|. Used for getting window local options. +/// - buf: Buffer number. Used for getting buffer local options. +/// Implies {scope} is "local". /// @param[out] err Error details, if any /// @return Option Information -Dictionary nvim_get_option_info(String name, Error *err) - FUNC_API_SINCE(7) +Dictionary nvim_get_option_info2(String name, Dict(option) *opts, Error *err) + FUNC_API_SINCE(11) { - return get_vimoption(name, err); + int scope = 0; + int opt_type = SREQ_GLOBAL; + void *from = NULL; + if (!validate_option_value_args(opts, &scope, &opt_type, &from, NULL, err)) { + return (Dictionary)ARRAY_DICT_INIT; + } + + buf_T *buf = (opt_type == SREQ_BUF) ? (buf_T *)from : curbuf; + win_T *win = (opt_type == SREQ_WIN) ? (win_T *)from : curwin; + + return get_vimoption(name, scope, buf, win, err); } + /// Sets the global value of an option. /// /// @param channel_id diff --git a/src/nvim/autocmd.c b/src/nvim/autocmd.c index c66ee4286e..2e83260a40 100644 --- a/src/nvim/autocmd.c +++ b/src/nvim/autocmd.c @@ -2758,3 +2758,32 @@ void do_autocmd_focusgained(bool gained) recursive = false; } + +void do_filetype_autocmd(buf_T *buf, bool force) +{ + static int ft_recursive = 0; + + if (ft_recursive > 0 && !force) { + return; // disallow recursion + } + + char **varp = &buf->b_p_ft; + int secure_save = secure; + + // Reset the secure flag, since the value of 'filetype' has + // been checked to be safe. + secure = 0; + + ft_recursive++; + did_filetype = true; + // Only pass true for "force" when it is true or + // used recursively, to avoid endless recurrence. + apply_autocmds(EVENT_FILETYPE, buf->b_p_ft, buf->b_fname, force, buf); + ft_recursive--; + + // Just in case the old "buf" is now invalid + if (varp != &(buf->b_p_ft)) { + varp = NULL; + } + secure = secure_save; +} diff --git a/src/nvim/edit.c b/src/nvim/edit.c index 0983d025e5..26101d06ed 100644 --- a/src/nvim/edit.c +++ b/src/nvim/edit.c @@ -2294,11 +2294,11 @@ static void stop_insert(pos_T *end_insert_pos, int esc, int nomove) // Don't do it when "restart_edit" was set and nothing was inserted, // otherwise CTRL-O w and then <Left> will clear "last_insert". ptr = get_inserted(); - if (did_restart_edit == 0 || (ptr != NULL - && (int)strlen(ptr) > new_insert_skip)) { + int added = ptr == NULL ? 0 : (int)strlen(ptr) - new_insert_skip; + if (did_restart_edit == 0 || added > 0) { xfree(last_insert); last_insert = ptr; - last_insert_skip = new_insert_skip; + last_insert_skip = added < 0 ? 0 : new_insert_skip; } else { xfree(ptr); } diff --git a/src/nvim/option.c b/src/nvim/option.c index 0aa2f8ab04..f672b3ab6f 100644 --- a/src/nvim/option.c +++ b/src/nvim/option.c @@ -5605,26 +5605,27 @@ long get_sidescrolloff_value(win_T *wp) return wp->w_p_siso < 0 ? p_siso : wp->w_p_siso; } -Dictionary get_vimoption(String name, Error *err) +Dictionary get_vimoption(String name, int scope, buf_T *buf, win_T *win, Error *err) { int opt_idx = findoption_len((const char *)name.data, name.size); VALIDATE_S(opt_idx >= 0, "option (not found)", name.data, { return (Dictionary)ARRAY_DICT_INIT; }); - return vimoption2dict(&options[opt_idx]); + + return vimoption2dict(&options[opt_idx], scope, buf, win); } Dictionary get_all_vimoptions(void) { Dictionary retval = ARRAY_DICT_INIT; for (size_t i = 0; options[i].fullname != NULL; i++) { - Dictionary opt_dict = vimoption2dict(&options[i]); + Dictionary opt_dict = vimoption2dict(&options[i], OPT_GLOBAL, curbuf, curwin); PUT(retval, options[i].fullname, DICTIONARY_OBJ(opt_dict)); } return retval; } -static Dictionary vimoption2dict(vimoption_T *opt) +static Dictionary vimoption2dict(vimoption_T *opt, int req_scope, buf_T *buf, win_T *win) { Dictionary dict = ARRAY_DICT_INIT; @@ -5649,9 +5650,25 @@ static Dictionary vimoption2dict(vimoption_T *opt) PUT(dict, "was_set", BOOL(opt->flags & P_WAS_SET)); - PUT(dict, "last_set_sid", INTEGER_OBJ(opt->last_set.script_ctx.sc_sid)); - PUT(dict, "last_set_linenr", INTEGER_OBJ(opt->last_set.script_ctx.sc_lnum)); - PUT(dict, "last_set_chan", INTEGER_OBJ((int64_t)opt->last_set.channel_id)); + LastSet last_set = { .channel_id = 0 }; + if (req_scope == OPT_GLOBAL) { + last_set = opt->last_set; + } else { + // Scope is either OPT_LOCAL or a fallback mode was requested. + if (opt->indir & PV_BUF) { + last_set = buf->b_p_script_ctx[opt->indir & PV_MASK]; + } + if (opt->indir & PV_WIN) { + last_set = win->w_p_script_ctx[opt->indir & PV_MASK]; + } + if (req_scope != OPT_LOCAL && last_set.script_ctx.sc_sid == 0) { + last_set = opt->last_set; + } + } + + PUT(dict, "last_set_sid", INTEGER_OBJ(last_set.script_ctx.sc_sid)); + PUT(dict, "last_set_linenr", INTEGER_OBJ(last_set.script_ctx.sc_lnum)); + PUT(dict, "last_set_chan", INTEGER_OBJ((int64_t)last_set.channel_id)); const char *type; Object def; diff --git a/src/nvim/optionstr.c b/src/nvim/optionstr.c index 170800b4e6..bf4ebbb3e2 100644 --- a/src/nvim/optionstr.c +++ b/src/nvim/optionstr.c @@ -1529,34 +1529,6 @@ static void do_syntax_autocmd(buf_T *buf, bool value_changed) syn_recursive--; } -static void do_filetype_autocmd(buf_T *buf, char **varp, int opt_flags, bool value_changed) -{ - // 'filetype' is set, trigger the FileType autocommand - // Skip this when called from a modeline and the filetype was - // already set to this value. - if (!(opt_flags & OPT_MODELINE) || value_changed) { - static int ft_recursive = 0; - int secure_save = secure; - - // Reset the secure flag, since the value of 'filetype' has - // been checked to be safe. - secure = 0; - - ft_recursive++; - did_filetype = true; - // Only pass true for "force" when the value changed or not - // used recursively, to avoid endless recurrence. - apply_autocmds(EVENT_FILETYPE, buf->b_p_ft, buf->b_fname, - value_changed || ft_recursive == 1, buf); - ft_recursive--; - // Just in case the old "buf" is now invalid - if (varp != &(buf->b_p_ft)) { - varp = NULL; - } - secure = secure_save; - } -} - static void do_spelllang_source(win_T *win) { char fname[200]; @@ -1884,7 +1856,12 @@ static char *did_set_string_option_for(buf_T *buf, win_T *win, int opt_idx, char if (varp == &buf->b_p_syn) { do_syntax_autocmd(buf, value_changed); } else if (varp == &buf->b_p_ft) { - do_filetype_autocmd(buf, varp, opt_flags, value_changed); + // 'filetype' is set, trigger the FileType autocommand + // Skip this when called from a modeline + // Force autocmd when the filetype was changed + if (!(opt_flags & OPT_MODELINE) || value_changed) { + do_filetype_autocmd(buf, value_changed); + } } else if (varp == &win->w_s->b_p_spl) { do_spelllang_source(win); } |