To: vim_dev@googlegroups.com Subject: Patch 8.0.0910 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 8.0.0910 Problem: Cannot create a terminal in the current window. Solution: Add option "curwin" and ++curwin. Files: src/terminal.c, runtime/doc/eval.txt, src/channel.c, src/structs.h, src/ex_cmds.h, src/testdir/test_terminal.vim *** ../vim-8.0.0909/src/terminal.c 2017-08-11 21:51:18.804637212 +0200 --- src/terminal.c 2017-08-11 22:14:57.926538594 +0200 *************** *** 244,250 **** } static void ! term_start(char_u *cmd, jobopt_T *opt) { exarg_T split_ea; win_T *old_curwin = curwin; --- 244,250 ---- } static void ! term_start(char_u *cmd, jobopt_T *opt, int forceit) { exarg_T split_ea; win_T *old_curwin = curwin; *************** *** 261,288 **** term->tl_finish = opt->jo_term_finish; ga_init2(&term->tl_scrollback, sizeof(sb_line_T), 300); - /* Open a new window or tab. */ vim_memset(&split_ea, 0, sizeof(split_ea)); ! split_ea.cmdidx = CMD_new; ! split_ea.cmd = (char_u *)"new"; ! split_ea.arg = (char_u *)""; ! if (opt->jo_term_rows > 0 && !(cmdmod.split & WSP_VERT)) { ! split_ea.line2 = opt->jo_term_rows; ! split_ea.addr_count = 1; } ! if (opt->jo_term_cols > 0 && (cmdmod.split & WSP_VERT)) { ! split_ea.line2 = opt->jo_term_cols; ! split_ea.addr_count = 1; ! } ! ex_splitview(&split_ea); ! if (curwin == old_curwin) ! { ! /* split failed */ ! vim_free(term); ! return; } term->tl_buffer = curbuf; curbuf->b_term = term; --- 261,303 ---- term->tl_finish = opt->jo_term_finish; ga_init2(&term->tl_scrollback, sizeof(sb_line_T), 300); vim_memset(&split_ea, 0, sizeof(split_ea)); ! if (opt->jo_curwin) { ! /* Create a new buffer in the current window. */ ! if (!can_abandon(curbuf, forceit)) ! { ! EMSG(_(e_nowrtmsg)); ! return; ! } ! if (do_ecmd(0, NULL, NULL, &split_ea, ECMD_ONE, ! ECMD_HIDE + (forceit ? ECMD_FORCEIT : 0), curwin) == FAIL) ! return; } ! else { ! /* Open a new window or tab. */ ! split_ea.cmdidx = CMD_new; ! split_ea.cmd = (char_u *)"new"; ! split_ea.arg = (char_u *)""; ! if (opt->jo_term_rows > 0 && !(cmdmod.split & WSP_VERT)) ! { ! split_ea.line2 = opt->jo_term_rows; ! split_ea.addr_count = 1; ! } ! if (opt->jo_term_cols > 0 && (cmdmod.split & WSP_VERT)) ! { ! split_ea.line2 = opt->jo_term_cols; ! split_ea.addr_count = 1; ! } ! ex_splitview(&split_ea); ! if (curwin == old_curwin) ! { ! /* split failed */ ! vim_free(term); ! return; ! } } term->tl_buffer = curbuf; curbuf->b_term = term; *************** *** 378,383 **** --- 393,400 ---- opt.jo_term_finish = 'c'; else if ((int)(p - cmd) == 4 && STRNICMP(cmd, "open", 4) == 0) opt.jo_term_finish = 'o'; + else if ((int)(p - cmd) == 6 && STRNICMP(cmd, "curwin", 6) == 0) + opt.jo_curwin = 1; else { if (*p) *************** *** 400,408 **** else opt.jo_term_rows = eap->line2; } - /* TODO: get more options from before the command */ ! term_start(cmd, &opt); } /* --- 417,424 ---- else opt.jo_term_rows = eap->line2; } ! term_start(cmd, &opt, eap->forceit); } /* *************** *** 2365,2377 **** JO_TIMEOUT_ALL + JO_STOPONEXIT + JO_EXIT_CB + JO_CLOSE_CALLBACK, JO2_TERM_NAME + JO2_TERM_FINISH ! + JO2_TERM_COLS + JO2_TERM_ROWS + JO2_VERTICAL + JO2_CWD + JO2_ENV) == FAIL) return; if (opt.jo_vertical) cmdmod.split = WSP_VERT; ! term_start(cmd, &opt); if (curbuf->b_term != NULL) rettv->vval.v_number = curbuf->b_fnum; --- 2381,2393 ---- JO_TIMEOUT_ALL + JO_STOPONEXIT + JO_EXIT_CB + JO_CLOSE_CALLBACK, JO2_TERM_NAME + JO2_TERM_FINISH ! + JO2_TERM_COLS + JO2_TERM_ROWS + JO2_VERTICAL + JO2_CURWIN + JO2_CWD + JO2_ENV) == FAIL) return; if (opt.jo_vertical) cmdmod.split = WSP_VERT; ! term_start(cmd, &opt, FALSE); if (curbuf->b_term != NULL) rettv->vval.v_number = curbuf->b_fnum; *** ../vim-8.0.0909/runtime/doc/eval.txt 2017-08-11 21:51:18.808637183 +0200 --- runtime/doc/eval.txt 2017-08-11 21:55:05.543014554 +0200 *************** *** 8077,8082 **** --- 8077,8085 ---- "term_cols" horizontal size to use for the terminal, instead of using 'termsize' "vertical" split the window vertically + "curwin" use the current window, do not split the + window; fails if the current buffer + cannot be |abandon|ed "term_finish" What to do when the job is finished: "close": close any windows "open": open window if needed *** ../vim-8.0.0909/src/channel.c 2017-08-11 22:22:30.735343146 +0200 --- src/channel.c 2017-08-11 22:21:18.947849890 +0200 *************** *** 4455,4460 **** --- 4455,4467 ---- opt->jo_set |= JO2_VERTICAL; opt->jo_vertical = get_tv_number(item); } + else if (STRCMP(hi->hi_key, "curwin") == 0) + { + if (!(supported2 & JO2_CURWIN)) + break; + opt->jo_set |= JO2_CURWIN; + opt->jo_curwin = get_tv_number(item); + } #endif else if (STRCMP(hi->hi_key, "env") == 0) { *** ../vim-8.0.0909/src/structs.h 2017-08-11 21:51:18.808637183 +0200 --- src/structs.h 2017-08-11 21:53:34.547665682 +0200 *************** *** 1691,1697 **** #define JO2_TERM_ROWS 0x0040 /* "term_rows" */ #define JO2_TERM_COLS 0x0080 /* "term_cols" */ #define JO2_VERTICAL 0x0100 /* "vertical" */ ! #define JO2_ALL 0x01FF #define JO_MODE_ALL (JO_MODE + JO_IN_MODE + JO_OUT_MODE + JO_ERR_MODE) #define JO_CB_ALL \ --- 1691,1698 ---- #define JO2_TERM_ROWS 0x0040 /* "term_rows" */ #define JO2_TERM_COLS 0x0080 /* "term_cols" */ #define JO2_VERTICAL 0x0100 /* "vertical" */ ! #define JO2_CURWIN 0x0200 /* "curwin" */ ! #define JO2_ALL 0x03FF #define JO_MODE_ALL (JO_MODE + JO_IN_MODE + JO_OUT_MODE + JO_ERR_MODE) #define JO_CB_ALL \ *************** *** 1752,1757 **** --- 1753,1759 ---- int jo_term_rows; int jo_term_cols; int jo_vertical; + int jo_curwin; char_u *jo_term_name; int jo_term_finish; #endif *** ../vim-8.0.0909/src/ex_cmds.h 2017-07-27 22:56:56.247891011 +0200 --- src/ex_cmds.h 2017-08-11 22:10:24.712465549 +0200 *************** *** 1484,1490 **** NEEDARG|EXTRA|TRLBAR|NOTRLCOM|CMDWIN, ADDR_LINES), EX(CMD_terminal, "terminal", ex_terminal, ! RANGE|NOTADR|FILES|TRLBAR|CMDWIN, ADDR_OTHER), EX(CMD_tfirst, "tfirst", ex_tag, RANGE|NOTADR|BANG|TRLBAR|ZEROR, --- 1484,1490 ---- NEEDARG|EXTRA|TRLBAR|NOTRLCOM|CMDWIN, ADDR_LINES), EX(CMD_terminal, "terminal", ex_terminal, ! RANGE|NOTADR|BANG|FILES|TRLBAR|CMDWIN, ADDR_OTHER), EX(CMD_tfirst, "tfirst", ex_tag, RANGE|NOTADR|BANG|TRLBAR|ZEROR, *** ../vim-8.0.0909/src/testdir/test_terminal.vim 2017-08-11 21:51:18.812637155 +0200 --- src/testdir/test_terminal.vim 2017-08-11 22:18:47.744917052 +0200 *************** *** 283,288 **** --- 283,320 ---- let size = term_getsize('') bwipe! call assert_equal([7, 27], size) + endfunc + + func Test_terminal_curwin() + let cmd = Get_cat_123_cmd() + call assert_equal(1, winnr('$')) + + split dummy + exe 'terminal ++curwin ' . cmd + call assert_equal(2, winnr('$')) + bwipe! + + split dummy + call term_start(cmd, {'curwin': 1}) + call assert_equal(2, winnr('$')) + bwipe! + + split dummy + call setline(1, 'change') + call assert_fails('terminal ++curwin ' . cmd, 'E37:') + call assert_equal(2, winnr('$')) + exe 'terminal! ++curwin ' . cmd + call assert_equal(2, winnr('$')) + bwipe! + + split dummy + call setline(1, 'change') + call assert_fails("call term_start(cmd, {'curwin': 1})", 'E37:') + call assert_equal(2, winnr('$')) + bwipe! + + split dummy + bwipe! endfunc *** ../vim-8.0.0909/src/version.c 2017-08-11 22:22:30.739343117 +0200 --- src/version.c 2017-08-11 22:23:11.375056248 +0200 *************** *** 771,772 **** --- 771,774 ---- { /* Add new patch number below this line */ + /**/ + 910, /**/ -- Close your shells, or I'll kill -9 you Tomorrow I'll quota you Remember the disks'll always be full And then while I'm away I'll write ~ everyday And I'll send-pr all my buggings to you. [ CVS log "Beatles style" for FreeBSD ports/INDEX, Satoshi Asami ] /// 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 ///