mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
ops: refactor get_spec_reg()
Return value is bool. errmsg (param) is bool in here and in getaltfname(). allocated (param) is bool.
This commit is contained in:
parent
015df9c66e
commit
58ad7fc578
@ -2659,9 +2659,8 @@ buf_T *setaltfname(char_u *ffname, char_u *sfname, linenr_T lnum)
|
|||||||
* Get alternate file name for current window.
|
* Get alternate file name for current window.
|
||||||
* Return NULL if there isn't any, and give error message if requested.
|
* Return NULL if there isn't any, and give error message if requested.
|
||||||
*/
|
*/
|
||||||
char_u *
|
char_u * getaltfname(
|
||||||
getaltfname (
|
bool errmsg // give error message
|
||||||
int errmsg /* give error message */
|
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
char_u *fname;
|
char_u *fname;
|
||||||
|
@ -3286,10 +3286,9 @@ void restore_cmdline_alloc(char_u *p)
|
|||||||
/// @returns FAIL for failure, OK otherwise
|
/// @returns FAIL for failure, OK otherwise
|
||||||
static bool cmdline_paste(int regname, bool literally, bool remcr)
|
static bool cmdline_paste(int regname, bool literally, bool remcr)
|
||||||
{
|
{
|
||||||
long i;
|
|
||||||
char_u *arg;
|
char_u *arg;
|
||||||
char_u *p;
|
char_u *p;
|
||||||
int allocated;
|
bool allocated;
|
||||||
struct cmdline_info save_ccline;
|
struct cmdline_info save_ccline;
|
||||||
|
|
||||||
/* check for valid regname; also accept special characters for CTRL-R in
|
/* check for valid regname; also accept special characters for CTRL-R in
|
||||||
@ -3311,7 +3310,7 @@ static bool cmdline_paste(int regname, bool literally, bool remcr)
|
|||||||
* things like going to another buffer when evaluating an expression. */
|
* things like going to another buffer when evaluating an expression. */
|
||||||
save_cmdline(&save_ccline);
|
save_cmdline(&save_ccline);
|
||||||
++textlock;
|
++textlock;
|
||||||
i = get_spec_reg(regname, &arg, &allocated, TRUE);
|
const bool i = get_spec_reg(regname, &arg, &allocated, true);
|
||||||
--textlock;
|
--textlock;
|
||||||
restore_cmdline(&save_ccline);
|
restore_cmdline(&save_ccline);
|
||||||
|
|
||||||
|
@ -1110,7 +1110,7 @@ int insert_reg(
|
|||||||
)
|
)
|
||||||
{
|
{
|
||||||
int retval = OK;
|
int retval = OK;
|
||||||
int allocated;
|
bool allocated;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* It is possible to get into an endless loop by having CTRL-R a in
|
* It is possible to get into an endless loop by having CTRL-R a in
|
||||||
@ -1187,75 +1187,75 @@ static void stuffescaped(const char *arg, int literally)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
// If "regname" is a special register, return true and store a pointer to its
|
||||||
* If "regname" is a special register, return TRUE and store a pointer to its
|
// value in "argp".
|
||||||
* value in "argp".
|
bool get_spec_reg(
|
||||||
*/
|
|
||||||
int get_spec_reg(
|
|
||||||
int regname,
|
int regname,
|
||||||
char_u **argp,
|
char_u **argp,
|
||||||
int *allocated, /* return: TRUE when value was allocated */
|
bool *allocated, // return: true when value was allocated
|
||||||
int errmsg /* give error message when failing */
|
bool errmsg // give error message when failing
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
size_t cnt;
|
size_t cnt;
|
||||||
|
|
||||||
*argp = NULL;
|
*argp = NULL;
|
||||||
*allocated = FALSE;
|
*allocated = false;
|
||||||
switch (regname) {
|
switch (regname) {
|
||||||
case '%': /* file name */
|
case '%': /* file name */
|
||||||
if (errmsg)
|
if (errmsg)
|
||||||
check_fname(); /* will give emsg if not set */
|
check_fname(); /* will give emsg if not set */
|
||||||
*argp = curbuf->b_fname;
|
*argp = curbuf->b_fname;
|
||||||
return TRUE;
|
return true;
|
||||||
|
|
||||||
case '#': /* alternate file name */
|
case '#': /* alternate file name */
|
||||||
*argp = getaltfname(errmsg); /* may give emsg if not set */
|
*argp = getaltfname(errmsg); /* may give emsg if not set */
|
||||||
return TRUE;
|
return true;
|
||||||
|
|
||||||
case '=': /* result of expression */
|
case '=': /* result of expression */
|
||||||
*argp = get_expr_line();
|
*argp = get_expr_line();
|
||||||
*allocated = TRUE;
|
*allocated = true;
|
||||||
return TRUE;
|
return true;
|
||||||
|
|
||||||
case ':': /* last command line */
|
case ':': /* last command line */
|
||||||
if (last_cmdline == NULL && errmsg)
|
if (last_cmdline == NULL && errmsg)
|
||||||
EMSG(_(e_nolastcmd));
|
EMSG(_(e_nolastcmd));
|
||||||
*argp = last_cmdline;
|
*argp = last_cmdline;
|
||||||
return TRUE;
|
return true;
|
||||||
|
|
||||||
case '/': /* last search-pattern */
|
case '/': /* last search-pattern */
|
||||||
if (last_search_pat() == NULL && errmsg)
|
if (last_search_pat() == NULL && errmsg)
|
||||||
EMSG(_(e_noprevre));
|
EMSG(_(e_noprevre));
|
||||||
*argp = last_search_pat();
|
*argp = last_search_pat();
|
||||||
return TRUE;
|
return true;
|
||||||
|
|
||||||
case '.': /* last inserted text */
|
case '.': /* last inserted text */
|
||||||
*argp = get_last_insert_save();
|
*argp = get_last_insert_save();
|
||||||
*allocated = TRUE;
|
*allocated = true;
|
||||||
if (*argp == NULL && errmsg)
|
if (*argp == NULL && errmsg)
|
||||||
EMSG(_(e_noinstext));
|
EMSG(_(e_noinstext));
|
||||||
return TRUE;
|
return true;
|
||||||
|
|
||||||
case Ctrl_F: /* Filename under cursor */
|
case Ctrl_F: /* Filename under cursor */
|
||||||
case Ctrl_P: /* Path under cursor, expand via "path" */
|
case Ctrl_P: /* Path under cursor, expand via "path" */
|
||||||
if (!errmsg)
|
if (!errmsg) {
|
||||||
return FALSE;
|
return false;
|
||||||
|
}
|
||||||
*argp = file_name_at_cursor(FNAME_MESS | FNAME_HYP
|
*argp = file_name_at_cursor(FNAME_MESS | FNAME_HYP
|
||||||
| (regname == Ctrl_P ? FNAME_EXP : 0), 1L, NULL);
|
| (regname == Ctrl_P ? FNAME_EXP : 0), 1L, NULL);
|
||||||
*allocated = TRUE;
|
*allocated = true;
|
||||||
return TRUE;
|
return true;
|
||||||
|
|
||||||
case Ctrl_W: /* word under cursor */
|
case Ctrl_W: /* word under cursor */
|
||||||
case Ctrl_A: /* WORD (mnemonic All) under cursor */
|
case Ctrl_A: /* WORD (mnemonic All) under cursor */
|
||||||
if (!errmsg)
|
if (!errmsg) {
|
||||||
return FALSE;
|
return false;
|
||||||
|
}
|
||||||
cnt = find_ident_under_cursor(argp, (regname == Ctrl_W
|
cnt = find_ident_under_cursor(argp, (regname == Ctrl_W
|
||||||
? (FIND_IDENT|FIND_STRING)
|
? (FIND_IDENT|FIND_STRING)
|
||||||
: FIND_STRING));
|
: FIND_STRING));
|
||||||
*argp = cnt ? vim_strnsave(*argp, cnt) : NULL;
|
*argp = cnt ? vim_strnsave(*argp, cnt) : NULL;
|
||||||
*allocated = TRUE;
|
*allocated = true;
|
||||||
return TRUE;
|
return true;
|
||||||
|
|
||||||
case Ctrl_L: // Line under cursor
|
case Ctrl_L: // Line under cursor
|
||||||
if (!errmsg) {
|
if (!errmsg) {
|
||||||
@ -1267,10 +1267,10 @@ int get_spec_reg(
|
|||||||
|
|
||||||
case '_': /* black hole: always empty */
|
case '_': /* black hole: always empty */
|
||||||
*argp = (char_u *)"";
|
*argp = (char_u *)"";
|
||||||
return TRUE;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return FALSE;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Paste a yank register into the command line.
|
/// Paste a yank register into the command line.
|
||||||
@ -2660,7 +2660,7 @@ void do_put(int regname, yankreg_T *reg, int dir, long count, int flags)
|
|||||||
int lendiff = 0;
|
int lendiff = 0;
|
||||||
pos_T old_pos;
|
pos_T old_pos;
|
||||||
char_u *insert_string = NULL;
|
char_u *insert_string = NULL;
|
||||||
int allocated = FALSE;
|
bool allocated = false;
|
||||||
long cnt;
|
long cnt;
|
||||||
|
|
||||||
if (flags & PUT_FIXINDENT)
|
if (flags & PUT_FIXINDENT)
|
||||||
@ -2756,7 +2756,7 @@ void do_put(int regname, yankreg_T *reg, int dir, long count, int flags)
|
|||||||
* For special registers '%' (file name), '#' (alternate file name) and
|
* For special registers '%' (file name), '#' (alternate file name) and
|
||||||
* ':' (last command line), etc. we have to create a fake yank register.
|
* ':' (last command line), etc. we have to create a fake yank register.
|
||||||
*/
|
*/
|
||||||
if (get_spec_reg(regname, &insert_string, &allocated, TRUE)) {
|
if (get_spec_reg(regname, &insert_string, &allocated, true)) {
|
||||||
if (insert_string == NULL)
|
if (insert_string == NULL)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -4915,8 +4915,8 @@ void *get_reg_contents(int regname, int flags)
|
|||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
char_u *retval;
|
char_u *retval;
|
||||||
int allocated;
|
bool allocated;
|
||||||
if (get_spec_reg(regname, &retval, &allocated, FALSE)) {
|
if (get_spec_reg(regname, &retval, &allocated, false)) {
|
||||||
if (retval == NULL)
|
if (retval == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
if (allocated) {
|
if (allocated) {
|
||||||
|
Loading…
Reference in New Issue
Block a user