forked from aniani/vim
updated for version 7.3.924
Problem: Python interface can't easily access options. Solution: Add vim.options, vim.window.options and vim.buffer.options. (ZyX)
This commit is contained in:
219
src/option.c
219
src/option.c
@@ -8820,6 +8820,144 @@ get_option_value(name, numval, stringval, opt_flags)
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3)
|
||||
/*
|
||||
* Returns the option attributes and its value. Unlike the above function it
|
||||
* will return either global value or local value of the option depending on
|
||||
* what was requested, but it will never return global value if it was
|
||||
* requested to return local one and vice versa. Neither it will return
|
||||
* buffer-local value if it was requested to return window-local one.
|
||||
*
|
||||
* Pretends that option is absent if it is not present in the requested scope
|
||||
* (i.e. has no global, window-local or buffer-local value depending on
|
||||
* opt_type). Uses
|
||||
*
|
||||
* Returned flags:
|
||||
* 0 hidden or unknown option
|
||||
* see SOPT_* in vim.h for other flags
|
||||
*
|
||||
* Possible opt_type values: see SREQ_* in vim.h
|
||||
*/
|
||||
int
|
||||
get_option_value_strict(name, numval, stringval, opt_type, from)
|
||||
char_u *name;
|
||||
long *numval;
|
||||
char_u **stringval; /* NULL when only obtaining attributes */
|
||||
int opt_type;
|
||||
void *from;
|
||||
{
|
||||
int opt_idx;
|
||||
char_u *varp;
|
||||
struct vimoption *p;
|
||||
int r = 0;
|
||||
|
||||
opt_idx = findoption(name);
|
||||
if (opt_idx < 0)
|
||||
return 0;
|
||||
|
||||
p = &(options[opt_idx]);
|
||||
|
||||
/* Hidden option */
|
||||
if (p->var == NULL)
|
||||
return 0;
|
||||
|
||||
if (p->flags & P_BOOL)
|
||||
r |= SOPT_BOOL;
|
||||
else if (p->flags & P_NUM)
|
||||
r |= SOPT_NUM;
|
||||
else if (p->flags & P_STRING)
|
||||
r |= SOPT_STRING;
|
||||
|
||||
if (p->indir == PV_NONE)
|
||||
{
|
||||
if (opt_type == SREQ_GLOBAL)
|
||||
r |= SOPT_GLOBAL;
|
||||
else
|
||||
return 0; /* Did not request global-only option */
|
||||
}
|
||||
else
|
||||
{
|
||||
if (p->indir & PV_BOTH)
|
||||
r |= SOPT_GLOBAL;
|
||||
else if (opt_type == SREQ_GLOBAL)
|
||||
return 0; /* Requested global option */
|
||||
|
||||
if (p->indir & PV_WIN)
|
||||
{
|
||||
if (opt_type == SREQ_BUF)
|
||||
return 0; /* Did not request window-local option */
|
||||
else
|
||||
r |= SOPT_WIN;
|
||||
}
|
||||
else if (p->indir & PV_BUF)
|
||||
{
|
||||
if (opt_type == SREQ_WIN)
|
||||
return 0; /* Did not request buffer-local option */
|
||||
else
|
||||
r |= SOPT_BUF;
|
||||
}
|
||||
}
|
||||
|
||||
if (stringval == NULL)
|
||||
return r;
|
||||
|
||||
if (opt_type == SREQ_GLOBAL)
|
||||
varp = p->var;
|
||||
else
|
||||
{
|
||||
if (opt_type == SREQ_BUF)
|
||||
{
|
||||
/* Special case: 'modified' is b_changed, but we also want to
|
||||
* consider it set when 'ff' or 'fenc' changed. */
|
||||
if (p->indir == PV_MOD)
|
||||
{
|
||||
*numval = bufIsChanged((buf_T *) from);
|
||||
varp = NULL;
|
||||
}
|
||||
#ifdef FEAT_CRYPT
|
||||
else if (p->indir == PV_KEY)
|
||||
{
|
||||
/* never return the value of the crypt key */
|
||||
*stringval = NULL;
|
||||
varp = NULL;
|
||||
}
|
||||
#endif
|
||||
else
|
||||
{
|
||||
aco_save_T aco;
|
||||
aucmd_prepbuf(&aco, (buf_T *) from);
|
||||
varp = get_varp(p);
|
||||
aucmd_restbuf(&aco);
|
||||
}
|
||||
}
|
||||
else if (opt_type == SREQ_WIN)
|
||||
{
|
||||
win_T *save_curwin;
|
||||
save_curwin = curwin;
|
||||
curwin = (win_T *) from;
|
||||
curbuf = curwin->w_buffer;
|
||||
varp = get_varp(p);
|
||||
curwin = save_curwin;
|
||||
curbuf = curwin->w_buffer;
|
||||
}
|
||||
if (varp == p->var)
|
||||
return (r | SOPT_UNSET);
|
||||
}
|
||||
|
||||
if (varp != NULL)
|
||||
{
|
||||
if (p->flags & P_STRING)
|
||||
*stringval = vim_strsave(*(char_u **)(varp));
|
||||
else if (p->flags & P_NUM)
|
||||
*numval = *(long *) varp;
|
||||
else
|
||||
*numval = *(int *)varp;
|
||||
}
|
||||
|
||||
return r;
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Set the value of option "name".
|
||||
* Use "string" for string options, use "number" for other options.
|
||||
@@ -9556,6 +9694,87 @@ comp_col()
|
||||
#endif
|
||||
}
|
||||
|
||||
/*
|
||||
* Unset local option value, similar to ":set opt<".
|
||||
*/
|
||||
|
||||
void
|
||||
unset_global_local_option(name, from)
|
||||
char_u *name;
|
||||
void *from;
|
||||
{
|
||||
struct vimoption *p;
|
||||
int opt_idx;
|
||||
|
||||
buf_T *buf = (buf_T *) from;
|
||||
win_T *win = (win_T *) from;
|
||||
|
||||
opt_idx = findoption(name);
|
||||
p = &(options[opt_idx]);
|
||||
|
||||
switch ((int)p->indir)
|
||||
{
|
||||
/* global option with local value: use local value if it's been set */
|
||||
case PV_EP:
|
||||
*buf->b_p_ep = NUL;
|
||||
break;
|
||||
case PV_KP:
|
||||
*buf->b_p_kp = NUL;
|
||||
break;
|
||||
case PV_PATH:
|
||||
*buf->b_p_path = NUL;
|
||||
break;
|
||||
case PV_AR:
|
||||
buf->b_p_ar = -1;
|
||||
break;
|
||||
case PV_TAGS:
|
||||
*buf->b_p_tags = NUL;
|
||||
break;
|
||||
#ifdef FEAT_FIND_ID
|
||||
case PV_DEF:
|
||||
*buf->b_p_def = NUL;
|
||||
break;
|
||||
case PV_INC:
|
||||
*buf->b_p_inc = NUL;
|
||||
break;
|
||||
#endif
|
||||
#ifdef FEAT_INS_EXPAND
|
||||
case PV_DICT:
|
||||
*buf->b_p_dict = NUL;
|
||||
break;
|
||||
case PV_TSR:
|
||||
*buf->b_p_tsr = NUL;
|
||||
break;
|
||||
#endif
|
||||
#ifdef FEAT_QUICKFIX
|
||||
case PV_EFM:
|
||||
*buf->b_p_efm = NUL;
|
||||
break;
|
||||
case PV_GP:
|
||||
*buf->b_p_gp = NUL;
|
||||
break;
|
||||
case PV_MP:
|
||||
*buf->b_p_mp = NUL;
|
||||
break;
|
||||
#endif
|
||||
#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
|
||||
case PV_BEXPR:
|
||||
*buf->b_p_bexpr = NUL;
|
||||
break;
|
||||
#endif
|
||||
#if defined(FEAT_CRYPT)
|
||||
case PV_CM:
|
||||
*buf->b_p_cm = NUL;
|
||||
break;
|
||||
#endif
|
||||
#ifdef FEAT_STL_OPT
|
||||
case PV_STL:
|
||||
*win->w_p_stl = NUL;
|
||||
break;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Get pointer to option variable, depending on local or global scope.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user