summaryrefslogtreecommitdiff
path: root/data/vim/patches/8.1.0401
blob: bc570efd651889b1b0617d6c08af9c7dd9432e1e (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
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
256
257
258
259
To: vim_dev@googlegroups.com
Subject: Patch 8.1.0401
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.0401
Problem:    Can't get swap name of another buffer.
Solution:   Add swapname(). (Ozaki Kiichi, closes #3441)
Files:	    runtime/doc/eval.txt, src/evalfunc.c, src/testdir/test_swap.vim


*** ../vim-8.1.0400/runtime/doc/eval.txt	2018-09-14 21:27:02.771741354 +0200
--- runtime/doc/eval.txt	2018-09-16 18:41:36.931933772 +0200
***************
*** 2410,2415 ****
--- 2417,2423 ----
  substitute({expr}, {pat}, {sub}, {flags})
  				String	all {pat} in {expr} replaced with {sub}
  swapinfo({fname})		Dict	information about swap file {fname}
+ swapname({expr})		String	swap file of buffer {expr}
  synID({lnum}, {col}, {trans})	Number	syntax ID at {lnum} and {col}
  synIDattr({synID}, {what} [, {mode}])
  				String	attribute {what} of syntax ID {synID}
***************
*** 8011,8017 ****
  		|submatch()| returns.  Example: >
  		   :echo substitute(s, '%\(\x\x\)', {m -> '0x' . m[1]}, 'g')
  
! swapinfo({fname})					swapinfo()
  		The result is a dictionary, which holds information about the
  		swapfile {fname}. The available fields are:
  			version VIM version
--- 8024,8030 ----
  		|submatch()| returns.  Example: >
  		   :echo substitute(s, '%\(\x\x\)', {m -> '0x' . m[1]}, 'g')
  
! swapinfo({fname})					*swapinfo()*
  		The result is a dictionary, which holds information about the
  		swapfile {fname}. The available fields are:
  			version VIM version
***************
*** 8023,8034 ****
--- 8036,8055 ----
  			mtime	last modification time in seconds
  			inode	Optional: INODE number of the file
  			dirty	1 if file was modified, 0 if not
+ 		Note that "user" and "host" are truncated to at most 39 bytes.
  		In case of failure an "error" item is added with the reason:
  			Cannot open file: file not found or in accessible
  			Cannot read file: cannot read first block
  			Not a swap file: does not contain correct block ID
  			Magic number mismatch: Info in first block is invalid
  
+ swapname({expr})					*swapname()*
+ 		The result is the swap file path of the buffer {expr}.
+ 		For the use of {expr}, see |bufname()| above.
+ 		If buffer {expr} is the current buffer, the result is equal to
+ 		|:swapname| (unless no swap file).
+ 		If buffer {expr} has no swap file, returns an empty string.
+ 
  synID({lnum}, {col}, {trans})				*synID()*
  		The result is a Number, which is the syntax ID at the position
  		{lnum} and {col} in the current window.
*** ../vim-8.1.0400/src/evalfunc.c	2018-09-14 21:27:02.775741320 +0200
--- src/evalfunc.c	2018-09-16 18:41:36.935933733 +0200
***************
*** 399,404 ****
--- 399,405 ----
  static void f_submatch(typval_T *argvars, typval_T *rettv);
  static void f_substitute(typval_T *argvars, typval_T *rettv);
  static void f_swapinfo(typval_T *argvars, typval_T *rettv);
+ static void f_swapname(typval_T *argvars, typval_T *rettv);
  static void f_synID(typval_T *argvars, typval_T *rettv);
  static void f_synIDattr(typval_T *argvars, typval_T *rettv);
  static void f_synIDtrans(typval_T *argvars, typval_T *rettv);
***************
*** 865,870 ****
--- 866,872 ----
      {"submatch",	1, 2, f_submatch},
      {"substitute",	4, 4, f_substitute},
      {"swapinfo",	1, 1, f_swapinfo},
+     {"swapname",	1, 1, f_swapname},
      {"synID",		3, 3, f_synID},
      {"synIDattr",	2, 3, f_synIDattr},
      {"synIDtrans",	1, 1, f_synIDtrans},
***************
*** 12342,12347 ****
--- 12344,12366 ----
  }
  
  /*
+  * "swapname(expr)" function
+  */
+     static void
+ f_swapname(typval_T *argvars, typval_T *rettv)
+ {
+     buf_T	*buf;
+ 
+     rettv->v_type = VAR_STRING;
+     buf = get_buf_tv(&argvars[0], FALSE);
+     if (buf == NULL || buf->b_ml.ml_mfp == NULL
+ 					|| buf->b_ml.ml_mfp->mf_fname == NULL)
+ 	rettv->vval.v_string = NULL;
+     else
+ 	rettv->vval.v_string = vim_strsave(buf->b_ml.ml_mfp->mf_fname);
+ }
+ 
+ /*
   * "synID(lnum, col, trans)" function
   */
      static void
*** ../vim-8.1.0400/src/testdir/test_swap.vim	2018-08-22 11:27:57.118946770 +0200
--- src/testdir/test_swap.vim	2018-09-16 18:41:36.935933733 +0200
***************
*** 1,5 ****
--- 1,9 ----
  " Tests for the swap feature
  
+ func s:swapname()
+   return trim(execute('swapname'))
+ endfunc
+ 
  " Tests for 'directory' option.
  func Test_swap_directory()
    if !has("unix")
***************
*** 17,23 ****
    " Verify that the swap file doesn't exist in the current directory
    call assert_equal([], glob(".Xtest1*.swp", 1, 1, 1))
    edit Xtest1
!   let swfname = split(execute("swapname"))[0]
    call assert_equal([swfname], glob(swfname, 1, 1, 1))
  
    " './dir', swap file in a directory relative to the file
--- 21,27 ----
    " Verify that the swap file doesn't exist in the current directory
    call assert_equal([], glob(".Xtest1*.swp", 1, 1, 1))
    edit Xtest1
!   let swfname = s:swapname()
    call assert_equal([swfname], glob(swfname, 1, 1, 1))
  
    " './dir', swap file in a directory relative to the file
***************
*** 27,33 ****
    edit Xtest1
    call assert_equal([], glob(swfname, 1, 1, 1))
    let swfname = "Xtest2/Xtest1.swp"
!   call assert_equal(swfname, split(execute("swapname"))[0])
    call assert_equal([swfname], glob("Xtest2/*", 1, 1, 1))
  
    " 'dir', swap file in directory relative to the current dir
--- 31,37 ----
    edit Xtest1
    call assert_equal([], glob(swfname, 1, 1, 1))
    let swfname = "Xtest2/Xtest1.swp"
!   call assert_equal(swfname, s:swapname())
    call assert_equal([swfname], glob("Xtest2/*", 1, 1, 1))
  
    " 'dir', swap file in directory relative to the current dir
***************
*** 38,44 ****
    edit Xtest2/Xtest3
    call assert_equal(["Xtest2/Xtest3"], glob("Xtest2/*", 1, 1, 1))
    let swfname = "Xtest.je/Xtest3.swp"
!   call assert_equal(swfname, split(execute("swapname"))[0])
    call assert_equal([swfname], glob("Xtest.je/*", 1, 1, 1))
  
    set dir&
--- 42,48 ----
    edit Xtest2/Xtest3
    call assert_equal(["Xtest2/Xtest3"], glob("Xtest2/*", 1, 1, 1))
    let swfname = "Xtest.je/Xtest3.swp"
!   call assert_equal(swfname, s:swapname())
    call assert_equal([swfname], glob("Xtest.je/*", 1, 1, 1))
  
    set dir&
***************
*** 70,76 ****
  	throw 'Skipped: cannot set second group on test file'
        else
  	split Xtest
! 	let swapname = substitute(execute('swapname'), '[[:space:]]', '', 'g')
  	call assert_match('Xtest', swapname)
  	" Group of swapfile must now match original file.
  	call assert_match(' ' . groups[1] . ' \d', system('ls -l ' . swapname))
--- 74,80 ----
  	throw 'Skipped: cannot set second group on test file'
        else
  	split Xtest
! 	let swapname = s:swapname()
  	call assert_match('Xtest', swapname)
  	" Group of swapfile must now match original file.
  	call assert_match(' ' . groups[1] . ' \d', system('ls -l ' . swapname))
***************
*** 102,108 ****
    new Xswapinfo
    call setline(1, ['one', 'two', 'three'])
    w
!   let fname = trim(execute('swapname'))
    call assert_match('Xswapinfo', fname)
    let info = swapinfo(fname)
  
--- 106,112 ----
    new Xswapinfo
    call setline(1, ['one', 'two', 'three'])
    w
!   let fname = s:swapname()
    call assert_match('Xswapinfo', fname)
    let info = swapinfo(fname)
  
***************
*** 136,138 ****
--- 140,163 ----
    call assert_equal('Not a swap file', info.error)
    call delete('Xnotaswapfile')
  endfunc
+ 
+ func Test_swapname()
+   edit Xtest1
+   let expected = s:swapname()
+   call assert_equal(expected, swapname('%'))
+ 
+   new Xtest2
+   let buf = bufnr('%')
+   let expected = s:swapname()
+   wincmd p
+   call assert_equal(expected, swapname(buf))
+ 
+   new Xtest3
+   setlocal noswapfile
+   call assert_equal('', swapname('%'))
+ 
+   bwipe!
+   call delete('Xtest1')
+   call delete('Xtest2')
+   call delete('Xtest3')
+ endfunc
*** ../vim-8.1.0400/src/version.c	2018-09-16 18:10:45.246181729 +0200
--- src/version.c	2018-09-16 18:42:35.483369791 +0200
***************
*** 796,797 ****
--- 796,799 ----
  {   /* Add new patch number below this line */
+ /**/
+     401,
  /**/

-- 
hundred-and-one symptoms of being an internet addict:
77. The phone company asks you to test drive their new PBX system

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