Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix MacVim's locale not having encoding when launched from Dock #1036

Merged
merged 1 commit into from
Apr 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/os_mac_conv.c
Original file line number Diff line number Diff line change
Expand Up @@ -576,6 +576,16 @@ mac_lang_init(void)
kLocaleRegionMask | kLocaleRegionVariantMask,
sizeof buf, buf) == noErr && *buf)
{
# ifdef FEAT_GUI_MACVIM
// This usually happens when the user directly launches from the Dock
// instead of terminal. macOS doesn't really provide the encoding part
// in the locale API, since it assumes everything is UTF-8 anyway. We
// should manually append a UTF-8 encoding component to the locale
// string. This helps tools that wants to parse the encoding compoennt
// of the locale.
strlcat(buf, ".UTF-8", sizeof(buf)/sizeof(char));
# endif

vim_setenv((char_u *)"LANG", (char_u *)buf);
# ifdef HAVE_LOCALE_H
setlocale(LC_ALL, "");
Expand Down
41 changes: 41 additions & 0 deletions src/testdir/test_macvim.vim
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
" Test for MacVim behaviors and regressions

source check.vim
source term_util.vim
CheckFeature gui_macvim

" Tests for basic existence of commands and options to make sure no
Expand Down Expand Up @@ -54,3 +55,43 @@ func Test_macvim_mappings()
call feedkeys("\<ForceClick>", "xt")
call assert_equal(5, g:marker_value)
endfunc

" Test that we correctly set the locale to have .UTF-8 if launching from the
" Dock or the $LANG env variable is not set.
func Test_macvim_default_locale_utf8()
CheckRunVimInTerminal
if !has('terminal') || !executable('/bin/sh')
return
endif
let buf = term_start('/bin/sh')

" Wait for shell prompt.
call WaitForAssert({-> assert_match('[$#] $', term_getline(buf, '.'))})

" Unset the $LANG environmental variable. This causes Vim to try to set a
" default one in macOS.
call term_sendkeys(buf, "unset LANG\<CR>")

" Run Vim and ask it to output the $LANG variable. It should be
" automatically created since it doesn't exist.
call term_sendkeys(buf, v:progpath
\ . " --clean -X"
\ . " -c 'echo $LANG'\<CR>")

" Wait for Vim to come up and show something in the status line.
let term_rows = term_getsize(buf)[0]
call term_wait(buf)
call WaitFor({-> len(term_getline(buf, term_rows)) > 0})

" Check that the locale actually has .UTF-8 in it. We can't check for
" "en_US.UTF-8" because we shouldn't assume what locale the tester is
" using.
call assert_match('^[a-zA-Z-_]\+\.UTF-8\>', term_getline(buf, term_rows), "Default locale doesn't have UTF-8 encoding set")

" Cleanly exist from Vim/terminal and clean up.
call term_sendkeys(buf, ":qall!\<CR>")
call term_wait(buf)
call WaitForAssert({-> assert_match('[$#] $', term_getline(buf, '.'))})
call StopShellInTerminal(buf)
exe buf . 'bwipe!'
endfunc