mirror of
https://github.com/neovim/neovim.git
synced 2025-09-28 14:08:32 +00:00
vim-patch:9.1.1544: :retab cannot be limited to indentation only (#34939)
Problem: :retab cannot be limited to indentation only
Solution: add the optional -indentonly parameter
(Hirohito Higashi)
closes: vim/vim#17730
836e54f5de
Co-authored-by: Hirohito Higashi <h.east.727@gmail.com>
This commit is contained in:
@@ -2290,6 +2290,11 @@ static const char *set_context_by_cmdname(const char *cmd, cmdidx_T cmdidx, expa
|
||||
xp->xp_pattern = (char *)arg;
|
||||
break;
|
||||
|
||||
case CMD_retab:
|
||||
xp->xp_context = EXPAND_RETAB;
|
||||
xp->xp_pattern = (char *)arg;
|
||||
break;
|
||||
|
||||
case CMD_messages:
|
||||
xp->xp_context = EXPAND_MESSAGES;
|
||||
xp->xp_pattern = (char *)arg;
|
||||
@@ -2768,6 +2773,16 @@ static char *get_scriptnames_arg(expand_T *xp FUNC_ATTR_UNUSED, int idx)
|
||||
return NameBuff;
|
||||
}
|
||||
|
||||
/// Function given to ExpandGeneric() to obtain the possible arguments of the
|
||||
/// ":retab {-indentonly}" option.
|
||||
static char *get_retab_arg(expand_T *xp FUNC_ATTR_UNUSED, int idx)
|
||||
{
|
||||
if (idx == 0) {
|
||||
return "-indentonly";
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/// Function given to ExpandGeneric() to obtain the possible arguments of the
|
||||
/// ":messages {clear}" command.
|
||||
static char *get_messages_arg(expand_T *xp FUNC_ATTR_UNUSED, int idx)
|
||||
@@ -2853,6 +2868,7 @@ static int ExpandOther(char *pat, expand_T *xp, regmatch_T *rmp, char ***matches
|
||||
{ EXPAND_ARGLIST, get_arglist_name, true, false },
|
||||
{ EXPAND_BREAKPOINT, get_breakadd_arg, true, true },
|
||||
{ EXPAND_SCRIPTNAMES, get_scriptnames_arg, true, false },
|
||||
{ EXPAND_RETAB, get_retab_arg, true, true },
|
||||
{ EXPAND_CHECKHEALTH, get_healthcheck_names, true, false },
|
||||
};
|
||||
int ret = FAIL;
|
||||
|
@@ -114,6 +114,7 @@ enum {
|
||||
EXPAND_FINDFUNC,
|
||||
EXPAND_FILETYPECMD,
|
||||
EXPAND_PATTERN_IN_BUF,
|
||||
EXPAND_RETAB,
|
||||
EXPAND_CHECKHEALTH,
|
||||
EXPAND_LUA,
|
||||
};
|
||||
|
@@ -3901,6 +3901,7 @@ M.funcs = {
|
||||
messages |:messages| suboptions
|
||||
option options
|
||||
packadd optional package |pack-add| names
|
||||
retab |:retab| suboptions
|
||||
runtime |:runtime| completion
|
||||
scriptnames sourced script names |:scriptnames|
|
||||
shellcmd Shell command
|
||||
|
@@ -1006,16 +1006,23 @@ void ex_retab(exarg_T *eap)
|
||||
|
||||
linenr_T first_line = 0; // first changed line
|
||||
linenr_T last_line = 0; // last changed line
|
||||
bool is_indent_only = false;
|
||||
|
||||
int save_list = curwin->w_p_list;
|
||||
curwin->w_p_list = 0; // don't want list mode here
|
||||
|
||||
new_ts_str = eap->arg;
|
||||
if (!tabstop_set(eap->arg, &new_vts_array)) {
|
||||
char *ptr = eap->arg;
|
||||
if (strncmp(ptr, "-indentonly", 11) == 0 && ascii_iswhite_or_nul(ptr[11])) {
|
||||
is_indent_only = true;
|
||||
ptr = skipwhite(ptr + 11);
|
||||
}
|
||||
|
||||
new_ts_str = ptr;
|
||||
if (!tabstop_set(ptr, &new_vts_array)) {
|
||||
return;
|
||||
}
|
||||
while (ascii_isdigit(*(eap->arg)) || *(eap->arg) == ',') {
|
||||
eap->arg++;
|
||||
while (ascii_isdigit(*ptr) || *ptr == ',') {
|
||||
ptr++;
|
||||
}
|
||||
|
||||
// This ensures that either new_vts_array and new_ts_str are freshly
|
||||
@@ -1025,10 +1032,10 @@ void ex_retab(exarg_T *eap)
|
||||
new_vts_array = curbuf->b_p_vts_array;
|
||||
new_ts_str = NULL;
|
||||
} else {
|
||||
new_ts_str = xmemdupz(new_ts_str, (size_t)(eap->arg - new_ts_str));
|
||||
new_ts_str = xmemdupz(new_ts_str, (size_t)(ptr - new_ts_str));
|
||||
}
|
||||
for (linenr_T lnum = eap->line1; !got_int && lnum <= eap->line2; lnum++) {
|
||||
char *ptr = ml_get(lnum);
|
||||
ptr = ml_get(lnum);
|
||||
int old_len = ml_get_len(lnum);
|
||||
int col = 0;
|
||||
int64_t vcol = 0;
|
||||
@@ -1106,6 +1113,10 @@ void ex_retab(exarg_T *eap)
|
||||
}
|
||||
got_tab = false;
|
||||
num_spaces = 0;
|
||||
|
||||
if (is_indent_only) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (ptr[col] == NUL) {
|
||||
break;
|
||||
|
@@ -90,6 +90,7 @@ static const char *command_complete[] = {
|
||||
[EXPAND_SYNTIME] = "syntime",
|
||||
[EXPAND_SETTINGS] = "option",
|
||||
[EXPAND_PACKADD] = "packadd",
|
||||
[EXPAND_RETAB] = "retab",
|
||||
[EXPAND_RUNTIME] = "runtime",
|
||||
[EXPAND_SHELLCMD] = "shellcmd",
|
||||
[EXPAND_SHELLCMDLINE] = "shellcmdline",
|
||||
|
Reference in New Issue
Block a user