aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/nvim/api/deprecated.c14
-rw-r--r--src/nvim/api/options.c33
-rw-r--r--src/nvim/option.c31
3 files changed, 65 insertions, 13 deletions
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..31a2fb3b80 100644
--- a/src/nvim/api/options.c
+++ b/src/nvim/api/options.c
@@ -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/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;