Hi,

I wrote a patch for the following todo item:

> Win32: When running ":make" and 'encoding' differs from the system locale, the
> output should be converted.  Esp. when 'encoding' is "utf-8". (Yongwei Wu)
> Should we use 'termencoding' for this?

I think using 'termencoding' for this is not so good.  Normally the encoding
of a command output is the same as the encoding of the terminal, but not
always the same.  I hear that some commands on Windows use utf-8 instead of
the current codepage.  So I added a new option 'cmdencoding' ('cenc').
What do you think of this?

It would be nice, if `:make` and other commands would support encoding
detection, but I think it's difficult because `:make` reads the output line by
line.  So encoding detection is not implemented now.

Regards,
Ken Takata

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.
# HG changeset patch
# Parent  2cc7f84f678149b42c75ee230dd601806846122d

diff --git a/runtime/doc/options.txt b/runtime/doc/options.txt
--- a/runtime/doc/options.txt
+++ b/runtime/doc/options.txt
@@ -1627,6 +1627,24 @@ A jump table for the options with a shor
 			The rest of the option value will be used for
 			{pattern}, this must be the last entry.
 
+					*'cmdencoding'* *'cenc'*
+'cmdencoding' 'cenc'	string	(default "")
+			global
+			{only available when compiled with the |+multi_byte|
+			feature}
+			{not in Vi}
+	Encoding used for reading/writing the output/input of external
+	commands.  When empty, encoding is not converted.
+	This is used for `:make`, `:lmake`, `:grep`, `:lgrep`, `:grepadd`,
+	`:lgrepadd`, `:cfile`, `:cgetfile`, `:caddfile`, `:lfile`, `:lgetfile`,
+	and `:laddfile`.
+
+	This would be mostly useful when you use MS-Windows and set 'encoding'
+	to "utf-8".  If iconv is enabled, setting 'cmdencoding' to "char" has
+	the same effect as setting to the system locale encoding.  Example: >
+		:set encoding=utf-8
+		:set cmdencoding=char	" system locale is used
+<
 						*'cmdheight'* *'ch'*
 'cmdheight' 'ch'	number	(default 1)
 			global
diff --git a/runtime/doc/quickfix.txt b/runtime/doc/quickfix.txt
--- a/runtime/doc/quickfix.txt
+++ b/runtime/doc/quickfix.txt
@@ -320,6 +320,7 @@ use this code: >
 	endfunction
 
 	au QuickfixCmdPost make call QfMakeConv()
+Another option is using 'cmdencoding'.
 
 
 EXECUTE A COMMAND IN ALL THE BUFFERS IN QUICKFIX OR LOCATION LIST:
@@ -586,11 +587,17 @@ 4. Using :make						*:make_makeprg*
 			   like |:cnext| and |:cprevious|, see above.
 			This command does not accept a comment, any "
 			characters are considered part of the arguments.
+			If the encoding of the program output differs from the
+			'encoding' option, you can use the 'cmdencoding'
+			option to specify the encoding.
 
 							*:lmak* *:lmake*
 :lmak[e][!] [arguments]
 			Same as ":make", except the location list for the
 			current window is used instead of the quickfix list.
+			If the encoding of the program output differs from the
+			'encoding' option, you can use the 'cmdencoding'
+			option to specify the encoding.
 
 The ":make" command executes the command given with the 'makeprg' option.
 This is done by passing the command to the shell given with the 'shell'
@@ -645,6 +652,7 @@ read the error messages: >
 	au QuickfixCmdPost make call QfMakeConv()
 
 (Example by Faque Cheng)
+Another option is using 'cmdencoding'.
 
 ==============================================================================
 5. Using :vimgrep and :grep				*grep* *lid*
diff --git a/src/option.c b/src/option.c
--- a/src/option.c
+++ b/src/option.c
@@ -781,6 +781,15 @@ static struct vimoption options[] =
 			    {(char_u *)"", (char_u *)0L}
 #endif
 			    SCRIPTID_INIT},
+    {"cmdencoding", "cenc", P_STRING|P_VI_DEF|P_RCLR,
+#ifdef FEAT_MBYTE
+			    (char_u *)&p_cenc, PV_NONE,
+			    {(char_u *)"", (char_u *)0L}
+#else
+			    (char_u *)NULL, PV_NONE,
+			    {(char_u *)0L, (char_u *)0L}
+#endif
+			    SCRIPTID_INIT},
     {"cmdheight",   "ch",   P_NUM|P_VI_DEF|P_RALL,
 			    (char_u *)&p_ch, PV_NONE,
 			    {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
@@ -6092,7 +6101,8 @@ did_set_string_option(
 
 #ifdef FEAT_MBYTE
     /* 'encoding' and 'fileencoding' */
-    else if (varp == &p_enc || gvarp == &p_fenc || varp == &p_tenc)
+    else if (varp == &p_enc || gvarp == &p_fenc || varp == &p_tenc
+							|| varp == &p_cenc)
     {
 	if (gvarp == &p_fenc)
 	{
diff --git a/src/option.h b/src/option.h
--- a/src/option.h
+++ b/src/option.h
@@ -410,6 +410,9 @@ EXTERN long	p_cwh;		/* 'cmdwinheight' */
 #ifdef FEAT_CLIPBOARD
 EXTERN char_u	*p_cb;		/* 'clipboard' */
 #endif
+#ifdef FEAT_MBYTE
+EXTERN char_u	*p_cenc;	/* 'cmdencoding' */
+#endif
 EXTERN long	p_ch;		/* 'cmdheight' */
 #if defined(FEAT_GUI_DIALOG) || defined(FEAT_CON_DIALOG)
 EXTERN int	p_confirm;	/* 'confirm' */
diff --git a/src/quickfix.c b/src/quickfix.c
--- a/src/quickfix.c
+++ b/src/quickfix.c
@@ -495,6 +495,7 @@ typedef struct {
     buf_T	*buf;
     linenr_T	buflnum;
     linenr_T	lnumlast;
+    vimconv_T	*vc;
 } qfstate_T;
 
     static char_u *
@@ -710,6 +711,30 @@ qf_get_next_file_line(qfstate_T *state)
     else
 	state->linebuf = IObuff;
 
+#ifdef FEAT_MBYTE
+    /* Convert a line if it contains a non-ASCII character. */
+    if (state->vc->vc_type != CONV_NONE && has_non_ascii(state->linebuf)) {
+	char_u	*line;
+
+	line = string_convert(state->vc, state->linebuf, &state->linelen);
+	if (line != NULL)
+	{
+	    if (state->linelen < IOSIZE)
+	    {
+		STRCPY(state->linebuf, line);
+		vim_free(line);
+	    }
+	    else
+	    {
+		vim_free(state->growbuf);
+		state->linebuf = state->growbuf = line;
+		state->growbufsiz = state->linelen < LINE_MAXLEN
+						? state->linelen : LINE_MAXLEN;
+	    }
+	}
+    }
+#endif
+
     return QF_OK;
 }
 
@@ -1103,7 +1128,7 @@ qf_init_ext(
     char_u	    *qf_title)
 {
     qfstate_T	    state = {NULL, 0, NULL, 0, NULL, NULL, NULL, NULL,
-			     NULL, 0, 0};
+			     NULL, 0, 0, NULL};
     qffields_T	    fields = {NULL, NULL, 0, 0L, 0, FALSE, NULL, 0, 0, 0};
 #ifdef FEAT_WINDOWS
     qfline_T	    *old_last = NULL;
@@ -1113,7 +1138,14 @@ qf_init_ext(
     static char_u   *last_efm = NULL;
     int		    retval = -1;	/* default: return error flag */
     int		    status;
-
+#ifdef FEAT_MBYTE
+    vimconv_T	    vc;
+
+    vc.vc_type = CONV_NONE;
+    if (p_cenc != NULL && *p_cenc != NUL)
+	convert_setup(&vc, p_cenc, p_enc);
+    state.vc = &vc;
+#endif
     fields.namebuf = alloc_id(CMDBUFFSIZE + 1, aid_qf_namebuf);
     fields.errmsglen = CMDBUFFSIZE + 1;
     fields.errmsg = alloc_id(fields.errmsglen, aid_qf_errmsg);
@@ -1276,6 +1308,10 @@ qf_init_end:
 #ifdef FEAT_WINDOWS
     qf_update_buffer(qi, old_last);
 #endif
+#ifdef FEAT_MBYTE
+    if (vc.vc_type != CONV_NONE)
+	convert_setup(&vc, NULL, NULL);
+#endif
 
     return retval;
 }

Raspunde prin e-mail lui