mirror of
https://github.com/vim/vim.git
synced 2025-07-26 11:04:33 -04:00
patch 9.0.1313: some settings use the current codepage instead of 'encoding'
Problem: Some settings use the current codepage instead of 'encoding'. Solution: Adjust how options are initialized. (Ken Takata, closes #11992)
This commit is contained in:
parent
bc3dc298b3
commit
ce3189d56e
28
src/misc1.c
28
src/misc1.c
@ -1311,6 +1311,32 @@ free_users(void)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if defined(MSWIN) || defined(PROTO)
|
||||||
|
/*
|
||||||
|
* Initilize $VIM and $VIMRUNTIME when 'enc' is updated.
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
init_vimdir(void)
|
||||||
|
{
|
||||||
|
int mustfree;
|
||||||
|
char_u *p;
|
||||||
|
|
||||||
|
mch_get_exe_name();
|
||||||
|
|
||||||
|
mustfree = FALSE;
|
||||||
|
didset_vim = FALSE;
|
||||||
|
p = vim_getenv((char_u *)"VIM", &mustfree);
|
||||||
|
if (mustfree)
|
||||||
|
vim_free(p);
|
||||||
|
|
||||||
|
mustfree = FALSE;
|
||||||
|
didset_vimruntime = FALSE;
|
||||||
|
p = vim_getenv((char_u *)"VIMRUNTIME", &mustfree);
|
||||||
|
if (mustfree)
|
||||||
|
vim_free(p);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Call expand_env() and store the result in an allocated string.
|
* Call expand_env() and store the result in an allocated string.
|
||||||
* This is not very memory efficient, this expects the result to be freed
|
* This is not very memory efficient, this expects the result to be freed
|
||||||
@ -1696,7 +1722,7 @@ vim_version_dir(char_u *vimdir)
|
|||||||
* Vim's version of getenv().
|
* Vim's version of getenv().
|
||||||
* Special handling of $HOME, $VIM and $VIMRUNTIME.
|
* Special handling of $HOME, $VIM and $VIMRUNTIME.
|
||||||
* Also does ACP to 'enc' conversion for Win32.
|
* Also does ACP to 'enc' conversion for Win32.
|
||||||
* "mustfree" is set to TRUE when returned is allocated, it must be
|
* "mustfree" is set to TRUE when the returned string is allocated. It must be
|
||||||
* initialized to FALSE by the caller.
|
* initialized to FALSE by the caller.
|
||||||
*/
|
*/
|
||||||
char_u *
|
char_u *
|
||||||
|
@ -600,6 +600,8 @@ set_init_1(int clean_arg)
|
|||||||
init_spell_chartab();
|
init_spell_chartab();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
set_init_default_encoding();
|
||||||
|
|
||||||
// Expand environment variables and things like "~" for the defaults.
|
// Expand environment variables and things like "~" for the defaults.
|
||||||
set_init_expand_env();
|
set_init_expand_env();
|
||||||
|
|
||||||
@ -618,7 +620,6 @@ set_init_1(int clean_arg)
|
|||||||
didset_options2();
|
didset_options2();
|
||||||
|
|
||||||
set_init_lang_env();
|
set_init_lang_env();
|
||||||
set_init_default_encoding();
|
|
||||||
|
|
||||||
#ifdef FEAT_MULTI_LANG
|
#ifdef FEAT_MULTI_LANG
|
||||||
// Set the default for 'helplang'.
|
// Set the default for 'helplang'.
|
||||||
|
@ -1054,9 +1054,12 @@ did_set_encoding(char_u **varp, char_u **gvarp, int opt_flags)
|
|||||||
}
|
}
|
||||||
|
|
||||||
#if defined(MSWIN)
|
#if defined(MSWIN)
|
||||||
// $HOME may have characters in active code page.
|
// $HOME, $VIM and $VIMRUNTIME may have characters in active code page.
|
||||||
if (varp == &p_enc)
|
if (varp == &p_enc)
|
||||||
|
{
|
||||||
init_homedir();
|
init_homedir();
|
||||||
|
init_vimdir();
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -254,7 +254,7 @@ static void restore_console_color_rgb(void);
|
|||||||
static int suppress_winsize = 1; // don't fiddle with console
|
static int suppress_winsize = 1; // don't fiddle with console
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static char_u *exe_path = NULL;
|
static WCHAR *exe_pathw = NULL;
|
||||||
|
|
||||||
static BOOL win8_or_later = FALSE;
|
static BOOL win8_or_later = FALSE;
|
||||||
static BOOL win10_22H2_or_later = FALSE;
|
static BOOL win10_22H2_or_later = FALSE;
|
||||||
@ -462,27 +462,45 @@ wait_for_single_object(
|
|||||||
# endif
|
# endif
|
||||||
#endif // !FEAT_GUI_MSWIN || VIMDLL
|
#endif // !FEAT_GUI_MSWIN || VIMDLL
|
||||||
|
|
||||||
static void
|
void
|
||||||
get_exe_name(void)
|
mch_get_exe_name(void)
|
||||||
{
|
{
|
||||||
// Maximum length of $PATH is more than MAXPATHL. 8191 is often mentioned
|
// Maximum length of $PATH is more than MAXPATHL. 8191 is often mentioned
|
||||||
// as the maximum length that works (plus a NUL byte).
|
// as the maximum length that works (plus a NUL byte).
|
||||||
#define MAX_ENV_PATH_LEN 8192
|
#define MAX_ENV_PATH_LEN 8192
|
||||||
char temp[MAX_ENV_PATH_LEN];
|
char temp[MAX_ENV_PATH_LEN];
|
||||||
char_u *p;
|
char_u *p;
|
||||||
|
WCHAR buf[MAX_PATH];
|
||||||
|
int updated = FALSE;
|
||||||
|
static int enc_prev = -1;
|
||||||
|
|
||||||
if (exe_name == NULL)
|
if (exe_name == NULL || exe_pathw == NULL || enc_prev != enc_codepage)
|
||||||
{
|
{
|
||||||
// store the name of the executable, may be used for $VIM
|
// store the name of the executable, may be used for $VIM
|
||||||
GetModuleFileName(NULL, temp, MAX_ENV_PATH_LEN - 1);
|
GetModuleFileNameW(NULL, buf, MAX_PATH);
|
||||||
if (*temp != NUL)
|
if (*buf != NUL)
|
||||||
exe_name = FullName_save((char_u *)temp, FALSE);
|
{
|
||||||
|
if (enc_codepage == -1)
|
||||||
|
enc_codepage = GetACP();
|
||||||
|
if (exe_name != NULL)
|
||||||
|
vim_free(exe_name);
|
||||||
|
exe_name = utf16_to_enc(buf, NULL);
|
||||||
|
enc_prev = enc_codepage;
|
||||||
|
|
||||||
|
WCHAR *wp = wcsrchr(buf, '\\');
|
||||||
|
if (wp != NULL)
|
||||||
|
*wp = NUL;
|
||||||
|
if (exe_pathw != NULL)
|
||||||
|
vim_free(exe_pathw);
|
||||||
|
exe_pathw = _wcsdup(buf);
|
||||||
|
updated = TRUE;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (exe_path != NULL || exe_name == NULL)
|
if (exe_pathw == NULL || !updated)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
exe_path = vim_strnsave(exe_name, gettail_sep(exe_name) - exe_name);
|
char_u *exe_path = utf16_to_enc(exe_pathw, NULL);
|
||||||
if (exe_path == NULL)
|
if (exe_path == NULL)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@ -503,6 +521,7 @@ get_exe_name(void)
|
|||||||
STRCAT(temp, exe_path);
|
STRCAT(temp, exe_path);
|
||||||
vim_setenv((char_u *)"PATH", (char_u *)temp);
|
vim_setenv((char_u *)"PATH", (char_u *)temp);
|
||||||
}
|
}
|
||||||
|
vim_free(exe_path);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -538,10 +557,10 @@ vimLoadLib(const char *name)
|
|||||||
|
|
||||||
// NOTE: Do not use mch_dirname() and mch_chdir() here, they may call
|
// NOTE: Do not use mch_dirname() and mch_chdir() here, they may call
|
||||||
// vimLoadLib() recursively, which causes a stack overflow.
|
// vimLoadLib() recursively, which causes a stack overflow.
|
||||||
if (exe_path == NULL)
|
if (exe_pathw == NULL)
|
||||||
get_exe_name();
|
mch_get_exe_name();
|
||||||
|
|
||||||
if (exe_path == NULL)
|
if (exe_pathw == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
WCHAR old_dirw[MAXPATHL];
|
WCHAR old_dirw[MAXPATHL];
|
||||||
@ -552,7 +571,7 @@ vimLoadLib(const char *name)
|
|||||||
// Change directory to where the executable is, both to make
|
// Change directory to where the executable is, both to make
|
||||||
// sure we find a .dll there and to avoid looking for a .dll
|
// sure we find a .dll there and to avoid looking for a .dll
|
||||||
// in the current directory.
|
// in the current directory.
|
||||||
SetCurrentDirectory((LPCSTR)exe_path);
|
SetCurrentDirectoryW(exe_pathw);
|
||||||
dll = LoadLibrary(name);
|
dll = LoadLibrary(name);
|
||||||
SetCurrentDirectoryW(old_dirw);
|
SetCurrentDirectoryW(old_dirw);
|
||||||
return dll;
|
return dll;
|
||||||
@ -3586,7 +3605,7 @@ mch_check_win(
|
|||||||
int argc UNUSED,
|
int argc UNUSED,
|
||||||
char **argv UNUSED)
|
char **argv UNUSED)
|
||||||
{
|
{
|
||||||
get_exe_name();
|
mch_get_exe_name();
|
||||||
|
|
||||||
#if defined(FEAT_GUI_MSWIN) && !defined(VIMDLL)
|
#if defined(FEAT_GUI_MSWIN) && !defined(VIMDLL)
|
||||||
return OK; // GUI always has a tty
|
return OK; // GUI always has a tty
|
||||||
|
@ -26,6 +26,7 @@ void vim_beep(unsigned val);
|
|||||||
void init_homedir(void);
|
void init_homedir(void);
|
||||||
void free_homedir(void);
|
void free_homedir(void);
|
||||||
void free_users(void);
|
void free_users(void);
|
||||||
|
void init_vimdir(void);
|
||||||
char_u *expand_env_save(char_u *src);
|
char_u *expand_env_save(char_u *src);
|
||||||
char_u *expand_env_save_opt(char_u *src, int one);
|
char_u *expand_env_save_opt(char_u *src, int one);
|
||||||
void expand_env(char_u *src, char_u *dst, int dstlen);
|
void expand_env(char_u *src, char_u *dst, int dstlen);
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
/* os_win32.c */
|
/* os_win32.c */
|
||||||
|
void mch_get_exe_name(void);
|
||||||
HINSTANCE vimLoadLib(const char *name);
|
HINSTANCE vimLoadLib(const char *name);
|
||||||
int mch_is_gui_executable(void);
|
int mch_is_gui_executable(void);
|
||||||
HINSTANCE find_imported_module_by_funcname(HINSTANCE hInst, const char *funcname);
|
HINSTANCE find_imported_module_by_funcname(HINSTANCE hInst, const char *funcname);
|
||||||
|
@ -695,6 +695,8 @@ static char *(features[]) =
|
|||||||
|
|
||||||
static int included_patches[] =
|
static int included_patches[] =
|
||||||
{ /* Add new patch number below this line */
|
{ /* Add new patch number below this line */
|
||||||
|
/**/
|
||||||
|
1313,
|
||||||
/**/
|
/**/
|
||||||
1312,
|
1312,
|
||||||
/**/
|
/**/
|
||||||
|
Loading…
x
Reference in New Issue
Block a user