Skip to content

Commit 4442bd7

Browse files
committed
Fix MacVim's locale not having encoding when launched from Dock
When launching MacVim not from terminal, macOS doesn't set the $LANG environment variable, and the locale API doesn't have a way to return the encoding (probably because everything is UTF-8). As such Vim would set the locale to something like "en_US", which breaks certain tools that expects an encoding part set. Fix this by simply appending ".UTF-8" to the constructed locale (e.g. "en_US.UTF-8") if $LANG doesn't exist. This makes sense as we default to UTF-8 in MacVim and macOS is basically UTF-8 native anyway. Fix macvim-dev#1033
1 parent dce1eac commit 4442bd7

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

src/os_mac_conv.c

+10
Original file line numberDiff line numberDiff line change
@@ -576,6 +576,16 @@ mac_lang_init(void)
576576
kLocaleRegionMask | kLocaleRegionVariantMask,
577577
sizeof buf, buf) == noErr && *buf)
578578
{
579+
# ifdef FEAT_GUI_MACVIM
580+
// This usually happens when the user directly launches from the Dock
581+
// instead of terminal. macOS doesn't really provide the encoding part
582+
// in the locale API, since it assumes everything is UTF-8 anyway. We
583+
// should manually append a UTF-8 encoding component to the locale
584+
// string. This helps tools that wants to parse the encoding compoennt
585+
// of the locale.
586+
strlcat(buf, ".UTF-8", sizeof(buf)/sizeof(char));
587+
# endif
588+
579589
vim_setenv((char_u *)"LANG", (char_u *)buf);
580590
# ifdef HAVE_LOCALE_H
581591
setlocale(LC_ALL, "");

0 commit comments

Comments
 (0)