0
0
mirror of https://github.com/vim/vim.git synced 2025-09-01 21:03:39 -04:00

patch 8.1.1210: support for user commands is spread out

Problem:    Support for user commands is spread out. No good reason to make
            user commands optional.
Solution:   Move user command support to usercmd.c.  Always enable the
            user_commands feature.
This commit is contained in:
Bram Moolenaar 2019-04-27 13:04:13 +02:00
parent 5431589d25
commit ac9fb18020
29 changed files with 1778 additions and 1738 deletions

View File

@ -98,6 +98,7 @@ SRC_ALL = \
src/textprop.c \
src/ui.c \
src/undo.c \
src/usercmd.c \
src/userfunc.c \
src/version.c \
src/version.h \
@ -212,6 +213,7 @@ SRC_ALL = \
src/proto/textprop.pro \
src/proto/ui.pro \
src/proto/undo.pro \
src/proto/usercmd.pro \
src/proto/userfunc.pro \
src/proto/version.pro \
src/proto/winclip.pro \

View File

@ -1,4 +1,4 @@
*eval.txt* For Vim version 8.1. Last change: 2019 Apr 21
*eval.txt* For Vim version 8.1. Last change: 2019 Apr 27
VIM REFERENCE MANUAL by Bram Moolenaar
@ -10550,7 +10550,7 @@ ttyin input is a terminal (tty)
ttyout output is a terminal (tty)
unix Unix version of Vim. *+unix*
unnamedplus Compiled with support for "unnamedplus" in 'clipboard'
user_commands User-defined commands.
user_commands User-defined commands. (always true)
vcon Win32: Virtual console support is working, can use
'termguicolors'. Also see |+vtp|.
vertsplit Compiled with vertically split windows |:vsplit|.

View File

@ -456,7 +456,8 @@ N *+textprop* |text-properties|
N *+timers* the |timer_start()| function
N *+title* Setting the window 'title' and 'icon'
N *+toolbar* |gui-toolbar|
N *+user_commands* User-defined commands. |user-commands|
T *+user_commands* User-defined commands. |user-commands|
Always enabled since 8.1.1210.
B *+vartabs* Variable-width tabstops. |'vartabstop'|
N *+viminfo* |'viminfo'|
*+vertsplit* Vertically split windows |:vsplit|; Always enabled

View File

@ -565,6 +565,7 @@ vimobj = \
$(OBJDIR)\term.obj \
$(OBJDIR)\ui.obj \
$(OBJDIR)\undo.obj \
$(OBJDIR)\usercmd.obj \
$(OBJDIR)\userfunc.obj \
$(OBJDIR)\version.obj \
$(OBJDIR)\window.obj \

View File

@ -757,6 +757,7 @@ OBJ = \
$(OUTDIR)/textprop.o \
$(OUTDIR)/ui.o \
$(OUTDIR)/undo.o \
$(OUTDIR)/usercmd.o \
$(OUTDIR)/userfunc.o \
$(OUTDIR)/version.o \
$(OUTDIR)/vimrc.o \

View File

@ -83,6 +83,7 @@ SRC = \
term.c \
ui.c \
undo.c \
usercmd.c \
userfunc.c \
window.c \
version.c
@ -144,6 +145,7 @@ OBJ = o/arabic.o \
o/term.o \
o/ui.o \
o/undo.o \
o/usercmd.o \
o/userfunc.o \
o/window.o \
$(TERMLIB)
@ -288,6 +290,8 @@ o/ui.o: ui.c $(SYMS)
o/undo.o: undo.c $(SYMS)
o/usercmd.o: usercmd.c $(SYMS)
o/userfunc.o: userfunc.c $(SYMS)
o/window.o: window.c $(SYMS)

View File

@ -269,6 +269,7 @@ LINK32_OBJS= \
"$(INTDIR)/term.obj" \
"$(INTDIR)/ui.obj" \
"$(INTDIR)/undo.obj" \
"$(INTDIR)/usercmd.obj" \
"$(INTDIR)/userfunc.obj" \
"$(INTDIR)/version.obj" \
"$(INTDIR)/window.obj"
@ -728,6 +729,10 @@ SOURCE=.\undo.c
# End Source File
# Begin Source File
SOURCE=.\usercmd.c
# End Source File
# Begin Source File
SOURCE=.\userfunc.c
# End Source File
# Begin Source File

View File

@ -93,6 +93,7 @@ SRC = arabic.c \
term.c \
ui.c \
undo.c \
usercmd.c \
userfunc.c \
window.c \
version.c
@ -156,6 +157,7 @@ OBJ = obj/arabic.o \
obj/term.o \
obj/ui.o \
obj/undo.o \
obj/usercmd.o \
obj/userfunc.o \
obj/window.o \
$(TERMLIB)
@ -218,6 +220,7 @@ PRO = proto/arabic.pro \
proto/termlib.pro \
proto/ui.pro \
proto/undo.pro \
proto/usercmd.pro \
proto/userfunc.pro \
proto/window.pro
@ -443,6 +446,9 @@ obj/ui.o: ui.c
obj/undo.o: undo.c
$(CCSYM) $@ undo.c
obj/usercmd.o: usercmd.c
$(CCSYM) $@ usercmd.c
obj/userfunc.o: userfunc.c
$(CCSYM) $@ userfunc.c

View File

@ -81,6 +81,7 @@ SRC = arabic.c \
term.c \
ui.c \
undo.c \
usercmd.c \
userfunc.c \
version.c \
window.c \

View File

@ -765,6 +765,7 @@ OBJ = \
$(OUTDIR)\textprop.obj \
$(OUTDIR)\ui.obj \
$(OUTDIR)\undo.obj \
$(OUTDIR)\usercmd.obj \
$(OUTDIR)\userfunc.obj \
$(OUTDIR)\winclip.obj \
$(OUTDIR)\window.obj \
@ -1550,6 +1551,8 @@ $(OUTDIR)/ui.obj: $(OUTDIR) ui.c $(INCL)
$(OUTDIR)/undo.obj: $(OUTDIR) undo.c $(INCL)
$(OUTDIR)/usercmd.obj: $(OUTDIR) usercmd.c $(INCL)
$(OUTDIR)/userfunc.obj: $(OUTDIR) userfunc.c $(INCL)
$(OUTDIR)/window.obj: $(OUTDIR) window.c $(INCL)
@ -1693,6 +1696,7 @@ proto.h: \
proto/textprop.pro \
proto/ui.pro \
proto/undo.pro \
proto/usercmd.pro \
proto/userfunc.pro \
proto/window.pro \
$(NETBEANS_PRO) \

View File

@ -146,6 +146,7 @@ SRC = \
term.c \
ui.c \
undo.c \
usercmd.c \
userfunc.c \
window.c \
version.c
@ -208,6 +209,7 @@ OBJ = \
term.o \
ui.o \
undo.o \
usercmd.o \
userfunc.o \
window.o \
$(TERMLIB)
@ -271,6 +273,7 @@ PRO = \
proto/termlib.pro \
proto/ui.pro \
proto/undo.pro \
proto/usercmd.pro \
proto/userfunc.pro \
proto/window.pro
@ -445,6 +448,8 @@ ui.o: ui.c
proto/ui.pro: ui.c
undo.o: undo.c
proto/undo.pro: undo.c
usercmd.o: usercmd.c
proto/usercmd.pro: usercmd.c
userfunc.o: userfunc.c
proto/userfunc.pro: userfunc.c
window.o: window.c

View File

@ -2,7 +2,7 @@
# Makefile for Vim on OpenVMS
#
# Maintainer: Zoltan Arpadffy <arpadffy@polarhome.com>
# Last change: 2019 Mar 22
# Last change: 2019 Apr 26
#
# This has script been tested on VMS 6.2 to 8.2 on DEC Alpha, VAX and IA64
# with MMS and MMK
@ -315,8 +315,8 @@ SRC = arabic.c autocmd.c beval.c blob.c blowfish.c buffer.c charset.c \
menu.c mbyte.c memfile.c memline.c message.c misc1.c misc2.c move.c \
normal.c ops.c option.c popupmnu.c quickfix.c regexp.c search.c \
sha256.c sign.c spell.c spellfile.c syntax.c tag.c term.c termlib.c \
textprop.c ui.c undo.c userfunc.c version.c screen.c window.c \
os_unix.c os_vms.c pathdef.c \
textprop.c ui.c undo.c usercmd.c userfunc.c version.c screen.c \
window.c os_unix.c os_vms.c pathdef.c \
$(GUI_SRC) $(PERL_SRC) $(PYTHON_SRC) $(TCL_SRC) \
$(RUBY_SRC) $(HANGULIN_SRC) $(MZSCH_SRC) $(XDIFF_SRC)
@ -330,7 +330,7 @@ OBJ = arabic.obj autocmd.obj beval.obj blob.obj blowfish.obj buffer.obj \
move.obj mbyte.obj normal.obj ops.obj option.obj popupmnu.obj \
quickfix.obj regexp.obj search.obj sha256.obj sign.obj spell.obj \
spellfile.obj syntax.obj tag.obj term.obj termlib.obj textprop.obj \
ui.obj undo.obj userfunc.obj screen.obj version.obj \
ui.obj undo.obj usercmd.obj userfunc.obj screen.obj version.obj \
window.obj os_unix.obj os_vms.obj pathdef.obj if_mzsch.obj \
$(GUI_OBJ) $(PERL_OBJ) $(PYTHON_OBJ) $(TCL_OBJ) \
$(RUBY_OBJ) $(HANGULIN_OBJ) $(MZSCH_OBJ) $(XDIFF_OBJ)
@ -744,10 +744,16 @@ undo.obj : undo.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 \
usercmd.obj : usercmd.c vim.h [.auto]config.h feature.h os_unix.h \
ascii.h keymap.h term.h macros.h option.h structs.h \
regexp.h gui.h beval.h [.proto]gui_beval.pro alloc.h ex_cmds.h spell.h \
proto.h globals.h
userfunc.obj : userfunc.c vim.h [.auto]config.h feature.h os_unix.h \
ascii.h keymap.h term.h macros.h option.h structs.h \
regexp.h gui.h beval.h [.proto]gui_beval.pro alloc.h ex_cmds.h spell.h \
proto.h globals.h
version.obj : version.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 \

View File

@ -1635,6 +1635,7 @@ BASIC_SRC = \
textprop.c \
ui.c \
undo.c \
usercmd.c \
userfunc.c \
version.c \
window.c \
@ -1747,6 +1748,7 @@ OBJ_COMMON = \
objects/textprop.o \
objects/ui.o \
objects/undo.o \
objects/usercmd.o \
objects/userfunc.o \
objects/version.o \
objects/window.o \
@ -1885,6 +1887,7 @@ PRO_AUTO = \
textprop.pro \
ui.pro \
undo.pro \
usercmd.pro \
userfunc.pro \
version.pro \
window.pro \
@ -3242,6 +3245,9 @@ objects/ui.o: ui.c
objects/undo.o: undo.c
$(CCC) -o $@ undo.c
objects/usercmd.o: usercmd.c
$(CCC) -o $@ usercmd.c
objects/userfunc.o: userfunc.c
$(CCC) -o $@ userfunc.c
@ -3657,6 +3663,10 @@ objects/undo.o: undo.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/usercmd.o: usercmd.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/userfunc.o: userfunc.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 \

View File

@ -28,6 +28,7 @@ buffer.c | manipulating buffers (loaded files)
debugger.c | vim script debugger
diff.c | diff mode (vimdiff)
eval.c | expression evaluation
evalfunc.c | built-in functions
fileio.c | reading and writing files
findfile.c | search for files in 'path'
fold.c | folding
@ -40,7 +41,7 @@ memfile.c | storing lines for buffers in a swapfile
memline.c | storing lines for buffers in memory
menu.c | menus
message.c | (error) messages
ops.c | handling operators ("d", "y", "p")
ops.c | handling operators ("d", "y", "p")
option.c | options
quickfix.c | quickfix commands (":make", ":cn")
regexp.c | pattern matching
@ -49,9 +50,11 @@ search.c | pattern searching
sign.c | signs
spell.c | spell checking
syntax.c | syntax and other highlighting
tag.c | tags
tag.c | tags
term.c | terminal handling, termcap codes
undo.c | undo and redo
usercmd.c | user defined commands
userfunc.c | user defined functions
window.c | handling split windows

View File

@ -925,11 +925,9 @@ free_buffer_stuff(
CHANGEDTICK(buf) = tick;
}
#endif
#ifdef FEAT_USR_CMDS
uc_clear(&buf->b_ucmds); /* clear local user commands */
#endif
uc_clear(&buf->b_ucmds); // clear local user commands
#ifdef FEAT_SIGNS
buf_delete_signs(buf, (char_u *)"*"); // delete any signs */
buf_delete_signs(buf, (char_u *)"*"); // delete any signs
#endif
#ifdef FEAT_NETBEANS_INTG
netbeans_file_killed(buf);

View File

@ -1120,10 +1120,10 @@ call_func_retnr(
return retval;
}
#if (defined(FEAT_USR_CMDS) && defined(FEAT_CMDL_COMPL)) \
#if defined(FEAT_CMDL_COMPL) \
|| defined(FEAT_COMPL_FUNC) || defined(PROTO)
# if (defined(FEAT_USR_CMDS) && defined(FEAT_CMDL_COMPL)) || defined(PROTO)
# if defined(FEAT_CMDL_COMPL) || defined(PROTO)
/*
* Call Vim script function "func" and return the result as a string.
* Returns NULL when calling the function fails.

View File

@ -6611,10 +6611,8 @@ f_has(typval_T *argvars, typval_T *rettv)
#if defined(FEAT_CLIPBOARD) && defined(FEAT_X11)
"unnamedplus",
#endif
#ifdef FEAT_USR_CMDS
"user-commands", /* was accidentally included in 5.4 */
"user_commands",
#endif
#ifdef FEAT_VARTABS
"vartabs",
#endif

View File

@ -1753,13 +1753,9 @@ EX(CMD_tilde, "~", do_sub,
ADDR_LINES),
#ifndef DO_DECLARE_EXCMD
#ifdef FEAT_USR_CMDS
CMD_SIZE, /* MUST be after all real commands! */
CMD_USER = -1, /* User-defined command */
CMD_USER_BUF = -2 /* User-defined command local to buffer */
#else
CMD_SIZE /* MUST be the last one! */
#endif
#endif
};
@ -1795,9 +1791,7 @@ struct exarg
int force_ff; /* ++ff= argument (first char of argument) */
int force_enc; /* ++enc= argument (index in cmd[]) */
int bad_char; /* BAD_KEEP, BAD_DROP or replacement byte */
#ifdef FEAT_USR_CMDS
int useridx; /* user command index */
#endif
char *errmsg; /* returned error message */
char_u *(*getline)(int, void *, int);
void *cookie; /* argument for getline() */

File diff suppressed because it is too large Load Diff

View File

@ -111,7 +111,7 @@ static int ExpandPackAddDir(char_u *pat, int *num_file, char_u ***file);
# ifdef FEAT_CMDHIST
static char_u *get_history_arg(expand_T *xp, int idx);
# endif
# if defined(FEAT_USR_CMDS) && defined(FEAT_EVAL)
# if defined(FEAT_EVAL)
static int ExpandUserDefined(expand_T *xp, regmatch_T *regmatch, int *num_file, char_u ***file);
static int ExpandUserList(expand_T *xp, int *num_file, char_u ***file);
# endif
@ -939,7 +939,7 @@ getcmdline_int(
{
xpc.xp_context = ccline.xp_context;
xpc.xp_pattern = ccline.cmdbuff;
# if defined(FEAT_USR_CMDS) && defined(FEAT_CMDL_COMPL)
# if defined(FEAT_CMDL_COMPL)
xpc.xp_arg = ccline.xp_arg;
# endif
}
@ -4210,7 +4210,7 @@ ExpandInit(expand_T *xp)
#endif
xp->xp_numfiles = -1;
xp->xp_files = NULL;
#if defined(FEAT_USR_CMDS) && defined(FEAT_EVAL) && defined(FEAT_CMDL_COMPL)
#if defined(FEAT_EVAL) && defined(FEAT_CMDL_COMPL)
xp->xp_arg = NULL;
#endif
xp->xp_line = NULL;
@ -4879,7 +4879,7 @@ set_cmd_context(
{
xp->xp_context = ccline.xp_context;
xp->xp_pattern = ccline.cmdbuff;
# if defined(FEAT_USR_CMDS) && defined(FEAT_CMDL_COMPL)
# if defined(FEAT_CMDL_COMPL)
xp->xp_arg = ccline.xp_arg;
# endif
}
@ -5130,7 +5130,7 @@ ExpandFromContext(
char *directories[] = {"syntax", "indent", "ftplugin", NULL};
return ExpandRTDir(pat, 0, num_file, file, directories);
}
# if defined(FEAT_USR_CMDS) && defined(FEAT_EVAL)
# if defined(FEAT_EVAL)
if (xp->xp_context == EXPAND_USER_LIST)
return ExpandUserList(xp, num_file, file);
# endif
@ -5149,7 +5149,7 @@ ExpandFromContext(
ret = ExpandSettings(xp, &regmatch, num_file, file);
else if (xp->xp_context == EXPAND_MAPPINGS)
ret = ExpandMappings(&regmatch, num_file, file);
# if defined(FEAT_USR_CMDS) && defined(FEAT_EVAL)
# if defined(FEAT_EVAL)
else if (xp->xp_context == EXPAND_USER_DEFINED)
ret = ExpandUserDefined(xp, &regmatch, num_file, file);
# endif
@ -5170,13 +5170,11 @@ ExpandFromContext(
#ifdef FEAT_CMDHIST
{EXPAND_HISTORY, get_history_arg, TRUE, TRUE},
#endif
#ifdef FEAT_USR_CMDS
{EXPAND_USER_COMMANDS, get_user_commands, FALSE, TRUE},
{EXPAND_USER_ADDR_TYPE, get_user_cmd_addr_type, FALSE, TRUE},
{EXPAND_USER_CMD_FLAGS, get_user_cmd_flags, FALSE, TRUE},
{EXPAND_USER_NARGS, get_user_cmd_nargs, FALSE, TRUE},
{EXPAND_USER_COMPLETE, get_user_cmd_complete, FALSE, TRUE},
#endif
#ifdef FEAT_EVAL
{EXPAND_USER_VARS, get_user_var_name, FALSE, TRUE},
{EXPAND_FUNCTIONS, get_function_name, FALSE, TRUE},
@ -5473,7 +5471,7 @@ expand_shellcmd(
}
# if defined(FEAT_USR_CMDS) && defined(FEAT_EVAL)
# if defined(FEAT_EVAL)
/*
* Call "user_expand_func()" to invoke a user defined Vim script function and
* return the result (either a string or a List).

View File

@ -379,10 +379,8 @@
/*
* +user_commands Allow the user to define his own commands.
* Now always enabled.
*/
#ifdef FEAT_NORMAL
# define FEAT_USR_CMDS
#endif
/*
* +printer ":hardcopy" command

View File

@ -336,3 +336,6 @@
(p) = NULL; \
} \
} while (0)
/* Wether a command index indicates a user command. */
#define IS_USER_CMDIDX(idx) ((int)(idx) < 0)

View File

@ -1082,10 +1082,8 @@ free_all_mem(void)
ui_remove_balloon();
# endif
# if defined(FEAT_USR_CMDS)
/* Clear user commands (before deleting buffers). */
// Clear user commands (before deleting buffers).
ex_comclear(NULL);
# endif
# ifdef FEAT_MENU
/* Clear menus. */
@ -1130,7 +1128,9 @@ free_all_mem(void)
free_search_patterns();
free_old_sub();
free_last_insert();
# if defined(FEAT_INS_EXPAND)
free_insexpand_stuff();
# endif
free_prev_shellcmd();
free_regexp_stuff();
free_tag_stuff();

View File

@ -227,6 +227,7 @@ void qsort(void *base, size_t elm_count, size_t elm_size, int (*cmp)(const void
# endif
# include "ui.pro"
# include "undo.pro"
# include "usercmd.pro"
# include "userfunc.pro"
# include "version.pro"
# include "window.pro"

View File

@ -19,16 +19,6 @@ int ends_excmd(int c);
char_u *find_nextcmd(char_u *p);
char_u *check_nextcmd(char_u *p);
char_u *get_command_name(expand_T *xp, int idx);
void ex_comclear(exarg_T *eap);
void uc_clear(garray_T *gap);
char_u *get_user_commands(expand_T *xp, int idx);
char_u *get_user_cmd_addr_type(expand_T *xp, int idx);
char_u *get_user_cmd_flags(expand_T *xp, int idx);
char_u *get_user_cmd_nargs(expand_T *xp, int idx);
char_u *get_user_cmd_complete(expand_T *xp, int idx);
int parse_addr_type_arg(char_u *value, int vallen, long *argt, int *addr_type_arg);
int parse_compl_arg(char_u *value, int vallen, int *complp, long *argt, char_u **compl_arg);
int cmdcomplete_str_to_type(char_u *complete_str);
void not_exiting(void);
void tabpage_close(int forceit);
void tabpage_close_other(tabpage_T *tp, int forceit);

18
src/proto/usercmd.pro Normal file
View File

@ -0,0 +1,18 @@
/* usercmd.c */
char_u *find_ucmd(exarg_T *eap, char_u *p, int *full, expand_T *xp, int *compl);
char_u *set_context_in_user_cmd(expand_T *xp, char_u *arg_in);
char_u *get_user_command_name(int idx);
char_u *get_user_commands(expand_T *xp, int idx);
char_u *get_user_cmd_addr_type(expand_T *xp, int idx);
char_u *get_user_cmd_flags(expand_T *xp, int idx);
char_u *get_user_cmd_nargs(expand_T *xp, int idx);
char_u *get_user_cmd_complete(expand_T *xp, int idx);
char *uc_fun_cmd(void);
void ex_command(exarg_T *eap);
void ex_comclear(exarg_T *eap);
void uc_clear(garray_T *gap);
void ex_delcommand(exarg_T *eap);
void do_ucmd(exarg_T *eap);
int parse_compl_arg(char_u *value, int vallen, int *complp, long *argt, char_u **compl_arg);
int cmdcomplete_str_to_type(char_u *complete_str);
/* vim: set ft=c : */

View File

@ -549,7 +549,7 @@ typedef struct expand
int xp_context; /* type of expansion */
char_u *xp_pattern; /* start of item to expand */
int xp_pattern_len; /* bytes in xp_pattern before cursor */
#if defined(FEAT_USR_CMDS) && defined(FEAT_EVAL) && defined(FEAT_CMDL_COMPL)
#if defined(FEAT_EVAL) && defined(FEAT_CMDL_COMPL)
char_u *xp_arg; /* completion function */
sctx_T xp_script_ctx; /* SCTX for completion function */
#endif
@ -2143,10 +2143,8 @@ struct file_buffer
/* First abbreviation local to a buffer. */
mapblock_T *b_first_abbr;
#endif
#ifdef FEAT_USR_CMDS
/* User commands local to the buffer. */
// User commands local to the buffer.
garray_T b_ucmds;
#endif
/*
* start and end of an operator, also used for '[ and ']
*/

1656
src/usercmd.c Normal file

File diff suppressed because it is too large Load Diff

View File

@ -672,11 +672,7 @@ static char *(features[]) =
#else
"-toolbar",
#endif
#ifdef FEAT_USR_CMDS
"+user_commands",
#else
"-user_commands",
#endif
#ifdef FEAT_VARTABS
"+vartabs",
#else
@ -771,6 +767,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
1210,
/**/
1209,
/**/