Skip to content
Permalink
Browse files

patch 8.1.1542: an OptionSet autocommand does not get enough info

Problem:    An OptionSet autocommand does not get enough info.
Solution:   Add v:option_command, v:option_oldlocal and v:option_oldglobal.
            (Latrice Wilgus, closes #4118)
  • Loading branch information...
brammool committed Jun 15, 2019
1 parent bffc504 commit d7c968794710f338d491072171df48f96612cf72
Showing with 752 additions and 87 deletions.
  1. +28 −10 runtime/doc/autocmd.txt
  2. +20 −1 runtime/doc/eval.txt
  3. +3 −0 runtime/doc/version8.txt
  4. +9 −2 src/eval.c
  5. +161 −15 src/option.c
  6. +6 −2 src/structs.h
  7. +490 −27 src/testdir/test_autocmd.vim
  8. +2 −0 src/version.c
  9. +33 −30 src/vim.h
@@ -1,4 +1,4 @@
*autocmd.txt* For Vim version 8.1. Last change: 2019 Jun 02
*autocmd.txt* For Vim version 8.1. Last change: 2019 Jun 15


VIM REFERENCE MANUAL by Bram Moolenaar
@@ -873,15 +873,33 @@ MenuPopup Just before showing the popup menu (under the
*OptionSet*
OptionSet After setting an option. The pattern is
matched against the long option name.
The |v:option_old| variable indicates the
old option value, |v:option_new| variable
indicates the newly set value, the
|v:option_type| variable indicates whether
it's global or local scoped and |<amatch>|
indicates what option has been set.

Is not triggered on startup and for the 'key'
option for obvious reasons.
|<amatch>| indicates what option has been set.

|v:option_type| indicates whether it's global
or local scoped
|v:option_command| indicates what type of
set/let command was used (follow the tag to
see the table).
|v:option_new| indicates the newly set value.
|v:option_oldlocal| hass the old local value.
|v:option_oldglobal| hass the old global
value
|v:option_old| indicates the old option value.

|v:option_oldlocal| is only set when |:set|
or |:setlocal| or a |modeline| was used to set
the option. Similarly |v:option_oldglobal| is
only set when |:set| or |:setglobal| was used.

Note that when setting a |global-local| string
option with |:set|, then |v:option_old| is the
old global value. However, for all other kinds
of options (local string options, global-local
number options, ...) it is the old local
value.

OptionSet is not triggered on startup and for
the 'key' option for obvious reasons.

Usage example: Check for the existence of the
directory in the 'backupdir' and 'undodir'
@@ -1943,10 +1943,29 @@ v:option_new New value of the option. Valid while executing an |OptionSet|
autocommand.
*v:option_old*
v:option_old Old value of the option. Valid while executing an |OptionSet|
autocommand.
autocommand. Depending on the command used for setting and the
kind of option this is either the local old value or the
global old value.
*v:option_oldlocal*
v:option_oldlocal
Old local value of the option. Valid while executing an
|OptionSet| autocommand.
*v:option_oldglobal*
v:option_oldglobal
Old global value of the option. Valid while executing an
|OptionSet| autocommand.
*v:option_type*
v:option_type Scope of the set command. Valid while executing an
|OptionSet| autocommand. Can be either "global" or "local"
*v:option_command*
v:option_command
Command used to set the option. Valid while executing an
|OptionSet| autocommand.
value option was set via ~
"setlocal" |:setlocal| or ":let l:xxx"
"setglobal" |:setglobal| or ":let g:xxx"
"set" |:set| or |:let|
"modeline" |modeline|
*v:operator* *operator-variable*
v:operator The last operator given in Normal mode. This is a single
character except for commands starting with <g> or <z>,
@@ -336,7 +336,10 @@ New Vim variables: ~
|v:null| an empty String, used for JSON
|v:option_new| new value of the option, used by |OptionSet|
|v:option_old| old value of the option, used by |OptionSet|
|v:option_oldlocal| old local value of the option, used by |OptionSet|
|v:option_oldglobal| old global value of the option, used by |OptionSet|
|v:option_type| scope of the set command, used by |OptionSet|
|v:option_command| command used to set the option, used by |OptionSet|
|v:progpath| the command with which Vim was invoked
|v:t_bool| value of Boolean type
|v:t_channel| value of Channel type
@@ -172,6 +172,9 @@ static struct vimvar
{VV_NAME("completed_item", VAR_DICT), VV_RO},
{VV_NAME("option_new", VAR_STRING), VV_RO},
{VV_NAME("option_old", VAR_STRING), VV_RO},
{VV_NAME("option_oldlocal", VAR_STRING), VV_RO},
{VV_NAME("option_oldglobal", VAR_STRING), VV_RO},
{VV_NAME("option_command", VAR_STRING), VV_RO},
{VV_NAME("option_type", VAR_STRING), VV_RO},
{VV_NAME("errors", VAR_LIST), 0},
{VV_NAME("false", VAR_SPECIAL), VV_RO},
@@ -337,7 +340,7 @@ eval_init(void)
for (i = 0; i < VV_LEN; ++i)
{
p = &vimvars[i];
if (STRLEN(p->vv_name) > 16)
if (STRLEN(p->vv_name) > DICTITEM16_KEY_LEN)
{
iemsg("INTERNAL: name too long, increase size of dictitem16_T");
getout(1);
@@ -9500,14 +9503,18 @@ last_set_msg(sctx_T script_ctx)
}

/*
* Reset v:option_new, v:option_old and v:option_type.
* reset v:option_new, v:option_old, v:option_oldlocal, v:option_oldglobal,
* v:option_type, and v:option_command.
*/
void
reset_v_option_vars(void)
{
set_vim_var_string(VV_OPTION_NEW, NULL, -1);
set_vim_var_string(VV_OPTION_OLD, NULL, -1);
set_vim_var_string(VV_OPTION_OLDLOCAL, NULL, -1);
set_vim_var_string(VV_OPTION_OLDGLOBAL, NULL, -1);
set_vim_var_string(VV_OPTION_TYPE, NULL, -1);
set_vim_var_string(VV_OPTION_COMMAND, NULL, -1);
}

/*

0 comments on commit d7c9687

Please sign in to comment.
You can’t perform that action at this time.