vim-patch:8.1.1886: command line expansion code is spread out (#19861)

Problem:    Command line expansion code is spread out.
Solution:   Move the code to cmdexpand.c. (Yegappan Lakshmanan, closes vim/vim#4831)
66b51420e0
This commit is contained in:
zeertzjq
2022-08-21 06:33:24 +08:00
committed by GitHub
parent ff5cfcdeab
commit 0d0a336c53
20 changed files with 1901 additions and 1861 deletions

View File

@@ -10,6 +10,7 @@
#include "nvim/buffer.h"
#include "nvim/charset.h"
#include "nvim/eval.h"
#include "nvim/ex_cmds.h"
#include "nvim/ex_cmds2.h"
#include "nvim/ex_getln.h"
#include "nvim/fileio.h"

View File

@@ -34,6 +34,7 @@
#include "nvim/change.h"
#include "nvim/channel.h"
#include "nvim/charset.h"
#include "nvim/cmdexpand.h"
#include "nvim/cursor.h"
#include "nvim/decoration.h"
#include "nvim/diff.h"

1745
src/nvim/cmdexpand.c Normal file

File diff suppressed because it is too large Load Diff

43
src/nvim/cmdexpand.h Normal file
View File

@@ -0,0 +1,43 @@
#ifndef NVIM_CMDEXPAND_H
#define NVIM_CMDEXPAND_H
#include "nvim/eval/typval.h"
#include "nvim/garray.h"
#include "nvim/types.h"
// Values for nextwild() and ExpandOne(). See ExpandOne() for meaning.
enum {
WILD_FREE = 1,
WILD_EXPAND_FREE = 2,
WILD_EXPAND_KEEP = 3,
WILD_NEXT = 4,
WILD_PREV = 5,
WILD_ALL = 6,
WILD_LONGEST = 7,
WILD_ALL_KEEP = 8,
WILD_CANCEL = 9,
WILD_APPLY = 10,
};
enum {
WILD_LIST_NOTFOUND = 0x01,
WILD_HOME_REPLACE = 0x02,
WILD_USE_NL = 0x04,
WILD_NO_BEEP = 0x08,
WILD_ADD_SLASH = 0x10,
WILD_KEEP_ALL = 0x20,
WILD_SILENT = 0x40,
WILD_ESCAPE = 0x80,
WILD_ICASE = 0x100,
WILD_ALLLINKS = 0x200,
WILD_IGNORE_COMPLETESLASH = 0x400,
WILD_NOERROR = 0x800, ///< sets EW_NOERROR
WILD_BUFLASTUSED = 0x1000,
BUF_DIFF_FILTER = 0x2000,
};
#ifdef INCLUDE_GENERATED_DECLARATIONS
# include "cmdexpand.h.generated.h"
#endif
#endif // NVIM_CMDEXPAND_H

View File

@@ -6,6 +6,7 @@
#include "nvim/ascii.h"
#include "nvim/charset.h"
#include "nvim/cmdhist.h"
#include "nvim/ex_cmds.h"
#include "nvim/ex_getln.h"
#include "nvim/regexp.h"
#include "nvim/strings.h"

View File

@@ -61,6 +61,7 @@
#include "nvim/buffer.h"
#include "nvim/charset.h"
#include "nvim/cmdexpand.h"
#include "nvim/diff.h"
#include "nvim/drawscreen.h"
#include "nvim/ex_getln.h"

View File

@@ -28,6 +28,7 @@
#include "nvim/eval/typval.h"
#include "nvim/eval/userfunc.h"
#include "nvim/eval/vars.h"
#include "nvim/ex_cmds.h"
#include "nvim/ex_cmds2.h"
#include "nvim/ex_docmd.h"
#include "nvim/ex_eval.h"

View File

@@ -14,6 +14,7 @@
#include "nvim/change.h"
#include "nvim/channel.h"
#include "nvim/charset.h"
#include "nvim/cmdexpand.h"
#include "nvim/cmdhist.h"
#include "nvim/context.h"
#include "nvim/cursor.h"
@@ -28,6 +29,7 @@
#include "nvim/eval/typval.h"
#include "nvim/eval/userfunc.h"
#include "nvim/eval/vars.h"
#include "nvim/ex_cmds.h"
#include "nvim/ex_docmd.h"
#include "nvim/ex_eval.h"
#include "nvim/ex_getln.h"
@@ -2751,84 +2753,6 @@ static void f_getcmdwintype(typval_T *argvars, typval_T *rettv, FunPtr fptr)
rettv->vval.v_string[0] = (char)cmdwin_type;
}
/// "getcompletion()" function
static void f_getcompletion(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
char_u *pat;
expand_T xpc;
bool filtered = false;
int options = WILD_SILENT | WILD_USE_NL | WILD_ADD_SLASH
| WILD_NO_BEEP | WILD_HOME_REPLACE;
if (argvars[1].v_type != VAR_STRING) {
semsg(_(e_invarg2), "type must be a string");
return;
}
const char *const type = tv_get_string(&argvars[1]);
if (argvars[2].v_type != VAR_UNKNOWN) {
filtered = (bool)tv_get_number_chk(&argvars[2], NULL);
}
if (p_wic) {
options |= WILD_ICASE;
}
// For filtered results, 'wildignore' is used
if (!filtered) {
options |= WILD_KEEP_ALL;
}
if (argvars[0].v_type != VAR_STRING) {
emsg(_(e_invarg));
return;
}
const char *pattern = tv_get_string(&argvars[0]);
if (strcmp(type, "cmdline") == 0) {
set_one_cmd_context(&xpc, pattern);
xpc.xp_pattern_len = STRLEN(xpc.xp_pattern);
xpc.xp_col = (int)STRLEN(pattern);
goto theend;
}
ExpandInit(&xpc);
xpc.xp_pattern = (char *)pattern;
xpc.xp_pattern_len = STRLEN(xpc.xp_pattern);
xpc.xp_context = cmdcomplete_str_to_type(type);
if (xpc.xp_context == EXPAND_NOTHING) {
semsg(_(e_invarg2), type);
return;
}
if (xpc.xp_context == EXPAND_MENUS) {
set_context_in_menu_cmd(&xpc, "menu", xpc.xp_pattern, false);
xpc.xp_pattern_len = STRLEN(xpc.xp_pattern);
}
if (xpc.xp_context == EXPAND_CSCOPE) {
set_context_in_cscope_cmd(&xpc, (const char *)xpc.xp_pattern, CMD_cscope);
xpc.xp_pattern_len = STRLEN(xpc.xp_pattern);
}
if (xpc.xp_context == EXPAND_SIGN) {
set_context_in_sign_cmd(&xpc, (char_u *)xpc.xp_pattern);
xpc.xp_pattern_len = STRLEN(xpc.xp_pattern);
}
theend:
pat = addstar((char_u *)xpc.xp_pattern, xpc.xp_pattern_len, xpc.xp_context);
ExpandOne(&xpc, pat, NULL, options, WILD_ALL_KEEP);
tv_list_alloc_ret(rettv, xpc.xp_numfiles);
for (int i = 0; i < xpc.xp_numfiles; i++) {
tv_list_append_string(rettv->vval.v_list, (const char *)xpc.xp_files[i],
-1);
}
xfree(pat);
ExpandCleanup(&xpc);
}
/// `getcwd([{win}[, {tab}]])` function
///
/// Every scope not specified implies the currently selected scope object.

View File

@@ -14,6 +14,7 @@
#include "nvim/buffer.h"
#include "nvim/change.h"
#include "nvim/charset.h"
#include "nvim/cmdexpand.h"
#include "nvim/cmdhist.h"
#include "nvim/cursor.h"
#include "nvim/debugger.h"

File diff suppressed because it is too large Load Diff

View File

@@ -2,42 +2,77 @@
#define NVIM_EX_GETLN_H
#include "nvim/eval/typval.h"
#include "nvim/ex_cmds.h"
#include "nvim/regexp_defs.h"
#include "nvim/ex_cmds_defs.h"
#include "nvim/types.h"
// Values for nextwild() and ExpandOne(). See ExpandOne() for meaning.
#define WILD_FREE 1
#define WILD_EXPAND_FREE 2
#define WILD_EXPAND_KEEP 3
#define WILD_NEXT 4
#define WILD_PREV 5
#define WILD_ALL 6
#define WILD_LONGEST 7
#define WILD_ALL_KEEP 8
#define WILD_CANCEL 9
#define WILD_APPLY 10
/// Command-line colors: one chunk
///
/// Defines a region which has the same highlighting.
typedef struct {
int start; ///< Colored chunk start.
int end; ///< Colored chunk end (exclusive, > start).
int attr; ///< Highlight attr.
} CmdlineColorChunk;
#define WILD_LIST_NOTFOUND 0x01
#define WILD_HOME_REPLACE 0x02
#define WILD_USE_NL 0x04
#define WILD_NO_BEEP 0x08
#define WILD_ADD_SLASH 0x10
#define WILD_KEEP_ALL 0x20
#define WILD_SILENT 0x40
#define WILD_ESCAPE 0x80
#define WILD_ICASE 0x100
#define WILD_ALLLINKS 0x200
#define WILD_IGNORE_COMPLETESLASH 0x400
#define WILD_NOERROR 0x800 // sets EW_NOERROR
#define WILD_BUFLASTUSED 0x1000
#define BUF_DIFF_FILTER 0x2000
/// Command-line colors
///
/// Holds data about all colors.
typedef kvec_t(CmdlineColorChunk) CmdlineColors;
// flags used by vim_strsave_fnameescape()
#define VSE_NONE 0
#define VSE_SHELL 1 ///< escape for a shell command
#define VSE_BUFFER 2 ///< escape for a ":buffer" command
/// Command-line coloring
///
/// Holds both what are the colors and what have been colored. Latter is used to
/// suppress unnecessary calls to coloring callbacks.
typedef struct {
unsigned prompt_id; ///< ID of the prompt which was colored last.
char *cmdbuff; ///< What exactly was colored last time or NULL.
CmdlineColors colors; ///< Last colors.
} ColoredCmdline;
typedef char *(*CompleteListItemGetter)(expand_T *, int);
/// Keeps track how much state must be sent to external ui.
typedef enum {
kCmdRedrawNone,
kCmdRedrawPos,
kCmdRedrawAll,
} CmdRedraw;
/// Variables shared between getcmdline(), redrawcmdline() and others.
/// These need to be saved when using CTRL-R |, that's why they are in a
/// structure.
typedef struct cmdline_info CmdlineInfo;
struct cmdline_info {
char_u *cmdbuff; ///< pointer to command line buffer
int cmdbufflen; ///< length of cmdbuff
int cmdlen; ///< number of chars in command line
int cmdpos; ///< current cursor position
int cmdspos; ///< cursor column on screen
int cmdfirstc; ///< ':', '/', '?', '=', '>' or NUL
int cmdindent; ///< number of spaces before cmdline
char_u *cmdprompt; ///< message in front of cmdline
int cmdattr; ///< attributes for prompt
int overstrike; ///< Typing mode on the command line. Shared by
///< getcmdline() and put_on_cmdline().
expand_T *xpc; ///< struct being used for expansion, xp_pattern
///< may point into cmdbuff
int xp_context; ///< type of expansion
char_u *xp_arg; ///< user-defined expansion arg
int input_fn; ///< when true Invoked for input() function
unsigned prompt_id; ///< Prompt number, used to disable coloring on errors.
Callback highlight_callback; ///< Callback used for coloring user input.
ColoredCmdline last_colors; ///< Last cmdline colors
int level; ///< current cmdline level
CmdlineInfo *prev_ccline; ///< pointer to saved cmdline state
char special_char; ///< last putcmdline char (used for redraws)
bool special_shift; ///< shift of last putcmdline char
CmdRedraw redraw_state; ///< needed redraw for external cmdline
};
/// flags used by vim_strsave_fnameescape()
enum {
VSE_NONE = 0,
VSE_SHELL = 1, ///< escape for a shell command
VSE_BUFFER = 2, ///< escape for a ":buffer" command
};
#ifdef INCLUDE_GENERATED_DECLARATIONS
# include "ex_getln.h.generated.h"

View File

@@ -20,6 +20,7 @@
#include "nvim/eval.h"
#include "nvim/eval/typval.h"
#include "nvim/event/loop.h"
#include "nvim/ex_cmds.h"
#include "nvim/ex_docmd.h"
#include "nvim/ex_getln.h"
#include "nvim/garray.h"

View File

@@ -8,9 +8,9 @@
#include "nvim/buffer.h"
#include "nvim/charset.h"
#include "nvim/cmdexpand.h"
#include "nvim/ex_cmds.h"
#include "nvim/ex_docmd.h"
#include "nvim/ex_getln.h"
#include "nvim/fileio.h"
#include "nvim/garray.h"
#include "nvim/globals.h"

View File

@@ -12,6 +12,7 @@
#include "nvim/buffer.h"
#include "nvim/change.h"
#include "nvim/charset.h"
#include "nvim/cmdexpand.h"
#include "nvim/cursor.h"
#include "nvim/drawscreen.h"
#include "nvim/edit.h"

View File

@@ -22,6 +22,7 @@
#include "nvim/eval/userfunc.h"
#include "nvim/event/loop.h"
#include "nvim/event/time.h"
#include "nvim/ex_cmds.h"
#include "nvim/ex_getln.h"
#include "nvim/extmark.h"
#include "nvim/func_attr.h"

View File

@@ -8,8 +8,8 @@
#include "nvim/ascii.h"
#include "nvim/charset.h"
#include "nvim/cmdexpand.h"
#include "nvim/eval.h"
#include "nvim/ex_getln.h"
#include "nvim/macros.h"
#include "nvim/map.h"
#include "nvim/memory.h"

View File

@@ -8,9 +8,9 @@
#include "nvim/ascii.h"
#include "nvim/charset.h"
#include "nvim/cmdexpand.h"
#include "nvim/eval.h"
#include "nvim/ex_docmd.h"
#include "nvim/ex_getln.h"
#include "nvim/file_search.h"
#include "nvim/fileio.h"
#include "nvim/garray.h"

View File

@@ -9,6 +9,7 @@
#include "nvim/ascii.h"
#include "nvim/autocmd.h"
#include "nvim/charset.h"
#include "nvim/cmdexpand.h"
#include "nvim/debugger.h"
#include "nvim/eval.h"
#include "nvim/eval/userfunc.h"
@@ -16,7 +17,6 @@
#include "nvim/ex_cmds2.h"
#include "nvim/ex_docmd.h"
#include "nvim/ex_eval.h"
#include "nvim/ex_getln.h"
#include "nvim/lua/executor.h"
#include "nvim/memline.h"
#include "nvim/option.h"

View File

@@ -15,10 +15,10 @@
#include "nvim/buffer.h"
#include "nvim/charset.h"
#include "nvim/cmdexpand.h"
#include "nvim/cursor.h"
#include "nvim/drawscreen.h"
#include "nvim/eval.h"
#include "nvim/ex_getln.h"
#include "nvim/extmark.h"
#include "nvim/fileio.h"
#include "nvim/fold.h"

View File

@@ -13,6 +13,7 @@
#include "nvim/ascii.h"
#include "nvim/buffer.h"
#include "nvim/charset.h"
#include "nvim/cmdexpand.h"
#include "nvim/cursor.h"
#include "nvim/drawscreen.h"
#include "nvim/edit.h"