To: vim_dev@googlegroups.com Subject: Patch 7.4.1529 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 7.4.1529 Problem: Specifying buffer number for channel not implemented yet. Solution: Implement passing a buffer number. Files: src/structs.h, src/channel.c, src/eval.c, src/testdir/test_channel.vim *** ../vim-7.4.1528/src/structs.h 2016-03-08 18:27:16.869343475 +0100 --- src/structs.h 2016-03-09 22:35:30.123823392 +0100 *************** *** 1409,1415 **** #define JO_IN_NAME 0x200000 /* "in-name" (JO_OUT_NAME << 2) */ #define JO_IN_TOP 0x400000 /* "in-top" */ #define JO_IN_BOT 0x800000 /* "in-bot" */ ! #define JO_ALL 0xffffff #define JO_MODE_ALL (JO_MODE + JO_IN_MODE + JO_OUT_MODE + JO_ERR_MODE) #define JO_CB_ALL \ --- 1409,1418 ---- #define JO_IN_NAME 0x200000 /* "in-name" (JO_OUT_NAME << 2) */ #define JO_IN_TOP 0x400000 /* "in-top" */ #define JO_IN_BOT 0x800000 /* "in-bot" */ ! #define JO_OUT_BUF 0x1000000 /* "out-buf" */ ! #define JO_ERR_BUF 0x2000000 /* "err-buf" (JO_OUT_BUF << 1) */ ! #define JO_IN_BUF 0x4000000 /* "in-buf" (JO_OUT_BUF << 2) */ ! #define JO_ALL 0xfffffff #define JO_MODE_ALL (JO_MODE + JO_IN_MODE + JO_OUT_MODE + JO_ERR_MODE) #define JO_CB_ALL \ *************** *** 1439,1444 **** --- 1442,1448 ---- job_io_T jo_io[4]; /* PART_OUT, PART_ERR, PART_IN */ char_u jo_io_name_buf[4][NUMBUFLEN]; char_u *jo_io_name[4]; /* not allocated! */ + int jo_io_buf[4]; linenr_T jo_in_top; linenr_T jo_in_bot; *** ../vim-7.4.1528/src/channel.c 2016-03-09 21:50:01.932868282 +0100 --- src/channel.c 2016-03-09 22:56:24.238494861 +0100 *************** *** 987,993 **** /* writing output to a buffer. Default mode is NL. */ if (!(opt->jo_set & JO_OUT_MODE)) channel->ch_part[PART_OUT].ch_mode = MODE_NL; ! channel->ch_part[PART_OUT].ch_buffer = find_buffer(opt->jo_io_name[PART_OUT], FALSE); ch_logs(channel, "writing out to buffer '%s'", (char *)channel->ch_part[PART_OUT].ch_buffer->b_ffname); --- 987,997 ---- /* writing output to a buffer. Default mode is NL. */ if (!(opt->jo_set & JO_OUT_MODE)) channel->ch_part[PART_OUT].ch_mode = MODE_NL; ! if (opt->jo_set & JO_OUT_BUF) ! channel->ch_part[PART_OUT].ch_buffer = ! buflist_findnr(opt->jo_io_buf[PART_OUT]); ! else ! channel->ch_part[PART_OUT].ch_buffer = find_buffer(opt->jo_io_name[PART_OUT], FALSE); ch_logs(channel, "writing out to buffer '%s'", (char *)channel->ch_part[PART_OUT].ch_buffer->b_ffname); *************** *** 1003,1008 **** --- 1007,1015 ---- if (opt->jo_io[PART_ERR] == JIO_OUT) channel->ch_part[PART_ERR].ch_buffer = channel->ch_part[PART_OUT].ch_buffer; + else if (opt->jo_set & JO_ERR_BUF) + channel->ch_part[PART_ERR].ch_buffer = + buflist_findnr(opt->jo_io_buf[PART_ERR]); else channel->ch_part[PART_ERR].ch_buffer = find_buffer(opt->jo_io_name[PART_ERR], TRUE); *** ../vim-7.4.1528/src/eval.c 2016-03-08 18:27:16.869343475 +0100 --- src/eval.c 2016-03-09 22:56:05.770690992 +0100 *************** *** 10119,10124 **** --- 10119,10145 ---- opt->jo_io_name[part] = get_tv_string_buf_chk(item, opt->jo_io_name_buf[part]); } + else if (STRCMP(hi->hi_key, "in-buf") == 0 + || STRCMP(hi->hi_key, "out-buf") == 0 + || STRCMP(hi->hi_key, "err-buf") == 0) + { + part = part_from_char(*hi->hi_key); + + if (!(supported & JO_OUT_IO)) + break; + opt->jo_set |= JO_OUT_BUF << (part - PART_OUT); + opt->jo_io_buf[part] = get_tv_number(item); + if (opt->jo_io_buf[part] <= 0) + { + EMSG2(_(e_invarg2), get_tv_string(item)); + return FAIL; + } + if (buflist_findnr(opt->jo_io_buf[part]) == NULL) + { + EMSGN(_(e_nobufnr), (long)opt->jo_io_buf[part]); + return FAIL; + } + } else if (STRCMP(hi->hi_key, "in-top") == 0 || STRCMP(hi->hi_key, "in-bot") == 0) { *************** *** 15156,15176 **** if ((opt.jo_set & JO_IN_IO) && opt.jo_io[PART_IN] == JIO_BUFFER) { ! buf_T *buf; /* check that we can find the buffer before starting the job */ ! if (!(opt.jo_set & JO_IN_NAME)) { ! EMSG(_("E915: in-io buffer requires in-name to be set")); ! return; } ! buf = buflist_find_by_name(opt.jo_io_name[PART_IN], FALSE); if (buf == NULL) return; if (buf->b_ml.ml_mfp == NULL) { ! EMSG2(_("E918: buffer must be loaded: %s"), ! opt.jo_io_name[PART_IN]); return; } job->jv_in_buf = buf; --- 15177,15212 ---- if ((opt.jo_set & JO_IN_IO) && opt.jo_io[PART_IN] == JIO_BUFFER) { ! buf_T *buf = NULL; /* check that we can find the buffer before starting the job */ ! if (opt.jo_set & JO_IN_BUF) { ! buf = buflist_findnr(opt.jo_io_buf[PART_IN]); ! if (buf == NULL) ! EMSGN(_(e_nobufnr), (long)opt.jo_io_buf[PART_IN]); ! } ! else if (!(opt.jo_set & JO_IN_NAME)) ! { ! EMSG(_("E915: in-io buffer requires in-buf or in-name to be set")); } ! else ! buf = buflist_find_by_name(opt.jo_io_name[PART_IN], FALSE); if (buf == NULL) return; if (buf->b_ml.ml_mfp == NULL) { ! char_u buf[NUMBUFLEN]; ! char_u *s; ! ! if (opt.jo_set & JO_IN_BUF) ! { ! sprintf((char *)buf, "%d", opt.jo_io_buf[PART_IN]); ! s = buf; ! } ! else ! s = opt.jo_io_name[PART_IN]; ! EMSG2(_("E918: buffer must be loaded: %s"), s); return; } job->jv_in_buf = buf; *** ../vim-7.4.1528/src/testdir/test_channel.vim 2016-03-09 20:54:48.196138852 +0100 --- src/testdir/test_channel.vim 2016-03-09 23:11:34.228833527 +0100 *************** *** 610,622 **** endtry endfunc ! func Test_pipe_to_buffer() if !has('job') return endif call ch_log('Test_pipe_to_buffer()') ! let job = job_start(s:python . " test_channel_pipe.py", ! \ {'out-io': 'buffer', 'out-name': 'pipe-output'}) call assert_equal("run", job_status(job)) try let handle = job_getchannel(job) --- 610,631 ---- endtry endfunc ! func Run_test_pipe_to_buffer(use_name) if !has('job') return endif call ch_log('Test_pipe_to_buffer()') ! let options = {'out-io': 'buffer'} ! if a:use_name ! let options['out-name'] = 'pipe-output' ! let firstline = 'Reading from channel output...' ! else ! sp pipe-output ! let options['out-buf'] = bufnr('%') ! quit ! let firstline = '' ! endif ! let job = job_start(s:python . " test_channel_pipe.py", options) call assert_equal("run", job_status(job)) try let handle = job_getchannel(job) *************** *** 626,645 **** call ch_sendraw(handle, "quit\n") sp pipe-output call s:waitFor('line("$") >= 6') ! call assert_equal(['Reading from channel output...', 'line one', 'line two', 'this', 'AND this', 'Goodbye!'], getline(1, '$')) bwipe! finally call job_stop(job) endtry 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) --- 635,671 ---- call ch_sendraw(handle, "quit\n") sp pipe-output call s:waitFor('line("$") >= 6') ! call assert_equal([firstline, 'line one', 'line two', 'this', 'AND this', 'Goodbye!'], getline(1, '$')) bwipe! finally call job_stop(job) endtry endfunc ! func Test_pipe_to_buffer_name() ! call Run_test_pipe_to_buffer(1) ! endfunc ! ! func Test_pipe_to_buffer_nr() ! call Run_test_pipe_to_buffer(0) ! endfunc ! ! func Run_test_pipe_err_to_buffer(use_name) if !has('job') return endif call ch_log('Test_pipe_err_to_buffer()') ! let options = {'err-io': 'buffer'} ! if a:use_name ! let options['err-name'] = 'pipe-err' ! let firstline = 'Reading from channel error...' ! else ! sp pipe-err ! let options['err-buf'] = bufnr('%') ! quit ! let firstline = '' ! endif ! let job = job_start(s:python . " test_channel_pipe.py", options) call assert_equal("run", job_status(job)) try let handle = job_getchannel(job) *************** *** 649,661 **** 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 --- 675,695 ---- call ch_sendraw(handle, "quit\n") sp pipe-err call s:waitFor('line("$") >= 5') ! call assert_equal([firstline, 'line one', 'line two', 'this', 'AND this'], getline(1, '$')) bwipe! finally call job_stop(job) endtry endfunc + func Test_pipe_err_to_buffer_name() + call Run_test_pipe_err_to_buffer(1) + endfunc + + func Test_pipe_err_to_buffer_nr() + call Run_test_pipe_err_to_buffer(0) + endfunc + func Test_pipe_both_to_buffer() if !has('job') return *************** *** 680,686 **** endtry endfunc ! func Test_pipe_from_buffer() if !has('job') return endif --- 714,720 ---- endtry endfunc ! func Run_test_pipe_from_buffer(use_name) if !has('job') return endif *************** *** 688,696 **** sp pipe-input call setline(1, ['echo one', 'echo two', 'echo three']) ! let job = job_start(s:python . " test_channel_pipe.py", ! \ {'in-io': 'buffer', 'in-name': 'pipe-input'}) call assert_equal("run", job_status(job)) try let handle = job_getchannel(job) --- 722,735 ---- sp pipe-input call setline(1, ['echo one', 'echo two', 'echo three']) + let options = {'in-io': 'buffer'} + if a:use_name + let options['in-name'] = 'pipe-input' + else + let options['in-buf'] = bufnr('%') + endif ! let job = job_start(s:python . " test_channel_pipe.py", options) call assert_equal("run", job_status(job)) try let handle = job_getchannel(job) *************** *** 703,708 **** --- 742,755 ---- endtry endfunc + func Test_pipe_from_buffer_name() + call Run_test_pipe_from_buffer(1) + endfunc + + func Test_pipe_from_buffer_nr() + call Run_test_pipe_from_buffer(0) + endfunc + func Test_pipe_to_nameless_buffer() if !has('job') return *** ../vim-7.4.1528/src/version.c 2016-03-09 22:18:52.166442971 +0100 --- src/version.c 2016-03-09 22:37:14.222715768 +0100 *************** *** 745,746 **** --- 745,748 ---- { /* Add new patch number below this line */ + /**/ + 1529, /**/ -- hundred-and-one symptoms of being an internet addict: 26. You check your mail. It says "no new messages." So you check it again. /// 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 ///