@@ -244,7 +244,7 @@ setup_job_options(jobopt_T *opt, int rows, int cols)
244244}
245245
246246 static void
247- term_start (char_u * cmd , jobopt_T * opt )
247+ term_start (char_u * cmd , jobopt_T * opt , int forceit )
248248{
249249 exarg_T split_ea ;
250250 win_T * old_curwin = curwin ;
@@ -261,28 +261,43 @@ term_start(char_u *cmd, jobopt_T *opt)
261261 term -> tl_finish = opt -> jo_term_finish ;
262262 ga_init2 (& term -> tl_scrollback , sizeof (sb_line_T ), 300 );
263263
264- /* Open a new window or tab. */
265264 vim_memset (& split_ea , 0 , sizeof (split_ea ));
266- split_ea .cmdidx = CMD_new ;
267- split_ea .cmd = (char_u * )"new" ;
268- split_ea .arg = (char_u * )"" ;
269- if (opt -> jo_term_rows > 0 && !(cmdmod .split & WSP_VERT ))
265+ if (opt -> jo_curwin )
270266 {
271- split_ea .line2 = opt -> jo_term_rows ;
272- split_ea .addr_count = 1 ;
267+ /* Create a new buffer in the current window. */
268+ if (!can_abandon (curbuf , forceit ))
269+ {
270+ EMSG (_ (e_nowrtmsg ));
271+ return ;
272+ }
273+ if (do_ecmd (0 , NULL , NULL , & split_ea , ECMD_ONE ,
274+ ECMD_HIDE + (forceit ? ECMD_FORCEIT : 0 ), curwin ) == FAIL )
275+ return ;
273276 }
274- if ( opt -> jo_term_cols > 0 && ( cmdmod . split & WSP_VERT ))
277+ else
275278 {
276- split_ea .line2 = opt -> jo_term_cols ;
277- split_ea .addr_count = 1 ;
278- }
279+ /* Open a new window or tab. */
280+ split_ea .cmdidx = CMD_new ;
281+ split_ea .cmd = (char_u * )"new" ;
282+ split_ea .arg = (char_u * )"" ;
283+ if (opt -> jo_term_rows > 0 && !(cmdmod .split & WSP_VERT ))
284+ {
285+ split_ea .line2 = opt -> jo_term_rows ;
286+ split_ea .addr_count = 1 ;
287+ }
288+ if (opt -> jo_term_cols > 0 && (cmdmod .split & WSP_VERT ))
289+ {
290+ split_ea .line2 = opt -> jo_term_cols ;
291+ split_ea .addr_count = 1 ;
292+ }
279293
280- ex_splitview (& split_ea );
281- if (curwin == old_curwin )
282- {
283- /* split failed */
284- vim_free (term );
285- return ;
294+ ex_splitview (& split_ea );
295+ if (curwin == old_curwin )
296+ {
297+ /* split failed */
298+ vim_free (term );
299+ return ;
300+ }
286301 }
287302 term -> tl_buffer = curbuf ;
288303 curbuf -> b_term = term ;
@@ -378,6 +393,8 @@ ex_terminal(exarg_T *eap)
378393 opt .jo_term_finish = 'c' ;
379394 else if ((int )(p - cmd ) == 4 && STRNICMP (cmd , "open" , 4 ) == 0 )
380395 opt .jo_term_finish = 'o' ;
396+ else if ((int )(p - cmd ) == 6 && STRNICMP (cmd , "curwin" , 6 ) == 0 )
397+ opt .jo_curwin = 1 ;
381398 else
382399 {
383400 if (* p )
@@ -400,9 +417,8 @@ ex_terminal(exarg_T *eap)
400417 else
401418 opt .jo_term_rows = eap -> line2 ;
402419 }
403- /* TODO: get more options from before the command */
404420
405- term_start (cmd , & opt );
421+ term_start (cmd , & opt , eap -> forceit );
406422}
407423
408424/*
@@ -2365,13 +2381,13 @@ f_term_start(typval_T *argvars, typval_T *rettv)
23652381 JO_TIMEOUT_ALL + JO_STOPONEXIT
23662382 + JO_EXIT_CB + JO_CLOSE_CALLBACK ,
23672383 JO2_TERM_NAME + JO2_TERM_FINISH
2368- + JO2_TERM_COLS + JO2_TERM_ROWS + JO2_VERTICAL
2384+ + JO2_TERM_COLS + JO2_TERM_ROWS + JO2_VERTICAL + JO2_CURWIN
23692385 + JO2_CWD + JO2_ENV ) == FAIL )
23702386 return ;
23712387
23722388 if (opt .jo_vertical )
23732389 cmdmod .split = WSP_VERT ;
2374- term_start (cmd , & opt );
2390+ term_start (cmd , & opt , FALSE );
23752391
23762392 if (curbuf -> b_term != NULL )
23772393 rettv -> vval .v_number = curbuf -> b_fnum ;
0 commit comments