1
0
forked from aniani/vim

patch 8.1.1886: command line expansion code is spread out

Problem:    Command line expansion code is spread out.
Solution:   Move the code to cmdexpand.c. (Yegappan Lakshmanan, closes #4831)
This commit is contained in:
Bram Moolenaar
2019-08-18 21:44:12 +02:00
parent db1085a563
commit 66b51420e0
15 changed files with 2145 additions and 2131 deletions

View File

@@ -24,6 +24,7 @@ SRC_ALL = \
src/change.c \ src/change.c \
src/channel.c \ src/channel.c \
src/charset.c \ src/charset.c \
src/cmdexpand.c \
src/cmdhist.c \ src/cmdhist.c \
src/crypt.c \ src/crypt.c \
src/crypt_zip.c \ src/crypt_zip.c \
@@ -175,6 +176,7 @@ SRC_ALL = \
src/proto/change.pro \ src/proto/change.pro \
src/proto/channel.pro \ src/proto/channel.pro \
src/proto/charset.pro \ src/proto/charset.pro \
src/proto/cmdexpand.pro \
src/proto/cmdhist.pro \ src/proto/cmdhist.pro \
src/proto/crypt.pro \ src/proto/crypt.pro \
src/proto/crypt_zip.pro \ src/proto/crypt_zip.pro \

View File

@@ -711,6 +711,7 @@ OBJ = \
$(OUTDIR)/buffer.o \ $(OUTDIR)/buffer.o \
$(OUTDIR)/change.o \ $(OUTDIR)/change.o \
$(OUTDIR)/charset.o \ $(OUTDIR)/charset.o \
$(OUTDIR)/cmdexpand.o \
$(OUTDIR)/cmdhist.o \ $(OUTDIR)/cmdhist.o \
$(OUTDIR)/crypt.o \ $(OUTDIR)/crypt.o \
$(OUTDIR)/crypt_zip.o \ $(OUTDIR)/crypt_zip.o \

View File

@@ -31,6 +31,7 @@ SRC = arabic.c \
buffer.c \ buffer.c \
change.c \ change.c \
charset.c \ charset.c \
cmdexpand.c \
cmdhist.c \ cmdhist.c \
crypt.c \ crypt.c \
crypt_zip.c \ crypt_zip.c \

View File

@@ -720,6 +720,7 @@ OBJ = \
$(OUTDIR)\buffer.obj \ $(OUTDIR)\buffer.obj \
$(OUTDIR)\change.obj \ $(OUTDIR)\change.obj \
$(OUTDIR)\charset.obj \ $(OUTDIR)\charset.obj \
$(OUTDIR)\cmdexpand.obj \
$(OUTDIR)\cmdhist.obj \ $(OUTDIR)\cmdhist.obj \
$(OUTDIR)\crypt.obj \ $(OUTDIR)\crypt.obj \
$(OUTDIR)\crypt_zip.obj \ $(OUTDIR)\crypt_zip.obj \
@@ -1450,6 +1451,8 @@ $(OUTDIR)/change.obj: $(OUTDIR) change.c $(INCL)
$(OUTDIR)/charset.obj: $(OUTDIR) charset.c $(INCL) $(OUTDIR)/charset.obj: $(OUTDIR) charset.c $(INCL)
$(OUTDIR)/cmdexpand.obj: $(OUTDIR) cmdexpand.c $(INCL)
$(OUTDIR)/cmdhist.obj: $(OUTDIR) cmdhist.c $(INCL) $(OUTDIR)/cmdhist.obj: $(OUTDIR) cmdhist.c $(INCL)
$(OUTDIR)/crypt.obj: $(OUTDIR) crypt.c $(INCL) $(OUTDIR)/crypt.obj: $(OUTDIR) crypt.c $(INCL)
@@ -1754,6 +1757,7 @@ proto.h: \
proto/buffer.pro \ proto/buffer.pro \
proto/change.pro \ proto/change.pro \
proto/charset.pro \ proto/charset.pro \
proto/cmdexpand.pro \
proto/cmdhist.pro \ proto/cmdhist.pro \
proto/crypt.pro \ proto/crypt.pro \
proto/crypt_zip.pro \ proto/crypt_zip.pro \

View File

@@ -2,7 +2,7 @@
# Makefile for Vim on OpenVMS # Makefile for Vim on OpenVMS
# #
# Maintainer: Zoltan Arpadffy <arpadffy@polarhome.com> # Maintainer: Zoltan Arpadffy <arpadffy@polarhome.com>
# Last change: 2019 Jul 14 # Last change: 2019 Aug 18
# #
# This has script been tested on VMS 6.2 to 8.2 on DEC Alpha, VAX and IA64 # This has script been tested on VMS 6.2 to 8.2 on DEC Alpha, VAX and IA64
# with MMS and MMK # with MMS and MMK
@@ -308,11 +308,11 @@ ALL_LIBS = $(LIBS) $(GUI_LIB_DIR) $(GUI_LIB) \
$(PERL_LIB) $(PYTHON_LIB) $(TCL_LIB) $(RUBY_LIB) $(PERL_LIB) $(PYTHON_LIB) $(TCL_LIB) $(RUBY_LIB)
SRC = arabic.c arglist.c autocmd.c beval.c blob.c blowfish.c buffer.c \ SRC = arabic.c arglist.c autocmd.c beval.c blob.c blowfish.c buffer.c \
change.c charset.c cmdhist.c crypt.c crypt_zip.c debugger.c dict.c \ change.c charset.c cmdexpand.c cmdhist.c crypt.c crypt_zip.c \
diff.c digraph.c edit.c eval.c evalfunc.c ex_cmds.c ex_cmds2.c \ debugger.c dict.c diff.c digraph.c edit.c eval.c evalfunc.c ex_cmds.c \
ex_docmd.c ex_eval.c ex_getln.c if_cscope.c if_xcmdsrv.c fileio.c \ ex_cmds2.c ex_docmd.c ex_eval.c ex_getln.c if_cscope.c if_xcmdsrv.c \
findfile.c fold.c getchar.c hardcopy.c hashtab.c highlight.c indent.c \ fileio.c findfile.c fold.c getchar.c hardcopy.c hashtab.c highlight.c \
insexpand.c json.c list.c main.c map.c mark.c menu.c mbyte.c \ indent.c insexpand.c json.c list.c main.c map.c mark.c menu.c mbyte.c \
memfile.c memline.c message.c misc1.c misc2.c move.c normal.c ops.c \ memfile.c memline.c message.c misc1.c misc2.c move.c normal.c ops.c \
option.c popupmnu.c popupwin.c profiler.c quickfix.c regexp.c \ option.c popupmnu.c popupwin.c profiler.c quickfix.c regexp.c \
search.c session.c sha256.c sign.c spell.c spellfile.c syntax.c tag.c \ search.c session.c sha256.c sign.c spell.c spellfile.c syntax.c tag.c \
@@ -323,18 +323,18 @@ SRC = arabic.c arglist.c autocmd.c beval.c blob.c blowfish.c buffer.c \
$(RUBY_SRC) $(HANGULIN_SRC) $(MZSCH_SRC) $(XDIFF_SRC) $(RUBY_SRC) $(HANGULIN_SRC) $(MZSCH_SRC) $(XDIFF_SRC)
OBJ = arabic.obj arglist.obj autocmd.obj beval.obj blob.obj blowfish.obj \ OBJ = arabic.obj arglist.obj autocmd.obj beval.obj blob.obj blowfish.obj \
buffer.obj change.obj charset.obj cmdhist.obj crypt.obj crypt_zip.obj \ buffer.obj change.obj charset.obj cmdexpand.obj cmdhist.obj \
debugger.obj dict.obj diff.obj digraph.obj edit.obj eval.obj \ crypt.obj crypt_zip.obj debugger.obj dict.obj diff.obj digraph.obj \
evalfunc.obj ex_cmds.obj ex_cmds2.obj ex_docmd.obj ex_eval.obj \ edit.obj eval.obj evalfunc.obj ex_cmds.obj ex_cmds2.obj ex_docmd.obj \
ex_getln.obj if_cscope.obj if_xcmdsrv.obj fileio.obj findfile.obj \ ex_eval.obj ex_getln.obj if_cscope.obj if_xcmdsrv.obj fileio.obj \
fold.obj getchar.obj hardcopy.obj hashtab.obj highlight.obj \ findfile.obj fold.obj getchar.obj hardcopy.obj hashtab.obj \
indent.obj insexpand.obj json.obj list.obj main.obj map.obj mark.obj \ highlight.obj indent.obj insexpand.obj json.obj list.obj main.obj \
menu.obj memfile.obj memline.obj message.obj misc1.obj misc2.obj \ map.obj mark.obj menu.obj memfile.obj memline.obj message.obj \
move.obj mbyte.obj normal.obj ops.obj option.obj popupmnu.obj \ misc1.obj misc2.obj move.obj mbyte.obj normal.obj ops.obj option.obj \
popupwin.obj profiler.obj quickfix.obj regexp.obj search.obj \ popupmnu.obj popupwin.obj profiler.obj quickfix.obj regexp.obj \
session.obj sha256.obj sign.obj spell.obj spellfile.obj syntax.obj \ search.obj session.obj sha256.obj sign.obj spell.obj spellfile.obj \
tag.obj term.obj termlib.obj testing.obj textprop.obj ui.obj undo.obj \ syntax.obj tag.obj term.obj termlib.obj testing.obj textprop.obj \
usercmd.obj userfunc.obj screen.obj version.obj \ ui.obj undo.obj usercmd.obj userfunc.obj screen.obj version.obj \
viminfo.obj window.obj os_unix.obj os_vms.obj pathdef.obj if_mzsch.obj \ viminfo.obj window.obj os_unix.obj os_vms.obj pathdef.obj if_mzsch.obj \
$(GUI_OBJ) $(PERL_OBJ) $(PYTHON_OBJ) $(TCL_OBJ) \ $(GUI_OBJ) $(PERL_OBJ) $(PYTHON_OBJ) $(TCL_OBJ) \
$(RUBY_OBJ) $(HANGULIN_OBJ) $(MZSCH_OBJ) $(XDIFF_OBJ) $(RUBY_OBJ) $(HANGULIN_OBJ) $(MZSCH_OBJ) $(XDIFF_OBJ)
@@ -523,6 +523,10 @@ charset.obj : charset.c vim.h [.auto]config.h feature.h os_unix.h \
ascii.h keymap.h term.h macros.h structs.h regexp.h \ ascii.h keymap.h term.h macros.h structs.h regexp.h \
gui.h beval.h [.proto]gui_beval.pro option.h ex_cmds.h proto.h \ gui.h beval.h [.proto]gui_beval.pro option.h ex_cmds.h proto.h \
globals.h globals.h
cmdexpand.obj : cmdexpand.c vim.h [.auto]config.h feature.h os_unix.h \
ascii.h keymap.h term.h macros.h structs.h regexp.h \
gui.h beval.h [.proto]gui_beval.pro option.h ex_cmds.h proto.h \
globals.h
cmdhist.obj : cmdhist.c vim.h [.auto]config.h feature.h os_unix.h \ cmdhist.obj : cmdhist.c vim.h [.auto]config.h feature.h os_unix.h \
ascii.h keymap.h term.h macros.h structs.h regexp.h \ ascii.h keymap.h term.h macros.h structs.h regexp.h \
gui.h beval.h [.proto]gui_beval.pro option.h ex_cmds.h proto.h \ gui.h beval.h [.proto]gui_beval.pro option.h ex_cmds.h proto.h \

View File

@@ -1585,6 +1585,7 @@ BASIC_SRC = \
buffer.c \ buffer.c \
change.c \ change.c \
charset.c \ charset.c \
cmdexpand.c \
cmdhist.c \ cmdhist.c \
crypt.c \ crypt.c \
crypt_zip.c \ crypt_zip.c \
@@ -1712,6 +1713,7 @@ OBJ_COMMON = \
objects/change.o \ objects/change.o \
objects/blob.o \ objects/blob.o \
objects/blowfish.o \ objects/blowfish.o \
objects/cmdexpand.o \
objects/cmdhist.o \ objects/cmdhist.o \
objects/crypt.o \ objects/crypt.o \
objects/crypt_zip.o \ objects/crypt_zip.o \
@@ -1852,6 +1854,7 @@ PRO_AUTO = \
buffer.pro \ buffer.pro \
change.pro \ change.pro \
charset.pro \ charset.pro \
cmdexpand.pro \
cmdhist.pro \ cmdhist.pro \
crypt.pro \ crypt.pro \
crypt_zip.pro \ crypt_zip.pro \
@@ -3013,6 +3016,9 @@ objects/change.o: change.c
objects/charset.o: charset.c objects/charset.o: charset.c
$(CCC) -o $@ charset.c $(CCC) -o $@ charset.c
objects/cmdexpand.o: cmdexpand.c
$(CCC) -o $@ cmdexpand.c
objects/cmdhist.o: cmdhist.c objects/cmdhist.o: cmdhist.c
$(CCC) -o $@ cmdhist.c $(CCC) -o $@ cmdhist.c
@@ -3514,6 +3520,10 @@ objects/charset.o: charset.c vim.h protodef.h auto/config.h feature.h os_unix.h
auto/osdef.h ascii.h keymap.h term.h macros.h option.h beval.h \ auto/osdef.h ascii.h keymap.h term.h macros.h option.h beval.h \
proto/gui_beval.pro structs.h regexp.h gui.h alloc.h ex_cmds.h spell.h \ proto/gui_beval.pro structs.h regexp.h gui.h alloc.h ex_cmds.h spell.h \
proto.h globals.h proto.h globals.h
objects/cmdexpand.o: cmdexpand.c vim.h protodef.h auto/config.h feature.h os_unix.h \
auto/osdef.h ascii.h keymap.h term.h macros.h option.h beval.h \
proto/gui_beval.pro structs.h regexp.h gui.h alloc.h ex_cmds.h spell.h \
proto.h globals.h
objects/cmdhist.o: cmdhist.c vim.h protodef.h auto/config.h feature.h os_unix.h \ objects/cmdhist.o: cmdhist.c vim.h protodef.h auto/config.h feature.h os_unix.h \
auto/osdef.h ascii.h keymap.h term.h macros.h option.h beval.h \ auto/osdef.h ascii.h keymap.h term.h macros.h option.h beval.h \
proto/gui_beval.pro structs.h regexp.h gui.h alloc.h ex_cmds.h spell.h \ proto/gui_beval.pro structs.h regexp.h gui.h alloc.h ex_cmds.h spell.h \

View File

@@ -28,6 +28,7 @@ autocmd.c | autocommands
blob.c | blob data type blob.c | blob data type
buffer.c | manipulating buffers (loaded files) buffer.c | manipulating buffers (loaded files)
change.c | handling changes to text change.c | handling changes to text
cmdexpand.c | command-line completion
cmdhist.c | command-line history cmdhist.c | command-line history
debugger.c | vim script debugger debugger.c | vim script debugger
diff.c | diff mode (vimdiff) diff.c | diff mode (vimdiff)

2031
src/cmdexpand.c Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -135,9 +135,6 @@ static void f_getchar(typval_T *argvars, typval_T *rettv);
static void f_getcharmod(typval_T *argvars, typval_T *rettv); static void f_getcharmod(typval_T *argvars, typval_T *rettv);
static void f_getcharsearch(typval_T *argvars, typval_T *rettv); static void f_getcharsearch(typval_T *argvars, typval_T *rettv);
static void f_getcmdline(typval_T *argvars, typval_T *rettv); static void f_getcmdline(typval_T *argvars, typval_T *rettv);
#if defined(FEAT_CMDL_COMPL)
static void f_getcompletion(typval_T *argvars, typval_T *rettv);
#endif
static void f_getcmdpos(typval_T *argvars, typval_T *rettv); static void f_getcmdpos(typval_T *argvars, typval_T *rettv);
static void f_getcmdtype(typval_T *argvars, typval_T *rettv); static void f_getcmdtype(typval_T *argvars, typval_T *rettv);
static void f_getcmdwintype(typval_T *argvars, typval_T *rettv); static void f_getcmdwintype(typval_T *argvars, typval_T *rettv);
@@ -4701,79 +4698,6 @@ f_getcmdwintype(typval_T *argvars UNUSED, typval_T *rettv)
#endif #endif
} }
#if defined(FEAT_CMDL_COMPL)
/*
* "getcompletion()" function
*/
static void
f_getcompletion(typval_T *argvars, typval_T *rettv)
{
char_u *pat;
expand_T xpc;
int filtered = FALSE;
int options = WILD_SILENT | WILD_USE_NL | WILD_ADD_SLASH
| WILD_NO_BEEP;
if (argvars[2].v_type != VAR_UNKNOWN)
filtered = 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;
ExpandInit(&xpc);
xpc.xp_pattern = tv_get_string(&argvars[0]);
xpc.xp_pattern_len = (int)STRLEN(xpc.xp_pattern);
xpc.xp_context = cmdcomplete_str_to_type(tv_get_string(&argvars[1]));
if (xpc.xp_context == EXPAND_NOTHING)
{
if (argvars[1].v_type == VAR_STRING)
semsg(_(e_invarg2), argvars[1].vval.v_string);
else
emsg(_(e_invarg));
return;
}
# if defined(FEAT_MENU)
if (xpc.xp_context == EXPAND_MENUS)
{
set_context_in_menu_cmd(&xpc, (char_u *)"menu", xpc.xp_pattern, FALSE);
xpc.xp_pattern_len = (int)STRLEN(xpc.xp_pattern);
}
# endif
#ifdef FEAT_CSCOPE
if (xpc.xp_context == EXPAND_CSCOPE)
{
set_context_in_cscope_cmd(&xpc, xpc.xp_pattern, CMD_cscope);
xpc.xp_pattern_len = (int)STRLEN(xpc.xp_pattern);
}
#endif
#ifdef FEAT_SIGNS
if (xpc.xp_context == EXPAND_SIGN)
{
set_context_in_sign_cmd(&xpc, xpc.xp_pattern);
xpc.xp_pattern_len = (int)STRLEN(xpc.xp_pattern);
}
#endif
pat = addstar(xpc.xp_pattern, xpc.xp_pattern_len, xpc.xp_context);
if ((rettv_list_alloc(rettv) != FAIL) && (pat != NULL))
{
int i;
ExpandOne(&xpc, pat, NULL, options, WILD_ALL_KEEP);
for (i = 0; i < xpc.xp_numfiles; i++)
list_append_string(rettv->vval.v_list, xpc.xp_files[i], -1);
}
vim_free(pat);
ExpandCleanup(&xpc);
}
#endif
/* /*
* "getcwd()" function * "getcwd()" function
* *

File diff suppressed because it is too large Load Diff

View File

@@ -66,6 +66,7 @@ extern int _stricoll(char *a, char *b);
# include "buffer.pro" # include "buffer.pro"
# include "change.pro" # include "change.pro"
# include "charset.pro" # include "charset.pro"
# include "cmdexpand.pro"
# include "cmdhist.pro" # include "cmdhist.pro"
# ifdef FEAT_CSCOPE # ifdef FEAT_CSCOPE
# include "if_cscope.pro" # include "if_cscope.pro"

14
src/proto/cmdexpand.pro Normal file
View File

@@ -0,0 +1,14 @@
/* cmdexpand.c */
int nextwild(expand_T *xp, int type, int options, int escape);
char_u *ExpandOne(expand_T *xp, char_u *str, char_u *orig, int options, int mode);
void ExpandInit(expand_T *xp);
void ExpandCleanup(expand_T *xp);
int showmatches(expand_T *xp, int wildmenu);
char_u *sm_gettail(char_u *s);
char_u *addstar(char_u *fname, int len, int context);
void set_cmd_context(expand_T *xp, char_u *str, int len, int col, int use_ccline);
int expand_cmdline(expand_T *xp, char_u *str, int col, int *matchcount, char_u ***matches);
int ExpandGeneric(expand_T *xp, regmatch_T *regmatch, int *num_file, char_u ***file, char_u *((*func)(expand_T *, int)), int escaped);
void globpath(char_u *path, char_u *file, garray_T *ga, int expand_options);
void f_getcompletion(typval_T *argvars, typval_T *rettv);
/* vim: set ft=c : */

View File

@@ -12,6 +12,7 @@ char_u *getexmodeline(int promptc, void *cookie, int indent, int do_concat);
int cmdline_overstrike(void); int cmdline_overstrike(void);
int cmdline_at_end(void); int cmdline_at_end(void);
colnr_T cmdline_getvcol_cursor(void); colnr_T cmdline_getvcol_cursor(void);
int realloc_cmdbuff(int len);
void free_arshape_buf(void); void free_arshape_buf(void);
void putcmdline(int c, int shift); void putcmdline(int c, int shift);
void unputcmdline(void); void unputcmdline(void);
@@ -21,19 +22,12 @@ void redrawcmdline(void);
void redrawcmdline_ex(int do_compute_cmdrow); void redrawcmdline_ex(int do_compute_cmdrow);
void redrawcmd(void); void redrawcmd(void);
void compute_cmdrow(void); void compute_cmdrow(void);
void cursorcmd(void);
void gotocmdline(int clr); void gotocmdline(int clr);
char_u *ExpandOne(expand_T *xp, char_u *str, char_u *orig, int options, int mode);
void ExpandInit(expand_T *xp);
void ExpandCleanup(expand_T *xp);
void ExpandEscape(expand_T *xp, char_u *str, int numfiles, char_u **files, int options);
char_u *vim_strsave_fnameescape(char_u *fname, int shell); char_u *vim_strsave_fnameescape(char_u *fname, int shell);
void escape_fname(char_u **pp);
void tilde_replace(char_u *orig_pat, int num_files, char_u **files); void tilde_replace(char_u *orig_pat, int num_files, char_u **files);
char_u *sm_gettail(char_u *s); cmdline_info_T *get_cmdline_info(void);
char_u *addstar(char_u *fname, int len, int context);
void set_cmd_context(expand_T *xp, char_u *str, int len, int col, int use_ccline);
int expand_cmdline(expand_T *xp, char_u *str, int col, int *matchcount, char_u ***matches);
int ExpandGeneric(expand_T *xp, regmatch_T *regmatch, int *num_file, char_u ***file, char_u *((*func)(expand_T *, int)), int escaped);
void globpath(char_u *path, char_u *file, garray_T *ga, int expand_options);
char_u *get_cmdline_str(void); char_u *get_cmdline_str(void);
int get_cmdline_pos(void); int get_cmdline_pos(void);
int set_cmdline_pos(int pos); int set_cmdline_pos(int pos);

View File

@@ -578,6 +578,33 @@ typedef struct expand
#define XP_BS_ONE 1 // uses one backslash before a space #define XP_BS_ONE 1 // uses one backslash before a space
#define XP_BS_THREE 2 // uses three backslashes before a space #define XP_BS_THREE 2 // uses three backslashes before a space
/*
* 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
{
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 */
# ifdef FEAT_EVAL
char_u *xp_arg; /* user-defined expansion arg */
int input_fn; /* when TRUE Invoked for input() function */
# endif
} cmdline_info_T;
/* /*
* Command modifiers ":vertical", ":browse", ":confirm" and ":hide" set a flag. * Command modifiers ":vertical", ":browse", ":confirm" and ":hide" set a flag.
* This needs to be saved for recursive commands, put them in a structure for * This needs to be saved for recursive commands, put them in a structure for

View File

@@ -769,6 +769,8 @@ static char *(features[]) =
static int included_patches[] = static int included_patches[] =
{ /* Add new patch number below this line */ { /* Add new patch number below this line */
/**/
1886,
/**/ /**/
1885, 1885,
/**/ /**/