Skip to content

Commit 5ffefbb

Browse files
committed
patch 8.2.2993: 'fileencodings' default value should depend on 'encoding'
Problem: 'fileencodings' default value should depend on 'encoding'. (Gary Johnson) Solution: When 'encoding' is "utf-8" use a different default value for 'fileencodings'.
1 parent 2346a63 commit 5ffefbb

5 files changed

Lines changed: 31 additions & 3 deletions

File tree

src/mbyte.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -733,8 +733,7 @@ mb_init(void)
733733

734734
// When using Unicode, set default for 'fileencodings'.
735735
if (enc_utf8 && !option_was_set((char_u *)"fencs"))
736-
set_string_option_direct((char_u *)"fencs", -1,
737-
(char_u *)"ucs-bom,utf-8,default,latin1", OPT_FREE, 0);
736+
set_fencs_unicode();
738737

739738
#if defined(HAVE_BIND_TEXTDOMAIN_CODESET) && defined(FEAT_GETTEXT)
740739
// GNU gettext 0.10.37 supports this feature: set the codeset used for

src/option.c

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -535,6 +535,19 @@ set_init_1(int clean_arg)
535535
#endif
536536
}
537537

538+
static char_u *fencs_utf8_default = (char_u *)"ucs-bom,utf-8,default,latin1";
539+
540+
/*
541+
* Set the "fileencodings" option to the default value for when 'encoding' is
542+
* utf-8.
543+
*/
544+
void
545+
set_fencs_unicode()
546+
{
547+
set_string_option_direct((char_u *)"fencs", -1, fencs_utf8_default,
548+
OPT_FREE, 0);
549+
}
550+
538551
/*
539552
* Set an option to its default value.
540553
* This does not take care of side effects!
@@ -558,9 +571,12 @@ set_option_default(
558571
dvi = ((flags & P_VI_DEF) || compatible) ? VI_DEFAULT : VIM_DEFAULT;
559572
if (flags & P_STRING)
560573
{
574+
// 'fencs' default value depends on 'encoding'
575+
if (options[opt_idx].var == (char_u *)&p_fencs && enc_utf8)
576+
set_fencs_unicode();
561577
// Use set_string_option_direct() for local options to handle
562578
// freeing and allocating the value.
563-
if (options[opt_idx].indir != PV_NONE)
579+
else if (options[opt_idx].indir != PV_NONE)
564580
set_string_option_direct(NULL, opt_idx,
565581
options[opt_idx].def_val[dvi], opt_flags, 0);
566582
else
@@ -1684,6 +1700,8 @@ do_set(
16841700
#endif
16851701
newval = term_bg_default();
16861702
}
1703+
else if ((char_u **)varp == &p_fencs && enc_utf8)
1704+
newval = fencs_utf8_default;
16871705

16881706
// expand environment variables and ~ (since the
16891707
// default value was already expanded, only

src/proto/option.pro

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/* option.c */
22
void set_init_1(int clean_arg);
3+
void set_fencs_unicode(void);
34
void set_string_default(char *name, char_u *val);
45
void set_number_default(char *name, long val);
56
void set_local_options_default(win_T *wp, int do_buffer);

src/testdir/test_options.vim

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1140,6 +1140,14 @@ func Test_opt_default()
11401140
call assert_equal('vt', &formatoptions)
11411141
set formatoptions&vim
11421142
call assert_equal('tcq', &formatoptions)
1143+
1144+
call assert_equal('ucs-bom,utf-8,default,latin1', &fencs)
1145+
set fencs=latin1
1146+
set fencs&
1147+
call assert_equal('ucs-bom,utf-8,default,latin1', &fencs)
1148+
set fencs=latin1
1149+
set all&
1150+
call assert_equal('ucs-bom,utf-8,default,latin1', &fencs)
11431151
endfunc
11441152

11451153
" Test for the 'cmdheight' option

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -750,6 +750,8 @@ static char *(features[]) =
750750

751751
static int included_patches[] =
752752
{ /* Add new patch number below this line */
753+
/**/
754+
2993,
753755
/**/
754756
2992,
755757
/**/

0 commit comments

Comments
 (0)