I found the manual:
:help empty
empty({expr}) empty()
Return the Number 1 if {expr} is empty, zero otherwise.
- A List or Dictionary is empty when it does not have any items.
- A String is empty when its length is zero.
- A Number and Float is empty when its value is zero.
- v:false, v:none and v:null are empty, v:true is not.
- A Job is empty when it failed to start.
- A Channel is empty when it is closed.
For a long List this is much faster than comparing the length with zero.
So, it does not work, because empty
does not check the file contents at all.
Still, I have not figured out, as to how to do this, if even possible.
Update
I am now able to determine if the file is completely empty with the following code, I structured it to functions, because they might be handy. This does not solve the problem of whitespace(s) in the buffer list file. So, I will be testing the other solution posted. And if working, accepting it.
" This defines the name and path of my buffer list file
let BufferListFile = $HOME . "/.vim/buflist.txt"
" This function returns true if the defined
" buffer list file exists
" No matter if it is readable by the user
" Gotten from https://stackoverflow.com/a/23496813/1997354
" Needs verification
function BufferListFileExists()
return (!empty(glob(g:BufferListFile)))
endfunction
" This function returns true if the defined
" buffer list file is readable by the user
function BufferListFileReadable()
return (filereadable(g:BufferListFile))
endfunction
" This function returns true if the defined
" buffer list file is completely empty
function BufferListFileEmpty()
return (getfsize(g:BufferListFile) == 0)
endfunction
" Debugging
echom BufferListFileExists()
echom BufferListFileReadable()
echom BufferListFileEmpty()
if (BufferListFileExists() && BufferListFileReadable() && BufferListFileEmpty())
echo "Empty"
else
echo "NotEmpty"
endif
empty
works on file contents; rather, it checks if it’s arguments are empty strings or not