Context: rename "buflist" => "bufs"

Given the other type names "jumps", "vars", etc., the name "buflist"
is somewhat unintuitive.
This commit is contained in:
Justin M. Keyes 2019-09-14 18:52:16 -07:00
parent f2c75ef9b4
commit ffdf8c4c12
8 changed files with 46 additions and 46 deletions

View File

@ -1003,14 +1003,14 @@ like the current |jumplist|, values of |registers|, and more, described below.
The following Context items are supported:
"jumps" |jumplist|
"regs" |registers|
"buflist" |buffer-list|
"bufs" |buffer-list|
"gvars" |global-variable|s
"sfuncs" |script-local| functions
"funcs" global and |script-local| functions
*context-dict*
Context objects are dictionaries with the following key-value pairs:
- "jumps", "regs", "buflist", "gvars":
- "jumps", "regs", "bufs", "gvars":
|readfile()|-style |List| representation of corresponding msgpack
objects (see |msgpackdump()| and |msgpackparse()|).
- "funcs" (includes |script-local| functions as well):

View File

@ -1419,7 +1419,7 @@ Dictionary nvim_get_color_map(void)
/// Gets a map of the current editor state.
///
/// @param opts Optional parameters.
/// - types: List of |context-types| ("regs", "jumps", "buflist",
/// - types: List of |context-types| ("regs", "jumps", "bufs",
/// "gvars", …) to gather, or empty for "all".
/// @param[out] err Error details, if any
///
@ -1453,8 +1453,8 @@ Dictionary nvim_get_context(Dictionary opts, Error *err)
int_types |= kCtxRegs;
} else if (strequal(s, "jumps")) {
int_types |= kCtxJumps;
} else if (strequal(s, "buflist")) {
int_types |= kCtxBuflist;
} else if (strequal(s, "bufs")) {
int_types |= kCtxBufs;
} else if (strequal(s, "gvars")) {
int_types |= kCtxGVars;
} else if (strequal(s, "sfuncs")) {

View File

@ -15,7 +15,7 @@
# include "context.c.generated.h"
#endif
int kCtxAll = (kCtxRegs | kCtxJumps | kCtxBuflist | kCtxGVars | kCtxSFuncs
int kCtxAll = (kCtxRegs | kCtxJumps | kCtxBufs | kCtxGVars | kCtxSFuncs
| kCtxFuncs);
static ContextVec ctx_stack = KV_INITIAL_VALUE;
@ -57,8 +57,8 @@ void ctx_free(Context *ctx)
if (ctx->jumps.data) {
msgpack_sbuffer_destroy(&ctx->jumps);
}
if (ctx->buflist.data) {
msgpack_sbuffer_destroy(&ctx->buflist);
if (ctx->bufs.data) {
msgpack_sbuffer_destroy(&ctx->bufs);
}
if (ctx->gvars.data) {
msgpack_sbuffer_destroy(&ctx->gvars);
@ -90,8 +90,8 @@ void ctx_save(Context *ctx, const int flags)
ctx_save_jumps(ctx);
}
if (flags & kCtxBuflist) {
ctx_save_buflist(ctx);
if (flags & kCtxBufs) {
ctx_save_bufs(ctx);
}
if (flags & kCtxGVars) {
@ -137,8 +137,8 @@ bool ctx_restore(Context *ctx, const int flags)
ctx_restore_jumps(ctx);
}
if (flags & kCtxBuflist) {
ctx_restore_buflist(ctx);
if (flags & kCtxBufs) {
ctx_restore_bufs(ctx);
}
if (flags & kCtxGVars) {
@ -200,20 +200,20 @@ static inline void ctx_restore_jumps(Context *ctx)
/// Saves the buffer list to a context.
///
/// @param ctx Save to this context.
static inline void ctx_save_buflist(Context *ctx)
static inline void ctx_save_bufs(Context *ctx)
FUNC_ATTR_NONNULL_ALL
{
msgpack_sbuffer_init(&ctx->buflist);
shada_encode_buflist(&ctx->buflist);
msgpack_sbuffer_init(&ctx->bufs);
shada_encode_buflist(&ctx->bufs);
}
/// Restores the buffer list from a context.
///
/// @param ctx Restore from this context.
static inline void ctx_restore_buflist(Context *ctx)
static inline void ctx_restore_bufs(Context *ctx)
FUNC_ATTR_NONNULL_ALL
{
shada_read_sbuf(&ctx->buflist, kShaDaWantInfo | kShaDaForceit);
shada_read_sbuf(&ctx->bufs, kShaDaWantInfo | kShaDaForceit);
}
/// Saves global variables to a context.
@ -337,7 +337,7 @@ Dictionary ctx_to_dict(Context *ctx)
PUT(rv, "regs", ARRAY_OBJ(sbuf_to_array(ctx->regs)));
PUT(rv, "jumps", ARRAY_OBJ(sbuf_to_array(ctx->jumps)));
PUT(rv, "buflist", ARRAY_OBJ(sbuf_to_array(ctx->buflist)));
PUT(rv, "bufs", ARRAY_OBJ(sbuf_to_array(ctx->bufs)));
PUT(rv, "gvars", ARRAY_OBJ(sbuf_to_array(ctx->gvars)));
PUT(rv, "funcs", ARRAY_OBJ(copy_array(ctx->funcs)));
@ -367,9 +367,9 @@ int ctx_from_dict(Dictionary dict, Context *ctx)
} else if (strequal(item.key.data, "jumps")) {
types |= kCtxJumps;
ctx->jumps = array_to_sbuf(item.value.data.array);
} else if (strequal(item.key.data, "buflist")) {
types |= kCtxBuflist;
ctx->buflist = array_to_sbuf(item.value.data.array);
} else if (strequal(item.key.data, "bufs")) {
types |= kCtxBufs;
ctx->bufs = array_to_sbuf(item.value.data.array);
} else if (strequal(item.key.data, "gvars")) {
types |= kCtxGVars;
ctx->gvars = array_to_sbuf(item.value.data.array);

View File

@ -8,7 +8,7 @@
typedef struct {
msgpack_sbuffer regs; ///< Registers.
msgpack_sbuffer jumps; ///< Jumplist.
msgpack_sbuffer buflist; ///< Buffer list.
msgpack_sbuffer bufs; ///< Buffer list.
msgpack_sbuffer gvars; ///< Global variables.
Array funcs; ///< Functions.
} Context;
@ -23,7 +23,7 @@ typedef kvec_t(Context) ContextVec;
#define CONTEXT_INIT (Context) { \
.regs = MSGPACK_SBUFFER_INIT, \
.jumps = MSGPACK_SBUFFER_INIT, \
.buflist = MSGPACK_SBUFFER_INIT, \
.bufs = MSGPACK_SBUFFER_INIT, \
.gvars = MSGPACK_SBUFFER_INIT, \
.funcs = ARRAY_DICT_INIT, \
}
@ -31,7 +31,7 @@ typedef kvec_t(Context) ContextVec;
typedef enum {
kCtxRegs = 1, ///< Registers
kCtxJumps = 2, ///< Jumplist
kCtxBuflist = 4, ///< Buffer list
kCtxBufs = 4, ///< Buffer list
kCtxGVars = 8, ///< Global variables
kCtxSFuncs = 16, ///< Script functions
kCtxFuncs = 32, ///< Functions

View File

@ -8002,8 +8002,8 @@ static void f_ctxpush(typval_T *argvars, typval_T *rettv, FunPtr fptr)
types |= kCtxRegs;
} else if (strequal((char *)tv_li->vval.v_string, "jumps")) {
types |= kCtxJumps;
} else if (strequal((char *)tv_li->vval.v_string, "buflist")) {
types |= kCtxBuflist;
} else if (strequal((char *)tv_li->vval.v_string, "bufs")) {
types |= kCtxBufs;
} else if (strequal((char *)tv_li->vval.v_string, "gvars")) {
types |= kCtxGVars;
} else if (strequal((char *)tv_li->vval.v_string, "sfuncs")) {

View File

@ -903,7 +903,7 @@ describe('API', function()
pcall_err(nvim, 'get_context', {types={'jumps', 'zub', 'zam',}}))
end)
it('returns map of current editor state', function()
local opts = {types={'regs', 'jumps', 'buflist', 'gvars'}}
local opts = {types={'regs', 'jumps', 'bufs', 'gvars'}}
eq({}, parse_context(nvim('get_context', {})))
feed('i1<cr>2<cr>3<c-[>ddddddqahjklquuu')
@ -929,7 +929,7 @@ describe('API', function()
{ k, v -> k != "l" || v != 1 })'), '!empty(v:val.f)')
]]):gsub('\n', '')),
['buflist'] = eval([[
['bufs'] = eval([[
filter(map(getbufinfo(), '{ "f": v:val.name }'), '!empty(v:val.f)')
]]),
@ -944,7 +944,7 @@ describe('API', function()
describe('nvim_load_context', function()
it('sets current editor state to given context dictionary', function()
local opts = {types={'regs', 'jumps', 'buflist', 'gvars'}}
local opts = {types={'regs', 'jumps', 'bufs', 'gvars'}}
eq({}, parse_context(nvim('get_context', opts)))
nvim('set_var', 'one', 1)

View File

@ -82,21 +82,21 @@ describe('context functions', function()
command('edit '..fname1)
command('edit '..fname2)
command('edit TEST')
local buflist = call('map', call('getbufinfo'), 'v:val.name')
local bufs = call('map', call('getbufinfo'), 'v:val.name')
call('ctxpush')
call('ctxpush', {'buflist'})
call('ctxpush', {'bufs'})
command('%bwipeout')
eq({''}, call('map', call('getbufinfo'), 'v:val.name'))
call('ctxpop')
eq({'', unpack(buflist)}, call('map', call('getbufinfo'), 'v:val.name'))
eq({'', unpack(bufs)}, call('map', call('getbufinfo'), 'v:val.name'))
command('%bwipeout')
eq({''}, call('map', call('getbufinfo'), 'v:val.name'))
call('ctxpop')
eq({'', unpack(buflist)}, call('map', call('getbufinfo'), 'v:val.name'))
eq({'', unpack(bufs)}, call('map', call('getbufinfo'), 'v:val.name'))
end)
it('saves and restores global variables properly', function()
@ -297,8 +297,8 @@ describe('context functions', function()
]]):gsub('\n', ''))
}
local with_buflist = {
['buflist'] = eval([[
local with_bufs = {
['bufs'] = eval([[
filter(map(getbufinfo(), '{ "f": v:val.name }'), '!empty(v:val.f)')
]])
}
@ -310,7 +310,7 @@ describe('context functions', function()
local with_all = {
['regs'] = with_regs['regs'],
['jumps'] = with_jumps['jumps'],
['buflist'] = with_buflist['buflist'],
['bufs'] = with_bufs['bufs'],
['gvars'] = with_gvars['gvars'],
}
@ -323,16 +323,16 @@ describe('context functions', function()
eq(with_gvars, parse_context(call('ctxget', 0)))
eq(with_all, parse_context(call('ctxget', 1)))
call('ctxpush', {'buflist'})
eq(with_buflist, parse_context(call('ctxget')))
eq(with_buflist, parse_context(call('ctxget', 0)))
call('ctxpush', {'bufs'})
eq(with_bufs, parse_context(call('ctxget')))
eq(with_bufs, parse_context(call('ctxget', 0)))
eq(with_gvars, parse_context(call('ctxget', 1)))
eq(with_all, parse_context(call('ctxget', 2)))
call('ctxpush', {'jumps'})
eq(with_jumps, parse_context(call('ctxget')))
eq(with_jumps, parse_context(call('ctxget', 0)))
eq(with_buflist, parse_context(call('ctxget', 1)))
eq(with_bufs, parse_context(call('ctxget', 1)))
eq(with_gvars, parse_context(call('ctxget', 2)))
eq(with_all, parse_context(call('ctxget', 3)))
@ -340,20 +340,20 @@ describe('context functions', function()
eq(with_regs, parse_context(call('ctxget')))
eq(with_regs, parse_context(call('ctxget', 0)))
eq(with_jumps, parse_context(call('ctxget', 1)))
eq(with_buflist, parse_context(call('ctxget', 2)))
eq(with_bufs, parse_context(call('ctxget', 2)))
eq(with_gvars, parse_context(call('ctxget', 3)))
eq(with_all, parse_context(call('ctxget', 4)))
call('ctxpop')
eq(with_jumps, parse_context(call('ctxget')))
eq(with_jumps, parse_context(call('ctxget', 0)))
eq(with_buflist, parse_context(call('ctxget', 1)))
eq(with_bufs, parse_context(call('ctxget', 1)))
eq(with_gvars, parse_context(call('ctxget', 2)))
eq(with_all, parse_context(call('ctxget', 3)))
call('ctxpop')
eq(with_buflist, parse_context(call('ctxget')))
eq(with_buflist, parse_context(call('ctxget', 0)))
eq(with_bufs, parse_context(call('ctxget')))
eq(with_bufs, parse_context(call('ctxget', 0)))
eq(with_gvars, parse_context(call('ctxget', 1)))
eq(with_all, parse_context(call('ctxget', 2)))

View File

@ -777,12 +777,12 @@ end
function module.parse_context(ctx)
local parsed = {}
for _, item in ipairs({'regs', 'jumps', 'buflist', 'gvars'}) do
for _, item in ipairs({'regs', 'jumps', 'bufs', 'gvars'}) do
parsed[item] = filter(function(v)
return type(v) == 'table'
end, module.call('msgpackparse', ctx[item]))
end
parsed['buflist'] = parsed['buflist'][1]
parsed['bufs'] = parsed['bufs'][1]
return map(function(v)
if #v == 0 then
return nil