To: vim_dev@googlegroups.com Subject: Patch 8.2.1757 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 8.2.1757 Problem: Mac: default locale is lacking the encoding. Solution: Add ".UTF-8 to the locale. (Yee Cheng Chin, closes #7022) Files: src/os_mac_conv.c, src/testdir/test_environ.vim *** ../vim-8.2.1756/src/os_mac_conv.c 2020-09-24 23:08:11.132478783 +0200 --- src/os_mac_conv.c 2020-09-27 15:51:03.699171047 +0200 *************** *** 570,581 **** { if (mch_getenv((char_u *)"LANG") == NULL) { ! char buf[20]; if (LocaleRefGetPartString(NULL, kLocaleLanguageMask | kLocaleLanguageVariantMask | kLocaleRegionMask | kLocaleRegionVariantMask, ! sizeof buf, buf) == noErr && *buf) { vim_setenv((char_u *)"LANG", (char_u *)buf); # ifdef HAVE_LOCALE_H setlocale(LC_ALL, ""); --- 570,586 ---- { if (mch_getenv((char_u *)"LANG") == NULL) { ! char buf[50]; ! ! // $LANG is not set, either because it was unset or Vim was started ! // from the Dock. Query the system locale. if (LocaleRefGetPartString(NULL, kLocaleLanguageMask | kLocaleLanguageVariantMask | kLocaleRegionMask | kLocaleRegionVariantMask, ! sizeof(buf) - 10, buf) == noErr && *buf) { + if (strcasestr(buf, "utf-8") == NULL) + strcat(buf, ".UTF-8"); vim_setenv((char_u *)"LANG", (char_u *)buf); # ifdef HAVE_LOCALE_H setlocale(LC_ALL, ""); *** ../vim-8.2.1756/src/testdir/test_environ.vim 2020-08-12 18:50:31.875655822 +0200 --- src/testdir/test_environ.vim 2020-09-27 16:02:21.800727786 +0200 *************** *** 2,7 **** --- 2,9 ---- scriptencoding utf-8 + source check.vim + func Test_environ() unlet! $TESTENV call assert_equal(0, has_key(environ(), 'TESTENV')) *************** *** 45,48 **** --- 47,69 ---- call assert_equal('', result) endfunc + func Test_mac_locale() + CheckFeature osxdarwin + + " If $LANG is not set then the system locale will be used. + " Run Vim after unsetting all the locale environmental vars, and capture the + " output of :lang. + let lang_results = system("unset LANG; unset LC_MESSAGES; " .. + \ shellescape(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 .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 should have UTF-8 encoding set, and LC_NUMERIC set to 'C'") + endfunc + " vim: shiftwidth=2 sts=2 expandtab *** ../vim-8.2.1756/src/version.c 2020-09-27 15:19:23.642118924 +0200 --- src/version.c 2020-09-27 16:02:39.080663293 +0200 *************** *** 752,753 **** --- 752,755 ---- { /* Add new patch number below this line */ + /**/ + 1757, /**/ -- Often you're less important than your furniture. If you think about it, you can get fired but your furniture stays behind, gainfully employed at the company that didn't need _you_ anymore. (Scott Adams - The Dilbert principle) /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\ /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\ \\\ an exciting new programming language -- http://www.Zimbu.org /// \\\ help me help AIDS victims -- http://ICCF-Holland.org ///