Yakov Lerner wrote:
I'm generating short temp names like /tmp/N or ~/tmp/N
where N is number. My first take on the TempName()
function was:

function! TempName()
   let x=1
   while filereadable("/tmp/".x)
       let x = x + 1
   endwhile
   return "/tmp/".x
endfun

Surprising problem came up. vim#1 choose name /tmp/3 and
swapfile for /tmp/3 exists (/tmp/.3.swp) but file /tmp/3 does not
exists. As a result, vim#2 tries to use /tmp/3. I am modifying
my TempName() to check explicitly for /tmp/.3.swp, but I maybe
we need a function in vim that check whether file x has
swapfiles ? I don't find such function.
The builtin function can take correctly into account various settings
associated with swapfile naming, no ? Is there better solution
to check that file x has/does not have swapfiles ?

Yakov



Checking for (any) swapfile would mean check for more than just /tmp/3.swp since if <file>.swp exists and you reply 'Edit anyway' to the ATTENTION message, Vim will use <file>.swo, then <file>.swn, ... It may go back to .saa (see ":help swap-file"). OTOH the swap file is not always in the same directory as the file, and if the file was edited by a different Vim, they may have different 'directory' settings.

IIUC, the nearest to a "hasswap()" function you can get is to run ":!vim -r" in the directory where you plan to open the file, and parse the output. Maybe an appropriate 'errorformat' can be contrived to regard that output as a "quickfix error list", but I'm not a specialist of such matters.


Best regards,
Tony.

Reply via email to