summaryrefslogtreecommitdiff
path: root/data/vim/patches/8.1.0692
blob: 103577179d3e59bfb6515c56607b5ab2e4f33ea1 (plain)
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
To: vim_dev@googlegroups.com
Subject: Patch 8.1.0692
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.0692
Problem:    If a buffer was deleted a channel can't write to it.
Solution:   When the buffer exists but was unloaded, prepare it for writing.
            (closes #3764)
Files:	    src/channel.c, src/testdir/test_channel.vim


*** ../vim-8.1.0691/src/channel.c	2018-12-21 16:04:16.312437516 +0100
--- src/channel.c	2019-01-04 23:59:05.527410601 +0100
***************
*** 1099,1104 ****
--- 1099,1123 ----
  }
  
  /*
+  * Prepare buffer "buf" for writing channel output to.
+  */
+ 	static void
+ prepare_buffer(buf_T *buf)
+ {
+     buf_T *save_curbuf = curbuf;
+ 
+     buf_copy_options(buf, BCO_ENTER);
+     curbuf = buf;
+ #ifdef FEAT_QUICKFIX
+     set_option_value((char_u *)"bt", 0L, (char_u *)"nofile", OPT_LOCAL);
+     set_option_value((char_u *)"bh", 0L, (char_u *)"hide", OPT_LOCAL);
+ #endif
+     if (curbuf->b_ml.ml_mfp == NULL)
+ 	ml_open(curbuf);
+     curbuf = save_curbuf;
+ }
+ 
+ /*
   * Find a buffer matching "name" or create a new one.
   * Returns NULL if there is something very wrong (error already reported).
   */
***************
*** 1120,1133 ****
  				     NULL, (linenr_T)0, BLN_LISTED | BLN_NEW);
  	if (buf == NULL)
  	    return NULL;
! 	buf_copy_options(buf, BCO_ENTER);
  	curbuf = buf;
- #ifdef FEAT_QUICKFIX
- 	set_option_value((char_u *)"bt", 0L, (char_u *)"nofile", OPT_LOCAL);
- 	set_option_value((char_u *)"bh", 0L, (char_u *)"hide", OPT_LOCAL);
- #endif
- 	if (curbuf->b_ml.ml_mfp == NULL)
- 	    ml_open(curbuf);
  	if (msg)
  	    ml_replace(1, (char_u *)(err ? "Reading from channel error..."
  				   : "Reading from channel output..."), TRUE);
--- 1139,1147 ----
  				     NULL, (linenr_T)0, BLN_LISTED | BLN_NEW);
  	if (buf == NULL)
  	    return NULL;
! 	prepare_buffer(buf);
! 
  	curbuf = buf;
  	if (msg)
  	    ml_replace(1, (char_u *)(err ? "Reading from channel error..."
  				   : "Reading from channel output..."), TRUE);
***************
*** 1244,1249 ****
--- 1258,1266 ----
  		ch_log(channel, "writing out to buffer '%s'",
  						       (char *)buf->b_ffname);
  		set_bufref(&channel->ch_part[PART_OUT].ch_bufref, buf);
+ 		// if the buffer was deleted or unloaded resurrect it
+ 		if (buf->b_ml.ml_mfp == NULL)
+ 		    prepare_buffer(buf);
  	    }
  	}
      }
***************
*** 1287,1292 ****
--- 1304,1312 ----
  		ch_log(channel, "writing err to buffer '%s'",
  						       (char *)buf->b_ffname);
  		set_bufref(&channel->ch_part[PART_ERR].ch_bufref, buf);
+ 		// if the buffer was deleted or unloaded resurrect it
+ 		if (buf->b_ml.ml_mfp == NULL)
+ 		    prepare_buffer(buf);
  	    }
  	}
      }
*** ../vim-8.1.0691/src/testdir/test_channel.vim	2018-12-14 22:42:10.191670447 +0100
--- src/testdir/test_channel.vim	2019-01-04 23:58:11.943811833 +0100
***************
*** 1645,1650 ****
--- 1645,1672 ----
    bwipe!
  endfunc
  
+ func Test_write_to_deleted_buffer()
+   if !executable('echo') || !has('job')
+     return
+   endif
+   let job = job_start('echo hello', {'out_io': 'buffer', 'out_name': 'test_buffer', 'out_msg': 0})
+   call WaitForAssert({-> assert_equal("dead", job_status(job))})
+   let bufnr = bufnr('test_buffer')
+   call assert_equal(['hello'], getbufline(bufnr, 1, '$'))
+   call assert_equal('nofile', getbufvar(bufnr, '&buftype'))
+   call assert_equal('hide', getbufvar(bufnr, '&bufhidden'))
+   bdel test_buffer
+   call assert_equal([], getbufline(bufnr, 1, '$'))
+ 
+   let job = job_start('echo hello', {'out_io': 'buffer', 'out_name': 'test_buffer', 'out_msg': 0})
+   call WaitForAssert({-> assert_equal("dead", job_status(job))})
+   call assert_equal(['hello'], getbufline(bufnr, 1, '$'))
+   call assert_equal('nofile', getbufvar(bufnr, '&buftype'))
+   call assert_equal('hide', getbufvar(bufnr, '&bufhidden'))
+ 
+   bwipe! test_buffer
+ endfunc
+ 
  func Test_cmd_parsing()
    if !has('unix')
      return
*** ../vim-8.1.0691/src/version.c	2019-01-04 23:09:45.249360567 +0100
--- src/version.c	2019-01-05 00:02:09.446027308 +0100
***************
*** 801,802 ****
--- 801,804 ----
  {   /* Add new patch number below this line */
+ /**/
+     692,
  /**/

-- 
hundred-and-one symptoms of being an internet addict:
107. When using your phone you forget that you don't have to use your
     keyboard.

 /// 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    ///