Skip to content

Commit 7151602

Browse files
committed
Merge remote-tracking branch 'vim/master'
2 parents c2d7e78 + e561a7e commit 7151602

9 files changed

Lines changed: 185 additions & 50 deletions

File tree

runtime/doc/terminal.txt

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
*terminal.txt* For Vim version 8.0. Last change: 2017 Aug 26
1+
*terminal.txt* For Vim version 8.0. Last change: 2017 Aug 29
22

33

44
VIM REFERENCE MANUAL by Bram Moolenaar
@@ -140,11 +140,17 @@ Syntax ~
140140
When the buffer associated with the terminal is unloaded or wiped out the job
141141
is killed, similar to calling `job_stop(job, "kill")`
142142

143-
By default the 'bufhidden' option of the buffer will be set to "hide".
144-
So long as the job is running: If the window is closed the buffer becomes
145-
hidden. The command will not be stopped. The `:buffer` command can be used
146-
to turn the current window into a terminal window. If there are unsaved
147-
changes this fails, use ! to force, as usual.
143+
So long as the job is running the window behaves like it contains a modified
144+
buffer. Trying to close the window with `CTRL-W :close` or `CTRL-W :hide`
145+
fails, unless "!" is added, in which case the job is ended. The text in the
146+
window is lost. The buffer still exists, but getting it in a window with
147+
`:buffer` will show an
148+
empty buffer.
149+
150+
You can use `CTRL-W :hide` to close the terminal window and make the buffer
151+
hidden, the job keeps running. The `:buffer` command can be used to turn the
152+
current window into a terminal window. If there are unsaved changes this
153+
fails, use ! to force, as usual.
148154

149155
To have a background job run without a window, and open the window when it's
150156
done, use options like this: >

src/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2295,6 +2295,7 @@ test_arglist \
22952295
test_visual \
22962296
test_window_cmd \
22972297
test_window_id \
2298+
test_windows_home \
22982299
test_writefile \
22992300
test_alot_latin \
23002301
test_alot_utf8 \

src/buffer.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5835,8 +5835,8 @@ buf_spname(buf_T *buf)
58355835
if (buf->b_term != NULL)
58365836
return term_get_status_text(buf->b_term);
58375837
#endif
5838-
if (buf->b_sfname != NULL)
5839-
return buf->b_sfname;
5838+
if (buf->b_fname != NULL)
5839+
return buf->b_fname;
58405840
return (char_u *)_("[Scratch]");
58415841
}
58425842

src/misc1.c

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -3756,10 +3756,33 @@ init_homedir(void)
37563756
var = mch_getenv((char_u *)"HOME");
37573757
#endif
37583758

3759-
if (var != NULL && *var == NUL) /* empty is same as not set */
3760-
var = NULL;
3761-
37623759
#ifdef WIN3264
3760+
/*
3761+
* Typically, $HOME is not defined on Windows, unless the user has
3762+
* specifically defined it for Vim's sake. However, on Windows NT
3763+
* platforms, $HOMEDRIVE and $HOMEPATH are automatically defined for
3764+
* each user. Try constructing $HOME from these.
3765+
*/
3766+
if (var == NULL || *var == NULL)
3767+
{
3768+
char_u *homedrive, *homepath;
3769+
3770+
homedrive = mch_getenv((char_u *)"HOMEDRIVE");
3771+
homepath = mch_getenv((char_u *)"HOMEPATH");
3772+
if (homepath == NULL || *homepath == NUL)
3773+
homepath = (char_u *)"\\";
3774+
if (homedrive != NULL
3775+
&& STRLEN(homedrive) + STRLEN(homepath) < MAXPATHL)
3776+
{
3777+
sprintf((char *)NameBuff, "%s%s", homedrive, homepath);
3778+
if (NameBuff[0] != NUL)
3779+
var = NameBuff;
3780+
}
3781+
}
3782+
3783+
if (var == NULL)
3784+
var = mch_getenv((char_u *)"USERPROFILE");
3785+
37633786
/*
37643787
* Weird but true: $HOME may contain an indirect reference to another
37653788
* variable, esp. "%USERPROFILE%". Happens when $USERPROFILE isn't set
@@ -3780,40 +3803,14 @@ init_homedir(void)
37803803
{
37813804
vim_snprintf((char *)NameBuff, MAXPATHL, "%s%s", exp, p + 1);
37823805
var = NameBuff;
3783-
/* Also set $HOME, it's needed for _viminfo. */
3784-
vim_setenv((char_u *)"HOME", NameBuff);
37853806
}
37863807
}
37873808
}
37883809

3789-
/*
3790-
* Typically, $HOME is not defined on Windows, unless the user has
3791-
* specifically defined it for Vim's sake. However, on Windows NT
3792-
* platforms, $HOMEDRIVE and $HOMEPATH are automatically defined for
3793-
* each user. Try constructing $HOME from these.
3794-
*/
3795-
if (var == NULL)
3796-
{
3797-
char_u *homedrive, *homepath;
3798-
3799-
homedrive = mch_getenv((char_u *)"HOMEDRIVE");
3800-
homepath = mch_getenv((char_u *)"HOMEPATH");
3801-
if (homepath == NULL || *homepath == NUL)
3802-
homepath = (char_u *)"\\";
3803-
if (homedrive != NULL
3804-
&& STRLEN(homedrive) + STRLEN(homepath) < MAXPATHL)
3805-
{
3806-
sprintf((char *)NameBuff, "%s%s", homedrive, homepath);
3807-
if (NameBuff[0] != NUL)
3808-
{
3809-
var = NameBuff;
3810-
/* Also set $HOME, it's needed for _viminfo. */
3811-
vim_setenv((char_u *)"HOME", NameBuff);
3812-
}
3813-
}
3814-
}
3810+
if (var != NULL && *var == NUL) /* empty is same as not set */
3811+
var = NULL;
38153812

3816-
# if defined(FEAT_MBYTE)
3813+
# ifdef FEAT_MBYTE
38173814
if (enc_utf8 && var != NULL)
38183815
{
38193816
int len;
@@ -3829,16 +3826,15 @@ init_homedir(void)
38293826
}
38303827
}
38313828
# endif
3832-
#endif
38333829

3834-
#if defined(MSWIN)
38353830
/*
38363831
* Default home dir is C:/
38373832
* Best assumption we can make in such a situation.
38383833
*/
38393834
if (var == NULL)
38403835
var = (char_u *)"C:/";
38413836
#endif
3837+
38423838
if (var != NULL)
38433839
{
38443840
#ifdef UNIX
@@ -4667,6 +4663,10 @@ home_replace(
46674663
homedir_env_orig = homedir_env = mch_getenv((char_u *)"SYS$LOGIN");
46684664
#else
46694665
homedir_env_orig = homedir_env = mch_getenv((char_u *)"HOME");
4666+
#endif
4667+
#ifdef WIN3264
4668+
if (homedir_env == NULL)
4669+
homedir_env_orig = homedir_env = mch_getenv((char_u *)"USERPROFILE");
46704670
#endif
46714671
/* Empty is the same as not set. */
46724672
if (homedir_env != NULL && *homedir_env == NUL)

src/terminal.c

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,7 @@
4444
* - add test for giving error for invalid 'termsize' value.
4545
* - support minimal size when 'termsize' is "rows*cols".
4646
* - support minimal size when 'termsize' is empty?
47-
* - do not set bufhidden to "hide"? works like a buffer with changes.
48-
* document that CTRL-W :hide can be used.
4947
* - GUI: when using tabs, focus in terminal, click on tab does not work.
50-
* - When $HOME was set by Vim (MS-Windows), do not pass it to the job.
5148
* - GUI: when 'confirm' is set and trying to exit Vim, dialog offers to save
5249
* changes to "!shell".
5350
* (justrajdeep, 2017 Aug 22)
@@ -399,10 +396,6 @@ term_start(typval_T *argvar, jobopt_T *opt, int forceit)
399396
* the job finished. */
400397
curbuf->b_p_ma = FALSE;
401398

402-
/* Set 'bufhidden' to "hide": allow closing the window. */
403-
set_string_option_direct((char_u *)"bufhidden", -1,
404-
(char_u *)"hide", OPT_FREE|OPT_LOCAL, 0);
405-
406399
set_term_and_win_size(term);
407400
setup_job_options(opt, term->tl_rows, term->tl_cols);
408401

src/testdir/Make_all.mak

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,8 @@ NEW_TESTS = test_arabic.res \
205205
test_writefile.res \
206206
test_alot_latin.res \
207207
test_alot_utf8.res \
208-
test_alot.res
208+
test_alot.res \
209+
test_windows_home.res
209210

210211

211212
# Explicit dependencies.

src/testdir/test_terminal.vim

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -429,6 +429,10 @@ func Test_zz_terminal_in_gui()
429429
if !CanRunGui()
430430
return
431431
endif
432+
433+
" Ignore the "failed to create input context" error.
434+
call test_ignore_error('E285:')
435+
432436
gui -f
433437

434438
call assert_equal(1, winnr('$'))

src/testdir/test_windows_home.vim

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
" Test for $HOME on Windows.
2+
3+
if !has('win32')
4+
finish
5+
endif
6+
7+
let s:env = {}
8+
9+
func s:restore_env()
10+
for i in keys(s:env)
11+
exe 'let ' . i . '=s:env["' . i . '"]'
12+
endfor
13+
endfunc
14+
15+
func s:save_env(...)
16+
for i in a:000
17+
exe 'let s:env["' . i . '"]=' . i
18+
endfor
19+
endfunc
20+
21+
func s:unlet_env(...)
22+
for i in a:000
23+
exe 'let ' . i . '=""'
24+
endfor
25+
endfunc
26+
27+
func CheckHomeIsMissingFromSubprocessEnvironment()
28+
silent! let out = system('set')
29+
let env = filter(split(out, "\n"), 'v:val=~"^HOME="')
30+
call assert_equal(0, len(env))
31+
endfunc
32+
33+
func CheckHomeIsInSubprocessEnvironment(exp)
34+
silent! let out = system('set')
35+
let env = filter(split(out, "\n"), 'v:val=~"^HOME="')
36+
let home = len(env) == 0 ? "" : substitute(env[0], '[^=]\+=', '', '')
37+
call assert_equal(a:exp, home)
38+
endfunc
39+
40+
func CheckHome(exp, ...)
41+
"call assert_equal(a:exp, $HOME)
42+
"call assert_equal(a:exp, expand('~', ':p'))
43+
if !a:0
44+
call CheckHomeIsMissingFromSubprocessEnvironment()
45+
else
46+
call CheckHomeIsInSubprocessEnvironment(a:exp)
47+
endif
48+
endfunc
49+
50+
func TestWindowsHome()
51+
command! -nargs=* SaveEnv call <SID>save_env(<f-args>)
52+
command! -nargs=* RestoreEnv call <SID>restore_env()
53+
command! -nargs=* UnletEnv call <SID>unlet_env(<f-args>)
54+
55+
SaveEnv $HOME $USERPROFILE $HOMEDRIVE $HOMEPATH
56+
try
57+
RestoreEnv
58+
UnletEnv $HOME $USERPROFILE $HOMEPATH
59+
let $HOMEDRIVE = 'C:'
60+
call CheckHome('C:\')
61+
62+
RestoreEnv
63+
UnletEnv $HOME $USERPROFILE
64+
let $HOMEDRIVE = 'C:'
65+
let $HOMEPATH = '\foobar'
66+
call CheckHome('C:\foobar')
67+
68+
RestoreEnv
69+
UnletEnv $HOME $HOMEDRIVE $HOMEPATH
70+
let $USERPROFILE = 'C:\foo'
71+
call CheckHome('C:\foo')
72+
73+
RestoreEnv
74+
UnletEnv $HOME
75+
let $USERPROFILE = 'C:\foo'
76+
let $HOMEDRIVE = 'C:'
77+
let $HOMEPATH = '\baz'
78+
call CheckHome('C:\foo')
79+
80+
RestoreEnv
81+
let $HOME = 'C:\bar'
82+
let $USERPROFILE = 'C:\foo'
83+
let $HOMEDRIVE = 'C:'
84+
let $HOMEPATH = '\baz'
85+
call CheckHome('C:\bar', 1)
86+
87+
RestoreEnv
88+
let $HOME = '%USERPROFILE%\bar'
89+
let $USERPROFILE = 'C:\foo'
90+
let $HOMEDRIVE = 'C:'
91+
let $HOMEPATH = '\baz'
92+
call CheckHome('%USERPROFILE%\bar', 1)
93+
94+
RestoreEnv
95+
let $HOME = '%USERPROFILE'
96+
let $USERPROFILE = 'C:\foo'
97+
let $HOMEDRIVE = 'C:'
98+
let $HOMEPATH = '\baz'
99+
call CheckHome('%USERPROFILE', 1)
100+
101+
RestoreEnv
102+
let $HOME = 'C:\%USERPROFILE%'
103+
let $USERPROFILE = 'C:\foo'
104+
let $HOMEDRIVE = 'C:'
105+
let $HOMEPATH = '\baz'
106+
call CheckHome('C:\%USERPROFILE%', 1)
107+
108+
if has('channel')
109+
RestoreEnv
110+
UnletEnv $HOME
111+
let env = ''
112+
let job = job_start('cmd /c set', {'out_cb': {ch,x->[env,execute('let env=x')]}})
113+
sleep 1
114+
let env = filter(split(env, "\n"), 'v:val=="HOME"')
115+
let home = len(env) == 0 ? "" : env[0]
116+
call assert_equal('', home)
117+
endif
118+
finally
119+
RestoreEnv
120+
delcommand SaveEnv
121+
delcommand RestoreEnv
122+
delcommand UnletEnv
123+
endtry
124+
endfunc

src/version.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -784,6 +784,12 @@ static char *(features[]) =
784784

785785
static int included_patches[] =
786786
{ /* Add new patch number below this line */
787+
/**/
788+
1013,
789+
/**/
790+
1012,
791+
/**/
792+
1011,
787793
/**/
788794
1010,
789795
/**/

0 commit comments

Comments
 (0)