Mercurial > vim
comparison src/eval.c @ 8386:3b9a306724ec v7.4.1485
commit https://github.com/vim/vim/commit/014069a7ac51557e531eb3c8b94e36f2193f6c21
Author: Bram Moolenaar <Bram@vim.org>
Date: Thu Mar 3 22:51:40 2016 +0100
patch 7.4.1485
Problem: Job input from buffer is not implemented.
Solution: Implement it. Add "in-top" and "in-bot" options.
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Thu, 03 Mar 2016 23:00:05 +0100 |
parents | 892d7dcf17ec |
children | be45d4921f1f |
comparison
equal
deleted
inserted
replaced
8385:4ee533cc650f | 8386:3b9a306724ec |
---|---|
9660 | 9660 |
9661 buf = find_buffer(&argvars[0]); | 9661 buf = find_buffer(&argvars[0]); |
9662 rettv->vval.v_number = (buf != NULL && buf->b_ml.ml_mfp != NULL); | 9662 rettv->vval.v_number = (buf != NULL && buf->b_ml.ml_mfp != NULL); |
9663 } | 9663 } |
9664 | 9664 |
9665 static buf_T *get_buf_tv(typval_T *tv, int curtab_only); | 9665 static buf_T * |
9666 buflist_find_by_name(char_u *name, int curtab_only) | |
9667 { | |
9668 int save_magic; | |
9669 char_u *save_cpo; | |
9670 buf_T *buf; | |
9671 | |
9672 /* Ignore 'magic' and 'cpoptions' here to make scripts portable */ | |
9673 save_magic = p_magic; | |
9674 p_magic = TRUE; | |
9675 save_cpo = p_cpo; | |
9676 p_cpo = (char_u *)""; | |
9677 | |
9678 buf = buflist_findnr(buflist_findpat(name, name + STRLEN(name), | |
9679 TRUE, FALSE, curtab_only)); | |
9680 | |
9681 p_magic = save_magic; | |
9682 p_cpo = save_cpo; | |
9683 return buf; | |
9684 } | |
9666 | 9685 |
9667 /* | 9686 /* |
9668 * Get buffer by number or pattern. | 9687 * Get buffer by number or pattern. |
9669 */ | 9688 */ |
9670 static buf_T * | 9689 static buf_T * |
9671 get_buf_tv(typval_T *tv, int curtab_only) | 9690 get_buf_tv(typval_T *tv, int curtab_only) |
9672 { | 9691 { |
9673 char_u *name = tv->vval.v_string; | 9692 char_u *name = tv->vval.v_string; |
9674 int save_magic; | |
9675 char_u *save_cpo; | |
9676 buf_T *buf; | 9693 buf_T *buf; |
9677 | 9694 |
9678 if (tv->v_type == VAR_NUMBER) | 9695 if (tv->v_type == VAR_NUMBER) |
9679 return buflist_findnr((int)tv->vval.v_number); | 9696 return buflist_findnr((int)tv->vval.v_number); |
9680 if (tv->v_type != VAR_STRING) | 9697 if (tv->v_type != VAR_STRING) |
9682 if (name == NULL || *name == NUL) | 9699 if (name == NULL || *name == NUL) |
9683 return curbuf; | 9700 return curbuf; |
9684 if (name[0] == '$' && name[1] == NUL) | 9701 if (name[0] == '$' && name[1] == NUL) |
9685 return lastbuf; | 9702 return lastbuf; |
9686 | 9703 |
9687 /* Ignore 'magic' and 'cpoptions' here to make scripts portable */ | 9704 buf = buflist_find_by_name(name, curtab_only); |
9688 save_magic = p_magic; | |
9689 p_magic = TRUE; | |
9690 save_cpo = p_cpo; | |
9691 p_cpo = (char_u *)""; | |
9692 | |
9693 buf = buflist_findnr(buflist_findpat(name, name + STRLEN(name), | |
9694 TRUE, FALSE, curtab_only)); | |
9695 | |
9696 p_magic = save_magic; | |
9697 p_cpo = save_cpo; | |
9698 | 9705 |
9699 /* If not found, try expanding the name, like done for bufexists(). */ | 9706 /* If not found, try expanding the name, like done for bufexists(). */ |
9700 if (buf == NULL) | 9707 if (buf == NULL) |
9701 buf = find_buffer(tv); | 9708 buf = find_buffer(tv); |
9702 | 9709 |
10107 if (!(supported & JO_OUT_IO)) | 10114 if (!(supported & JO_OUT_IO)) |
10108 break; | 10115 break; |
10109 opt->jo_set |= JO_OUT_NAME << (part - PART_OUT); | 10116 opt->jo_set |= JO_OUT_NAME << (part - PART_OUT); |
10110 opt->jo_io_name[part] = | 10117 opt->jo_io_name[part] = |
10111 get_tv_string_buf_chk(item, opt->jo_io_name_buf[part]); | 10118 get_tv_string_buf_chk(item, opt->jo_io_name_buf[part]); |
10119 } | |
10120 else if (STRCMP(hi->hi_key, "in-top") == 0 | |
10121 || STRCMP(hi->hi_key, "in-bot") == 0) | |
10122 { | |
10123 linenr_T *lp; | |
10124 | |
10125 if (!(supported & JO_OUT_IO)) | |
10126 break; | |
10127 if (hi->hi_key[3] == 't') | |
10128 { | |
10129 lp = &opt->jo_in_top; | |
10130 opt->jo_set |= JO_IN_TOP; | |
10131 } | |
10132 else | |
10133 { | |
10134 lp = &opt->jo_in_bot; | |
10135 opt->jo_set |= JO_IN_BOT; | |
10136 } | |
10137 *lp = get_tv_number(item); | |
10138 if (*lp < 0) | |
10139 { | |
10140 EMSG2(_(e_invarg2), get_tv_string(item)); | |
10141 return FAIL; | |
10142 } | |
10112 } | 10143 } |
10113 else if (STRCMP(hi->hi_key, "callback") == 0) | 10144 else if (STRCMP(hi->hi_key, "callback") == 0) |
10114 { | 10145 { |
10115 if (!(supported & JO_CALLBACK)) | 10146 if (!(supported & JO_CALLBACK)) |
10116 break; | 10147 break; |
15101 opt.jo_mode = MODE_NL; | 15132 opt.jo_mode = MODE_NL; |
15102 if (get_job_options(&argvars[1], &opt, | 15133 if (get_job_options(&argvars[1], &opt, |
15103 JO_MODE_ALL + JO_CB_ALL + JO_TIMEOUT_ALL | 15134 JO_MODE_ALL + JO_CB_ALL + JO_TIMEOUT_ALL |
15104 + JO_STOPONEXIT + JO_EXIT_CB + JO_OUT_IO) == FAIL) | 15135 + JO_STOPONEXIT + JO_EXIT_CB + JO_OUT_IO) == FAIL) |
15105 return; | 15136 return; |
15137 | |
15138 if ((opt.jo_set & JO_IN_IO) && opt.jo_io[PART_IN] == JIO_BUFFER) | |
15139 { | |
15140 buf_T *buf; | |
15141 | |
15142 /* check that we can find the buffer before starting the job */ | |
15143 if (!(opt.jo_set & JO_IN_NAME)) | |
15144 { | |
15145 EMSG(_("E915: in-io buffer requires in-name to be set")); | |
15146 return; | |
15147 } | |
15148 buf = buflist_find_by_name(opt.jo_io_name[PART_IN], FALSE); | |
15149 if (buf == NULL) | |
15150 return; | |
15151 if (buf->b_ml.ml_mfp == NULL) | |
15152 { | |
15153 EMSG2(_("E918: buffer must be loaded: %s"), | |
15154 opt.jo_io_name[PART_IN]); | |
15155 return; | |
15156 } | |
15157 job->jv_in_buf = buf; | |
15158 } | |
15159 | |
15106 job_set_options(job, &opt); | 15160 job_set_options(job, &opt); |
15107 | 15161 |
15108 #ifndef USE_ARGV | 15162 #ifndef USE_ARGV |
15109 ga_init2(&ga, (int)sizeof(char*), 20); | 15163 ga_init2(&ga, (int)sizeof(char*), 20); |
15110 #endif | 15164 #endif |
15190 #else | 15244 #else |
15191 # ifdef FEAT_CHANNEL | 15245 # ifdef FEAT_CHANNEL |
15192 ch_logs(NULL, "Starting job: %s", (char *)cmd); | 15246 ch_logs(NULL, "Starting job: %s", (char *)cmd); |
15193 # endif | 15247 # endif |
15194 mch_start_job((char *)cmd, job, &opt); | 15248 mch_start_job((char *)cmd, job, &opt); |
15249 #endif | |
15250 | |
15251 #ifdef FEAT_CHANNEL | |
15252 channel_write_in(job->jv_channel); | |
15195 #endif | 15253 #endif |
15196 | 15254 |
15197 theend: | 15255 theend: |
15198 #ifdef USE_ARGV | 15256 #ifdef USE_ARGV |
15199 vim_free(argv); | 15257 vim_free(argv); |