diff options
author | Bram Moolenaar <Bram@vim.org> | 2019-03-30 13:53:47 +0100 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2019-03-30 13:53:47 +0100 |
commit | 7591bb39d58ece38a5fef984a08ea9012616c1f9 (patch) | |
tree | e5e5b82ffd29f4f922ebfb5a97ea12a8b3624b7c | |
parent | de5b3800427328170574f1950ae75776e020f4e7 (diff) |
patch 8.1.1076: file for Insert mode is much too bigv8.1.1076
Problem: File for Insert mode is much too big.
Solution: Split off the code for Insert completion. (Yegappan Lakshmanan,
closes #4044)
-rw-r--r-- | Filelist | 2 | ||||
-rw-r--r-- | src/Make_bc5.mak | 1 | ||||
-rw-r--r-- | src/Make_cyg_ming.mak | 1 | ||||
-rw-r--r-- | src/Make_dice.mak | 4 | ||||
-rw-r--r-- | src/Make_ivc.mak | 5 | ||||
-rw-r--r-- | src/Make_manx.mak | 6 | ||||
-rw-r--r-- | src/Make_morph.mak | 1 | ||||
-rw-r--r-- | src/Make_mvc.mak | 4 | ||||
-rw-r--r-- | src/Make_sas.mak | 5 | ||||
-rw-r--r-- | src/Make_vms.mms | 21 | ||||
-rw-r--r-- | src/Makefile | 10 | ||||
-rw-r--r-- | src/edit.c | 4018 | ||||
-rw-r--r-- | src/evalfunc.c | 2 | ||||
-rw-r--r-- | src/globals.h | 4 | ||||
-rw-r--r-- | src/insexpand.c | 3992 | ||||
-rw-r--r-- | src/misc2.c | 1 | ||||
-rw-r--r-- | src/proto.h | 3 | ||||
-rw-r--r-- | src/proto/edit.pro | 19 | ||||
-rw-r--r-- | src/proto/insexpand.pro | 50 | ||||
-rw-r--r-- | src/search.c | 4 | ||||
-rw-r--r-- | src/spell.c | 2 | ||||
-rw-r--r-- | src/structs.h | 40 | ||||
-rw-r--r-- | src/tag.c | 2 | ||||
-rw-r--r-- | src/version.c | 2 |
24 files changed, 4176 insertions, 4023 deletions
@@ -48,6 +48,7 @@ SRC_ALL = \ src/hardcopy.c \ src/hashtab.c \ src/indent.c \ + src/insexpand.c \ src/json.c \ src/json_test.c \ src/kword_test.c \ @@ -175,6 +176,7 @@ SRC_ALL = \ src/proto/hardcopy.pro \ src/proto/hashtab.pro \ src/proto/indent.pro \ + src/proto/insexpand.pro \ src/proto/json.pro \ src/proto/list.pro \ src/proto/main.pro \ diff --git a/src/Make_bc5.mak b/src/Make_bc5.mak index 7b5b0f2ccf..1c13931d31 100644 --- a/src/Make_bc5.mak +++ b/src/Make_bc5.mak @@ -534,6 +534,7 @@ vimobj = \ $(OBJDIR)\hardcopy.obj \ $(OBJDIR)\hashtab.obj \ $(OBJDIR)\indent.obj \ + $(OBJDIR)\insexpand.obj \ $(OBJDIR)\json.obj \ $(OBJDIR)\list.obj \ $(OBJDIR)\main.obj \ diff --git a/src/Make_cyg_ming.mak b/src/Make_cyg_ming.mak index 98210c1f0e..e439de3517 100644 --- a/src/Make_cyg_ming.mak +++ b/src/Make_cyg_ming.mak @@ -721,6 +721,7 @@ OBJ = \ $(OUTDIR)/hardcopy.o \ $(OUTDIR)/hashtab.o \ $(OUTDIR)/indent.o \ + $(OUTDIR)/insexpand.o \ $(OUTDIR)/json.o \ $(OUTDIR)/list.o \ $(OUTDIR)/main.o \ diff --git a/src/Make_dice.mak b/src/Make_dice.mak index 2025974fc5..5bad80b850 100644 --- a/src/Make_dice.mak +++ b/src/Make_dice.mak @@ -51,6 +51,7 @@ SRC = \ hardcopy.c \ hashtab.c \ indent.c \ + insexpand.c \ json.c \ list.c \ main.c \ @@ -110,6 +111,7 @@ OBJ = o/arabic.o \ o/hardcopy.o \ o/hashtab.o \ o/indent.o \ + o/insexpand.o \ o/json.o \ o/list.o \ o/main.o \ @@ -213,6 +215,8 @@ o/hashtab.o: hashtab.c $(SYMS) o/indent.o: indent.c $(SYMS) +o/insexpand.o: insexpand.c $(SYMS) + o/json.o: json.c $(SYMS) o/list.o: list.c $(SYMS) diff --git a/src/Make_ivc.mak b/src/Make_ivc.mak index 0691e8dfc1..27b2c336d7 100644 --- a/src/Make_ivc.mak +++ b/src/Make_ivc.mak @@ -235,6 +235,7 @@ LINK32_OBJS= \ "$(INTDIR)/hardcopy.obj" \ "$(INTDIR)/hashtab.obj" \ "$(INTDIR)/indent.obj" \ + "$(INTDIR)/insexpand.obj" \ "$(INTDIR)/json.obj" \ "$(INTDIR)/list.obj" \ "$(INTDIR)/main.obj" \ @@ -439,6 +440,10 @@ SOURCE=.\hashtab.c SOURCE=.\indent.c # End Source File # Begin Source File +# +SOURCE=.\insexpand.c +# End Source File +# Begin Source File SOURCE=.\gui.c diff --git a/src/Make_manx.mak b/src/Make_manx.mak index 2cbc3df6aa..d150e4b6fc 100644 --- a/src/Make_manx.mak +++ b/src/Make_manx.mak @@ -61,6 +61,7 @@ SRC = arabic.c \ hardcopy.c \ hashtab.c \ indent.c \ + insexpand.c \ json.c \ list.c \ main.c \ @@ -122,6 +123,7 @@ OBJ = obj/arabic.o \ obj/hardcopy.o \ obj/hashtab.o \ obj/indent.o \ + obj/insexpand.o \ obj/json.o \ obj/list.o \ obj/main.o \ @@ -181,6 +183,7 @@ PRO = proto/arabic.pro \ proto/hardcopy.pro \ proto/hashtab.pro \ proto/indent.pro \ + proto/insexpand.pro \ proto/json.pro \ proto/list.pro \ proto/main.pro \ @@ -335,6 +338,9 @@ obj/hashtab.o: hashtab.c obj/indent.o: indent.c $(CCSYM) $@ indent.c +obj/insexpand.o: insexpand.c + $(CCSYM) $@ insexpand.c + obj/json.o: json.c $(CCSYM) $@ json.c diff --git a/src/Make_morph.mak b/src/Make_morph.mak index af231fb7b5..b224c67adc 100644 --- a/src/Make_morph.mak +++ b/src/Make_morph.mak @@ -49,6 +49,7 @@ SRC = arabic.c \ hardcopy.c \ hashtab.c \ indent.c \ + insexpand.c \ json.c \ list.c \ main.c \ diff --git a/src/Make_mvc.mak b/src/Make_mvc.mak index c29314c023..d71a3d3827 100644 --- a/src/Make_mvc.mak +++ b/src/Make_mvc.mak @@ -725,6 +725,7 @@ OBJ = \ $(OUTDIR)\hardcopy.obj \ $(OUTDIR)\hashtab.obj \ $(OUTDIR)\indent.obj \ + $(OUTDIR)\insexpand.obj \ $(OUTDIR)\json.obj \ $(OUTDIR)\list.obj \ $(OUTDIR)\main.obj \ @@ -1416,6 +1417,8 @@ $(OUTDIR)/hashtab.obj: $(OUTDIR) hashtab.c $(INCL) $(OUTDIR)/indent.obj: $(OUTDIR) indent.c $(INCL) +$(OUTDIR)/insexpand.obj: $(OUTDIR) insexpand.c $(INCL) + $(OUTDIR)/gui.obj: $(OUTDIR) gui.c $(INCL) $(GUI_INCL) $(OUTDIR)/gui_beval.obj: $(OUTDIR) gui_beval.c $(INCL) $(GUI_INCL) @@ -1648,6 +1651,7 @@ proto.h: \ proto/hardcopy.pro \ proto/hashtab.pro \ proto/indent.pro \ + proto/insexpand.pro \ proto/json.pro \ proto/list.pro \ proto/main.pro \ diff --git a/src/Make_sas.mak b/src/Make_sas.mak index 6ba00fbd67..09650c31f6 100644 --- a/src/Make_sas.mak +++ b/src/Make_sas.mak @@ -114,6 +114,7 @@ SRC = \ hardcopy.c \ hashtab.c \ indent.c \ + insexpand.c \ json.c \ list.c \ main.c \ @@ -174,6 +175,7 @@ OBJ = \ hardcopy.o \ hashtab.o \ indent.o \ + insexpand.o \ json.o \ list.o \ main.o \ @@ -234,6 +236,7 @@ PRO = \ proto/hardcopy.pro \ proto/hashtab.pro \ proto/indent.pro \ + proto/insexpand.pro \ proto/json.pro \ proto/list.pro \ proto/main.pro \ @@ -373,6 +376,8 @@ hashtab.o: hashtab.c proto/hashtab.pro: hashtab.c indent.o: indent.c proto/indent.pro: indent.c +insexpand.o: insexpand.c +proto/insexpand.pro: insexpand.c json.o: json.c proto/json.pro: json.c list.o: list.c diff --git a/src/Make_vms.mms b/src/Make_vms.mms index 9159496fd3..bc8aee69f6 100644 --- a/src/Make_vms.mms +++ b/src/Make_vms.mms @@ -311,9 +311,9 @@ SRC = arabic.c autocmd.c beval.c blob.c blowfish.c buffer.c charset.c \ crypt.c crypt_zip.c dict.c diff.c digraph.c edit.c eval.c evalfunc.c \ ex_cmds.c ex_cmds2.c ex_docmd.c ex_eval.c ex_getln.c if_cscope.c \ if_xcmdsrv.c fileio.c findfile.c fold.c getchar.c hardcopy.c \ - hashtab.c indent.c json.c list.c main.c mark.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 \ + hashtab.c indent.c insexpand.c json.c list.c main.c mark.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 @@ -325,13 +325,13 @@ OBJ = arabic.obj autocmd.obj beval.obj blob.obj blowfish.obj buffer.obj \ edit.obj eval.obj evalfunc.obj ex_cmds.obj ex_cmds2.obj ex_docmd.obj \ ex_eval.obj ex_getln.obj if_cscope.obj if_xcmdsrv.obj \ fileio.obj findfile.obj fold.obj getchar.obj hardcopy.obj hashtab.obj \ - indent.obj json.obj list.obj main.obj mark.obj menu.obj memfile.obj \ - memline.obj message.obj misc1.obj misc2.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 window.obj os_unix.obj os_vms.obj \ - pathdef.obj if_mzsch.obj \ + indent.obj insexpand.obj json.obj list.obj main.obj mark.obj \ + menu.obj memfile.obj memline.obj message.obj misc1.obj misc2.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 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) @@ -603,6 +603,7 @@ if_mzsch.obj : if_mzsch.c vim.h [.auto]config.h feature.h os_unix.h \ regexp.h gui.h beval.h [.proto]gui_beval.pro ex_cmds.h proto.h \ globals.h if_mzsch.h indent.obj : indent.c vim.h [.auto]config.h feature.h os_unix.h +insexpand.obj : insexpand.c vim.h [.auto]config.h feature.h os_unix.h json.obj : json.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 \ diff --git a/src/Makefile b/src/Makefile index 5fa37907fe..35471ae9b0 100644 --- a/src/Makefile +++ b/src/Makefile @@ -1599,6 +1599,7 @@ BASIC_SRC = \ if_cscope.c \ if_xcmdsrv.c \ indent.c \ + insexpand.c \ json.c \ list.c \ main.c \ @@ -1713,6 +1714,7 @@ OBJ_COMMON = \ objects/if_cscope.o \ objects/if_xcmdsrv.o \ objects/indent.o \ + objects/insexpand.o \ objects/list.o \ objects/mark.o \ objects/memline.o \ @@ -1844,6 +1846,7 @@ PRO_AUTO = \ if_ruby.pro \ if_xcmdsrv.pro \ indent.pro \ + insexpand.pro \ json.pro \ list.pro \ main.pro \ @@ -3098,6 +3101,9 @@ objects/if_tcl.o: if_tcl.c objects/indent.o: indent.c $(CCC) -o $@ indent.c +objects/insexpand.o: insexpand.c + $(CCC) -o $@ insexpand.c + objects/json.o: json.c $(CCC) -o $@ json.c @@ -3500,6 +3506,10 @@ objects/indent.o: indent.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/insexpand.o: insexpand.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/json.o: json.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 \ diff --git a/src/edit.c b/src/edit.c index dcead23f54..0b5d0e8086 100644 --- a/src/edit.c +++ b/src/edit.c @@ -13,210 +13,18 @@ #include "vim.h" -#ifdef FEAT_INS_EXPAND -/* - * Definitions used for CTRL-X submode. - * Note: If you change CTRL-X submode, you must also maintain ctrl_x_msgs[] and - * ctrl_x_mode_names[]. - */ -# define CTRL_X_WANT_IDENT 0x100 - -# define CTRL_X_NORMAL 0 /* CTRL-N CTRL-P completion, default */ -# define CTRL_X_NOT_DEFINED_YET 1 -# define CTRL_X_SCROLL 2 -# define CTRL_X_WHOLE_LINE 3 -# define CTRL_X_FILES 4 -# define CTRL_X_TAGS (5 + CTRL_X_WANT_IDENT) -# define CTRL_X_PATH_PATTERNS (6 + CTRL_X_WANT_IDENT) -# define CTRL_X_PATH_DEFINES (7 + CTRL_X_WANT_IDENT) -# define CTRL_X_FINISHED 8 -# define CTRL_X_DICTIONARY (9 + CTRL_X_WANT_IDENT) -# define CTRL_X_THESAURUS (10 + CTRL_X_WANT_IDENT) -# define CTRL_X_CMDLINE 11 -# define CTRL_X_FUNCTION 12 -# define CTRL_X_OMNI 13 -# define CTRL_X_SPELL 14 -# define CTRL_X_LOCAL_MSG 15 /* only used in "ctrl_x_msgs" */ -# define CTRL_X_EVAL 16 /* for builtin function complete() */ - -# define CTRL_X_MSG(i) ctrl_x_msgs[(i) & ~CTRL_X_WANT_IDENT] -# define CTRL_X_MODE_LINE_OR_EVAL(m) ((m) == CTRL_X_WHOLE_LINE || (m) == CTRL_X_EVAL) - -// Message for CTRL-X mode, index is ctrl_x_mode. -static char *ctrl_x_msgs[] = -{ - N_(" Keyword completion (^N^P)"), // CTRL_X_NORMAL, ^P/^N compl. - N_(" ^X mode (^]^D^E^F^I^K^L^N^O^Ps^U^V^Y)"), - NULL, // CTRL_X_SCROLL: depends on state - N_(" Whole line completion (^L^N^P)"), - N_(" File name completion (^F^N^P)"), - N_(" Tag completion (^]^N^P)"), - N_(" Path pattern completion (^N^P)"), - N_(" Definition completion (^D^N^P)"), - NULL, // CTRL_X_FINISHED - N_(" Dictionary completion (^K^N^P)"), - N_(" Thesaurus completion (^T^N^P)"), - N_(" Command-line completion (^V^N^P)"), - N_(" User defined completion (^U^N^P)"), - N_(" Omni completion (^O^N^P)"), - N_(" Spelling suggestion (s^N^P)"), - N_(" Keyword Local completion (^N^P)"), - NULL, // CTRL_X_EVAL doesn't use msg. -}; - -static char *ctrl_x_mode_names[] = { - "keyword", - "ctrl_x", - "unknown", // CTRL_X_SCROLL - "whole_line", - "files", - "tags", - "path_patterns", - "path_defines", - "unknown", // CTRL_X_FINISHED - "dictionary", - "thesaurus", - "cmdline", - "function", - "omni", - "spell", - NULL, // CTRL_X_LOCAL_MSG only used in "ctrl_x_msgs" - "eval" - }; - - -static char e_hitend[] = N_("Hit end of paragraph"); -# ifdef FEAT_COMPL_FUNC -static char e_complwin[] = N_("E839: Completion function changed window"); -static char e_compldel[] = N_("E840: Completion function deleted text"); -# endif - -/* - * Structure used to store one match for insert completion. - */ -typedef struct compl_S compl_T; -struct compl_S -{ - compl_T *cp_next; - compl_T *cp_prev; - char_u *cp_str; /* matched text */ - char cp_icase; /* TRUE or FALSE: ignore case */ - char_u *(cp_text[CPT_COUNT]); /* text for the menu */ - char_u *cp_fname; /* file containing the match, allocated when - * cp_flags has FREE_FNAME */ - int cp_flags; /* ORIGINAL_TEXT, CONT_S_IPOS or FREE_FNAME */ - int cp_number; /* sequence number */ -}; - -# define ORIGINAL_TEXT (1) /* the original text when the expansion begun */ -# define FREE_FNAME (2) - -/* - * All the current matches are stored in a list. - * "compl_first_match" points to the start of the list. - * "compl_curr_match" points to the currently selected entry. - * "compl_shown_match" is different from compl_curr_match during - * ins_compl_get_exp(). - */ -static compl_T *compl_first_match = NULL; -static compl_T *compl_curr_match = NULL; -static compl_T *compl_shown_match = NULL; -static compl_T *compl_old_match = NULL; - -/* After using a cursor key <Enter> selects a match in the popup menu, - * otherwise it inserts a line break. */ -static int compl_enter_selects = FALSE; - -/* When "compl_leader" is not NULL only matches that start with this string - * are used. */ -static char_u *compl_leader = NULL; - -static int compl_get_longest = FALSE; /* put longest common string - in compl_leader */ - -static int compl_no_insert = FALSE; /* FALSE: select & insert - TRUE: noinsert */ -static int compl_no_select = FALSE; /* FALSE: select & insert - TRUE: noselect */ - -static int compl_used_match; /* Selected one of the matches. When - FALSE the match was edited or using - the longest common string. */ - -static int compl_was_interrupted = FALSE; /* didn't finish finding - completions. */ - -static int compl_restarting = FALSE; /* don't insert match */ - -/* When the first completion is done "compl_started" is set. When it's - * FALSE the word to be completed must be located. */ -static int compl_started = FALSE; - -/* Which Ctrl-X mode are we in? */ -static int ctrl_x_mode = CTRL_X_NORMAL; +#define BACKSPACE_CHAR 1 +#define BACKSPACE_WORD 2 +#define BACKSPACE_WORD_NOT_SPACE 3 +#define BACKSPACE_LINE 4 +#ifdef FEAT_INS_EXPAND /* Set when doing something for completion that may call edit() recursively, * which is not allowed. */ -static int compl_busy = FALSE; - -static int compl_matches = 0; -static char_u *compl_pattern = NULL; -static int compl_direction = FORWARD; -static int compl_shows_dir = FORWARD; -static int compl_pending = 0; /* > 1 for postponed CTRL-N */ -static pos_T compl_startpos; -static colnr_T compl_col = 0; /* column where the text starts - * that is being completed */ -static char_u *compl_orig_text = NULL; /* text as it was before - * completion started */ -static int compl_cont_mode = 0; -static expand_T compl_xp; - -static int compl_opt_refresh_always = FALSE; -static int compl_opt_suppress_empty = FALSE; - -static void ins_ctrl_x(void); -static int has_compl_option(int dict_opt); -static int ins_compl_accept_char(int c); -static int ins_compl_add(char_u *str, int len, int icase, char_u *fname, char_u **cptext, int cdir, int flags, int adup); -static void ins_compl_longest_match(compl_T *match); -static void ins_compl_del_pum(void); -static int pum_wanted(void); -static void ins_compl_files(int count, char_u **files, int thesaurus, int flags, regmatch_T *regmatch, char_u *buf, int *dir); -static char_u *find_line_end(char_u *ptr); -static void ins_compl_free(void); -static void ins_compl_clear(void); -static char_u *ins_compl_mode(void); -static int ins_compl_bs(void); -static int ins_compl_need_restart(void); -static void ins_compl_new_leader(void); -static void ins_compl_addleader(int c); -static int ins_compl_len(void); -static void ins_compl_restart(void); -static void ins_compl_set_original_text(char_u *str); -static void ins_compl_addfrommatch(void); -static int ins_compl_prep(int c); -static void ins_compl_fixRedoBufForLeader(char_u *ptr_arg); -# if defined(FEAT_COMPL_FUNC) || defined(FEAT_EVAL) -static void ins_compl_add_list(list_T *list); -static void ins_compl_add_dict(dict_T *dict); -# endif -static void ins_compl_delete(void); -static void ins_compl_insert(int in_compl_func); -static int ins_compl_key2dir(int c); -static int ins_compl_pum_key(int c); -static int ins_compl_key2count(int c); -static int ins_complete(int c, int enable_pum); -static void show_pum(int prev_w_wrow, int prev_w_leftcol); -static unsigned quote_meta(char_u *dest, char_u *str, int len); +static int compl_busy = FALSE; #endif /* FEAT_INS_EXPAND */ -#define BACKSPACE_CHAR 1 -#define BACKSPACE_WORD 2 -#define BACKSPACE_WORD_NOT_SPACE 3 -#define BACKSPACE_LINE 4 -static void ins_redraw(int ready); static void ins_ctrl_v(void); #ifdef FEAT_JOB_CHANNEL static void init_prompt(int cmdchar_todo); @@ -226,12 +34,9 @@ static void insert_special(int, int, int); static void internal_format(int textwidth, int second_indent, int flags, int format_only, int c); static void check_auto_format(int); static void redo_literal(int c); -static void start_arrow(pos_T *end_insert_pos); static void start_arrow_common(pos_T *end_insert_pos, int change); #ifdef FEAT_SPELL static void check_spell_redraw(void); -static void spell_back_to_badword(void); -static int spell_bad_len = 0; /* length of located bad word */ #endif static void stop_insert(pos_T *end_insert_pos, int esc, int nomove); static int echeck_abbr(int); @@ -274,7 +79,6 @@ static void ins_pagedown(void); static void ins_drop(void); #endif static int ins_tab(void); -static int ins_eol(int c); #ifdef FEAT_DIGRAPHS static int ins_digraph(void); #endif @@ -285,7 +89,6 @@ static void ins_try_si(int c); #if defined(FEAT_EVAL) static char_u *do_insert_char_pre(int c); #endif -static int ins_apply_autocmds(event_T event); static colnr_T Insstart_textlen; /* length of line when insert started */ static colnr_T Insstart_blank_vcol; /* vcol for first inserted blank */ @@ -393,7 +196,7 @@ edit( #ifdef FEAT_INS_EXPAND /* Don't allow recursive insert mode when busy with completion. */ - if (compl_started || compl_busy || pum_visible()) + if (ins_compl_active() || compl_busy || pum_visible()) { emsg(_(e_secure)); return FALSE; @@ -834,28 +637,26 @@ edit( * and the cursor is still in the completed word. Only when there is * a match, skip this when no matches were found. */ - if (compl_started + if (ins_compl_active() && pum_wanted() - && curwin->w_cursor.col >= compl_col - && (compl_shown_match == NULL - || compl_shown_match != compl_shown_match->cp_next)) + && curwin->w_cursor.col >= ins_compl_col() + && ins_compl_has_shown_match()) { /* BS: Delete one character from "compl_leader". */ if ((c == K_BS || c == Ctrl_H) - && curwin->w_cursor.col > compl_col + && curwin->w_cursor.col > ins_compl_col() && (c = ins_compl_bs()) == NUL) continue; /* When no match was selected or it was edited. */ - if (!compl_used_match) + if (!ins_compl_used_match()) { /* CTRL-L: Add one character from the current match to * "compl_leader". Except when at the original match and * there is nothing to add, CTRL-L works like CTRL-P then. */ if (c == Ctrl_L - && (!CTRL_X_MODE_LINE_OR_EVAL(ctrl_x_mode) - || (int)STRLEN(compl_shown_match->cp_str) - > curwin->w_cursor.col - compl_col)) + && (!ctrl_x_mode_line_or_eval() + || ins_compl_long_shown_match())) { ins_compl_addfrommatch(); continue; @@ -883,8 +684,9 @@ edit( } /* Pressing CTRL-Y selects the current match. When - * compl_enter_selects is set the Enter key does the same. */ - if ((c == Ctrl_Y || (compl_enter_selects + * ins_compl_enter_selects() is set the Enter key does the + * same. */ + if ((c == Ctrl_Y || (ins_compl_enter_selects() && (c == CAR || c == K_KENTER || c == NL))) && stop_arrow() == OK) { @@ -896,7 +698,7 @@ edit( /* Prepare for or stop CTRL-X mode. This doesn't do completion, but * it does fix up the text when finishing completion. */ - compl_get_longest = FALSE; + ins_compl_init_get_longest(); if (ins_compl_prep(c)) continue; #endif @@ -939,7 +741,7 @@ edit( #endif #ifdef FEAT_INS_EXPAND - if ((c == Ctrl_V || c == Ctrl_Q) && ctrl_x_mode == CTRL_X_CMDLINE) + if ((c == Ctrl_V || c == Ctrl_Q) && ctrl_x_mode_cmdline()) goto docomplete; #endif if (c == Ctrl_V || c == Ctrl_Q) @@ -952,7 +754,7 @@ edit( #ifdef FEAT_CINDENT if (cindent_on() # ifdef FEAT_INS_EXPAND - && ctrl_x_mode == 0 + && ctrl_x_mode_none() # endif ) { @@ -1073,7 +875,7 @@ doESCkey: case Ctrl_O: /* execute one command */ #ifdef FEAT_COMPL_FUNC - if (ctrl_x_mode == CTRL_X_OMNI) + if (ctrl_x_mode_omni()) goto docomplete; #endif if (echeck_abbr(Ctrl_O + ABBR_OFF)) @@ -1149,14 +951,14 @@ doESCkey: case Ctrl_D: /* Make indent one shiftwidth smaller. */ #if defined(FEAT_INS_EXPAND) && defined(FEAT_FIND_ID) - if (ctrl_x_mode == CTRL_X_PATH_DEFINES) + if (ctrl_x_mode_path_defines()) goto docomplete; #endif /* FALLTHROUGH */ case Ctrl_T: /* Make indent one shiftwidth greater. */ # ifdef FEAT_INS_EXPAND - if (c == Ctrl_T && ctrl_x_mode == CTRL_X_THESAURUS) + if (c == Ctrl_T && ctrl_x_mode_thesaurus()) { if (has_compl_option(FALSE)) goto docomplete; @@ -1200,7 +1002,7 @@ doESCkey: case Ctrl_U: /* delete all inserted text in current line */ # ifdef FEAT_COMPL_FUNC /* CTRL-X CTRL-U completes with 'completefunc'. */ - if (ctrl_x_mode == CTRL_X_FUNCTION) + if (ctrl_x_mode_function()) goto docomplete; # endif did_backspace = ins_bs(c, BACKSPACE_LINE, &inserted_space); @@ -1382,7 +1184,7 @@ doESCkey: case TAB: /* TAB or Complete patterns along path */ #if defined(FEAT_INS_EXPAND) && defined(FEAT_FIND_ID) - if (ctrl_x_mode == CTRL_X_PATH_PATTERNS) + if (ctrl_x_mode_path_patterns()) goto docomplete; #endif inserted_space = FALSE; @@ -1436,7 +1238,7 @@ doESCkey: #if defined(FEAT_DIGRAPHS) || defined(FEAT_INS_EXPAND) case Ctrl_K: /* digraph or keyword completion */ # ifdef FEAT_INS_EXPAND - if (ctrl_x_mode == CTRL_X_DICTIONARY) + if (ctrl_x_mode_dictionary()) { if (has_compl_option(TRUE)) goto docomplete; @@ -1457,25 +1259,25 @@ doESCkey: break; case Ctrl_RSB: /* Tag name completion after ^X */ - if (ctrl_x_mode != CTRL_X_TAGS) + if (!ctrl_x_mode_tags()) goto normalchar; goto docomplete; case Ctrl_F: /* File name completion after ^X */ - if (ctrl_x_mode != CTRL_X_FILES) + if (!ctrl_x_mode_files()) goto normalchar; goto docomplete; case 's': /* Spelling completion after ^X */ case Ctrl_S: - if (ctrl_x_mode != CTRL_X_SPELL) + if (!ctrl_x_mode_spell()) goto normalchar; goto docomplete; #endif case Ctrl_L: /* Whole line completion after ^X */ #ifdef FEAT_INS_EXPAND - if (ctrl_x_mode != CTRL_X_WHOLE_LINE) + if (!ctrl_x_mode_whole_line()) #endif { /* CTRL-L with 'insertmode' set: Leave Insert mode */ @@ -1495,8 +1297,7 @@ doESCkey: /* if 'complete' is empty then plain ^P is no longer special, * but it is under other ^X modes */ if (*curbuf->b_p_cpt == NUL - && (ctrl_x_mode == CTRL_X_NORMAL - || ctrl_x_mode == CTRL_X_WHOLE_LINE) + && (ctrl_x_mode_normal() || ctrl_x_mode_whole_line()) && !(compl_cont_status & CONT_LOCAL)) goto normalchar; @@ -1608,7 +1409,7 @@ normalchar: if (c != K_CURSORHOLD #ifdef FEAT_COMPL_FUNC /* but not in CTRL-X mode, a script can't restore the state */ - && ctrl_x_mode == CTRL_X_NORMAL + && ctrl_x_mode_normal() #endif ) did_cursorhold = FALSE; @@ -1620,7 +1421,7 @@ normalchar: #ifdef FEAT_CINDENT if (can_cindent && cindent_on() # ifdef FEAT_INS_EXPAND - && ctrl_x_mode == CTRL_X_NORMAL + && ctrl_x_mode_normal() # endif ) { @@ -1641,6 +1442,12 @@ force_cindent: /* NOTREACHED */ } + int +ins_need_undo_get(void) +{ + return ins_need_undo; +} + /* * Redraw for Insert mode. * This is postponed until getting the next character to make '$' in the 'cpo' @@ -1648,7 +1455,7 @@ force_cindent: * Only redraw when there are no characters available. This speeds up * inserting sequences of characters (e.g., for CTRL-R). */ - static void + void ins_redraw( int ready UNUSED) /* not busy with something */ { @@ -2313,3719 +2120,6 @@ del_char_after_col(int limit_col UNUSED) return TRUE; } -#if defined(FEAT_INS_EXPAND) || defined(PROTO) -/* - * CTRL-X pressed in Insert mode. - */ - static void -ins_ctrl_x(void) -{ - /* CTRL-X after CTRL-X CTRL-V doesn't do anything, so that CTRL-X - * CTRL-V works like CTRL-N */ - if (ctrl_x_mode != CTRL_X_CMDLINE) - { - /* if the next ^X<> won't ADD nothing, then reset - * compl_cont_status */ - if (compl_cont_status & CONT_N_ADDS) - compl_cont_status |= CONT_INTRPT; - else - compl_cont_status = 0; - /* We're not sure which CTRL-X mode it will be yet */ - ctrl_x_mode = CTRL_X_NOT_DEFINED_YET; - edit_submode = (char_u *)_(CTRL_X_MSG(ctrl_x_mode)); - edit_submode_pre = NULL; - showmode(); - } -} - -/* - * Whether other than default completion has been selected. - */ - int -ctrl_x_mode_not_default(void) -{ - return ctrl_x_mode != CTRL_X_NORMAL; -} - -/* - * Whether CTRL-X was typed without a following character. - */ - int -ctrl_x_mode_not_defined_yet(void) -{ - return ctrl_x_mode == CTRL_X_NOT_DEFINED_YET; -} - -/* - * Return TRUE if the 'dict' or 'tsr' option can be used. - */ - static int -has_compl_option(int dict_opt) -{ - if (dict_opt ? (*curbuf->b_p_dict == NUL && *p_dict == NUL -# ifdef FEAT_SPELL - && !curwin->w_p_spell -# endif - ) - : (*curbuf->b_p_tsr == NUL && *p_tsr == NUL)) - { - ctrl_x_mode = CTRL_X_NORMAL; - edit_submode = NULL; - msg_attr(dict_opt ? _("'dictionary' option is empty") - : _("'thesaurus' option is empty"), - HL_ATTR(HLF_E)); - if (emsg_silent == 0) - { - vim_beep(BO_COMPL); - setcursor(); - out_flush(); -#ifdef FEAT_EVAL - if (!get_vim_var_nr(VV_TESTING)) -#endif - ui_delay(2000L, FALSE); - } - return FALSE; - } - return TRUE; -} - -/* - * Is the character 'c' a valid key to go to or keep us in CTRL-X mode? - * This depends on the current mode. - */ - int -vim_is_ctrl_x_key(int c) -{ - // Always allow ^R - let its results then be checked - if (c == Ctrl_R) - return TRUE; - - /* Accept <PageUp> and <PageDown> if the popup menu is visible. */ - if (ins_compl_pum_key(c)) - return TRUE; - - switch (ctrl_x_mode) - { - case 0: /* Not in any CTRL-X mode */ - return (c == Ctrl_N || c == Ctrl_P || c == Ctrl_X); - case CTRL_X_NOT_DEFINED_YET: - return ( c == Ctrl_X || c == Ctrl_Y || c == Ctrl_E - || c == Ctrl_L || c == Ctrl_F || c == Ctrl_RSB - || c == Ctrl_I || c == Ctrl_D || c == Ctrl_P - || c == Ctrl_N || c == Ctrl_T || c == Ctrl_V - || c == Ctrl_Q || c == Ctrl_U || c == Ctrl_O - || c == Ctrl_S || c == Ctrl_K || c == 's'); - case CTRL_X_SCROLL: - return (c == Ctrl_Y || c == Ctrl_E); - case CTRL_X_WHOLE_LINE: - return (c == Ctrl_L || c == Ctrl_P || c == Ctrl_N); - case CTRL_X_FILES: - return (c == Ctrl_F || c == Ctrl_P || c == Ctrl_N); - case CTRL_X_DICTIONARY: - return (c == Ctrl_K || c == Ctrl_P || c == Ctrl_N); - case CTRL_X_THESAURUS: - return (c == Ctrl_T || c == Ctrl_P || c == Ctrl_N); - case CTRL_X_TAGS: - return (c == Ctrl_RSB || c == Ctrl_P || c == Ctrl_N); -#ifdef FEAT_FIND_ID - case CTRL_X_PATH_PATTERNS: - return (c == Ctrl_P || c == Ctrl_N); - case CTRL_X_PATH_DEFINES: - return (c == Ctrl_D || c == Ctrl_P || c == Ctrl_N); -#endif - case CTRL_X_CMDLINE: - return (c == Ctrl_V || c == Ctrl_Q || c == Ctrl_P || c == Ctrl_N - || c == Ctrl_X); -#ifdef FEAT_COMPL_FUNC - case CTRL_X_FUNCTION: - return (c == Ctrl_U || c == Ctrl_P || c == Ctrl_N); - case CTRL_X_OMNI: - return (c == Ctrl_O || c == Ctrl_P || c == Ctrl_N); -#endif - case CTRL_X_SPELL: - return (c == Ctrl_S || c == Ctrl_P || c == Ctrl_N); - case CTRL_X_EVAL: - return (c == Ctrl_P || c == Ctrl_N); - } - internal_error("vim_is_ctrl_x_key()"); - return FALSE; -} - -/* - * Return TRUE when character "c" is part of the item curren |