diff options
author | Bram Moolenaar <Bram@vim.org> | 2021-06-13 20:27:36 +0200 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2021-06-13 20:27:36 +0200 |
commit | 5ffefbb35aba2448099314a9e09714d2f3b2b1bd (patch) | |
tree | e7a38623964613b43058b65f61aa296ec3432c09 /src/option.c | |
parent | 2346a6378483c9871016f9fc821ec5cbea638f13 (diff) |
patch 8.2.2993: 'fileencodings' default value should depend on 'encoding'v8.2.2993
Problem: 'fileencodings' default value should depend on 'encoding'. (Gary
Johnson)
Solution: When 'encoding' is "utf-8" use a different default value for
'fileencodings'.
Diffstat (limited to 'src/option.c')
-rw-r--r-- | src/option.c | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/src/option.c b/src/option.c index 33d29a1fc4..dd44fe4ac4 100644 --- a/src/option.c +++ b/src/option.c @@ -535,6 +535,19 @@ set_init_1(int clean_arg) #endif } +static char_u *fencs_utf8_default = (char_u *)"ucs-bom,utf-8,default,latin1"; + +/* + * Set the "fileencodings" option to the default value for when 'encoding' is + * utf-8. + */ + void +set_fencs_unicode() +{ + set_string_option_direct((char_u *)"fencs", -1, fencs_utf8_default, + OPT_FREE, 0); +} + /* * Set an option to its default value. * This does not take care of side effects! @@ -558,9 +571,12 @@ set_option_default( dvi = ((flags & P_VI_DEF) || compatible) ? VI_DEFAULT : VIM_DEFAULT; if (flags & P_STRING) { + // 'fencs' default value depends on 'encoding' + if (options[opt_idx].var == (char_u *)&p_fencs && enc_utf8) + set_fencs_unicode(); // Use set_string_option_direct() for local options to handle // freeing and allocating the value. - if (options[opt_idx].indir != PV_NONE) + else if (options[opt_idx].indir != PV_NONE) set_string_option_direct(NULL, opt_idx, options[opt_idx].def_val[dvi], opt_flags, 0); else @@ -1684,6 +1700,8 @@ do_set( #endif newval = term_bg_default(); } + else if ((char_u **)varp == &p_fencs && enc_utf8) + newval = fencs_utf8_default; // expand environment variables and ~ (since the // default value was already expanded, only |