Currently it's hard to distinguish between Quickfix or Location list windows.
Unless I'm mistaken, but when either window is open the only way I could check
which one is open is by using :ls and checking if it reports the name of any
buffer as "[Quickfix List]" or "[Location List]".
I think it would be much easier if function bufname() had a second argument and
when it's not zero it would return a special buffer name. Please see the patch
attached.
Regards,
Kent
--
--
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.
diff --git a/runtime/doc/eval.txt b/runtime/doc/eval.txt
index 04edbd3..c87a17a 100644
--- a/runtime/doc/eval.txt
+++ b/runtime/doc/eval.txt
@@ -1983,7 +1983,7 @@ browsedir({title}, {initdir}) String put up a directory requester
bufexists({expr}) Number |TRUE| if buffer {expr} exists
buflisted({expr}) Number |TRUE| if buffer {expr} is listed
bufloaded({expr}) Number |TRUE| if buffer {expr} is loaded
-bufname({expr}) String Name of the buffer {expr}
+bufname({expr} [, {special}]) String Name of the buffer {expr}
bufnr({expr} [, {create}]) Number Number of the buffer {expr}
bufwinid({expr}) Number window ID of buffer {expr}
bufwinnr({expr}) Number window number of buffer {expr}
@@ -2647,7 +2647,8 @@ bufloaded({expr}) *bufloaded()*
{expr} exists and is loaded (shown in a window or hidden).
The {expr} argument is used like with |bufexists()|.
-bufname({expr}) *bufname()*
+ *bufname()*
+bufname({expr} [, {special}])
The result is the name of a buffer, as it is displayed by the
":ls" command.
If {expr} is a Number, that buffer number's name is given.
@@ -2669,11 +2670,14 @@ bufname({expr}) *bufname()*
number, force it to be a Number by adding zero to it: >
:echo bufname("3" + 0)
< If the buffer doesn't exist, or doesn't have a name, an empty
- string is returned. >
+ string is returned.
+ If the {special} argument is present and not zero, a special
+ buffer name is returned instead. >
bufname("#") alternate buffer name
bufname(3) name of buffer 3
bufname("%") name of current buffer
bufname("file2") name of buffer where "file2" matches.
+ bufname("%", 1) "[Quickfix List]" for the quickfix window.
< *buffer_name()*
Obsolete name: buffer_name().
diff --git a/src/evalfunc.c b/src/evalfunc.c
index 0095661..46773cb 100644
--- a/src/evalfunc.c
+++ b/src/evalfunc.c
@@ -475,11 +475,11 @@ static struct fst
{"browsedir", 2, 2, f_browsedir},
{"bufexists", 1, 1, f_bufexists},
{"buffer_exists", 1, 1, f_bufexists}, /* obsolete */
- {"buffer_name", 1, 1, f_bufname}, /* obsolete */
+ {"buffer_name", 1, 2, f_bufname}, /* obsolete */
{"buffer_number", 1, 1, f_bufnr}, /* obsolete */
{"buflisted", 1, 1, f_buflisted},
{"bufloaded", 1, 1, f_bufloaded},
- {"bufname", 1, 1, f_bufname},
+ {"bufname", 1, 2, f_bufname},
{"bufnr", 1, 2, f_bufnr},
{"bufwinid", 1, 1, f_bufwinid},
{"bufwinnr", 1, 1, f_bufwinnr},
@@ -1543,16 +1543,33 @@ get_buf_tv(typval_T *tv, int curtab_only)
f_bufname(typval_T *argvars, typval_T *rettv)
{
buf_T *buf;
+ int error = FALSE;
+ char_u *name = NULL;
(void)get_tv_number(&argvars[0]); /* issue errmsg if type error */
++emsg_off;
buf = get_buf_tv(&argvars[0], FALSE);
+ --emsg_off;
+
rettv->v_type = VAR_STRING;
- if (buf != NULL && buf->b_fname != NULL)
+
+ /* If the buffer is found and the second argument is not zero return
+ * a special buffer name. */
+ if (buf != NULL
+ && argvars[1].v_type != VAR_UNKNOWN
+ && get_tv_number_chk(&argvars[1], &error) != 0
+ && !error)
+ {
+ name = buf_spname(buf);
+ if (name != NULL)
+ rettv->vval.v_string = vim_strsave(name);
+ else
+ rettv->vval.v_string = NULL;
+ }
+ else if (buf != NULL && buf->b_fname != NULL)
rettv->vval.v_string = vim_strsave(buf->b_fname);
else
rettv->vval.v_string = NULL;
- --emsg_off;
}
/*