136982Re: expand('%:p') doesn't work properly when opening a new file in a non-existing directory?
- Mar 30, 2013
On 30/03/13 07:35, Hong Xu wrote:
> Hi Tony,
> Thanks for your reply.
> I have noticed that I can not write to disk if I create a new file in a
> non-existing directory; what I am concerning is the unexpected behavior
> of `expand('%:p')`. I am currently encountering an issue in my plugin: I
> call `expand('%:p')` to obtain the full path, but in the given case
> above, I would get a truncated path. So I think this behavior should not
> be expected. Do you think so?
I think that you cannot get the full path if there is no disk path.
Maybe you ought to get '' rather than 'a/a.b'. Or maybe it is intended
(perhaps vi-compatible) behaviour, and you can test the value (on Unix:
either empty, or doesn't start with a slash; on Windows: either empty,
or the second character is not a colon) to determine that you didn't get
a real path. (Empty is for a [No Name] buffer.)
let filepath = expand('%:p')
if ((has('unix') && (filepath =~ '/.*')) || (!has('unix') && (filepath
" we have a real path
" we don't
Now that I think of it, a better test might be filereadable() or
filewritable(). Or :w in a try-catch block.
INSPECTOR END OF FILM: Move along. There's nothing to see! Keep moving!
[Suddenly he notices the cameras.]
INSPECTOR END OF FILM: (to Camera) All right, put that away sonny.
[He walks over to it and puts his hand over the lens.]
"Monty Python and the Holy Grail" PYTHON (MONTY)
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@....
For more options, visit https://groups.google.com/groups/opt_out.
- << Previous post in topic