mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
ops.c: breakout shared register type formatting code
This commit is contained in:
parent
2359f6f144
commit
c1487b9685
@ -10623,8 +10623,6 @@ static void f_getregtype(typval_T *argvars, typval_T *rettv)
|
|||||||
{
|
{
|
||||||
char_u *strregname;
|
char_u *strregname;
|
||||||
int regname;
|
int regname;
|
||||||
char_u buf[NUMBUFLEN + 2];
|
|
||||||
long reglen = 0;
|
|
||||||
|
|
||||||
if (argvars[0].v_type != VAR_UNKNOWN) {
|
if (argvars[0].v_type != VAR_UNKNOWN) {
|
||||||
strregname = get_tv_string_chk(&argvars[0]);
|
strregname = get_tv_string_chk(&argvars[0]);
|
||||||
@ -10641,18 +10639,13 @@ static void f_getregtype(typval_T *argvars, typval_T *rettv)
|
|||||||
if (regname == 0)
|
if (regname == 0)
|
||||||
regname = '"';
|
regname = '"';
|
||||||
|
|
||||||
buf[0] = NUL;
|
colnr_T reglen = 0;
|
||||||
buf[1] = NUL;
|
char buf[NUMBUFLEN + 2];
|
||||||
switch (get_reg_type(regname, ®len)) {
|
char_u reg_type = get_reg_type(regname, ®len);
|
||||||
case MLINE: buf[0] = 'V'; break;
|
format_reg_type(reg_type, reglen, buf, ARRAY_SIZE(buf));
|
||||||
case MCHAR: buf[0] = 'v'; break;
|
|
||||||
case MBLOCK:
|
|
||||||
buf[0] = Ctrl_V;
|
|
||||||
sprintf((char *)buf + 1, "%" PRId64, (int64_t)(reglen + 1));
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
rettv->v_type = VAR_STRING;
|
rettv->v_type = VAR_STRING;
|
||||||
rettv->vval.v_string = vim_strsave(buf);
|
rettv->vval.v_string = (char_u *)xstrdup(buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -2558,23 +2558,7 @@ static void yank_do_autocmd(oparg_T *oap, yankreg_T *reg)
|
|||||||
|
|
||||||
// the register type
|
// the register type
|
||||||
char buf[NUMBUFLEN+2];
|
char buf[NUMBUFLEN+2];
|
||||||
buf[0] = NUL;
|
format_reg_type(reg->y_type, reg->y_width, buf, ARRAY_SIZE(buf));
|
||||||
buf[1] = NUL;
|
|
||||||
switch (reg->y_type) {
|
|
||||||
case MLINE:
|
|
||||||
buf[0] = 'V';
|
|
||||||
break;
|
|
||||||
case MCHAR:
|
|
||||||
buf[0] = 'v';
|
|
||||||
break;
|
|
||||||
case MBLOCK:
|
|
||||||
buf[0] = Ctrl_V;
|
|
||||||
snprintf(buf + 1, ARRAY_SIZE(buf) - 1, "%" PRId64,
|
|
||||||
(int64_t)(reg->y_width + 1));
|
|
||||||
break;
|
|
||||||
case MAUTO:
|
|
||||||
assert(false);
|
|
||||||
}
|
|
||||||
dict_add_nr_str(dict, "regtype", 0, (char_u *)buf);
|
dict_add_nr_str(dict, "regtype", 0, (char_u *)buf);
|
||||||
|
|
||||||
// name of requested register or the empty string for an unnamed operation.
|
// name of requested register or the empty string for an unnamed operation.
|
||||||
@ -4703,7 +4687,7 @@ theend:
|
|||||||
* Used for getregtype()
|
* Used for getregtype()
|
||||||
* Returns MAUTO for error.
|
* Returns MAUTO for error.
|
||||||
*/
|
*/
|
||||||
char_u get_reg_type(int regname, long *reglen)
|
char_u get_reg_type(int regname, colnr_T *reg_width)
|
||||||
{
|
{
|
||||||
switch (regname) {
|
switch (regname) {
|
||||||
case '%': /* file name */
|
case '%': /* file name */
|
||||||
@ -4726,13 +4710,45 @@ char_u get_reg_type(int regname, long *reglen)
|
|||||||
yankreg_T *reg = get_yank_register(regname, YREG_PASTE);
|
yankreg_T *reg = get_yank_register(regname, YREG_PASTE);
|
||||||
|
|
||||||
if (reg->y_array != NULL) {
|
if (reg->y_array != NULL) {
|
||||||
if (reglen != NULL && reg->y_type == MBLOCK)
|
if (reg_width != NULL && reg->y_type == MBLOCK) {
|
||||||
*reglen = reg->y_width;
|
*reg_width = reg->y_width;
|
||||||
|
}
|
||||||
return reg->y_type;
|
return reg->y_type;
|
||||||
}
|
}
|
||||||
return MAUTO;
|
return MAUTO;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Format the register type as a string.
|
||||||
|
///
|
||||||
|
/// @param reg_type The register type.
|
||||||
|
/// @param reg_width The width, only used if "reg_type" is MBLOCK.
|
||||||
|
/// @param[out] buf Buffer to store formatted string. The allocated size should
|
||||||
|
/// be at least NUMBUFLEN+2 to always fit the value.
|
||||||
|
/// @param buf_len The allocated size of the buffer.
|
||||||
|
void format_reg_type(char_u reg_type, colnr_T reg_width,
|
||||||
|
char* buf, size_t buf_len)
|
||||||
|
FUNC_ATTR_NONNULL_ALL
|
||||||
|
{
|
||||||
|
assert(buf_len > 1);
|
||||||
|
switch (reg_type) {
|
||||||
|
case MLINE:
|
||||||
|
buf[0] = 'V';
|
||||||
|
buf[1] = NUL;
|
||||||
|
break;
|
||||||
|
case MCHAR:
|
||||||
|
buf[0] = 'v';
|
||||||
|
buf[1] = NUL;
|
||||||
|
break;
|
||||||
|
case MBLOCK:
|
||||||
|
snprintf(buf, buf_len, CTRL_V_STR "%" PRIdCOLNR, reg_width + 1);
|
||||||
|
break;
|
||||||
|
case MAUTO:
|
||||||
|
buf[0] = NUL;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/// When `flags` has `kGRegList` return a list with text `s`.
|
/// When `flags` has `kGRegList` return a list with text `s`.
|
||||||
/// Otherwise just return `s`.
|
/// Otherwise just return `s`.
|
||||||
///
|
///
|
||||||
|
@ -2,7 +2,11 @@
|
|||||||
#define NVIM_POS_H
|
#define NVIM_POS_H
|
||||||
|
|
||||||
typedef long linenr_T; // line number type
|
typedef long linenr_T; // line number type
|
||||||
typedef int colnr_T; // column number type
|
|
||||||
|
/// Column number type
|
||||||
|
typedef int colnr_T;
|
||||||
|
/// Format used to print values which have colnr_T type
|
||||||
|
#define PRIdCOLNR "d"
|
||||||
|
|
||||||
#define MAXLNUM 0x7fffffff // maximum (invalid) line number
|
#define MAXLNUM 0x7fffffff // maximum (invalid) line number
|
||||||
#define MAXCOL 0x7fffffff // maximum column number, 31 bits
|
#define MAXCOL 0x7fffffff // maximum column number, 31 bits
|
||||||
|
Loading…
Reference in New Issue
Block a user