mirror of
https://github.com/neovim/neovim.git
synced 2025-10-08 02:46:31 +00:00
Context: rename "buflist" => "bufs"
Given the other type names "jumps", "vars", etc., the name "buflist" is somewhat unintuitive.
This commit is contained in:
@@ -1003,14 +1003,14 @@ like the current |jumplist|, values of |registers|, and more, described below.
|
|||||||
The following Context items are supported:
|
The following Context items are supported:
|
||||||
"jumps" |jumplist|
|
"jumps" |jumplist|
|
||||||
"regs" |registers|
|
"regs" |registers|
|
||||||
"buflist" |buffer-list|
|
"bufs" |buffer-list|
|
||||||
"gvars" |global-variable|s
|
"gvars" |global-variable|s
|
||||||
"sfuncs" |script-local| functions
|
"sfuncs" |script-local| functions
|
||||||
"funcs" global and |script-local| functions
|
"funcs" global and |script-local| functions
|
||||||
|
|
||||||
*context-dict*
|
*context-dict*
|
||||||
Context objects are dictionaries with the following key-value pairs:
|
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
|
|readfile()|-style |List| representation of corresponding msgpack
|
||||||
objects (see |msgpackdump()| and |msgpackparse()|).
|
objects (see |msgpackdump()| and |msgpackparse()|).
|
||||||
- "funcs" (includes |script-local| functions as well):
|
- "funcs" (includes |script-local| functions as well):
|
||||||
|
@@ -1419,7 +1419,7 @@ Dictionary nvim_get_color_map(void)
|
|||||||
/// Gets a map of the current editor state.
|
/// Gets a map of the current editor state.
|
||||||
///
|
///
|
||||||
/// @param opts Optional parameters.
|
/// @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".
|
/// "gvars", …) to gather, or empty for "all".
|
||||||
/// @param[out] err Error details, if any
|
/// @param[out] err Error details, if any
|
||||||
///
|
///
|
||||||
@@ -1453,8 +1453,8 @@ Dictionary nvim_get_context(Dictionary opts, Error *err)
|
|||||||
int_types |= kCtxRegs;
|
int_types |= kCtxRegs;
|
||||||
} else if (strequal(s, "jumps")) {
|
} else if (strequal(s, "jumps")) {
|
||||||
int_types |= kCtxJumps;
|
int_types |= kCtxJumps;
|
||||||
} else if (strequal(s, "buflist")) {
|
} else if (strequal(s, "bufs")) {
|
||||||
int_types |= kCtxBuflist;
|
int_types |= kCtxBufs;
|
||||||
} else if (strequal(s, "gvars")) {
|
} else if (strequal(s, "gvars")) {
|
||||||
int_types |= kCtxGVars;
|
int_types |= kCtxGVars;
|
||||||
} else if (strequal(s, "sfuncs")) {
|
} else if (strequal(s, "sfuncs")) {
|
||||||
|
@@ -15,7 +15,7 @@
|
|||||||
# include "context.c.generated.h"
|
# include "context.c.generated.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
int kCtxAll = (kCtxRegs | kCtxJumps | kCtxBuflist | kCtxGVars | kCtxSFuncs
|
int kCtxAll = (kCtxRegs | kCtxJumps | kCtxBufs | kCtxGVars | kCtxSFuncs
|
||||||
| kCtxFuncs);
|
| kCtxFuncs);
|
||||||
|
|
||||||
static ContextVec ctx_stack = KV_INITIAL_VALUE;
|
static ContextVec ctx_stack = KV_INITIAL_VALUE;
|
||||||
@@ -57,8 +57,8 @@ void ctx_free(Context *ctx)
|
|||||||
if (ctx->jumps.data) {
|
if (ctx->jumps.data) {
|
||||||
msgpack_sbuffer_destroy(&ctx->jumps);
|
msgpack_sbuffer_destroy(&ctx->jumps);
|
||||||
}
|
}
|
||||||
if (ctx->buflist.data) {
|
if (ctx->bufs.data) {
|
||||||
msgpack_sbuffer_destroy(&ctx->buflist);
|
msgpack_sbuffer_destroy(&ctx->bufs);
|
||||||
}
|
}
|
||||||
if (ctx->gvars.data) {
|
if (ctx->gvars.data) {
|
||||||
msgpack_sbuffer_destroy(&ctx->gvars);
|
msgpack_sbuffer_destroy(&ctx->gvars);
|
||||||
@@ -90,8 +90,8 @@ void ctx_save(Context *ctx, const int flags)
|
|||||||
ctx_save_jumps(ctx);
|
ctx_save_jumps(ctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (flags & kCtxBuflist) {
|
if (flags & kCtxBufs) {
|
||||||
ctx_save_buflist(ctx);
|
ctx_save_bufs(ctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (flags & kCtxGVars) {
|
if (flags & kCtxGVars) {
|
||||||
@@ -137,8 +137,8 @@ bool ctx_restore(Context *ctx, const int flags)
|
|||||||
ctx_restore_jumps(ctx);
|
ctx_restore_jumps(ctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (flags & kCtxBuflist) {
|
if (flags & kCtxBufs) {
|
||||||
ctx_restore_buflist(ctx);
|
ctx_restore_bufs(ctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (flags & kCtxGVars) {
|
if (flags & kCtxGVars) {
|
||||||
@@ -200,20 +200,20 @@ static inline void ctx_restore_jumps(Context *ctx)
|
|||||||
/// Saves the buffer list to a context.
|
/// Saves the buffer list to a context.
|
||||||
///
|
///
|
||||||
/// @param ctx Save to this 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
|
FUNC_ATTR_NONNULL_ALL
|
||||||
{
|
{
|
||||||
msgpack_sbuffer_init(&ctx->buflist);
|
msgpack_sbuffer_init(&ctx->bufs);
|
||||||
shada_encode_buflist(&ctx->buflist);
|
shada_encode_buflist(&ctx->bufs);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Restores the buffer list from a context.
|
/// Restores the buffer list from a context.
|
||||||
///
|
///
|
||||||
/// @param ctx Restore from this 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
|
FUNC_ATTR_NONNULL_ALL
|
||||||
{
|
{
|
||||||
shada_read_sbuf(&ctx->buflist, kShaDaWantInfo | kShaDaForceit);
|
shada_read_sbuf(&ctx->bufs, kShaDaWantInfo | kShaDaForceit);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Saves global variables to a context.
|
/// 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, "regs", ARRAY_OBJ(sbuf_to_array(ctx->regs)));
|
||||||
PUT(rv, "jumps", ARRAY_OBJ(sbuf_to_array(ctx->jumps)));
|
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, "gvars", ARRAY_OBJ(sbuf_to_array(ctx->gvars)));
|
||||||
PUT(rv, "funcs", ARRAY_OBJ(copy_array(ctx->funcs)));
|
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")) {
|
} else if (strequal(item.key.data, "jumps")) {
|
||||||
types |= kCtxJumps;
|
types |= kCtxJumps;
|
||||||
ctx->jumps = array_to_sbuf(item.value.data.array);
|
ctx->jumps = array_to_sbuf(item.value.data.array);
|
||||||
} else if (strequal(item.key.data, "buflist")) {
|
} else if (strequal(item.key.data, "bufs")) {
|
||||||
types |= kCtxBuflist;
|
types |= kCtxBufs;
|
||||||
ctx->buflist = array_to_sbuf(item.value.data.array);
|
ctx->bufs = array_to_sbuf(item.value.data.array);
|
||||||
} else if (strequal(item.key.data, "gvars")) {
|
} else if (strequal(item.key.data, "gvars")) {
|
||||||
types |= kCtxGVars;
|
types |= kCtxGVars;
|
||||||
ctx->gvars = array_to_sbuf(item.value.data.array);
|
ctx->gvars = array_to_sbuf(item.value.data.array);
|
||||||
|
@@ -8,7 +8,7 @@
|
|||||||
typedef struct {
|
typedef struct {
|
||||||
msgpack_sbuffer regs; ///< Registers.
|
msgpack_sbuffer regs; ///< Registers.
|
||||||
msgpack_sbuffer jumps; ///< Jumplist.
|
msgpack_sbuffer jumps; ///< Jumplist.
|
||||||
msgpack_sbuffer buflist; ///< Buffer list.
|
msgpack_sbuffer bufs; ///< Buffer list.
|
||||||
msgpack_sbuffer gvars; ///< Global variables.
|
msgpack_sbuffer gvars; ///< Global variables.
|
||||||
Array funcs; ///< Functions.
|
Array funcs; ///< Functions.
|
||||||
} Context;
|
} Context;
|
||||||
@@ -23,7 +23,7 @@ typedef kvec_t(Context) ContextVec;
|
|||||||
#define CONTEXT_INIT (Context) { \
|
#define CONTEXT_INIT (Context) { \
|
||||||
.regs = MSGPACK_SBUFFER_INIT, \
|
.regs = MSGPACK_SBUFFER_INIT, \
|
||||||
.jumps = MSGPACK_SBUFFER_INIT, \
|
.jumps = MSGPACK_SBUFFER_INIT, \
|
||||||
.buflist = MSGPACK_SBUFFER_INIT, \
|
.bufs = MSGPACK_SBUFFER_INIT, \
|
||||||
.gvars = MSGPACK_SBUFFER_INIT, \
|
.gvars = MSGPACK_SBUFFER_INIT, \
|
||||||
.funcs = ARRAY_DICT_INIT, \
|
.funcs = ARRAY_DICT_INIT, \
|
||||||
}
|
}
|
||||||
@@ -31,7 +31,7 @@ typedef kvec_t(Context) ContextVec;
|
|||||||
typedef enum {
|
typedef enum {
|
||||||
kCtxRegs = 1, ///< Registers
|
kCtxRegs = 1, ///< Registers
|
||||||
kCtxJumps = 2, ///< Jumplist
|
kCtxJumps = 2, ///< Jumplist
|
||||||
kCtxBuflist = 4, ///< Buffer list
|
kCtxBufs = 4, ///< Buffer list
|
||||||
kCtxGVars = 8, ///< Global variables
|
kCtxGVars = 8, ///< Global variables
|
||||||
kCtxSFuncs = 16, ///< Script functions
|
kCtxSFuncs = 16, ///< Script functions
|
||||||
kCtxFuncs = 32, ///< Functions
|
kCtxFuncs = 32, ///< Functions
|
||||||
|
@@ -8002,8 +8002,8 @@ static void f_ctxpush(typval_T *argvars, typval_T *rettv, FunPtr fptr)
|
|||||||
types |= kCtxRegs;
|
types |= kCtxRegs;
|
||||||
} else if (strequal((char *)tv_li->vval.v_string, "jumps")) {
|
} else if (strequal((char *)tv_li->vval.v_string, "jumps")) {
|
||||||
types |= kCtxJumps;
|
types |= kCtxJumps;
|
||||||
} else if (strequal((char *)tv_li->vval.v_string, "buflist")) {
|
} else if (strequal((char *)tv_li->vval.v_string, "bufs")) {
|
||||||
types |= kCtxBuflist;
|
types |= kCtxBufs;
|
||||||
} else if (strequal((char *)tv_li->vval.v_string, "gvars")) {
|
} else if (strequal((char *)tv_li->vval.v_string, "gvars")) {
|
||||||
types |= kCtxGVars;
|
types |= kCtxGVars;
|
||||||
} else if (strequal((char *)tv_li->vval.v_string, "sfuncs")) {
|
} else if (strequal((char *)tv_li->vval.v_string, "sfuncs")) {
|
||||||
|
@@ -903,7 +903,7 @@ describe('API', function()
|
|||||||
pcall_err(nvim, 'get_context', {types={'jumps', 'zub', 'zam',}}))
|
pcall_err(nvim, 'get_context', {types={'jumps', 'zub', 'zam',}}))
|
||||||
end)
|
end)
|
||||||
it('returns map of current editor state', function()
|
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', {})))
|
eq({}, parse_context(nvim('get_context', {})))
|
||||||
|
|
||||||
feed('i1<cr>2<cr>3<c-[>ddddddqahjklquuu')
|
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)')
|
{ k, v -> k != "l" || v != 1 })'), '!empty(v:val.f)')
|
||||||
]]):gsub('\n', '')),
|
]]):gsub('\n', '')),
|
||||||
|
|
||||||
['buflist'] = eval([[
|
['bufs'] = eval([[
|
||||||
filter(map(getbufinfo(), '{ "f": v:val.name }'), '!empty(v:val.f)')
|
filter(map(getbufinfo(), '{ "f": v:val.name }'), '!empty(v:val.f)')
|
||||||
]]),
|
]]),
|
||||||
|
|
||||||
@@ -944,7 +944,7 @@ describe('API', function()
|
|||||||
|
|
||||||
describe('nvim_load_context', function()
|
describe('nvim_load_context', function()
|
||||||
it('sets current editor state to given context dictionary', 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)))
|
eq({}, parse_context(nvim('get_context', opts)))
|
||||||
|
|
||||||
nvim('set_var', 'one', 1)
|
nvim('set_var', 'one', 1)
|
||||||
|
@@ -82,21 +82,21 @@ describe('context functions', function()
|
|||||||
command('edit '..fname1)
|
command('edit '..fname1)
|
||||||
command('edit '..fname2)
|
command('edit '..fname2)
|
||||||
command('edit TEST')
|
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')
|
||||||
call('ctxpush', {'buflist'})
|
call('ctxpush', {'bufs'})
|
||||||
|
|
||||||
command('%bwipeout')
|
command('%bwipeout')
|
||||||
eq({''}, call('map', call('getbufinfo'), 'v:val.name'))
|
eq({''}, call('map', call('getbufinfo'), 'v:val.name'))
|
||||||
|
|
||||||
call('ctxpop')
|
call('ctxpop')
|
||||||
eq({'', unpack(buflist)}, call('map', call('getbufinfo'), 'v:val.name'))
|
eq({'', unpack(bufs)}, call('map', call('getbufinfo'), 'v:val.name'))
|
||||||
|
|
||||||
command('%bwipeout')
|
command('%bwipeout')
|
||||||
eq({''}, call('map', call('getbufinfo'), 'v:val.name'))
|
eq({''}, call('map', call('getbufinfo'), 'v:val.name'))
|
||||||
|
|
||||||
call('ctxpop')
|
call('ctxpop')
|
||||||
eq({'', unpack(buflist)}, call('map', call('getbufinfo'), 'v:val.name'))
|
eq({'', unpack(bufs)}, call('map', call('getbufinfo'), 'v:val.name'))
|
||||||
end)
|
end)
|
||||||
|
|
||||||
it('saves and restores global variables properly', function()
|
it('saves and restores global variables properly', function()
|
||||||
@@ -297,8 +297,8 @@ describe('context functions', function()
|
|||||||
]]):gsub('\n', ''))
|
]]):gsub('\n', ''))
|
||||||
}
|
}
|
||||||
|
|
||||||
local with_buflist = {
|
local with_bufs = {
|
||||||
['buflist'] = eval([[
|
['bufs'] = eval([[
|
||||||
filter(map(getbufinfo(), '{ "f": v:val.name }'), '!empty(v:val.f)')
|
filter(map(getbufinfo(), '{ "f": v:val.name }'), '!empty(v:val.f)')
|
||||||
]])
|
]])
|
||||||
}
|
}
|
||||||
@@ -310,7 +310,7 @@ describe('context functions', function()
|
|||||||
local with_all = {
|
local with_all = {
|
||||||
['regs'] = with_regs['regs'],
|
['regs'] = with_regs['regs'],
|
||||||
['jumps'] = with_jumps['jumps'],
|
['jumps'] = with_jumps['jumps'],
|
||||||
['buflist'] = with_buflist['buflist'],
|
['bufs'] = with_bufs['bufs'],
|
||||||
['gvars'] = with_gvars['gvars'],
|
['gvars'] = with_gvars['gvars'],
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -323,16 +323,16 @@ describe('context functions', function()
|
|||||||
eq(with_gvars, parse_context(call('ctxget', 0)))
|
eq(with_gvars, parse_context(call('ctxget', 0)))
|
||||||
eq(with_all, parse_context(call('ctxget', 1)))
|
eq(with_all, parse_context(call('ctxget', 1)))
|
||||||
|
|
||||||
call('ctxpush', {'buflist'})
|
call('ctxpush', {'bufs'})
|
||||||
eq(with_buflist, parse_context(call('ctxget')))
|
eq(with_bufs, parse_context(call('ctxget')))
|
||||||
eq(with_buflist, parse_context(call('ctxget', 0)))
|
eq(with_bufs, parse_context(call('ctxget', 0)))
|
||||||
eq(with_gvars, parse_context(call('ctxget', 1)))
|
eq(with_gvars, parse_context(call('ctxget', 1)))
|
||||||
eq(with_all, parse_context(call('ctxget', 2)))
|
eq(with_all, parse_context(call('ctxget', 2)))
|
||||||
|
|
||||||
call('ctxpush', {'jumps'})
|
call('ctxpush', {'jumps'})
|
||||||
eq(with_jumps, parse_context(call('ctxget')))
|
eq(with_jumps, parse_context(call('ctxget')))
|
||||||
eq(with_jumps, parse_context(call('ctxget', 0)))
|
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_gvars, parse_context(call('ctxget', 2)))
|
||||||
eq(with_all, parse_context(call('ctxget', 3)))
|
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')))
|
||||||
eq(with_regs, parse_context(call('ctxget', 0)))
|
eq(with_regs, parse_context(call('ctxget', 0)))
|
||||||
eq(with_jumps, parse_context(call('ctxget', 1)))
|
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_gvars, parse_context(call('ctxget', 3)))
|
||||||
eq(with_all, parse_context(call('ctxget', 4)))
|
eq(with_all, parse_context(call('ctxget', 4)))
|
||||||
|
|
||||||
call('ctxpop')
|
call('ctxpop')
|
||||||
eq(with_jumps, parse_context(call('ctxget')))
|
eq(with_jumps, parse_context(call('ctxget')))
|
||||||
eq(with_jumps, parse_context(call('ctxget', 0)))
|
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_gvars, parse_context(call('ctxget', 2)))
|
||||||
eq(with_all, parse_context(call('ctxget', 3)))
|
eq(with_all, parse_context(call('ctxget', 3)))
|
||||||
|
|
||||||
call('ctxpop')
|
call('ctxpop')
|
||||||
eq(with_buflist, parse_context(call('ctxget')))
|
eq(with_bufs, parse_context(call('ctxget')))
|
||||||
eq(with_buflist, parse_context(call('ctxget', 0)))
|
eq(with_bufs, parse_context(call('ctxget', 0)))
|
||||||
eq(with_gvars, parse_context(call('ctxget', 1)))
|
eq(with_gvars, parse_context(call('ctxget', 1)))
|
||||||
eq(with_all, parse_context(call('ctxget', 2)))
|
eq(with_all, parse_context(call('ctxget', 2)))
|
||||||
|
|
||||||
|
@@ -777,12 +777,12 @@ end
|
|||||||
|
|
||||||
function module.parse_context(ctx)
|
function module.parse_context(ctx)
|
||||||
local parsed = {}
|
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)
|
parsed[item] = filter(function(v)
|
||||||
return type(v) == 'table'
|
return type(v) == 'table'
|
||||||
end, module.call('msgpackparse', ctx[item]))
|
end, module.call('msgpackparse', ctx[item]))
|
||||||
end
|
end
|
||||||
parsed['buflist'] = parsed['buflist'][1]
|
parsed['bufs'] = parsed['bufs'][1]
|
||||||
return map(function(v)
|
return map(function(v)
|
||||||
if #v == 0 then
|
if #v == 0 then
|
||||||
return nil
|
return nil
|
||||||
|
Reference in New Issue
Block a user