Indexing into l:smart_buffer.path breaks on older vim versions
Closed this issue · 7 comments
Commit 4ac1ddd uses l:smart_buffer.path[sep:]
, which is OK on one system with vim 8.2, but crashes the plugin for vim 7.4. Untested for other versions.
Reproducible with :call lightline#bufferline#buffers()
, resulting in:
Error detected while processing function lightline#bufferline#buffers..<SNR>24_get_buffer_names..<SNR>24_get_buffer_paths:
(...)
E121: Undefined variable: sep:
E15: Invalid expression: sep != -1 && l:smart_buffer.path[sep:] ==# s:dirsep
Using the older concatenation syntax sep . ':'
on lines 213 and 222 fixes the issue for me, PR incoming.
The expression [sep:]
returns the substring from index sep
to the end of the string. Concatenating :
to sep
is not the same and thus won’t work.
Does it work for you if you add a space between sep
and :
(leading to [sep :]
)?
You're right, here are some sanity checks added near line 209:
if strlen(l:name)
let l:smart_buffer.path = fnamemodify(l:name, ':p:~:.')
let sep = strridx(l:smart_buffer.path, s:dirsep)
let dbg1 = l:smart_buffer.path[19:]
let dbg2 = l:smart_buffer.path[sep . ':']
let dbg3 = l:smart_buffer.path[sep :]
echom "sbp: " . l:smart_buffer.path
echom "dbg0: " . sep
echom "dbg1: " . dbg1
echom "dbg2: " . dbg2
echom "dbg3: " . dbg3
if sep != -1 && l:smart_buffer.path[sep . ':'] ==# s:dirsep
let sep = strridx(l:smart_buffer.path, s:dirsep, sep - 1)
echom "dbg4: " . sep
endif
So I guess sep . ':'
makes the l:smart_buffer.path[sep . ':'] ==# s:dirsep
check evaluate true, and sep
is always updated provided it's not -1 ...
Should we proceed with sep :
then?
Just to make sure, the error you mentioned in your first post is gone if you insert a space between sep
and :
?
Yes, I've been using sep :
since this morning and it appears to work fine.
Do you mind adjusting your PR to that solution? It seems like the correct fix for this issue.
Done, thanks!
Fixed by #97