aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/option.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/nvim/option.c')
-rw-r--r--src/nvim/option.c80
1 files changed, 23 insertions, 57 deletions
diff --git a/src/nvim/option.c b/src/nvim/option.c
index 8f2cd4546b..77a13b16b1 100644
--- a/src/nvim/option.c
+++ b/src/nvim/option.c
@@ -358,7 +358,14 @@ void set_init_1(bool clean_arg)
{
const char *shell = os_getenv("SHELL");
if (shell != NULL) {
- set_string_default("sh", (char *) shell, false);
+ if (vim_strchr((const char_u *)shell, ' ') != NULL) {
+ const size_t len = strlen(shell) + 3; // two quotes and a trailing NUL
+ char *const cmd = xmalloc(len);
+ snprintf(cmd, len, "\"%s\"", shell);
+ set_string_default("sh", cmd, true);
+ } else {
+ set_string_default("sh", (char *)shell, false);
+ }
}
}
@@ -658,7 +665,7 @@ set_option_default(
}
// The default value is not insecure.
- uint32_t *flagsp = insecure_flag(opt_idx, opt_flags);
+ uint32_t *flagsp = insecure_flag(curwin, opt_idx, opt_flags);
*flagsp = *flagsp & ~P_INSECURE;
}
@@ -700,10 +707,9 @@ static void set_string_default(const char *name, char *val, bool allocated)
xfree(options[opt_idx].def_val[VI_DEFAULT]);
}
- options[opt_idx].def_val[VI_DEFAULT] = (char_u *) (
- allocated
- ? (char_u *) val
- : (char_u *) xstrdup(val));
+ options[opt_idx].def_val[VI_DEFAULT] = allocated
+ ? (char_u *)val
+ : (char_u *)xstrdup(val);
options[opt_idx].flags |= P_DEF_ALLOCED;
}
}
@@ -1593,7 +1599,7 @@ int do_set(
saved_newval = (newval != NULL) ? xstrdup((char *)newval) : 0;
{
- uint32_t *p = insecure_flag(opt_idx, opt_flags);
+ uint32_t *p = insecure_flag(curwin, opt_idx, opt_flags);
const int secure_saved = secure;
// When an option is set in the sandbox, from a
@@ -1720,7 +1726,7 @@ static void did_set_option(
/* When an option is set in the sandbox, from a modeline or in secure mode
* set the P_INSECURE flag. Otherwise, if a new value is stored reset the
* flag. */
- uint32_t *p = insecure_flag(opt_idx, opt_flags);
+ uint32_t *p = insecure_flag(curwin, opt_idx, opt_flags);
if (!value_checked && (secure
|| sandbox != 0
|| (opt_flags & OPT_MODELINE))) {
@@ -2059,12 +2065,12 @@ static void check_string_option(char_u **pp)
/// Return true when option "opt" was set from a modeline or in secure mode.
/// Return false when it wasn't.
/// Return -1 for an unknown option.
-int was_set_insecurely(char_u *opt, int opt_flags)
+int was_set_insecurely(win_T *const wp, char_u *opt, int opt_flags)
{
int idx = findoption((const char *)opt);
if (idx >= 0) {
- uint32_t *flagp = insecure_flag(idx, opt_flags);
+ uint32_t *flagp = insecure_flag(wp, idx, opt_flags);
return (*flagp & P_INSECURE) != 0;
}
internal_error("was_set_insecurely()");
@@ -2073,16 +2079,16 @@ int was_set_insecurely(char_u *opt, int opt_flags)
/// Get a pointer to the flags used for the P_INSECURE flag of option
/// "opt_idx". For some local options a local flags field is used.
-static uint32_t *insecure_flag(int opt_idx, int opt_flags)
+static uint32_t *insecure_flag(win_T *const wp, int opt_idx, int opt_flags)
{
if (opt_flags & OPT_LOCAL)
switch ((int)options[opt_idx].indir) {
- case PV_STL: return &curwin->w_p_stl_flags;
- case PV_FDE: return &curwin->w_p_fde_flags;
- case PV_FDT: return &curwin->w_p_fdt_flags;
- case PV_INDE: return &curbuf->b_p_inde_flags;
- case PV_FEX: return &curbuf->b_p_fex_flags;
- case PV_INEX: return &curbuf->b_p_inex_flags;
+ case PV_STL: return &wp->w_p_stl_flags;
+ case PV_FDE: return &wp->w_p_fde_flags;
+ case PV_FDT: return &wp->w_p_fdt_flags;
+ case PV_INDE: return &wp->w_buffer->b_p_inde_flags;
+ case PV_FEX: return &wp->w_buffer->b_p_fex_flags;
+ case PV_INEX: return &wp->w_buffer->b_p_inex_flags;
}
// Nothing special, return global flags field.
@@ -6886,46 +6892,6 @@ int get_sts_value(void)
return (int)result;
}
-/// Check matchpairs option for "*initc".
-/// If there is a match set "*initc" to the matching character and "*findc" to
-/// the opposite character. Set "*backwards" to the direction.
-/// When "switchit" is true swap the direction.
-void find_mps_values(int *initc, int *findc, int *backwards, int switchit)
-{
- char_u *ptr = curbuf->b_p_mps;
-
- while (*ptr != NUL) {
- if (utf_ptr2char(ptr) == *initc) {
- if (switchit) {
- *findc = *initc;
- *initc = utf_ptr2char(ptr + utfc_ptr2len(ptr) + 1);
- *backwards = true;
- } else {
- *findc = utf_ptr2char(ptr + utfc_ptr2len(ptr) + 1);
- *backwards = false;
- }
- return;
- }
- char_u *prev = ptr;
- ptr += utfc_ptr2len(ptr) + 1;
- if (utf_ptr2char(ptr) == *initc) {
- if (switchit) {
- *findc = *initc;
- *initc = utf_ptr2char(prev);
- *backwards = false;
- } else {
- *findc = utf_ptr2char(prev);
- *backwards = true;
- }
- return;
- }
- ptr += utfc_ptr2len(ptr);
- if (*ptr == ',') {
- ptr++;
- }
- }
-}
-
/// This is called when 'breakindentopt' is changed and when a window is
/// initialized
static bool briopt_check(win_T *wp)