Patch 8.0.1781
Problem: File names in quickfix window are not always shortened.
Solution: Shorten the file name when opening the quickfix window. (Yegappan
Lakshmanan, closes #2851, closes #2846)
Files: src/testdir/test_quickfix.vim, src/fileio.c, src/proto/fileio.pro,
src/quickfix.c
*** ../vim-8.0.1780/src/testdir/test_quickfix.vim 2018-04-24
15:48:05.780784369 +0200
--- src/testdir/test_quickfix.vim 2018-05-01 14:07:14.651622097 +0200
***************
*** 3201,3203 ****
--- 3201,3227 ----
au! QuickFixCmdPost
new | only
endfunc
+
+ " Test for shortening/simplifying the file name when opening the
+ " quickfix window or when displaying the quickfix list
+ func Test_shorten_fname()
+ if !has('unix')
+ return
+ endif
+ %bwipe
+ " Create a quickfix list with a absolute path filename
+ let fname = getcwd() . '/test_quickfix.vim'
+ call setqflist([], ' ', {'lines':[fname . ":20:Line20"], 'efm':'%f:%l:%m'})
+ call assert_equal(fname, bufname('test_quickfix.vim'))
+ " Opening the quickfix window should simplify the file path
+ cwindow
+ call assert_equal('test_quickfix.vim', bufname('test_quickfix.vim'))
+ cclose
+ %bwipe
+ " Create a quickfix list with a absolute path filename
+ call setqflist([], ' ', {'lines':[fname . ":20:Line20"], 'efm':'%f:%l:%m'})
+ call assert_equal(fname, bufname('test_quickfix.vim'))
+ " Displaying the quickfix list should simplify the file path
+ silent! clist
+ call assert_equal('test_quickfix.vim', bufname('test_quickfix.vim'))
+ endfunc
*** ../vim-8.0.1780/src/fileio.c 2018-04-30 15:40:39.481735733 +0200
--- src/fileio.c 2018-05-01 14:13:53.829267673 +0200
***************
*** 6163,6169 ****
}
/*
! * Shorten filenames for all buffers.
* When "force" is TRUE: Use full path from now on for files currently being
* edited, both for file name and swap file name. Try to shorten the file
* names a bit, if safe to do so.
--- 6163,6169 ----
}
/*
! * Shorten filename of a buffer.
* When "force" is TRUE: Use full path from now on for files currently being
* edited, both for file name and swap file name. Try to shorten the file
* names a bit, if safe to do so.
***************
*** 6172,6205 ****
* name.
*/
void
shorten_fnames(int force)
{
char_u dirname[MAXPATHL];
buf_T *buf;
- char_u *p;
mch_dirname(dirname, MAXPATHL);
FOR_ALL_BUFFERS(buf)
{
! if (buf->b_fname != NULL
! #ifdef FEAT_QUICKFIX
! && !bt_nofile(buf)
! #endif
! && !path_with_url(buf->b_fname)
! && (force
! || buf->b_sfname == NULL
! || mch_isFullName(buf->b_sfname)))
! {
! VIM_CLEAR(buf->b_sfname);
! p = shorten_fname(buf->b_ffname, dirname);
! if (p != NULL)
! {
! buf->b_sfname = vim_strsave(p);
! buf->b_fname = buf->b_sfname;
! }
! if (p == NULL || buf->b_fname == NULL)
! buf->b_fname = buf->b_ffname;
! }
/* Always make the swap file name a full path, a "nofile" buffer may
* also have a swap file. */
--- 6172,6215 ----
* name.
*/
void
+ shorten_buf_fname(buf_T *buf, char_u *dirname, int force)
+ {
+ char_u *p;
+
+ if (buf->b_fname != NULL
+ #ifdef FEAT_QUICKFIX
+ && !bt_nofile(buf)
+ #endif
+ && !path_with_url(buf->b_fname)
+ && (force
+ || buf->b_sfname == NULL
+ || mch_isFullName(buf->b_sfname)))
+ {
+ VIM_CLEAR(buf->b_sfname);
+ p = shorten_fname(buf->b_ffname, dirname);
+ if (p != NULL)
+ {
+ buf->b_sfname = vim_strsave(p);
+ buf->b_fname = buf->b_sfname;
+ }
+ if (p == NULL || buf->b_fname == NULL)
+ buf->b_fname = buf->b_ffname;
+ }
+ }
+
+ /*
+ * Shorten filenames for all buffers.
+ */
+ void
shorten_fnames(int force)
{
char_u dirname[MAXPATHL];
buf_T *buf;
mch_dirname(dirname, MAXPATHL);
FOR_ALL_BUFFERS(buf)
{
! shorten_buf_fname(buf, dirname, force);
/* Always make the swap file name a full path, a "nofile" buffer may
* also have a swap file. */
*** ../vim-8.0.1780/src/proto/fileio.pro 2018-02-10 18:15:00.758098776
+0100
--- src/proto/fileio.pro 2018-05-01 14:13:53.829267673 +0200
***************
*** 11,16 ****
--- 11,17 ----
void msg_add_lines(int insert_space, long lnum, off_T nchars);
char_u *shorten_fname1(char_u *full_path);
char_u *shorten_fname(char_u *full_path, char_u *dir_name);
+ void shorten_buf_fname(buf_T *buf, char_u *dirname, int force);
void shorten_fnames(int force);
void shorten_filenames(char_u **fnames, int count);
char_u *modname(char_u *fname, char_u *ext, int prepend_dot);
*** ../vim-8.0.1780/src/quickfix.c 2018-04-29 12:22:49.167522589 +0200
--- src/quickfix.c 2018-05-01 14:27:06.931849698 +0200
***************
*** 2736,2741 ****
--- 2736,2744 ----
idx2 = (-idx2 > i) ? 0 : idx2 + i + 1;
}
+ /* Shorten all the file names, so that it is easy to read */
+ shorten_fnames(FALSE);
+
/*
* Get the attributes for the different quickfix highlight items. Note
* that this depends on syntax items defined in the qf.vim syntax file
***************
*** 3542,3547 ****
--- 3545,3554 ----
/* Check if there is anything to display */
if (qi->qf_curlist < qi->qf_listcount)
{
+ char_u dirname[MAXPATHL];
+
+ *dirname = NUL;
+
/* Add one line for each error */
if (old_last == NULL)
{
***************
*** 3562,3568 ****
--- 3569,3585 ----
if (qfp->qf_type == 1) /* :helpgrep */
STRCPY(IObuff, gettail(errbuf->b_fname));
else
+ {
+ /* shorten the file name if not done already */
+ if (errbuf->b_sfname == NULL
+ || mch_isFullName(errbuf->b_sfname))
+ {
+ if (*dirname == NUL)
+ mch_dirname(dirname, MAXPATHL);
+ shorten_buf_fname(errbuf, dirname, FALSE);
+ }
STRCPY(IObuff, errbuf->b_fname);
+ }
len = (int)STRLEN(IObuff);
}
else
*** ../vim-8.0.1780/src/version.c 2018-04-30 18:03:06.260235050 +0200
--- src/version.c 2018-05-01 14:27:13.943803262 +0200
***************
*** 763,764 ****
--- 763,766 ----
{ /* Add new patch number below this line */
+ /**/
+ 1781,
/**/
--
LAUNCELOT leaps into SHOT with a mighty cry and runs the GUARD through and
hacks him to the floor. Blood. Swashbuckling music (perhaps).
LAUNCELOT races through into the castle screaming.
SECOND SENTRY: Hey!
"Monty Python and the Holy Grail" PYTHON (MONTY) PICTURES LTD
/// 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].
For more options, visit https://groups.google.com/d/optout.