-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix macOS default locale to have UTF-8 encoding set
If LANG is unset in macOS (either manually or when launching GUI version of Vim from the Dock where this environmental variable is not set by the OS), Vim tries to query the system locale and set that. However, the system API doesn't set the encoding part, and there are tools like new versions of Python that seems to want to have an explicit encoding bit set. Also, macOS defaults to UTF-8 anyway, so just make sure to append ".UTF-8" to the locale to explicitly set it. Also, add regression test for both this change and for 509f803 (vim#7003) which added logic to make sure we set LC_NUMERIC to "C" in the default locale detection. This is a port of macvim-dev/macvim#1036
- Loading branch information
Showing
4 changed files
with
36 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
" Test for locale behaviors | ||
|
||
source check.vim | ||
source term_util.vim | ||
|
||
" Test that on macOS, we correctly set the default locale to have UTF-8 | ||
" encoding and LC_NUMERIC is set to "C", if $LANG env variable is not set. | ||
func Test_macos_default_locale() | ||
if !has('osxdarwin') | ||
return | ||
endif | ||
|
||
" Run Vim after unsetting all the locale environmental vars, and capture the | ||
" output of :lang. | ||
let lang_results = system("unset LANG; unset LC_MESSAGES; " .. | ||
\ v:progpath .. | ||
\ " --clean -esX -c 'redir @a' -c 'lang' -c 'put a' -c 'print' -c 'qa!' ") | ||
|
||
" Check that: | ||
" 1. The locale is the form of <locale>.UTF-8. | ||
" 2. Check that fourth item (LC_NUMERIC) is properly set to "C". | ||
" Example match: "en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8" | ||
call assert_match('"\([a-zA-Z_]\+\.UTF-8/\)\{3}C\(/[a-zA-Z_]\+\.UTF-8\)\{2}"', lang_results, "Default locale doesn't have UTF-8 encoding set") | ||
endfunc | ||
|
||
" vim: shiftwidth=2 sts=2 expandtab |