mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
encoding: Always use "utf-8" as default for &encoding
Preverve the locale-depedency for fileencodings=default
This commit is contained in:
parent
cb62594042
commit
49b06a8f2a
@ -798,6 +798,8 @@ EXTERN bool enc_utf8 INIT(= false); /* UTF-8 encoded Unicode */
|
||||
EXTERN int enc_latin1like INIT(= TRUE); /* 'encoding' is latin1 comp. */
|
||||
EXTERN int has_mbyte INIT(= 0); /* any multi-byte encoding */
|
||||
|
||||
/// Encoding used when 'fencs' is set to "default"
|
||||
EXTERN char_u *fenc_default INIT(= NULL);
|
||||
|
||||
/*
|
||||
* To speed up BYTELEN() we fill a table with the byte lengths whenever
|
||||
|
@ -2417,11 +2417,8 @@ char_u *enc_canonize(char_u *enc) FUNC_ATTR_NONNULL_RET
|
||||
int i;
|
||||
|
||||
if (STRCMP(enc, "default") == 0) {
|
||||
/* Use the default encoding as it's found by set_init_1(). */
|
||||
char_u *r = get_encoding_default();
|
||||
if (r == NULL)
|
||||
r = (char_u *)"latin1";
|
||||
return vim_strsave(r);
|
||||
// Use the default encoding as found by set_init_1().
|
||||
return vim_strsave(fenc_default);
|
||||
}
|
||||
|
||||
/* copy "enc" to allocated memory, with room for two '-' */
|
||||
|
@ -776,59 +776,38 @@ void set_init_1(void)
|
||||
/* Parse default for 'listchars'. */
|
||||
(void)set_chars_option(&p_lcs);
|
||||
|
||||
/* enc_locale() will try to find the encoding of the current locale. */
|
||||
// enc_locale() will try to find the encoding of the current locale.
|
||||
// This will be used when 'default' is used as encoding specifier
|
||||
// in 'fileencodings'
|
||||
char_u *p = enc_locale();
|
||||
if (p != NULL) {
|
||||
char_u *save_enc;
|
||||
if (p == NULL) {
|
||||
// use utf-8 as 'default' if locale encoding can't be detected.
|
||||
p = vim_strsave((char_u *)"utf-8");
|
||||
}
|
||||
fenc_default = p;
|
||||
|
||||
/* Try setting 'encoding' and check if the value is valid.
|
||||
* If not, go back to the default "utf-8". */
|
||||
save_enc = p_enc;
|
||||
p_enc = (char_u *) p;
|
||||
if (STRCMP(p_enc, "gb18030") == 0) {
|
||||
/* We don't support "gb18030", but "cp936" is a good substitute
|
||||
* for practical purposes, thus use that. It's not an alias to
|
||||
* still support conversion between gb18030 and utf-8. */
|
||||
p_enc = vim_strsave((char_u *)"cp936");
|
||||
xfree(p);
|
||||
}
|
||||
if (mb_init() == NULL) {
|
||||
opt_idx = findoption((char_u *)"encoding");
|
||||
if (opt_idx >= 0) {
|
||||
options[opt_idx].def_val[VI_DEFAULT] = p_enc;
|
||||
options[opt_idx].flags |= P_DEF_ALLOCED;
|
||||
}
|
||||
// Initialize multibyte (utf-8) handling
|
||||
mb_init();
|
||||
|
||||
#if defined(MSWIN) || defined(MACOS)
|
||||
if (STRCMP(p_enc, "latin1") == 0
|
||||
|| enc_utf8
|
||||
) {
|
||||
/* Adjust the default for 'isprint' and 'iskeyword' to match
|
||||
* latin1. */
|
||||
set_string_option_direct((char_u *)"isp", -1,
|
||||
ISP_LATIN1, OPT_FREE, SID_NONE);
|
||||
set_string_option_direct((char_u *)"isk", -1,
|
||||
ISK_LATIN1, OPT_FREE, SID_NONE);
|
||||
opt_idx = findoption((char_u *)"isp");
|
||||
if (opt_idx >= 0)
|
||||
options[opt_idx].def_val[VIM_DEFAULT] = ISP_LATIN1;
|
||||
opt_idx = findoption((char_u *)"isk");
|
||||
if (opt_idx >= 0)
|
||||
options[opt_idx].def_val[VIM_DEFAULT] = ISK_LATIN1;
|
||||
(void)init_chartab();
|
||||
}
|
||||
#endif
|
||||
|
||||
} else {
|
||||
xfree(p_enc);
|
||||
// mb_init() failed; fallback to utf8 and try again.
|
||||
p_enc = save_enc;
|
||||
mb_init();
|
||||
}
|
||||
} else {
|
||||
// enc_locale() failed; initialize the default (utf8).
|
||||
mb_init();
|
||||
if (STRCMP(p_enc, "latin1") == 0
|
||||
|| enc_utf8
|
||||
) {
|
||||
/* Adjust the default for 'isprint' and 'iskeyword' to match
|
||||
* latin1. */
|
||||
set_string_option_direct((char_u *)"isp", -1,
|
||||
ISP_LATIN1, OPT_FREE, SID_NONE);
|
||||
set_string_option_direct((char_u *)"isk", -1,
|
||||
ISK_LATIN1, OPT_FREE, SID_NONE);
|
||||
opt_idx = findoption((char_u *)"isp");
|
||||
if (opt_idx >= 0)
|
||||
options[opt_idx].def_val[VIM_DEFAULT] = ISP_LATIN1;
|
||||
opt_idx = findoption((char_u *)"isk");
|
||||
if (opt_idx >= 0)
|
||||
options[opt_idx].def_val[VIM_DEFAULT] = ISK_LATIN1;
|
||||
(void)init_chartab();
|
||||
}
|
||||
#endif
|
||||
|
||||
// Don't change &encoding when resetting to defaults with ":set all&".
|
||||
opt_idx = findoption((char_u *)"encoding");
|
||||
@ -4669,16 +4648,6 @@ char_u *get_highlight_default(void)
|
||||
return (char_u *)NULL;
|
||||
}
|
||||
|
||||
char_u *get_encoding_default(void)
|
||||
{
|
||||
int i;
|
||||
|
||||
i = findoption((char_u *)"enc");
|
||||
if (i >= 0)
|
||||
return options[i].def_val[VI_DEFAULT];
|
||||
return (char_u *)NULL;
|
||||
}
|
||||
|
||||
/*
|
||||
* Translate a string like "t_xx", "<t_xx>" or "<S-Tab>" to a key number.
|
||||
*/
|
||||
|
Loading…
Reference in New Issue
Block a user