diff options
author | Björn Linse <bjorn.linse@gmail.com> | 2015-08-29 16:11:56 +0200 |
---|---|---|
committer | Björn Linse <bjorn.linse@gmail.com> | 2015-09-08 10:53:27 +0200 |
commit | 6769438cd1392df684c7840ecb81335dc905c87d (patch) | |
tree | 120fdb05d504384c07b86bf0fe21badcc409573c | |
parent | dc9652e68de163290abee880a74bf1727c715a1e (diff) | |
download | rneovim-6769438cd1392df684c7840ecb81335dc905c87d.tar.gz rneovim-6769438cd1392df684c7840ecb81335dc905c87d.tar.bz2 rneovim-6769438cd1392df684c7840ecb81335dc905c87d.zip |
encoding: don't allow changing encoding after startup scripts
-rw-r--r-- | src/nvim/globals.h | 6 | ||||
-rw-r--r-- | src/nvim/main.c | 1 | ||||
-rw-r--r-- | src/nvim/option.c | 13 |
3 files changed, 17 insertions, 3 deletions
diff --git a/src/nvim/globals.h b/src/nvim/globals.h index e5a993aa5a..183e8fcff2 100644 --- a/src/nvim/globals.h +++ b/src/nvim/globals.h @@ -633,6 +633,10 @@ EXTERN int silent_mode INIT(= FALSE); /* set to TRUE when "-s" commandline argument * used for ex */ +// Set to true when sourcing of startup scripts (nvimrc) is done. +// Used for options that cannot be changed after startup scripts. +EXTERN bool did_source_startup_scripts INIT(= false); + EXTERN pos_T VIsual; /* start position of active Visual selection */ EXTERN int VIsual_active INIT(= FALSE); /* whether Visual mode is active */ @@ -1078,6 +1082,8 @@ EXTERN garray_T error_ga * Excluded are errors that are only used once and debugging messages. */ EXTERN char_u e_abort[] INIT(= N_("E470: Command aborted")); +EXTERN char_u e_afterinit[] INIT(= N_( + "E905: Cannot set this option after startup")); EXTERN char_u e_api_spawn_failed[] INIT(= N_("E903: Could not spawn API job")); EXTERN char_u e_argreq[] INIT(= N_("E471: Argument required")); EXTERN char_u e_backslash[] INIT(= N_("E10: \\ should be followed by /, ? or &")); diff --git a/src/nvim/main.c b/src/nvim/main.c index dd2b813b1c..27f8340ec7 100644 --- a/src/nvim/main.c +++ b/src/nvim/main.c @@ -1911,6 +1911,7 @@ static void source_startup_scripts(mparm_T *parmp) need_wait_return = TRUE; secure = 0; } + did_source_startup_scripts = true; TIME_MSG("sourcing vimrc file(s)"); } diff --git a/src/nvim/option.c b/src/nvim/option.c index 6e82c45edf..dba3bd8a26 100644 --- a/src/nvim/option.c +++ b/src/nvim/option.c @@ -575,6 +575,12 @@ void set_init_1(void) mb_init(); } + // Don't change &encoding when resetting to defaults with ":set all&". + opt_idx = findoption((char_u *)"encoding"); + if (opt_idx >= 0) { + options[opt_idx].flags |= P_NODEFAULT; + } + /* Set the default for 'helplang'. */ set_helplang_default(get_mess_lang()); } @@ -2271,10 +2277,11 @@ did_set_string_option ( else if (varp == &p_ei) { if (check_ei() == FAIL) errmsg = e_invarg; - } /* 'encoding' and 'fileencoding' */ - else if (varp == &p_enc || gvarp == &p_fenc) { - if (gvarp == &p_fenc) { + } else if (varp == &p_enc || gvarp == &p_fenc) { + if (varp == &p_enc && did_source_startup_scripts) { + errmsg = e_afterinit; + } else if (gvarp == &p_fenc) { if (!MODIFIABLE(curbuf) && opt_flags != OPT_GLOBAL) errmsg = e_modifiable; else if (vim_strchr(*varp, ',') != NULL) |