1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
|
To: vim_dev@googlegroups.com
Subject: Patch 8.1.0087
Fcc: outbox
From: Bram Moolenaar <Bram@moolenaar.net>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
------------
Patch 8.1.0087
Problem: v:shell_error is always zero when using terminal for "!cmd".
Solution: Use "exitval" of terminal-job. (Ozaki Kiichi, closes #2994)
Files: src/os_unix.c, src/os_win32.c, src/proto/terminal.pro,
src/terminal.c, src/testdir/test_terminal.vim
*** ../vim-8.1.0086/src/os_unix.c 2018-06-13 20:49:47.444338292 +0200
--- src/os_unix.c 2018-06-19 19:53:43.794232600 +0200
***************
*** 4365,4370 ****
--- 4365,4371 ----
char_u *tofree2 = NULL;
int retval = -1;
buf_T *buf;
+ job_T *job;
aco_save_T aco;
oparg_T oa; /* operator arguments */
***************
*** 4374,4379 ****
--- 4375,4385 ----
init_job_options(&opt);
ch_log(NULL, "starting terminal for system command '%s'", cmd);
buf = term_start(NULL, argv, &opt, TERM_START_SYSTEM);
+ if (buf == NULL)
+ goto theend;
+
+ job = term_getjob(buf->b_term);
+ ++job->jv_refcount;
/* Find a window to make "buf" curbuf. */
aucmd_prepbuf(&aco, buf);
***************
*** 4391,4399 ****
else
normal_cmd(&oa, TRUE);
}
! retval = 0;
ch_log(NULL, "system command finished");
/* restore curwin/curbuf and a few other things */
aucmd_restbuf(&aco);
--- 4397,4407 ----
else
normal_cmd(&oa, TRUE);
}
! retval = job->jv_exitval;
ch_log(NULL, "system command finished");
+ job_unref(job);
+
/* restore curwin/curbuf and a few other things */
aucmd_restbuf(&aco);
*** ../vim-8.1.0086/src/os_win32.c 2018-06-12 21:11:08.626548598 +0200
--- src/os_win32.c 2018-06-19 19:53:43.798232583 +0200
***************
*** 4796,4801 ****
--- 4796,4802 ----
long_u cmdlen;
int retval = -1;
buf_T *buf;
+ job_T *job;
aco_save_T aco;
oparg_T oa; /* operator arguments */
***************
*** 4826,4831 ****
--- 4827,4835 ----
if (buf == NULL)
return 255;
+ job = term_getjob(buf->b_term);
+ ++job->jv_refcount;
+
/* Find a window to make "buf" curbuf. */
aucmd_prepbuf(&aco, buf);
***************
*** 4842,4850 ****
else
normal_cmd(&oa, TRUE);
}
! retval = 0;
ch_log(NULL, "system command finished");
/* restore curwin/curbuf and a few other things */
aucmd_restbuf(&aco);
--- 4846,4856 ----
else
normal_cmd(&oa, TRUE);
}
! retval = job->jv_exitval;
ch_log(NULL, "system command finished");
+ job_unref(job);
+
/* restore curwin/curbuf and a few other things */
aucmd_restbuf(&aco);
*** ../vim-8.1.0086/src/proto/terminal.pro 2018-05-17 13:52:53.000000000 +0200
--- src/proto/terminal.pro 2018-06-19 19:53:43.798232583 +0200
***************
*** 55,59 ****
--- 55,60 ----
void f_term_start(typval_T *argvars, typval_T *rettv);
void f_term_wait(typval_T *argvars, typval_T *rettv);
void term_send_eof(channel_T *ch);
+ job_T *term_getjob(term_T *term);
int terminal_enabled(void);
/* vim: set ft=c : */
*** ../vim-8.1.0086/src/terminal.c 2018-06-18 22:15:46.255521457 +0200
--- src/terminal.c 2018-06-19 19:53:43.798232583 +0200
***************
*** 5336,5341 ****
--- 5336,5347 ----
}
}
+ job_T *
+ term_getjob(term_T *term)
+ {
+ return term != NULL ? term->tl_job : NULL;
+ }
+
# if defined(WIN3264) || defined(PROTO)
/**************************************
*** ../vim-8.1.0086/src/testdir/test_terminal.vim 2018-06-12 18:04:28.038267855 +0200
--- src/testdir/test_terminal.vim 2018-06-19 19:55:56.917638761 +0200
***************
*** 522,550 ****
exe buf . 'bwipe'
endfunc
- " must be last, we can't go back from GUI to terminal
- func Test_zz_terminal_in_gui()
- if !CanRunGui()
- return
- endif
-
- " Ignore the "failed to create input context" error.
- call test_ignore_error('E285:')
-
- gui -f
-
- call assert_equal(1, winnr('$'))
- let buf = Run_shell_in_terminal({'term_finish': 'close'})
- call Stop_shell_in_terminal(buf)
- call term_wait(buf)
-
- " closing window wipes out the terminal buffer a with finished job
- call WaitForAssert({-> assert_equal(1, winnr('$'))})
- call assert_equal("", bufname(buf))
-
- unlet g:job
- endfunc
-
func Test_terminal_list_args()
let buf = term_start([&shell, &shellcmdflag, 'echo "123"'])
call assert_fails(buf . 'bwipe', 'E517')
--- 522,527 ----
***************
*** 1546,1548 ****
--- 1523,1580 ----
exe buf . 'bwipe!'
endfunc
+
+ " must be nearly the last, we can't go back from GUI to terminal
+ func Test_zz1_terminal_in_gui()
+ if !CanRunGui()
+ return
+ endif
+
+ " Ignore the "failed to create input context" error.
+ call test_ignore_error('E285:')
+
+ gui -f
+
+ call assert_equal(1, winnr('$'))
+ let buf = Run_shell_in_terminal({'term_finish': 'close'})
+ call Stop_shell_in_terminal(buf)
+ call term_wait(buf)
+
+ " closing window wipes out the terminal buffer a with finished job
+ call WaitForAssert({-> assert_equal(1, winnr('$'))})
+ call assert_equal("", bufname(buf))
+
+ unlet g:job
+ endfunc
+
+ func Test_zz2_terminal_guioptions_bang()
+ if !has('gui_running')
+ return
+ endif
+ set guioptions+=!
+
+ let filename = 'Xtestscript'
+ if has('win32')
+ let filename .= '.bat'
+ let prefix = ''
+ let contents = ['@echo off', 'exit %1']
+ else
+ let filename .= '.sh'
+ let prefix = './'
+ let contents = ['#!/bin/sh', 'exit $1']
+ endif
+ call writefile(contents, filename)
+ call setfperm(filename, 'rwxrwx---')
+
+ " Check if v:shell_error is equal to the exit status.
+ let exitval = 0
+ execute printf(':!%s%s %d', prefix, filename, exitval)
+ call assert_equal(exitval, v:shell_error)
+
+ let exitval = 9
+ execute printf(':!%s%s %d', prefix, filename, exitval)
+ call assert_equal(exitval, v:shell_error)
+
+ set guioptions&
+ call delete(filename)
+ endfunc
*** ../vim-8.1.0086/src/version.c 2018-06-19 19:46:01.703936337 +0200
--- src/version.c 2018-06-19 19:50:34.551011945 +0200
***************
*** 763,764 ****
--- 763,766 ----
{ /* Add new patch number below this line */
+ /**/
+ 87,
/**/
--
From "know your smileys":
:-) Funny
|-) Funny Oriental
(-: Funny Australian
/// 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 ///
|