mirror of
https://github.com/vim/vim.git
synced 2025-09-29 04:34:16 -04:00
patch 7.4.1522
Problem: Cannot write channel err to a buffer. Solution: Implement it.
This commit is contained in:
@@ -871,7 +871,7 @@ channel_set_job(channel_T *channel, job_T *job, jobopt_T *options)
|
|||||||
* Find a buffer matching "name" or create a new one.
|
* Find a buffer matching "name" or create a new one.
|
||||||
*/
|
*/
|
||||||
static buf_T *
|
static buf_T *
|
||||||
find_buffer(char_u *name)
|
find_buffer(char_u *name, int err)
|
||||||
{
|
{
|
||||||
buf_T *buf = NULL;
|
buf_T *buf = NULL;
|
||||||
buf_T *save_curbuf = curbuf;
|
buf_T *save_curbuf = curbuf;
|
||||||
@@ -890,7 +890,8 @@ find_buffer(char_u *name)
|
|||||||
curbuf = buf;
|
curbuf = buf;
|
||||||
if (curbuf->b_ml.ml_mfp == NULL)
|
if (curbuf->b_ml.ml_mfp == NULL)
|
||||||
ml_open(curbuf);
|
ml_open(curbuf);
|
||||||
ml_replace(1, (char_u *)"Reading from channel output...", TRUE);
|
ml_replace(1, (char_u *)(err ? "Reading from channel error..."
|
||||||
|
: "Reading from channel output..."), TRUE);
|
||||||
changed_bytes(1, 0);
|
changed_bytes(1, 0);
|
||||||
curbuf = save_curbuf;
|
curbuf = save_curbuf;
|
||||||
}
|
}
|
||||||
@@ -968,10 +969,27 @@ channel_set_options(channel_T *channel, jobopt_T *opt)
|
|||||||
if (!(opt->jo_set & JO_OUT_MODE))
|
if (!(opt->jo_set & JO_OUT_MODE))
|
||||||
channel->ch_part[PART_OUT].ch_mode = MODE_NL;
|
channel->ch_part[PART_OUT].ch_mode = MODE_NL;
|
||||||
channel->ch_part[PART_OUT].ch_buffer =
|
channel->ch_part[PART_OUT].ch_buffer =
|
||||||
find_buffer(opt->jo_io_name[PART_OUT]);
|
find_buffer(opt->jo_io_name[PART_OUT], FALSE);
|
||||||
ch_logs(channel, "writing to buffer '%s'",
|
ch_logs(channel, "writing out to buffer '%s'",
|
||||||
(char *)channel->ch_part[PART_OUT].ch_buffer->b_ffname);
|
(char *)channel->ch_part[PART_OUT].ch_buffer->b_ffname);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ((opt->jo_set & JO_ERR_IO) && (opt->jo_io[PART_ERR] == JIO_BUFFER
|
||||||
|
|| (opt->jo_io[PART_ERR] == JIO_OUT && (opt->jo_set & JO_OUT_IO)
|
||||||
|
&& opt->jo_io[PART_OUT] == JIO_BUFFER)))
|
||||||
|
{
|
||||||
|
/* writing err to a buffer. Default mode is NL. */
|
||||||
|
if (!(opt->jo_set & JO_ERR_MODE))
|
||||||
|
channel->ch_part[PART_ERR].ch_mode = MODE_NL;
|
||||||
|
if (opt->jo_io[PART_ERR] == JIO_OUT)
|
||||||
|
channel->ch_part[PART_ERR].ch_buffer =
|
||||||
|
channel->ch_part[PART_OUT].ch_buffer;
|
||||||
|
else
|
||||||
|
channel->ch_part[PART_ERR].ch_buffer =
|
||||||
|
find_buffer(opt->jo_io_name[PART_ERR], TRUE);
|
||||||
|
ch_logs(channel, "writing err to buffer '%s'",
|
||||||
|
(char *)channel->ch_part[PART_ERR].ch_buffer->b_ffname);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@@ -633,6 +633,53 @@ func Test_pipe_to_buffer()
|
|||||||
endtry
|
endtry
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
|
func Test_pipe_err_to_buffer()
|
||||||
|
if !has('job')
|
||||||
|
return
|
||||||
|
endif
|
||||||
|
call ch_log('Test_pipe_err_to_buffer()')
|
||||||
|
let job = job_start(s:python . " test_channel_pipe.py",
|
||||||
|
\ {'err-io': 'buffer', 'err-name': 'pipe-err'})
|
||||||
|
call assert_equal("run", job_status(job))
|
||||||
|
try
|
||||||
|
let handle = job_getchannel(job)
|
||||||
|
call ch_sendraw(handle, "echoerr line one\n")
|
||||||
|
call ch_sendraw(handle, "echoerr line two\n")
|
||||||
|
call ch_sendraw(handle, "doubleerr this\n")
|
||||||
|
call ch_sendraw(handle, "quit\n")
|
||||||
|
sp pipe-err
|
||||||
|
call s:waitFor('line("$") >= 5')
|
||||||
|
call assert_equal(['Reading from channel error...', 'line one', 'line two', 'this', 'AND this'], getline(1, '$'))
|
||||||
|
bwipe!
|
||||||
|
finally
|
||||||
|
call job_stop(job)
|
||||||
|
endtry
|
||||||
|
endfunc
|
||||||
|
|
||||||
|
func Test_pipe_both_to_buffer()
|
||||||
|
if !has('job')
|
||||||
|
return
|
||||||
|
endif
|
||||||
|
call ch_log('Test_pipe_both_to_buffer()')
|
||||||
|
let job = job_start(s:python . " test_channel_pipe.py",
|
||||||
|
\ {'out-io': 'buffer', 'out-name': 'pipe-err', 'err-io': 'out'})
|
||||||
|
call assert_equal("run", job_status(job))
|
||||||
|
try
|
||||||
|
let handle = job_getchannel(job)
|
||||||
|
call ch_sendraw(handle, "echo line one\n")
|
||||||
|
call ch_sendraw(handle, "echoerr line two\n")
|
||||||
|
call ch_sendraw(handle, "double this\n")
|
||||||
|
call ch_sendraw(handle, "doubleerr that\n")
|
||||||
|
call ch_sendraw(handle, "quit\n")
|
||||||
|
sp pipe-err
|
||||||
|
call s:waitFor('line("$") >= 7')
|
||||||
|
call assert_equal(['Reading from channel output...', 'line one', 'line two', 'this', 'AND this', 'that', 'AND that', 'Goodbye!'], getline(1, '$'))
|
||||||
|
bwipe!
|
||||||
|
finally
|
||||||
|
call job_stop(job)
|
||||||
|
endtry
|
||||||
|
endfunc
|
||||||
|
|
||||||
func Test_pipe_from_buffer()
|
func Test_pipe_from_buffer()
|
||||||
if !has('job')
|
if !has('job')
|
||||||
return
|
return
|
||||||
|
@@ -743,6 +743,8 @@ static char *(features[]) =
|
|||||||
|
|
||||||
static int included_patches[] =
|
static int included_patches[] =
|
||||||
{ /* Add new patch number below this line */
|
{ /* Add new patch number below this line */
|
||||||
|
/**/
|
||||||
|
1522,
|
||||||
/**/
|
/**/
|
||||||
1521,
|
1521,
|
||||||
/**/
|
/**/
|
||||||
|
Reference in New Issue
Block a user