On Saturday, August 6, 2016 at 1:02:18 PM UTC-4, Bram Moolenaar wrote:
>
> The problem with this solution is that the names are translated.
> A more direct solution would be better.
>
> The 'buftype' option is "quickfix" for both quickfix and location list.
> We can't change that without causing problems.
>
> Perhaps we should add a buftype({expr}) function, that can get the
> buffer type of any buffer, and make a difference between "quickfix" and
> "loclist".
I see. Even though it's quite awkward to add a new function just to accommodate
this particular case, i'm attaching my attempt to implement it.
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/src/evalfunc.c b/src/evalfunc.c
index 8b5ad22..035a68c 100644
--- a/src/evalfunc.c
+++ b/src/evalfunc.c
@@ -65,6 +65,7 @@ static void f_buflisted(typval_T *argvars, typval_T *rettv);
static void f_bufloaded(typval_T *argvars, typval_T *rettv);
static void f_bufname(typval_T *argvars, typval_T *rettv);
static void f_bufnr(typval_T *argvars, typval_T *rettv);
+static void f_buftype(typval_T *argvars, typval_T *rettv);
static void f_bufwinid(typval_T *argvars, typval_T *rettv);
static void f_bufwinnr(typval_T *argvars, typval_T *rettv);
static void f_byte2line(typval_T *argvars, typval_T *rettv);
@@ -484,6 +485,7 @@ static struct fst
{"bufloaded", 1, 1, f_bufloaded},
{"bufname", 1, 1, f_bufname},
{"bufnr", 1, 2, f_bufnr},
+ {"buftype", 1, 1, f_buftype},
{"bufwinid", 1, 1, f_bufwinid},
{"bufwinnr", 1, 1, f_bufwinnr},
{"byte2line", 1, 1, f_byte2line},
@@ -1592,6 +1594,41 @@ f_bufnr(typval_T *argvars, typval_T *rettv)
rettv->vval.v_number = -1;
}
+/*
+ * "buftype(expr)" function
+ */
+ static void
+f_buftype(typval_T *argvars, typval_T *rettv)
+{
+ buf_T *buf;
+ win_T *win;
+ char_u *val;
+ tabpage_T *tp;
+
+ (void)get_tv_number(&argvars[0]); /* issue errmsg if type error */
+ ++emsg_off;
+ buf = get_buf_tv(&argvars[0], FALSE);
+ rettv->v_type = VAR_STRING;
+ if (buf != NULL && buf->b_p_bt != NULL)
+ {
+ val = buf->b_p_bt;
+#if defined(FEAT_QUICKFIX) && defined(FEAT_WINDOWS)
+ /*
+ * For location list window, w_llist_ref points to the location list.
+ * For quickfix window, w_llist_ref is NULL.
+ */
+ if (bt_quickfix(buf)
+ && find_win_for_buf(buf, &win, &tp) == OK
+ && win->w_llist_ref != NULL)
+ val = (char_u *)"loclist";
+#endif
+ rettv->vval.v_string = vim_strsave(val);
+ }
+ else
+ rettv->vval.v_string = NULL;
+ --emsg_off;
+}
+
static void
buf_win_common(typval_T *argvars, typval_T *rettv, int get_nr)
{