comparison src/testdir/test_listchars.vim @ 23952:44be09b25619 v8.2.2518

patch 8.2.2518: 'listchars' should be window-local Commit: https://github.com/vim/vim/commit/eed9d46293f0842aad0d50ff3a526f9a48b12421 Author: Bram Moolenaar <Bram@vim.org> Date: Mon Feb 15 20:38:25 2021 +0100 patch 8.2.2518: 'listchars' should be window-local Problem: 'listchars' should be window-local. Solution: Make 'listchars' global-local. (Yegappan Lakshmanan, Marco Hinz, closes #5206, closes #7850)
author Bram Moolenaar <Bram@vim.org>
date Mon, 15 Feb 2021 20:45:04 +0100
parents 0bd44e94dd14
children 4d88e660ce32
comparison
equal deleted inserted replaced
23951:c58a5a123ca5 23952:44be09b25619
232 let &encoding=oldencoding 232 let &encoding=oldencoding
233 enew! 233 enew!
234 set listchars& ff& 234 set listchars& ff&
235 endfunction 235 endfunction
236 236
237 " Check for the value of the 'listchars' option
238 func s:CheckListCharsValue(expected)
239 call assert_equal(a:expected, &listchars)
240 call assert_equal(a:expected, getwinvar(0, '&listchars'))
241 endfunc
242
243 " Test for using a window local value for 'listchars'
244 func Test_listchars_window_local()
245 %bw!
246 set list listchars&
247 new
248 " set a local value for 'listchars'
249 setlocal listchars=tab:+-,eol:#
250 call s:CheckListCharsValue('tab:+-,eol:#')
251 " When local value is reset, global value should be used
252 setlocal listchars=
253 call s:CheckListCharsValue('eol:$')
254 " Use 'setlocal <' to copy global value
255 setlocal listchars=space:.,extends:>
256 setlocal listchars<
257 call s:CheckListCharsValue('eol:$')
258 " Use 'set <' to copy global value
259 setlocal listchars=space:.,extends:>
260 set listchars<
261 call s:CheckListCharsValue('eol:$')
262 " Changing global setting should not change the local setting
263 setlocal listchars=space:.,extends:>
264 setglobal listchars=tab:+-,eol:#
265 call s:CheckListCharsValue('space:.,extends:>')
266 " when split opening a new window, local value should be copied
267 split
268 call s:CheckListCharsValue('space:.,extends:>')
269 " clearing local value in one window should not change the other window
270 set listchars&
271 call s:CheckListCharsValue('eol:$')
272 close
273 call s:CheckListCharsValue('space:.,extends:>')
274
275 " use different values for 'listchars' items in two different windows
276 call setline(1, ["\t one two "])
277 setlocal listchars=tab:<->,lead:_,space:.,trail:@,eol:#
278 split
279 setlocal listchars=tab:[.],lead:#,space:_,trail:.,eol:&
280 split
281 set listchars=tab:+-+,lead:^,space:>,trail:<,eol:%
282 call assert_equal(['+------+^^one>>two<<%'], ScreenLines(1, virtcol('$')))
283 close
284 call assert_equal(['[......]##one__two..&'], ScreenLines(1, virtcol('$')))
285 close
286 call assert_equal(['<------>__one..two@@#'], ScreenLines(1, virtcol('$')))
287 " changing the global setting should not change the local value
288 setglobal listchars=tab:[.],lead:#,space:_,trail:.,eol:&
289 call assert_equal(['<------>__one..two@@#'], ScreenLines(1, virtcol('$')))
290 set listchars<
291 call assert_equal(['[......]##one__two..&'], ScreenLines(1, virtcol('$')))
292
293 " Using setglobal in a window with local setting should not affect the
294 " window. But should impact other windows using the global setting.
295 enew! | only
296 call setline(1, ["\t one two "])
297 set listchars=tab:[.],lead:#,space:_,trail:.,eol:&
298 split
299 setlocal listchars=tab:+-+,lead:^,space:>,trail:<,eol:%
300 split
301 setlocal listchars=tab:<->,lead:_,space:.,trail:@,eol:#
302 setglobal listchars=tab:{.},lead:-,space:=,trail:#,eol:$
303 call assert_equal(['<------>__one..two@@#'], ScreenLines(1, virtcol('$')))
304 close
305 call assert_equal(['+------+^^one>>two<<%'], ScreenLines(1, virtcol('$')))
306 close
307 call assert_equal(['{......}--one==two##$'], ScreenLines(1, virtcol('$')))
308
309 " Setting the global setting to the default value should not impact a window
310 " using a local setting
311 split
312 setlocal listchars=tab:<->,lead:_,space:.,trail:@,eol:#
313 setglobal listchars&vim
314 call assert_equal(['<------>__one..two@@#'], ScreenLines(1, virtcol('$')))
315 close
316 call assert_equal(['^I one two $'], ScreenLines(1, virtcol('$')))
317
318 " Setting the local setting to the default value should not impact a window
319 " using a global setting
320 set listchars=tab:{.},lead:-,space:=,trail:#,eol:$
321 split
322 setlocal listchars=tab:<->,lead:_,space:.,trail:@,eol:#
323 call assert_equal(['<------>__one..two@@#'], ScreenLines(1, virtcol('$')))
324 setlocal listchars&vim
325 call assert_equal(['^I one two $'], ScreenLines(1, virtcol('$')))
326 close
327 call assert_equal(['{......}--one==two##$'], ScreenLines(1, virtcol('$')))
328
329 " Using set in a window with a local setting should change it to use the
330 " global setting and also impact other windows using the global setting
331 split
332 setlocal listchars=tab:<->,lead:_,space:.,trail:@,eol:#
333 call assert_equal(['<------>__one..two@@#'], ScreenLines(1, virtcol('$')))
334 set listchars=tab:+-+,lead:^,space:>,trail:<,eol:%
335 call assert_equal(['+------+^^one>>two<<%'], ScreenLines(1, virtcol('$')))
336 close
337 call assert_equal(['+------+^^one>>two<<%'], ScreenLines(1, virtcol('$')))
338
339 %bw!
340 set list& listchars&
341 endfunc
342
237 " vim: shiftwidth=2 sts=2 expandtab 343 " vim: shiftwidth=2 sts=2 expandtab