Skip to content

Commit 2c7292d

Browse files
committed
patch 8.0.0420: text garbled when the system encoding differs from 'encoding'
Problem: When running :make the output may be in the system encoding, different from 'encoding'. Solution: Add the 'makeencoding' option. (Ken Takata)
1 parent 214641f commit 2c7292d

File tree

16 files changed

+328
-16
lines changed

16 files changed

+328
-16
lines changed

runtime/doc/options.txt

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4994,6 +4994,25 @@ A jump table for the options with a short description can be found at |Q_op|.
49944994
This option cannot be set from a |modeline| or in the |sandbox|, for
49954995
security reasons.
49964996

4997+
*'makeencoding'* *'menc'*
4998+
'makeencoding' 'menc' string (default "")
4999+
global or local to buffer |global-local|
5000+
{only available when compiled with the |+multi_byte|
5001+
feature}
5002+
{not in Vi}
5003+
Encoding used for reading the output of external commands. When empty,
5004+
encoding is not converted.
5005+
This is used for `:make`, `:lmake`, `:grep`, `:lgrep`, `:grepadd`,
5006+
`:lgrepadd`, `:cfile`, `:cgetfile`, `:caddfile`, `:lfile`, `:lgetfile`,
5007+
and `:laddfile`.
5008+
5009+
This would be mostly useful when you use MS-Windows and set 'encoding'
5010+
to "utf-8". If |+iconv| is enabled and GNU libiconv is used, setting
5011+
'makeencoding' to "char" has the same effect as setting to the system
5012+
locale encoding. Example: >
5013+
:set encoding=utf-8
5014+
:set makeencoding=char " system locale is used
5015+
<
49975016
*'makeprg'* *'mp'*
49985017
'makeprg' 'mp' string (default "make", VMS: "MMS")
49995018
global or local to buffer |global-local|

runtime/doc/quickfix.txt

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,9 @@ processing a quickfix or location list command, it will be aborted.
164164
keep Vim running while compiling. If you give the
165165
name of the errorfile, the 'errorfile' option will
166166
be set to [errorfile]. See |:cc| for [!].
167+
If the encoding of the error file differs from the
168+
'encoding' option, you can use the 'makeencoding'
169+
option to specify the encoding.
167170

168171
*:lf* *:lfile*
169172
:lf[ile][!] [errorfile] Same as ":cfile", except the location list for the
@@ -175,6 +178,9 @@ processing a quickfix or location list command, it will be aborted.
175178
:cg[etfile] [errorfile] *:cg* *:cgetfile*
176179
Read the error file. Just like ":cfile" but don't
177180
jump to the first error.
181+
If the encoding of the error file differs from the
182+
'encoding' option, you can use the 'makeencoding'
183+
option to specify the encoding.
178184

179185

180186
:lg[etfile] [errorfile] *:lg* *:lgetfile*
@@ -185,6 +191,9 @@ processing a quickfix or location list command, it will be aborted.
185191
:caddf[ile] [errorfile] Read the error file and add the errors from the
186192
errorfile to the current quickfix list. If a quickfix
187193
list is not present, then a new list is created.
194+
If the encoding of the error file differs from the
195+
'encoding' option, you can use the 'makeencoding'
196+
option to specify the encoding.
188197

189198
*:laddf* *:laddfile*
190199
:laddf[ile] [errorfile] Same as ":caddfile", except the location list for the
@@ -320,6 +329,7 @@ use this code: >
320329
endfunction
321330
322331
au QuickfixCmdPost make call QfMakeConv()
332+
Another option is using 'makeencoding'.
323333

324334

325335
EXECUTE A COMMAND IN ALL THE BUFFERS IN QUICKFIX OR LOCATION LIST:
@@ -586,6 +596,9 @@ lists, use ":cnewer 99" first.
586596
like |:cnext| and |:cprevious|, see above.
587597
This command does not accept a comment, any "
588598
characters are considered part of the arguments.
599+
If the encoding of the program output differs from the
600+
'encoding' option, you can use the 'makeencoding'
601+
option to specify the encoding.
589602

590603
*:lmak* *:lmake*
591604
:lmak[e][!] [arguments]
@@ -645,6 +658,7 @@ read the error messages: >
645658
au QuickfixCmdPost make call QfMakeConv()
646659
647660
(Example by Faque Cheng)
661+
Another option is using 'makeencoding'.
648662

649663
==============================================================================
650664
5. Using :vimgrep and :grep *grep* *lid*
@@ -759,6 +773,9 @@ id-utils) in a similar way to its compiler integration (see |:make| above).
759773
When 'grepprg' is "internal" this works like
760774
|:vimgrep|. Note that the pattern needs to be
761775
enclosed in separator characters then.
776+
If the encoding of the program output differs from the
777+
'encoding' option, you can use the 'makeencoding'
778+
option to specify the encoding.
762779

763780
*:lgr* *:lgrep*
764781
:lgr[ep][!] [arguments] Same as ":grep", except the location list for the
@@ -783,6 +800,10 @@ id-utils) in a similar way to its compiler integration (see |:make| above).
783800
\ | catch /E480:/
784801
\ | endtry"
785802
<
803+
If the encoding of the program output differs from the
804+
'encoding' option, you can use the 'makeencoding'
805+
option to specify the encoding.
806+
786807
*:lgrepa* *:lgrepadd*
787808
:lgrepa[dd][!] [arguments]
788809
Same as ":grepadd", except the location list for the

runtime/doc/quickref.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -782,6 +782,7 @@ Short explanation of each option: *option-list*
782782
'macatsui' Mac GUI: use ATSUI text drawing
783783
'magic' changes special characters in search patterns
784784
'makeef' 'mef' name of the errorfile for ":make"
785+
'makeencoding' 'menc' encoding of external make/grep commands
785786
'makeprg' 'mp' program to use for the ":make" command
786787
'matchpairs' 'mps' pairs of characters that "%" can match
787788
'matchtime' 'mat' tenths of a second to show matching paren

src/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2157,6 +2157,7 @@ test_arglist \
21572157
test_listlbr \
21582158
test_listlbr_utf8 \
21592159
test_lua \
2160+
test_makeencoding \
21602161
test_man \
21612162
test_mapping \
21622163
test_marks \

src/buffer.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2255,6 +2255,9 @@ free_buf_options(
22552255
clear_string_option(&buf->b_p_lw);
22562256
#endif
22572257
clear_string_option(&buf->b_p_bkc);
2258+
#ifdef FEAT_MBYTE
2259+
clear_string_option(&buf->b_p_menc);
2260+
#endif
22582261
}
22592262

22602263
/*

src/if_cscope.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1242,7 +1242,7 @@ cs_find_common(
12421242
wp = curwin;
12431243
/* '-' starts a new error list */
12441244
if (qf_init(wp, tmp, (char_u *)"%f%*\\t%l%*\\t%m",
1245-
*qfpos == '-', cmdline) > 0)
1245+
*qfpos == '-', cmdline, NULL) > 0)
12461246
{
12471247
# ifdef FEAT_WINDOWS
12481248
if (postponed_split != 0)

src/main.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -559,11 +559,16 @@ vim_main2(void)
559559
*/
560560
if (params.edit_type == EDIT_QF)
561561
{
562+
char_u *enc = NULL;
563+
564+
# ifdef FEAT_MBYTE
565+
enc = p_menc;
566+
# endif
562567
if (params.use_ef != NULL)
563568
set_string_option_direct((char_u *)"ef", -1,
564569
params.use_ef, OPT_FREE, SID_CARG);
565570
vim_snprintf((char *)IObuff, IOSIZE, "cfile %s", p_ef);
566-
if (qf_init(NULL, p_ef, p_efm, TRUE, IObuff) < 0)
571+
if (qf_init(NULL, p_ef, p_efm, TRUE, IObuff, enc) < 0)
567572
{
568573
out_char('\n');
569574
mch_exit(3);

src/option.c

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,9 @@
139139
# define PV_LISP OPT_BUF(BV_LISP)
140140
# define PV_LW OPT_BOTH(OPT_BUF(BV_LW))
141141
#endif
142+
#ifdef FEAT_MBYTE
143+
# define PV_MENC OPT_BOTH(OPT_BUF(BV_MENC))
144+
#endif
142145
#define PV_MA OPT_BUF(BV_MA)
143146
#define PV_ML OPT_BUF(BV_ML)
144147
#define PV_MOD OPT_BUF(BV_MOD)
@@ -1898,6 +1901,15 @@ static struct vimoption options[] =
18981901
#else
18991902
(char_u *)NULL, PV_NONE,
19001903
{(char_u *)NULL, (char_u *)0L}
1904+
#endif
1905+
SCRIPTID_INIT},
1906+
{"makeencoding","menc", P_STRING|P_VI_DEF,
1907+
#ifdef FEAT_MBYTE
1908+
(char_u *)&p_menc, PV_MENC,
1909+
{(char_u *)"", (char_u *)0L}
1910+
#else
1911+
(char_u *)NULL, PV_NONE,
1912+
{(char_u *)0L, (char_u *)0L}
19011913
#endif
19021914
SCRIPTID_INIT},
19031915
{"makeprg", "mp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
@@ -5686,6 +5698,9 @@ check_buf_options(buf_T *buf)
56865698
check_string_option(&buf->b_p_lw);
56875699
#endif
56885700
check_string_option(&buf->b_p_bkc);
5701+
#ifdef FEAT_MBYTE
5702+
check_string_option(&buf->b_p_menc);
5703+
#endif
56895704
}
56905705

56915706
/*
@@ -6289,8 +6304,9 @@ did_set_string_option(
62896304
#endif
62906305

62916306
#ifdef FEAT_MBYTE
6292-
/* 'encoding' and 'fileencoding' */
6293-
else if (varp == &p_enc || gvarp == &p_fenc || varp == &p_tenc)
6307+
/* 'encoding', 'fileencoding', 'termencoding' and 'makeencoding' */
6308+
else if (varp == &p_enc || gvarp == &p_fenc || varp == &p_tenc
6309+
|| gvarp == &p_menc)
62946310
{
62956311
if (gvarp == &p_fenc)
62966312
{
@@ -10424,6 +10440,11 @@ unset_global_local_option(char_u *name, void *from)
1042410440
case PV_LW:
1042510441
clear_string_option(&buf->b_p_lw);
1042610442
break;
10443+
#endif
10444+
#ifdef FEAT_MBYTE
10445+
case PV_MENC:
10446+
clear_string_option(&buf->b_p_menc);
10447+
break;
1042710448
#endif
1042810449
}
1042910450
}
@@ -10478,6 +10499,9 @@ get_varp_scope(struct vimoption *p, int opt_flags)
1047810499
case PV_LW: return (char_u *)&(curbuf->b_p_lw);
1047910500
#endif
1048010501
case PV_BKC: return (char_u *)&(curbuf->b_p_bkc);
10502+
#ifdef FEAT_MBYTE
10503+
case PV_MENC: return (char_u *)&(curbuf->b_p_menc);
10504+
#endif
1048110505
}
1048210506
return NULL; /* "cannot happen" */
1048310507
}
@@ -10553,6 +10577,10 @@ get_varp(struct vimoption *p)
1055310577
case PV_LW: return *curbuf->b_p_lw != NUL
1055410578
? (char_u *)&(curbuf->b_p_lw) : p->var;
1055510579
#endif
10580+
#ifdef FEAT_MBYTE
10581+
case PV_MENC: return *curbuf->b_p_menc != NUL
10582+
? (char_u *)&(curbuf->b_p_menc) : p->var;
10583+
#endif
1055610584

1055710585
#ifdef FEAT_ARABIC
1055810586
case PV_ARAB: return (char_u *)&(curwin->w_p_arab);
@@ -11154,6 +11182,9 @@ buf_copy_options(buf_T *buf, int flags)
1115411182
#ifdef FEAT_LISP
1115511183
buf->b_p_lw = empty_option;
1115611184
#endif
11185+
#ifdef FEAT_MBYTE
11186+
buf->b_p_menc = empty_option;
11187+
#endif
1115711188

1115811189
/*
1115911190
* Don't copy the options set by ex_help(), use the saved values,

src/option.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -630,6 +630,9 @@ EXTERN char_u *p_luadll; /* 'luadll' */
630630
EXTERN int p_macatsui; /* 'macatsui' */
631631
#endif
632632
EXTERN int p_magic; /* 'magic' */
633+
#ifdef FEAT_MBYTE
634+
EXTERN char_u *p_menc; /* 'makeencoding' */
635+
#endif
633636
#ifdef FEAT_QUICKFIX
634637
EXTERN char_u *p_mef; /* 'makeef' */
635638
EXTERN char_u *p_mp; /* 'makeprg' */
@@ -1064,6 +1067,9 @@ enum
10641067
#ifdef FEAT_LISP
10651068
, BV_LISP
10661069
, BV_LW
1070+
#endif
1071+
#ifdef FEAT_MBYTE
1072+
, BV_MENC
10671073
#endif
10681074
, BV_MA
10691075
, BV_ML

src/proto/quickfix.pro

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* quickfix.c */
2-
int qf_init(win_T *wp, char_u *efile, char_u *errorformat, int newlist, char_u *qf_title);
2+
int qf_init(win_T *wp, char_u *efile, char_u *errorformat, int newlist, char_u *qf_title, char_u *enc);
33
void qf_free_all(win_T *wp);
44
void copy_loclist(win_T *from, win_T *to);
55
void qf_jump(qf_info_T *qi, int dir, int errornr, int forceit);

0 commit comments

Comments
 (0)