To: vim_dev@googlegroups.com Subject: Patch 8.2.2993 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 8.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'. Files: src/mbyte.c, src/option.c, src/proto/option.pro, src/testdir/test_options.vim *** ../vim-8.2.2992/src/mbyte.c 2021-06-04 17:11:44.516100707 +0200 --- src/mbyte.c 2021-06-13 20:14:31.026449788 +0200 *************** *** 733,740 **** // When using Unicode, set default for 'fileencodings'. if (enc_utf8 && !option_was_set((char_u *)"fencs")) ! set_string_option_direct((char_u *)"fencs", -1, ! (char_u *)"ucs-bom,utf-8,default,latin1", OPT_FREE, 0); #if defined(HAVE_BIND_TEXTDOMAIN_CODESET) && defined(FEAT_GETTEXT) // GNU gettext 0.10.37 supports this feature: set the codeset used for --- 733,739 ---- // When using Unicode, set default for 'fileencodings'. if (enc_utf8 && !option_was_set((char_u *)"fencs")) ! set_fencs_unicode(); #if defined(HAVE_BIND_TEXTDOMAIN_CODESET) && defined(FEAT_GETTEXT) // GNU gettext 0.10.37 supports this feature: set the codeset used for *** ../vim-8.2.2992/src/option.c 2021-06-02 13:28:11.435120452 +0200 --- src/option.c 2021-06-13 20:20:27.590208534 +0200 *************** *** 535,540 **** --- 535,553 ---- #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,566 **** dvi = ((flags & P_VI_DEF) || compatible) ? VI_DEFAULT : VIM_DEFAULT; if (flags & P_STRING) { // Use set_string_option_direct() for local options to handle // freeing and allocating the value. ! if (options[opt_idx].indir != PV_NONE) set_string_option_direct(NULL, opt_idx, options[opt_idx].def_val[dvi], opt_flags, 0); else --- 571,582 ---- 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. ! 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,1689 **** --- 1700,1707 ---- #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 *** ../vim-8.2.2992/src/proto/option.pro 2020-12-31 17:40:57.536087870 +0100 --- src/proto/option.pro 2021-06-13 20:14:34.998450906 +0200 *************** *** 1,5 **** --- 1,6 ---- /* option.c */ void set_init_1(int clean_arg); + void set_fencs_unicode(void); void set_string_default(char *name, char_u *val); void set_number_default(char *name, long val); void set_local_options_default(win_T *wp, int do_buffer); *** ../vim-8.2.2992/src/testdir/test_options.vim 2021-06-12 13:46:38.055854976 +0200 --- src/testdir/test_options.vim 2021-06-13 20:24:08.813816632 +0200 *************** *** 1140,1145 **** --- 1140,1153 ---- call assert_equal('vt', &formatoptions) set formatoptions&vim call assert_equal('tcq', &formatoptions) + + call assert_equal('ucs-bom,utf-8,default,latin1', &fencs) + set fencs=latin1 + set fencs& + call assert_equal('ucs-bom,utf-8,default,latin1', &fencs) + set fencs=latin1 + set all& + call assert_equal('ucs-bom,utf-8,default,latin1', &fencs) endfunc " Test for the 'cmdheight' option *** ../vim-8.2.2992/src/version.c 2021-06-13 18:38:44.688673497 +0200 --- src/version.c 2021-06-13 20:27:01.789432221 +0200 *************** *** 752,753 **** --- 752,755 ---- { /* Add new patch number below this line */ + /**/ + 2993, /**/ -- BEDEVERE: Why do you think she is a witch? SECOND VILLAGER: She turned me into a newt. BEDEVERE: A newt? SECOND VILLAGER: (After looking at himself for some time) I got better. "Monty Python and the Holy Grail" PYTHON (MONTY) PICTURES LTD /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\ /// \\\ \\\ sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ /// \\\ help me help AIDS victims -- http://ICCF-Holland.org ///