mirror of
https://github.com/vim/vim.git
synced 2025-09-23 03:43:49 -04:00
patch 8.0.1781: file names in quickfix window are not shortened
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)
This commit is contained in:
52
src/fileio.c
52
src/fileio.c
@@ -6163,7 +6163,7 @@ shorten_fname(char_u *full_path, char_u *dir_name)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Shorten filenames for all buffers.
|
* Shorten filename of a buffer.
|
||||||
* When "force" is TRUE: Use full path from now on for files currently being
|
* 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
|
* edited, both for file name and swap file name. Try to shorten the file
|
||||||
* names a bit, if safe to do so.
|
* names a bit, if safe to do so.
|
||||||
@@ -6172,34 +6172,44 @@ shorten_fname(char_u *full_path, char_u *dir_name)
|
|||||||
* name.
|
* name.
|
||||||
*/
|
*/
|
||||||
void
|
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)
|
shorten_fnames(int force)
|
||||||
{
|
{
|
||||||
char_u dirname[MAXPATHL];
|
char_u dirname[MAXPATHL];
|
||||||
buf_T *buf;
|
buf_T *buf;
|
||||||
char_u *p;
|
|
||||||
|
|
||||||
mch_dirname(dirname, MAXPATHL);
|
mch_dirname(dirname, MAXPATHL);
|
||||||
FOR_ALL_BUFFERS(buf)
|
FOR_ALL_BUFFERS(buf)
|
||||||
{
|
{
|
||||||
if (buf->b_fname != NULL
|
shorten_buf_fname(buf, dirname, force);
|
||||||
#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
|
/* Always make the swap file name a full path, a "nofile" buffer may
|
||||||
* also have a swap file. */
|
* also have a swap file. */
|
||||||
|
@@ -11,6 +11,7 @@ void msg_add_fname(buf_T *buf, char_u *fname);
|
|||||||
void msg_add_lines(int insert_space, long lnum, off_T nchars);
|
void msg_add_lines(int insert_space, long lnum, off_T nchars);
|
||||||
char_u *shorten_fname1(char_u *full_path);
|
char_u *shorten_fname1(char_u *full_path);
|
||||||
char_u *shorten_fname(char_u *full_path, char_u *dir_name);
|
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_fnames(int force);
|
||||||
void shorten_filenames(char_u **fnames, int count);
|
void shorten_filenames(char_u **fnames, int count);
|
||||||
char_u *modname(char_u *fname, char_u *ext, int prepend_dot);
|
char_u *modname(char_u *fname, char_u *ext, int prepend_dot);
|
||||||
|
@@ -2736,6 +2736,9 @@ qf_list(exarg_T *eap)
|
|||||||
idx2 = (-idx2 > i) ? 0 : idx2 + i + 1;
|
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
|
* Get the attributes for the different quickfix highlight items. Note
|
||||||
* that this depends on syntax items defined in the qf.vim syntax file
|
* that this depends on syntax items defined in the qf.vim syntax file
|
||||||
@@ -3542,6 +3545,10 @@ qf_fill_buffer(qf_info_T *qi, buf_T *buf, qfline_T *old_last)
|
|||||||
/* Check if there is anything to display */
|
/* Check if there is anything to display */
|
||||||
if (qi->qf_curlist < qi->qf_listcount)
|
if (qi->qf_curlist < qi->qf_listcount)
|
||||||
{
|
{
|
||||||
|
char_u dirname[MAXPATHL];
|
||||||
|
|
||||||
|
*dirname = NUL;
|
||||||
|
|
||||||
/* Add one line for each error */
|
/* Add one line for each error */
|
||||||
if (old_last == NULL)
|
if (old_last == NULL)
|
||||||
{
|
{
|
||||||
@@ -3562,7 +3569,17 @@ qf_fill_buffer(qf_info_T *qi, buf_T *buf, qfline_T *old_last)
|
|||||||
if (qfp->qf_type == 1) /* :helpgrep */
|
if (qfp->qf_type == 1) /* :helpgrep */
|
||||||
STRCPY(IObuff, gettail(errbuf->b_fname));
|
STRCPY(IObuff, gettail(errbuf->b_fname));
|
||||||
else
|
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);
|
STRCPY(IObuff, errbuf->b_fname);
|
||||||
|
}
|
||||||
len = (int)STRLEN(IObuff);
|
len = (int)STRLEN(IObuff);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@@ -3201,3 +3201,27 @@ func Test_lhelpgrep_autocmd()
|
|||||||
au! QuickFixCmdPost
|
au! QuickFixCmdPost
|
||||||
new | only
|
new | only
|
||||||
endfunc
|
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
|
||||||
|
@@ -761,6 +761,8 @@ static char *(features[]) =
|
|||||||
|
|
||||||
static int included_patches[] =
|
static int included_patches[] =
|
||||||
{ /* Add new patch number below this line */
|
{ /* Add new patch number below this line */
|
||||||
|
/**/
|
||||||
|
1781,
|
||||||
/**/
|
/**/
|
||||||
1780,
|
1780,
|
||||||
/**/
|
/**/
|
||||||
|
Reference in New Issue
Block a user