Patch 8.2.0208
Problem: Fnamemodify() does not apply ":~" when followed by ":.".
Solution: Don't let a failing ":." cause the ":~" to be skipped. (Yasuhiro
Matsumoto, closes #5577)
Files: runtime/doc/cmdline.txt, src/filepath.c,
src/testdir/test_fnamemodify.vim
*** ../vim-8.2.0207/runtime/doc/cmdline.txt 2019-12-17 21:27:14.686319918
+0100
--- runtime/doc/cmdline.txt 2020-02-04 22:18:08.570088014 +0100
***************
*** 933,940 ****
directory.
:. Reduce file name to be relative to current directory, if
possible. File name is unmodified if it is not below the
! current directory, but on MS-Windows the drive is removed if
! it is the current drive.
For maximum shortness, use ":~:.".
:h Head of the file name (the last component and any separators
removed). Cannot be used with :e, :r or :t.
--- 933,939 ----
directory.
:. Reduce file name to be relative to current directory, if
possible. File name is unmodified if it is not below the
! current directory.
For maximum shortness, use ":~:.".
:h Head of the file name (the last component and any separators
removed). Cannot be used with :e, :r or :t.
***************
*** 943,949 ****
separator is removed. Thus ":p:h" on a directory name results
on the directory name itself (without trailing slash).
When the file name is an absolute path (starts with "/" for
! Unix; "x:\" for WIN32; "drive:" for Amiga), that part is not
removed. When there is no head (path is relative to current
directory) the result is empty.
:t Tail of the file name (last component of the name). Must
--- 942,948 ----
separator is removed. Thus ":p:h" on a directory name results
on the directory name itself (without trailing slash).
When the file name is an absolute path (starts with "/" for
! Unix; "x:\" for Win32; "drive:" for Amiga), that part is not
removed. When there is no head (path is relative to current
directory) the result is empty.
:t Tail of the file name (last component of the name). Must
*** ../vim-8.2.0207/src/filepath.c 2020-01-26 15:52:33.019833259 +0100
--- src/filepath.c 2020-02-04 22:22:11.536740977 +0100
***************
*** 301,306 ****
--- 301,307 ----
char_u dirname[MAXPATHL];
int c;
int has_fullname = 0;
+ int has_homerelative = 0;
#ifdef MSWIN
char_u *fname_start = *fnamep;
int has_shortname = 0;
***************
*** 412,418 ****
}
pbuf = NULL;
// Need full path first (use expand_env() to remove a "~/")
! if (!has_fullname)
{
if (c == '.' && **fnamep == '~')
p = pbuf = expand_env_save(*fnamep);
--- 413,419 ----
}
pbuf = NULL;
// Need full path first (use expand_env() to remove a "~/")
! if (!has_fullname && !has_homerelative)
{
if (c == '.' && **fnamep == '~')
p = pbuf = expand_env_save(*fnamep);
***************
*** 428,438 ****
{
if (c == '.')
{
mch_dirname(dirname, MAXPATHL);
! s = shorten_fname(p, dirname);
! if (s != NULL)
{
! *fnamep = s;
if (pbuf != NULL)
{
vim_free(*bufp); // free any allocated file name
--- 429,456 ----
{
if (c == '.')
{
+ size_t namelen;
+
mch_dirname(dirname, MAXPATHL);
! if (has_homerelative)
! {
! s = vim_strsave(dirname);
! if (s != NULL)
! {
! home_replace(NULL, s, dirname, MAXPATHL, TRUE);
! vim_free(s);
! }
! }
! namelen = STRLEN(dirname);
!
! // Do not call shorten_fname() here since it removes the prefix
! // even though the path does not have a prefix.
! if (fnamencmp(p, dirname, namelen) == 0)
{
! p += namelen;
! while (*p && vim_ispathsep(*p))
! ++p;
! *fnamep = p;
if (pbuf != NULL)
{
vim_free(*bufp); // free any allocated file name
***************
*** 453,458 ****
--- 471,477 ----
*fnamep = s;
vim_free(*bufp);
*bufp = s;
+ has_homerelative = TRUE;
}
}
}
***************
*** 701,706 ****
--- 720,726 ----
rettv->vval.v_string = NULL;
if (argvars[0].v_type != VAR_STRING)
+ // Returning an empty string means it failed.
return;
// Return the current directory
*** ../vim-8.2.0207/src/testdir/test_fnamemodify.vim 2019-10-08
23:20:07.000000000 +0200
--- src/testdir/test_fnamemodify.vim 2020-02-04 22:18:08.570088014 +0100
***************
*** 3,10 ****
--- 3,12 ----
func Test_fnamemodify()
let save_home = $HOME
let save_shell = &shell
+ let save_shellslash = &shellslash
let $HOME = fnamemodify('.', ':p:h:h')
set shell=sh
+ set shellslash
call assert_equal('/', fnamemodify('.', ':p')[-1:])
call assert_equal('r', fnamemodify('.', ':p:h')[-1:])
***************
*** 28,33 ****
--- 30,44 ----
call assert_equal('fb2.tar.gz', fnamemodify('abc.fb2.tar.gz', ':e:e:e:e'))
call assert_equal('tar', fnamemodify('abc.fb2.tar.gz', ':e:e:r'))
+ let cwd = getcwd()
+ call mkdir($HOME . '/XXXXXXXX/a', 'p')
+ call mkdir($HOME . '/XXXXXXXX/b', 'p')
+ call chdir($HOME . '/XXXXXXXX/a/')
+ call assert_equal('foo', fnamemodify($HOME . '/XXXXXXXX/a/foo', ':p:~:.'))
+ call assert_equal('~/XXXXXXXX/b/foo', fnamemodify($HOME .
'/XXXXXXXX/b/foo', ':p:~:.'))
+ call chdir(cwd)
+ call delete($HOME . '/XXXXXXXX', 'rf')
+
call assert_equal('''abc def''', fnamemodify('abc def', ':S'))
call assert_equal('''abc" "def''', fnamemodify('abc" "def', ':S'))
call assert_equal('''abc"%"def''', fnamemodify('abc"%"def', ':S'))
***************
*** 44,49 ****
--- 55,61 ----
let $HOME = save_home
let &shell = save_shell
+ let &shellslash = save_shellslash
endfunc
func Test_fnamemodify_er()
*** ../vim-8.2.0207/src/version.c 2020-02-04 21:54:03.277158742 +0100
--- src/version.c 2020-02-04 22:20:46.629178501 +0100
***************
*** 744,745 ****
--- 744,747 ----
{ /* Add new patch number below this line */
+ /**/
+ 208,
/**/
--
The technology involved in making anything invisible is so infinitely
complex that nine hundred and ninety-nine billion, nine hundred and
ninety-nine million, nine hundred and ninety-nine thousand, nine hundred
and ninety-nine times out of a trillion it is much simpler and more
effective just to take the thing away and do without it.
-- Douglas Adams, "The Hitchhiker's Guide to the Galaxy"
/// Bram Moolenaar -- [email protected] -- http://www.Moolenaar.net \\\
/// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\ an exciting new programming language -- http://www.Zimbu.org ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///
--
--
You received this message from the "vim_dev" 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_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/vim_dev/202002042123.014LNf0v007773%40masaka.moolenaar.net.