Skip to content

Commit 5a3a49e

Browse files
committed
patch 8.0.1624: options for term_dumpdiff() and term_dumpload() not implemented
Problem: Options for term_dumpdiff() and term_dumpload() not implemented yet. Solution: Implement the relevant options.
1 parent 3e8d385 commit 5a3a49e

3 files changed

Lines changed: 44 additions & 15 deletions

File tree

runtime/doc/eval.txt

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
*eval.txt* For Vim version 8.0. Last change: 2018 Mar 18
1+
*eval.txt* For Vim version 8.0. Last change: 2018 Mar 20
22

33

44
VIM REFERENCE MANUAL by Bram Moolenaar
@@ -8190,7 +8190,20 @@ term_dumpdiff({filename}, {filename} [, {options}])
81908190
the second file. The middle part shows the differences.
81918191
The parts are separated by a line of dashes.
81928192

8193-
{options} are not implemented yet.
8193+
If the {options} argument is present, it must be a Dict with
8194+
these possible members:
8195+
"term_name" name to use for the buffer name, instead
8196+
of the first file name.
8197+
"term_rows" vertical size to use for the terminal,
8198+
instead of using 'termsize'
8199+
"term_cols" horizontal size to use for the terminal,
8200+
instead of using 'termsize'
8201+
"vertical" split the window vertically
8202+
"curwin" use the current window, do not split the
8203+
window; fails if the current buffer
8204+
cannot be |abandon|ed
8205+
"norestore" do not add the terminal window to a
8206+
session file
81948207

81958208
Each character in the middle part indicates a difference. If
81968209
there are multiple differences only the first in this list is
@@ -8213,7 +8226,7 @@ term_dumpload({filename} [, {options}])
82138226
Returns the buffer number or zero when it fails.
82148227
Also see |terminal-diff|.
82158228

8216-
{options} are not implemented yet.
8229+
For {options} see |term_dumpdiff()|.
82178230

82188231
*term_dumpwrite()*
82198232
term_dumpwrite({buf}, {filename} [, {options}])
@@ -9237,7 +9250,7 @@ visualextra Compiled with extra Visual mode commands.
92379250
vms VMS version of Vim.
92389251
vreplace Compiled with |gR| and |gr| commands.
92399252
vtp Compiled for vcon support |+vtp| (check vcon to find
9240-
out if it works in the current console)).
9253+
out if it works in the current console).
92419254
wildignore Compiled with 'wildignore' option.
92429255
wildmenu Compiled with 'wildmenu' option.
92439256
win32 Win32 version of Vim (MS-Windows 95 and later, 32 or

src/terminal.c

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,7 @@ term_start(
342342
buf_T *old_curbuf = NULL;
343343
int res;
344344
buf_T *newbuf;
345+
int vertical = opt->jo_vertical || (cmdmod.split & WSP_VERT);
345346

346347
if (check_restricted() || check_secure())
347348
return NULL;
@@ -411,17 +412,19 @@ term_start(
411412
split_ea.cmdidx = CMD_new;
412413
split_ea.cmd = (char_u *)"new";
413414
split_ea.arg = (char_u *)"";
414-
if (opt->jo_term_rows > 0 && !(cmdmod.split & WSP_VERT))
415+
if (opt->jo_term_rows > 0 && !vertical)
415416
{
416417
split_ea.line2 = opt->jo_term_rows;
417418
split_ea.addr_count = 1;
418419
}
419-
if (opt->jo_term_cols > 0 && (cmdmod.split & WSP_VERT))
420+
if (opt->jo_term_cols > 0 && vertical)
420421
{
421422
split_ea.line2 = opt->jo_term_cols;
422423
split_ea.addr_count = 1;
423424
}
424425

426+
if (vertical)
427+
cmdmod.split |= WSP_VERT;
425428
ex_splitview(&split_ea);
426429
if (curwin == old_curwin)
427430
{
@@ -437,11 +440,9 @@ term_start(
437440
{
438441
/* Only one size was taken care of with :new, do the other one. With
439442
* "curwin" both need to be done. */
440-
if (opt->jo_term_rows > 0 && (opt->jo_curwin
441-
|| (cmdmod.split & WSP_VERT)))
443+
if (opt->jo_term_rows > 0 && (opt->jo_curwin || vertical))
442444
win_setheight(opt->jo_term_rows);
443-
if (opt->jo_term_cols > 0 && (opt->jo_curwin
444-
|| !(cmdmod.split & WSP_VERT)))
445+
if (opt->jo_term_cols > 0 && (opt->jo_curwin || !vertical))
445446
win_setwidth(opt->jo_term_cols);
446447
}
447448

@@ -3732,6 +3733,7 @@ term_load_dump(typval_T *argvars, typval_T *rettv, int do_diff)
37323733
char_u buf2[NUMBUFLEN];
37333734
char_u *fname1;
37343735
char_u *fname2 = NULL;
3736+
char_u *fname_tofree = NULL;
37353737
FILE *fd1;
37363738
FILE *fd2 = NULL;
37373739
char_u *textline = NULL;
@@ -3763,10 +3765,23 @@ term_load_dump(typval_T *argvars, typval_T *rettv, int do_diff)
37633765
}
37643766

37653767
init_job_options(&opt);
3766-
/* TODO: use the {options} argument */
3768+
if (argvars[do_diff ? 2 : 1].v_type != VAR_UNKNOWN
3769+
&& get_job_options(&argvars[do_diff ? 2 : 1], &opt, 0,
3770+
JO2_TERM_NAME + JO2_TERM_COLS + JO2_TERM_ROWS
3771+
+ JO2_VERTICAL + JO2_CURWIN + JO2_NORESTORE) == FAIL)
3772+
goto theend;
37673773

3768-
/* TODO: use the file name arguments for the buffer name */
3769-
opt.jo_term_name = (char_u *)"dump diff";
3774+
if (opt.jo_term_name == NULL)
3775+
{
3776+
int len = STRLEN(fname1) + 12;
3777+
3778+
fname_tofree = alloc(len);
3779+
if (fname_tofree != NULL)
3780+
{
3781+
vim_snprintf((char *)fname_tofree, len, "dump diff %s", fname1);
3782+
opt.jo_term_name = fname_tofree;
3783+
}
3784+
}
37703785

37713786
buf = term_start(&argvars[0], NULL, &opt, TERM_START_NOJOB);
37723787
if (buf != NULL && buf->b_term != NULL)
@@ -3937,6 +3952,7 @@ term_load_dump(typval_T *argvars, typval_T *rettv, int do_diff)
39373952

39383953
theend:
39393954
vim_free(textline);
3955+
vim_free(fname_tofree);
39403956
fclose(fd1);
39413957
if (fd2 != NULL)
39423958
fclose(fd2);
@@ -4541,8 +4557,6 @@ f_term_start(typval_T *argvars, typval_T *rettv)
45414557
+ JO2_NORESTORE + JO2_TERM_KILL) == FAIL)
45424558
return;
45434559

4544-
if (opt.jo_vertical)
4545-
cmdmod.split = WSP_VERT;
45464560
buf = term_start(&argvars[0], NULL, &opt, 0);
45474561

45484562
if (buf != NULL && buf->b_term != NULL)

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -766,6 +766,8 @@ static char *(features[]) =
766766

767767
static int included_patches[] =
768768
{ /* Add new patch number below this line */
769+
/**/
770+
1624,
769771
/**/
770772
1623,
771773
/**/

0 commit comments

Comments
 (0)