Mercurial > vim
annotate src/insexpand.c @ 29801:ac6f7c97adef
Added tag v9.0.0239 for changeset ae63d041243bf702ade9b1fe3576d83b11cf54dc
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sun, 21 Aug 2022 20:15:04 +0200 |
parents | f538704ca03b |
children | b5bd6521f417 |
rev | line source |
---|---|
16142
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1 /* vi:set ts=8 sts=4 sw=4 noet: |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2 * |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3 * VIM - Vi IMproved by Bram Moolenaar |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4 * |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5 * Do ":help uganda" in Vim to read copying and usage conditions. |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6 * Do ":help credits" in Vim to see a list of people who contributed. |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
7 * See README.txt for an overview of the Vim source code. |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
8 */ |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
9 |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
10 /* |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
11 * insexpand.c: functions for Insert mode completion |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
12 */ |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
13 |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
14 #include "vim.h" |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
15 |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
16 /* |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
17 * Definitions used for CTRL-X submode. |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
18 * Note: If you change CTRL-X submode, you must also maintain ctrl_x_msgs[] and |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
19 * ctrl_x_mode_names[] below. |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
20 */ |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
21 # define CTRL_X_WANT_IDENT 0x100 |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
22 |
18933
82c732e8d23d
patch 8.2.0027: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18872
diff
changeset
|
23 # define CTRL_X_NORMAL 0 // CTRL-N CTRL-P completion, default |
16142
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
24 # define CTRL_X_NOT_DEFINED_YET 1 |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
25 # define CTRL_X_SCROLL 2 |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
26 # define CTRL_X_WHOLE_LINE 3 |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
27 # define CTRL_X_FILES 4 |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
28 # define CTRL_X_TAGS (5 + CTRL_X_WANT_IDENT) |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
29 # define CTRL_X_PATH_PATTERNS (6 + CTRL_X_WANT_IDENT) |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
30 # define CTRL_X_PATH_DEFINES (7 + CTRL_X_WANT_IDENT) |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
31 # define CTRL_X_FINISHED 8 |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
32 # define CTRL_X_DICTIONARY (9 + CTRL_X_WANT_IDENT) |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
33 # define CTRL_X_THESAURUS (10 + CTRL_X_WANT_IDENT) |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
34 # define CTRL_X_CMDLINE 11 |
18872
410155e75efa
patch 8.1.2422: "make depend" does not work correctly for libvterm
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
35 # define CTRL_X_FUNCTION 12 |
16142
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
36 # define CTRL_X_OMNI 13 |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
37 # define CTRL_X_SPELL 14 |
18933
82c732e8d23d
patch 8.2.0027: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18872
diff
changeset
|
38 # define CTRL_X_LOCAL_MSG 15 // only used in "ctrl_x_msgs" |
82c732e8d23d
patch 8.2.0027: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18872
diff
changeset
|
39 # define CTRL_X_EVAL 16 // for builtin function complete() |
25707
31db9c6df4e3
patch 8.2.3389: cannot stop insert mode completion without side effects
Bram Moolenaar <Bram@vim.org>
parents:
25513
diff
changeset
|
40 # define CTRL_X_CMDLINE_CTRL_X 17 // CTRL-X typed in CTRL_X_CMDLINE |
16142
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
41 |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
42 # define CTRL_X_MSG(i) ctrl_x_msgs[(i) & ~CTRL_X_WANT_IDENT] |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
43 |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
44 // Message for CTRL-X mode, index is ctrl_x_mode. |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
45 static char *ctrl_x_msgs[] = |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
46 { |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
47 N_(" Keyword completion (^N^P)"), // CTRL_X_NORMAL, ^P/^N compl. |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
48 N_(" ^X mode (^]^D^E^F^I^K^L^N^O^Ps^U^V^Y)"), |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
49 NULL, // CTRL_X_SCROLL: depends on state |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
50 N_(" Whole line completion (^L^N^P)"), |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
51 N_(" File name completion (^F^N^P)"), |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
52 N_(" Tag completion (^]^N^P)"), |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
53 N_(" Path pattern completion (^N^P)"), |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
54 N_(" Definition completion (^D^N^P)"), |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
55 NULL, // CTRL_X_FINISHED |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
56 N_(" Dictionary completion (^K^N^P)"), |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
57 N_(" Thesaurus completion (^T^N^P)"), |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
58 N_(" Command-line completion (^V^N^P)"), |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
59 N_(" User defined completion (^U^N^P)"), |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
60 N_(" Omni completion (^O^N^P)"), |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
61 N_(" Spelling suggestion (s^N^P)"), |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
62 N_(" Keyword Local completion (^N^P)"), |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
63 NULL, // CTRL_X_EVAL doesn't use msg. |
25707
31db9c6df4e3
patch 8.2.3389: cannot stop insert mode completion without side effects
Bram Moolenaar <Bram@vim.org>
parents:
25513
diff
changeset
|
64 N_(" Command-line completion (^V^N^P)"), |
16142
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
65 }; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
66 |
17813
8ca20b0a3dc3
patch 8.1.1903: cannot build without the +eval feature
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
67 #if defined(FEAT_COMPL_FUNC) || defined(FEAT_EVAL) |
16142
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
68 static char *ctrl_x_mode_names[] = { |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
69 "keyword", |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
70 "ctrl_x", |
25862
6776d3fbf13b
patch 8.2.3465: cannot detect insert scroll mode
Bram Moolenaar <Bram@vim.org>
parents:
25707
diff
changeset
|
71 "scroll", |
16142
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
72 "whole_line", |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
73 "files", |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
74 "tags", |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
75 "path_patterns", |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
76 "path_defines", |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
77 "unknown", // CTRL_X_FINISHED |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
78 "dictionary", |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
79 "thesaurus", |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
80 "cmdline", |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
81 "function", |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
82 "omni", |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
83 "spell", |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
84 NULL, // CTRL_X_LOCAL_MSG only used in "ctrl_x_msgs" |
25707
31db9c6df4e3
patch 8.2.3389: cannot stop insert mode completion without side effects
Bram Moolenaar <Bram@vim.org>
parents:
25513
diff
changeset
|
85 "eval", |
31db9c6df4e3
patch 8.2.3389: cannot stop insert mode completion without side effects
Bram Moolenaar <Bram@vim.org>
parents:
25513
diff
changeset
|
86 "cmdline", |
16142
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
87 }; |
17813
8ca20b0a3dc3
patch 8.1.1903: cannot build without the +eval feature
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
88 #endif |
16142
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
89 |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
90 /* |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
91 * Array indexes used for cp_text[]. |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
92 */ |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
93 #define CPT_ABBR 0 // "abbr" |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
94 #define CPT_MENU 1 // "menu" |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
95 #define CPT_KIND 2 // "kind" |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
96 #define CPT_INFO 3 // "info" |
19047
a3fce2763e83
patch 8.2.0084: complete item "user_data" can only be a string
Bram Moolenaar <Bram@vim.org>
parents:
18933
diff
changeset
|
97 #define CPT_COUNT 4 // Number of entries |
16142
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
98 |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
99 /* |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
100 * Structure used to store one match for insert completion. |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
101 */ |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
102 typedef struct compl_S compl_T; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
103 struct compl_S |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
104 { |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
105 compl_T *cp_next; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
106 compl_T *cp_prev; |
16237
56451a2677dc
patch 8.1.1123: no way to avoid filtering for autocomplete function
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
107 char_u *cp_str; // matched text |
56451a2677dc
patch 8.1.1123: no way to avoid filtering for autocomplete function
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
108 char_u *(cp_text[CPT_COUNT]); // text for the menu |
19051
c6248ef5b41b
patch 8.2.0086: build error for small version
Bram Moolenaar <Bram@vim.org>
parents:
19047
diff
changeset
|
109 #ifdef FEAT_EVAL |
19047
a3fce2763e83
patch 8.2.0084: complete item "user_data" can only be a string
Bram Moolenaar <Bram@vim.org>
parents:
18933
diff
changeset
|
110 typval_T cp_user_data; |
19051
c6248ef5b41b
patch 8.2.0086: build error for small version
Bram Moolenaar <Bram@vim.org>
parents:
19047
diff
changeset
|
111 #endif |
16237
56451a2677dc
patch 8.1.1123: no way to avoid filtering for autocomplete function
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
112 char_u *cp_fname; // file containing the match, allocated when |
16239
5df26b29e809
patch 8.1.1124: insert completion flags are mixed up
Bram Moolenaar <Bram@vim.org>
parents:
16237
diff
changeset
|
113 // cp_flags has CP_FREE_FNAME |
5df26b29e809
patch 8.1.1124: insert completion flags are mixed up
Bram Moolenaar <Bram@vim.org>
parents:
16237
diff
changeset
|
114 int cp_flags; // CP_ values |
16237
56451a2677dc
patch 8.1.1123: no way to avoid filtering for autocomplete function
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
115 int cp_number; // sequence number |
16142
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
116 }; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
117 |
16239
5df26b29e809
patch 8.1.1124: insert completion flags are mixed up
Bram Moolenaar <Bram@vim.org>
parents:
16237
diff
changeset
|
118 // values for cp_flags |
5df26b29e809
patch 8.1.1124: insert completion flags are mixed up
Bram Moolenaar <Bram@vim.org>
parents:
16237
diff
changeset
|
119 # define CP_ORIGINAL_TEXT 1 // the original text when the expansion begun |
5df26b29e809
patch 8.1.1124: insert completion flags are mixed up
Bram Moolenaar <Bram@vim.org>
parents:
16237
diff
changeset
|
120 # define CP_FREE_FNAME 2 // cp_fname is allocated |
5df26b29e809
patch 8.1.1124: insert completion flags are mixed up
Bram Moolenaar <Bram@vim.org>
parents:
16237
diff
changeset
|
121 # define CP_CONT_S_IPOS 4 // use CONT_S_IPOS for compl_cont_status |
5df26b29e809
patch 8.1.1124: insert completion flags are mixed up
Bram Moolenaar <Bram@vim.org>
parents:
16237
diff
changeset
|
122 # define CP_EQUAL 8 // ins_compl_equal() always returns TRUE |
5df26b29e809
patch 8.1.1124: insert completion flags are mixed up
Bram Moolenaar <Bram@vim.org>
parents:
16237
diff
changeset
|
123 # define CP_ICASE 16 // ins_compl_equal() ignores case |
24327
44e42eac77cb
patch 8.2.2704: adding a lot of completions can be a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
23772
diff
changeset
|
124 # define CP_FAST 32 // use fast_breakcheck instead of ui_breakcheck |
16142
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
125 |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
126 static char e_hitend[] = N_("Hit end of paragraph"); |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
127 |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
128 /* |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
129 * All the current matches are stored in a list. |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
130 * "compl_first_match" points to the start of the list. |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
131 * "compl_curr_match" points to the currently selected entry. |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
132 * "compl_shown_match" is different from compl_curr_match during |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
133 * ins_compl_get_exp(). |
26850
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
134 * "compl_old_match" points to previous "compl_curr_match". |
16142
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
135 */ |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
136 static compl_T *compl_first_match = NULL; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
137 static compl_T *compl_curr_match = NULL; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
138 static compl_T *compl_shown_match = NULL; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
139 static compl_T *compl_old_match = NULL; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
140 |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
141 // After using a cursor key <Enter> selects a match in the popup menu, |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
142 // otherwise it inserts a line break. |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
143 static int compl_enter_selects = FALSE; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
144 |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
145 // When "compl_leader" is not NULL only matches that start with this string |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
146 // are used. |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
147 static char_u *compl_leader = NULL; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
148 |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
149 static int compl_get_longest = FALSE; // put longest common string |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
150 // in compl_leader |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
151 |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
152 static int compl_no_insert = FALSE; // FALSE: select & insert |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
153 // TRUE: noinsert |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
154 static int compl_no_select = FALSE; // FALSE: select & insert |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
155 // TRUE: noselect |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
156 |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
157 // Selected one of the matches. When FALSE the match was edited or using the |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
158 // longest common string. |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
159 static int compl_used_match; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
160 |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
161 // didn't finish finding completions. |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
162 static int compl_was_interrupted = FALSE; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
163 |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
164 // Set when character typed while looking for matches and it means we should |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
165 // stop looking for matches. |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
166 static int compl_interrupted = FALSE; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
167 |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
168 static int compl_restarting = FALSE; // don't insert match |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
169 |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
170 // When the first completion is done "compl_started" is set. When it's |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
171 // FALSE the word to be completed must be located. |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
172 static int compl_started = FALSE; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
173 |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
174 // Which Ctrl-X mode are we in? |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
175 static int ctrl_x_mode = CTRL_X_NORMAL; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
176 |
26944
8dbdd68627bd
patch 8.2.4001: insert complete code uses global variables
Bram Moolenaar <Bram@vim.org>
parents:
26921
diff
changeset
|
177 static int compl_matches = 0; // number of completion matches |
16142
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
178 static char_u *compl_pattern = NULL; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
179 static int compl_direction = FORWARD; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
180 static int compl_shows_dir = FORWARD; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
181 static int compl_pending = 0; // > 1 for postponed CTRL-N |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
182 static pos_T compl_startpos; |
26944
8dbdd68627bd
patch 8.2.4001: insert complete code uses global variables
Bram Moolenaar <Bram@vim.org>
parents:
26921
diff
changeset
|
183 // Length in bytes of the text being completed (this is deleted to be replaced |
8dbdd68627bd
patch 8.2.4001: insert complete code uses global variables
Bram Moolenaar <Bram@vim.org>
parents:
26921
diff
changeset
|
184 // by the match.) |
8dbdd68627bd
patch 8.2.4001: insert complete code uses global variables
Bram Moolenaar <Bram@vim.org>
parents:
26921
diff
changeset
|
185 static int compl_length = 0; |
16142
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
186 static colnr_T compl_col = 0; // column where the text starts |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
187 // that is being completed |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
188 static char_u *compl_orig_text = NULL; // text as it was before |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
189 // completion started |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
190 static int compl_cont_mode = 0; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
191 static expand_T compl_xp; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
192 |
26944
8dbdd68627bd
patch 8.2.4001: insert complete code uses global variables
Bram Moolenaar <Bram@vim.org>
parents:
26921
diff
changeset
|
193 // List of flags for method of completion. |
8dbdd68627bd
patch 8.2.4001: insert complete code uses global variables
Bram Moolenaar <Bram@vim.org>
parents:
26921
diff
changeset
|
194 static int compl_cont_status = 0; |
8dbdd68627bd
patch 8.2.4001: insert complete code uses global variables
Bram Moolenaar <Bram@vim.org>
parents:
26921
diff
changeset
|
195 # define CONT_ADDING 1 // "normal" or "adding" expansion |
8dbdd68627bd
patch 8.2.4001: insert complete code uses global variables
Bram Moolenaar <Bram@vim.org>
parents:
26921
diff
changeset
|
196 # define CONT_INTRPT (2 + 4) // a ^X interrupted the current expansion |
8dbdd68627bd
patch 8.2.4001: insert complete code uses global variables
Bram Moolenaar <Bram@vim.org>
parents:
26921
diff
changeset
|
197 // it's set only iff N_ADDS is set |
8dbdd68627bd
patch 8.2.4001: insert complete code uses global variables
Bram Moolenaar <Bram@vim.org>
parents:
26921
diff
changeset
|
198 # define CONT_N_ADDS 4 // next ^X<> will add-new or expand-current |
8dbdd68627bd
patch 8.2.4001: insert complete code uses global variables
Bram Moolenaar <Bram@vim.org>
parents:
26921
diff
changeset
|
199 # define CONT_S_IPOS 8 // next ^X<> will set initial_pos? |
8dbdd68627bd
patch 8.2.4001: insert complete code uses global variables
Bram Moolenaar <Bram@vim.org>
parents:
26921
diff
changeset
|
200 // if so, word-wise-expansion will set SOL |
8dbdd68627bd
patch 8.2.4001: insert complete code uses global variables
Bram Moolenaar <Bram@vim.org>
parents:
26921
diff
changeset
|
201 # define CONT_SOL 16 // pattern includes start of line, just for |
8dbdd68627bd
patch 8.2.4001: insert complete code uses global variables
Bram Moolenaar <Bram@vim.org>
parents:
26921
diff
changeset
|
202 // word-wise expansion, not set for ^X^L |
8dbdd68627bd
patch 8.2.4001: insert complete code uses global variables
Bram Moolenaar <Bram@vim.org>
parents:
26921
diff
changeset
|
203 # define CONT_LOCAL 32 // for ctrl_x_mode 0, ^X^P/^X^N do a local |
8dbdd68627bd
patch 8.2.4001: insert complete code uses global variables
Bram Moolenaar <Bram@vim.org>
parents:
26921
diff
changeset
|
204 // expansion, (eg use complete=.) |
8dbdd68627bd
patch 8.2.4001: insert complete code uses global variables
Bram Moolenaar <Bram@vim.org>
parents:
26921
diff
changeset
|
205 |
16142
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
206 static int compl_opt_refresh_always = FALSE; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
207 static int compl_opt_suppress_empty = FALSE; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
208 |
19047
a3fce2763e83
patch 8.2.0084: complete item "user_data" can only be a string
Bram Moolenaar <Bram@vim.org>
parents:
18933
diff
changeset
|
209 static int ins_compl_add(char_u *str, int len, char_u *fname, char_u **cptext, typval_T *user_data, int cdir, int flags, int adup); |
16142
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
210 static void ins_compl_longest_match(compl_T *match); |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
211 static void ins_compl_del_pum(void); |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
212 static void ins_compl_files(int count, char_u **files, int thesaurus, int flags, regmatch_T *regmatch, char_u *buf, int *dir); |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
213 static char_u *find_line_end(char_u *ptr); |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
214 static void ins_compl_free(void); |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
215 static int ins_compl_need_restart(void); |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
216 static void ins_compl_new_leader(void); |
26944
8dbdd68627bd
patch 8.2.4001: insert complete code uses global variables
Bram Moolenaar <Bram@vim.org>
parents:
26921
diff
changeset
|
217 static int get_compl_len(void); |
16142
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
218 static void ins_compl_restart(void); |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
219 static void ins_compl_set_original_text(char_u *str); |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
220 static void ins_compl_fixRedoBufForLeader(char_u *ptr_arg); |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
221 # if defined(FEAT_COMPL_FUNC) || defined(FEAT_EVAL) |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
222 static void ins_compl_add_list(list_T *list); |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
223 static void ins_compl_add_dict(dict_T *dict); |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
224 # endif |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
225 static int ins_compl_key2dir(int c); |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
226 static int ins_compl_pum_key(int c); |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
227 static int ins_compl_key2count(int c); |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
228 static void show_pum(int prev_w_wrow, int prev_w_leftcol); |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
229 static unsigned quote_meta(char_u *dest, char_u *str, int len); |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
230 |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
231 #ifdef FEAT_SPELL |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
232 static void spell_back_to_badword(void); |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
233 static int spell_bad_len = 0; // length of located bad word |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
234 #endif |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
235 |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
236 /* |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
237 * CTRL-X pressed in Insert mode. |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
238 */ |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
239 void |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
240 ins_ctrl_x(void) |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
241 { |
25707
31db9c6df4e3
patch 8.2.3389: cannot stop insert mode completion without side effects
Bram Moolenaar <Bram@vim.org>
parents:
25513
diff
changeset
|
242 if (!ctrl_x_mode_cmdline()) |
16142
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
243 { |
26850
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
244 // if the next ^X<> won't ADD nothing, then reset compl_cont_status |
16142
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
245 if (compl_cont_status & CONT_N_ADDS) |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
246 compl_cont_status |= CONT_INTRPT; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
247 else |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
248 compl_cont_status = 0; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
249 // We're not sure which CTRL-X mode it will be yet |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
250 ctrl_x_mode = CTRL_X_NOT_DEFINED_YET; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
251 edit_submode = (char_u *)_(CTRL_X_MSG(ctrl_x_mode)); |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
252 edit_submode_pre = NULL; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
253 showmode(); |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
254 } |
25707
31db9c6df4e3
patch 8.2.3389: cannot stop insert mode completion without side effects
Bram Moolenaar <Bram@vim.org>
parents:
25513
diff
changeset
|
255 else |
31db9c6df4e3
patch 8.2.3389: cannot stop insert mode completion without side effects
Bram Moolenaar <Bram@vim.org>
parents:
25513
diff
changeset
|
256 // CTRL-X in CTRL-X CTRL-V mode behaves differently to make CTRL-X |
31db9c6df4e3
patch 8.2.3389: cannot stop insert mode completion without side effects
Bram Moolenaar <Bram@vim.org>
parents:
25513
diff
changeset
|
257 // CTRL-V look like CTRL-N |
31db9c6df4e3
patch 8.2.3389: cannot stop insert mode completion without side effects
Bram Moolenaar <Bram@vim.org>
parents:
25513
diff
changeset
|
258 ctrl_x_mode = CTRL_X_CMDLINE_CTRL_X; |
26042
6b39ab99e367
patch 8.2.3555: ModeChanged is not triggered on every mode change
Bram Moolenaar <Bram@vim.org>
parents:
25990
diff
changeset
|
259 |
28397
d1702731786c
patch 8.2.4723: the ModeChanged autocmd event is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
27140
diff
changeset
|
260 may_trigger_modechanged(); |
16142
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
261 } |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
262 |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
263 /* |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
264 * Functions to check the current CTRL-X mode. |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
265 */ |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
266 int ctrl_x_mode_none(void) { return ctrl_x_mode == 0; } |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
267 int ctrl_x_mode_normal(void) { return ctrl_x_mode == CTRL_X_NORMAL; } |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
268 int ctrl_x_mode_scroll(void) { return ctrl_x_mode == CTRL_X_SCROLL; } |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
269 int ctrl_x_mode_whole_line(void) { return ctrl_x_mode == CTRL_X_WHOLE_LINE; } |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
270 int ctrl_x_mode_files(void) { return ctrl_x_mode == CTRL_X_FILES; } |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
271 int ctrl_x_mode_tags(void) { return ctrl_x_mode == CTRL_X_TAGS; } |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
272 int ctrl_x_mode_path_patterns(void) { |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
273 return ctrl_x_mode == CTRL_X_PATH_PATTERNS; } |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
274 int ctrl_x_mode_path_defines(void) { |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
275 return ctrl_x_mode == CTRL_X_PATH_DEFINES; } |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
276 int ctrl_x_mode_dictionary(void) { return ctrl_x_mode == CTRL_X_DICTIONARY; } |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
277 int ctrl_x_mode_thesaurus(void) { return ctrl_x_mode == CTRL_X_THESAURUS; } |
25707
31db9c6df4e3
patch 8.2.3389: cannot stop insert mode completion without side effects
Bram Moolenaar <Bram@vim.org>
parents:
25513
diff
changeset
|
278 int ctrl_x_mode_cmdline(void) { |
31db9c6df4e3
patch 8.2.3389: cannot stop insert mode completion without side effects
Bram Moolenaar <Bram@vim.org>
parents:
25513
diff
changeset
|
279 return ctrl_x_mode == CTRL_X_CMDLINE |
31db9c6df4e3
patch 8.2.3389: cannot stop insert mode completion without side effects
Bram Moolenaar <Bram@vim.org>
parents:
25513
diff
changeset
|
280 || ctrl_x_mode == CTRL_X_CMDLINE_CTRL_X; } |
16142
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
281 int ctrl_x_mode_function(void) { return ctrl_x_mode == CTRL_X_FUNCTION; } |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
282 int ctrl_x_mode_omni(void) { return ctrl_x_mode == CTRL_X_OMNI; } |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
283 int ctrl_x_mode_spell(void) { return ctrl_x_mode == CTRL_X_SPELL; } |
26944
8dbdd68627bd
patch 8.2.4001: insert complete code uses global variables
Bram Moolenaar <Bram@vim.org>
parents:
26921
diff
changeset
|
284 static int ctrl_x_mode_eval(void) { return ctrl_x_mode == CTRL_X_EVAL; } |
16142
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
285 int ctrl_x_mode_line_or_eval(void) { |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
286 return ctrl_x_mode == CTRL_X_WHOLE_LINE || ctrl_x_mode == CTRL_X_EVAL; } |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
287 |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
288 /* |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
289 * Whether other than default completion has been selected. |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
290 */ |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
291 int |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
292 ctrl_x_mode_not_default(void) |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
293 { |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
294 return ctrl_x_mode != CTRL_X_NORMAL; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
295 } |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
296 |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
297 /* |
25707
31db9c6df4e3
patch 8.2.3389: cannot stop insert mode completion without side effects
Bram Moolenaar <Bram@vim.org>
parents:
25513
diff
changeset
|
298 * Whether CTRL-X was typed without a following character, |
31db9c6df4e3
patch 8.2.3389: cannot stop insert mode completion without side effects
Bram Moolenaar <Bram@vim.org>
parents:
25513
diff
changeset
|
299 * not including when in CTRL-X CTRL-V mode. |
16142
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
300 */ |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
301 int |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
302 ctrl_x_mode_not_defined_yet(void) |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
303 { |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
304 return ctrl_x_mode == CTRL_X_NOT_DEFINED_YET; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
305 } |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
306 |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
307 /* |
26944
8dbdd68627bd
patch 8.2.4001: insert complete code uses global variables
Bram Moolenaar <Bram@vim.org>
parents:
26921
diff
changeset
|
308 * Return TRUE if currently in "normal" or "adding" insert completion matches |
8dbdd68627bd
patch 8.2.4001: insert complete code uses global variables
Bram Moolenaar <Bram@vim.org>
parents:
26921
diff
changeset
|
309 * state |
8dbdd68627bd
patch 8.2.4001: insert complete code uses global variables
Bram Moolenaar <Bram@vim.org>
parents:
26921
diff
changeset
|
310 */ |
8dbdd68627bd
patch 8.2.4001: insert complete code uses global variables
Bram Moolenaar <Bram@vim.org>
parents:
26921
diff
changeset
|
311 int |
8dbdd68627bd
patch 8.2.4001: insert complete code uses global variables
Bram Moolenaar <Bram@vim.org>
parents:
26921
diff
changeset
|
312 compl_status_adding(void) |
8dbdd68627bd
patch 8.2.4001: insert complete code uses global variables
Bram Moolenaar <Bram@vim.org>
parents:
26921
diff
changeset
|
313 { |
8dbdd68627bd
patch 8.2.4001: insert complete code uses global variables
Bram Moolenaar <Bram@vim.org>
parents:
26921
diff
changeset
|
314 return compl_cont_status & CONT_ADDING; |
8dbdd68627bd
patch 8.2.4001: insert complete code uses global variables
Bram Moolenaar <Bram@vim.org>
parents:
26921
diff
changeset
|
315 } |
8dbdd68627bd
patch 8.2.4001: insert complete code uses global variables
Bram Moolenaar <Bram@vim.org>
parents:
26921
diff
changeset
|
316 |
8dbdd68627bd
patch 8.2.4001: insert complete code uses global variables
Bram Moolenaar <Bram@vim.org>
parents:
26921
diff
changeset
|
317 /* |
8dbdd68627bd
patch 8.2.4001: insert complete code uses global variables
Bram Moolenaar <Bram@vim.org>
parents:
26921
diff
changeset
|
318 * Return TRUE if the completion pattern includes start of line, just for |
8dbdd68627bd
patch 8.2.4001: insert complete code uses global variables
Bram Moolenaar <Bram@vim.org>
parents:
26921
diff
changeset
|
319 * word-wise expansion. |
8dbdd68627bd
patch 8.2.4001: insert complete code uses global variables
Bram Moolenaar <Bram@vim.org>
parents:
26921
diff
changeset
|
320 */ |
8dbdd68627bd
patch 8.2.4001: insert complete code uses global variables
Bram Moolenaar <Bram@vim.org>
parents:
26921
diff
changeset
|
321 int |
8dbdd68627bd
patch 8.2.4001: insert complete code uses global variables
Bram Moolenaar <Bram@vim.org>
parents:
26921
diff
changeset
|
322 compl_status_sol(void) |
8dbdd68627bd
patch 8.2.4001: insert complete code uses global variables
Bram Moolenaar <Bram@vim.org>
parents:
26921
diff
changeset
|
323 { |
8dbdd68627bd
patch 8.2.4001: insert complete code uses global variables
Bram Moolenaar <Bram@vim.org>
parents:
26921
diff
changeset
|
324 return compl_cont_status & CONT_SOL; |
8dbdd68627bd
patch 8.2.4001: insert complete code uses global variables
Bram Moolenaar <Bram@vim.org>
parents:
26921
diff
changeset
|
325 } |
8dbdd68627bd
patch 8.2.4001: insert complete code uses global variables
Bram Moolenaar <Bram@vim.org>
parents:
26921
diff
changeset
|
326 |
8dbdd68627bd
patch 8.2.4001: insert complete code uses global variables
Bram Moolenaar <Bram@vim.org>
parents:
26921
diff
changeset
|
327 /* |
8dbdd68627bd
patch 8.2.4001: insert complete code uses global variables
Bram Moolenaar <Bram@vim.org>
parents:
26921
diff
changeset
|
328 * Return TRUE if ^X^P/^X^N will do a local completion (i.e. use complete=.) |
8dbdd68627bd
patch 8.2.4001: insert complete code uses global variables
Bram Moolenaar <Bram@vim.org>
parents:
26921
diff
changeset
|
329 */ |
8dbdd68627bd
patch 8.2.4001: insert complete code uses global variables
Bram Moolenaar <Bram@vim.org>
parents:
26921
diff
changeset
|
330 int |
8dbdd68627bd
patch 8.2.4001: insert complete code uses global variables
Bram Moolenaar <Bram@vim.org>
parents:
26921
diff
changeset
|
331 compl_status_local(void) |
8dbdd68627bd
patch 8.2.4001: insert complete code uses global variables
Bram Moolenaar <Bram@vim.org>
parents:
26921
diff
changeset
|
332 { |
8dbdd68627bd
patch 8.2.4001: insert complete code uses global variables
Bram Moolenaar <Bram@vim.org>
parents:
26921
diff
changeset
|
333 return compl_cont_status & CONT_LOCAL; |
8dbdd68627bd
patch 8.2.4001: insert complete code uses global variables
Bram Moolenaar <Bram@vim.org>
parents:
26921
diff
changeset
|
334 } |
8dbdd68627bd
patch 8.2.4001: insert complete code uses global variables
Bram Moolenaar <Bram@vim.org>
parents:
26921
diff
changeset
|
335 |
8dbdd68627bd
patch 8.2.4001: insert complete code uses global variables
Bram Moolenaar <Bram@vim.org>
parents:
26921
diff
changeset
|
336 /* |
8dbdd68627bd
patch 8.2.4001: insert complete code uses global variables
Bram Moolenaar <Bram@vim.org>
parents:
26921
diff
changeset
|
337 * Clear the completion status flags |
8dbdd68627bd
patch 8.2.4001: insert complete code uses global variables
Bram Moolenaar <Bram@vim.org>
parents:
26921
diff
changeset
|
338 */ |
8dbdd68627bd
patch 8.2.4001: insert complete code uses global variables
Bram Moolenaar <Bram@vim.org>
parents:
26921
diff
changeset
|
339 void |
8dbdd68627bd
patch 8.2.4001: insert complete code uses global variables
Bram Moolenaar <Bram@vim.org>
parents:
26921
diff
changeset
|
340 compl_status_clear(void) |
8dbdd68627bd
patch 8.2.4001: insert complete code uses global variables
Bram Moolenaar <Bram@vim.org>
parents:
26921
diff
changeset
|
341 { |
8dbdd68627bd
patch 8.2.4001: insert complete code uses global variables
Bram Moolenaar <Bram@vim.org>
parents:
26921
diff
changeset
|
342 compl_cont_status = 0; |
8dbdd68627bd
patch 8.2.4001: insert complete code uses global variables
Bram Moolenaar <Bram@vim.org>
parents:
26921
diff
changeset
|
343 } |
8dbdd68627bd
patch 8.2.4001: insert complete code uses global variables
Bram Moolenaar <Bram@vim.org>
parents:
26921
diff
changeset
|
344 |
8dbdd68627bd
patch 8.2.4001: insert complete code uses global variables
Bram Moolenaar <Bram@vim.org>
parents:
26921
diff
changeset
|
345 /* |
8dbdd68627bd
patch 8.2.4001: insert complete code uses global variables
Bram Moolenaar <Bram@vim.org>
parents:
26921
diff
changeset
|
346 * Return TRUE if completion is using the forward direction matches |
8dbdd68627bd
patch 8.2.4001: insert complete code uses global variables
Bram Moolenaar <Bram@vim.org>
parents:
26921
diff
changeset
|
347 */ |
8dbdd68627bd
patch 8.2.4001: insert complete code uses global variables
Bram Moolenaar <Bram@vim.org>
parents:
26921
diff
changeset
|
348 static int |
8dbdd68627bd
patch 8.2.4001: insert complete code uses global variables
Bram Moolenaar <Bram@vim.org>
parents:
26921
diff
changeset
|
349 compl_dir_forward(void) |
8dbdd68627bd
patch 8.2.4001: insert complete code uses global variables
Bram Moolenaar <Bram@vim.org>
parents:
26921
diff
changeset
|
350 { |
8dbdd68627bd
patch 8.2.4001: insert complete code uses global variables
Bram Moolenaar <Bram@vim.org>
parents:
26921
diff
changeset
|
351 return compl_direction == FORWARD; |
8dbdd68627bd
patch 8.2.4001: insert complete code uses global variables
Bram Moolenaar <Bram@vim.org>
parents:
26921
diff
changeset
|
352 } |
8dbdd68627bd
patch 8.2.4001: insert complete code uses global variables
Bram Moolenaar <Bram@vim.org>
parents:
26921
diff
changeset
|
353 |
8dbdd68627bd
patch 8.2.4001: insert complete code uses global variables
Bram Moolenaar <Bram@vim.org>
parents:
26921
diff
changeset
|
354 /* |
8dbdd68627bd
patch 8.2.4001: insert complete code uses global variables
Bram Moolenaar <Bram@vim.org>
parents:
26921
diff
changeset
|
355 * Return TRUE if currently showing forward completion matches |
8dbdd68627bd
patch 8.2.4001: insert complete code uses global variables
Bram Moolenaar <Bram@vim.org>
parents:
26921
diff
changeset
|
356 */ |
8dbdd68627bd
patch 8.2.4001: insert complete code uses global variables
Bram Moolenaar <Bram@vim.org>
parents:
26921
diff
changeset
|
357 static int |
8dbdd68627bd
patch 8.2.4001: insert complete code uses global variables
Bram Moolenaar <Bram@vim.org>
parents:
26921
diff
changeset
|
358 compl_shows_dir_forward(void) |
8dbdd68627bd
patch 8.2.4001: insert complete code uses global variables
Bram Moolenaar <Bram@vim.org>
parents:
26921
diff
changeset
|
359 { |
8dbdd68627bd
patch 8.2.4001: insert complete code uses global variables
Bram Moolenaar <Bram@vim.org>
parents:
26921
diff
changeset
|
360 return compl_shows_dir == FORWARD; |
8dbdd68627bd
patch 8.2.4001: insert complete code uses global variables
Bram Moolenaar <Bram@vim.org>
parents:
26921
diff
changeset
|
361 } |
8dbdd68627bd
patch 8.2.4001: insert complete code uses global variables
Bram Moolenaar <Bram@vim.org>
parents:
26921
diff
changeset
|
362 |
8dbdd68627bd
patch 8.2.4001: insert complete code uses global variables
Bram Moolenaar <Bram@vim.org>
parents:
26921
diff
changeset
|
363 /* |
8dbdd68627bd
patch 8.2.4001: insert complete code uses global variables
Bram Moolenaar <Bram@vim.org>
parents:
26921
diff
changeset
|
364 * Return TRUE if currently showing backward completion matches |
8dbdd68627bd
patch 8.2.4001: insert complete code uses global variables
Bram Moolenaar <Bram@vim.org>
parents:
26921
diff
changeset
|
365 */ |
8dbdd68627bd
patch 8.2.4001: insert complete code uses global variables
Bram Moolenaar <Bram@vim.org>
parents:
26921
diff
changeset
|
366 static int |
8dbdd68627bd
patch 8.2.4001: insert complete code uses global variables
Bram Moolenaar <Bram@vim.org>
parents:
26921
diff
changeset
|
367 compl_shows_dir_backward(void) |
8dbdd68627bd
patch 8.2.4001: insert complete code uses global variables
Bram Moolenaar <Bram@vim.org>
parents:
26921
diff
changeset
|
368 { |
8dbdd68627bd
patch 8.2.4001: insert complete code uses global variables
Bram Moolenaar <Bram@vim.org>
parents:
26921
diff
changeset
|
369 return compl_shows_dir == BACKWARD; |
8dbdd68627bd
patch 8.2.4001: insert complete code uses global variables
Bram Moolenaar <Bram@vim.org>
parents:
26921
diff
changeset
|
370 } |
8dbdd68627bd
patch 8.2.4001: insert complete code uses global variables
Bram Moolenaar <Bram@vim.org>
parents:
26921
diff
changeset
|
371 |
8dbdd68627bd
patch 8.2.4001: insert complete code uses global variables
Bram Moolenaar <Bram@vim.org>
parents:
26921
diff
changeset
|
372 /* |
8dbdd68627bd
patch 8.2.4001: insert complete code uses global variables
Bram Moolenaar <Bram@vim.org>
parents:
26921
diff
changeset
|
373 * Return TRUE if the 'dictionary' or 'thesaurus' option can be used. |
16142
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
374 */ |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
375 int |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
376 has_compl_option(int dict_opt) |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
377 { |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
378 if (dict_opt ? (*curbuf->b_p_dict == NUL && *p_dict == NUL |
17809
59f8948b7590
patch 8.1.1901: the +insert_expand feature is not always available
Bram Moolenaar <Bram@vim.org>
parents:
17775
diff
changeset
|
379 #ifdef FEAT_SPELL |
16142
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
380 && !curwin->w_p_spell |
17809
59f8948b7590
patch 8.1.1901: the +insert_expand feature is not always available
Bram Moolenaar <Bram@vim.org>
parents:
17775
diff
changeset
|
381 #endif |
16142
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
382 ) |
25974
416237f1de22
patch 8.2.3520: cannot define a function for thesaurus completion
Bram Moolenaar <Bram@vim.org>
parents:
25862
diff
changeset
|
383 : (*curbuf->b_p_tsr == NUL && *p_tsr == NUL |
416237f1de22
patch 8.2.3520: cannot define a function for thesaurus completion
Bram Moolenaar <Bram@vim.org>
parents:
25862
diff
changeset
|
384 #ifdef FEAT_COMPL_FUNC |
25990
ac330e2fecc4
patch 8.2.3528: 'thesaurus' and 'thesaurusfunc' do not have the same scope
Bram Moolenaar <Bram@vim.org>
parents:
25984
diff
changeset
|
385 && *curbuf->b_p_tsrfu == NUL && *p_tsrfu == NUL |
25974
416237f1de22
patch 8.2.3520: cannot define a function for thesaurus completion
Bram Moolenaar <Bram@vim.org>
parents:
25862
diff
changeset
|
386 #endif |
416237f1de22
patch 8.2.3520: cannot define a function for thesaurus completion
Bram Moolenaar <Bram@vim.org>
parents:
25862
diff
changeset
|
387 )) |
16142
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
388 { |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
389 ctrl_x_mode = CTRL_X_NORMAL; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
390 edit_submode = NULL; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
391 msg_attr(dict_opt ? _("'dictionary' option is empty") |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
392 : _("'thesaurus' option is empty"), |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
393 HL_ATTR(HLF_E)); |
22742
f7f2d73ff85e
patch 8.2.1919: assert_fails() setting emsg_silent changes normal execution
Bram Moolenaar <Bram@vim.org>
parents:
22726
diff
changeset
|
394 if (emsg_silent == 0 && !in_assert_fails) |
16142
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
395 { |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
396 vim_beep(BO_COMPL); |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
397 setcursor(); |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
398 out_flush(); |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
399 #ifdef FEAT_EVAL |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
400 if (!get_vim_var_nr(VV_TESTING)) |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
401 #endif |
18642
bbea1f108187
patch 8.1.2313: debugging where a delay comes from is not easy
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
402 ui_delay(2004L, FALSE); |
16142
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
403 } |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
404 return FALSE; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
405 } |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
406 return TRUE; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
407 } |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
408 |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
409 /* |
26944
8dbdd68627bd
patch 8.2.4001: insert complete code uses global variables
Bram Moolenaar <Bram@vim.org>
parents:
26921
diff
changeset
|
410 * Is the character "c" a valid key to go to or keep us in CTRL-X mode? |
16142
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
411 * This depends on the current mode. |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
412 */ |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
413 int |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
414 vim_is_ctrl_x_key(int c) |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
415 { |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
416 // Always allow ^R - let its results then be checked |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
417 if (c == Ctrl_R) |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
418 return TRUE; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
419 |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
420 // Accept <PageUp> and <PageDown> if the popup menu is visible. |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
421 if (ins_compl_pum_key(c)) |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
422 return TRUE; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
423 |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
424 switch (ctrl_x_mode) |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
425 { |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
426 case 0: // Not in any CTRL-X mode |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
427 return (c == Ctrl_N || c == Ctrl_P || c == Ctrl_X); |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
428 case CTRL_X_NOT_DEFINED_YET: |
25707
31db9c6df4e3
patch 8.2.3389: cannot stop insert mode completion without side effects
Bram Moolenaar <Bram@vim.org>
parents:
25513
diff
changeset
|
429 case CTRL_X_CMDLINE_CTRL_X: |
16142
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
430 return ( c == Ctrl_X || c == Ctrl_Y || c == Ctrl_E |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
431 || c == Ctrl_L || c == Ctrl_F || c == Ctrl_RSB |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
432 || c == Ctrl_I || c == Ctrl_D || c == Ctrl_P |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
433 || c == Ctrl_N || c == Ctrl_T || c == Ctrl_V |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
434 || c == Ctrl_Q || c == Ctrl_U || c == Ctrl_O |
25707
31db9c6df4e3
patch 8.2.3389: cannot stop insert mode completion without side effects
Bram Moolenaar <Bram@vim.org>
parents:
25513
diff
changeset
|
435 || c == Ctrl_S || c == Ctrl_K || c == 's' |
31db9c6df4e3
patch 8.2.3389: cannot stop insert mode completion without side effects
Bram Moolenaar <Bram@vim.org>
parents:
25513
diff
changeset
|
436 || c == Ctrl_Z); |
16142
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
437 case CTRL_X_SCROLL: |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
438 return (c == Ctrl_Y || c == Ctrl_E); |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
439 case CTRL_X_WHOLE_LINE: |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
440 return (c == Ctrl_L || c == Ctrl_P || c == Ctrl_N); |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
441 case CTRL_X_FILES: |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
442 return (c == Ctrl_F || c == Ctrl_P || c == Ctrl_N); |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
443 case CTRL_X_DICTIONARY: |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
444 return (c == Ctrl_K || c == Ctrl_P || c == Ctrl_N); |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
445 case CTRL_X_THESAURUS: |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
446 return (c == Ctrl_T || c == Ctrl_P || c == Ctrl_N); |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
447 case CTRL_X_TAGS: |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
448 return (c == Ctrl_RSB || c == Ctrl_P || c == Ctrl_N); |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
449 #ifdef FEAT_FIND_ID |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
450 case CTRL_X_PATH_PATTERNS: |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
451 return (c == Ctrl_P || c == Ctrl_N); |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
452 case CTRL_X_PATH_DEFINES: |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
453 return (c == Ctrl_D || c == Ctrl_P || c == Ctrl_N); |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
454 #endif |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
455 case CTRL_X_CMDLINE: |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
456 return (c == Ctrl_V || c == Ctrl_Q || c == Ctrl_P || c == Ctrl_N |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
457 || c == Ctrl_X); |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
458 #ifdef FEAT_COMPL_FUNC |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
459 case CTRL_X_FUNCTION: |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
460 return (c == Ctrl_U || c == Ctrl_P || c == Ctrl_N); |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
461 case CTRL_X_OMNI: |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
462 return (c == Ctrl_O || c == Ctrl_P || c == Ctrl_N); |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
463 #endif |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
464 case CTRL_X_SPELL: |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
465 return (c == Ctrl_S || c == Ctrl_P || c == Ctrl_N); |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
466 case CTRL_X_EVAL: |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
467 return (c == Ctrl_P || c == Ctrl_N); |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
468 } |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
469 internal_error("vim_is_ctrl_x_key()"); |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
470 return FALSE; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
471 } |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
472 |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
473 /* |
26944
8dbdd68627bd
patch 8.2.4001: insert complete code uses global variables
Bram Moolenaar <Bram@vim.org>
parents:
26921
diff
changeset
|
474 * Return TRUE if "match" is the original text when the completion began. |
26850
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
475 */ |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
476 static int |
26944
8dbdd68627bd
patch 8.2.4001: insert complete code uses global variables
Bram Moolenaar <Bram@vim.org>
parents:
26921
diff
changeset
|
477 match_at_original_text(compl_T *match) |
26850
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
478 { |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
479 return match->cp_flags & CP_ORIGINAL_TEXT; |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
480 } |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
481 |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
482 /* |
26944
8dbdd68627bd
patch 8.2.4001: insert complete code uses global variables
Bram Moolenaar <Bram@vim.org>
parents:
26921
diff
changeset
|
483 * Returns TRUE if "match" is the first match in the completion list. |
8dbdd68627bd
patch 8.2.4001: insert complete code uses global variables
Bram Moolenaar <Bram@vim.org>
parents:
26921
diff
changeset
|
484 */ |
8dbdd68627bd
patch 8.2.4001: insert complete code uses global variables
Bram Moolenaar <Bram@vim.org>
parents:
26921
diff
changeset
|
485 static int |
8dbdd68627bd
patch 8.2.4001: insert complete code uses global variables
Bram Moolenaar <Bram@vim.org>
parents:
26921
diff
changeset
|
486 is_first_match(compl_T *match) |
8dbdd68627bd
patch 8.2.4001: insert complete code uses global variables
Bram Moolenaar <Bram@vim.org>
parents:
26921
diff
changeset
|
487 { |
8dbdd68627bd
patch 8.2.4001: insert complete code uses global variables
Bram Moolenaar <Bram@vim.org>
parents:
26921
diff
changeset
|
488 return match == compl_first_match; |
8dbdd68627bd
patch 8.2.4001: insert complete code uses global variables
Bram Moolenaar <Bram@vim.org>
parents:
26921
diff
changeset
|
489 } |
8dbdd68627bd
patch 8.2.4001: insert complete code uses global variables
Bram Moolenaar <Bram@vim.org>
parents:
26921
diff
changeset
|
490 |
8dbdd68627bd
patch 8.2.4001: insert complete code uses global variables
Bram Moolenaar <Bram@vim.org>
parents:
26921
diff
changeset
|
491 /* |
16142
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
492 * Return TRUE when character "c" is part of the item currently being |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
493 * completed. Used to decide whether to abandon complete mode when the menu |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
494 * is visible. |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
495 */ |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
496 int |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
497 ins_compl_accept_char(int c) |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
498 { |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
499 if (ctrl_x_mode & CTRL_X_WANT_IDENT) |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
500 // When expanding an identifier only accept identifier chars. |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
501 return vim_isIDc(c); |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
502 |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
503 switch (ctrl_x_mode) |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
504 { |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
505 case CTRL_X_FILES: |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
506 // When expanding file name only accept file name chars. But not |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
507 // path separators, so that "proto/<Tab>" expands files in |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
508 // "proto", not "proto/" as a whole |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
509 return vim_isfilec(c) && !vim_ispathsep(c); |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
510 |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
511 case CTRL_X_CMDLINE: |
25707
31db9c6df4e3
patch 8.2.3389: cannot stop insert mode completion without side effects
Bram Moolenaar <Bram@vim.org>
parents:
25513
diff
changeset
|
512 case CTRL_X_CMDLINE_CTRL_X: |
16142
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
513 case CTRL_X_OMNI: |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
514 // Command line and Omni completion can work with just about any |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
515 // printable character, but do stop at white space. |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
516 return vim_isprintc(c) && !VIM_ISWHITE(c); |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
517 |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
518 case CTRL_X_WHOLE_LINE: |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
519 // For while line completion a space can be part of the line. |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
520 return vim_isprintc(c); |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
521 } |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
522 return vim_iswordc(c); |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
523 } |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
524 |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
525 /* |
26850
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
526 * Get the completed text by inferring the case of the originally typed text. |
29406
979ce206409a
patch 9.0.0045: reading past end of completion with a long line
Bram Moolenaar <Bram@vim.org>
parents:
29355
diff
changeset
|
527 * If the result is in allocated memory "tofree" is set to it. |
26850
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
528 */ |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
529 static char_u * |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
530 ins_compl_infercase_gettext( |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
531 char_u *str, |
29406
979ce206409a
patch 9.0.0045: reading past end of completion with a long line
Bram Moolenaar <Bram@vim.org>
parents:
29355
diff
changeset
|
532 int char_len, |
979ce206409a
patch 9.0.0045: reading past end of completion with a long line
Bram Moolenaar <Bram@vim.org>
parents:
29355
diff
changeset
|
533 int compl_char_len, |
979ce206409a
patch 9.0.0045: reading past end of completion with a long line
Bram Moolenaar <Bram@vim.org>
parents:
29355
diff
changeset
|
534 int min_len, |
979ce206409a
patch 9.0.0045: reading past end of completion with a long line
Bram Moolenaar <Bram@vim.org>
parents:
29355
diff
changeset
|
535 char_u **tofree) |
26850
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
536 { |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
537 int *wca; // Wide character array. |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
538 char_u *p; |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
539 int i, c; |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
540 int has_lower = FALSE; |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
541 int was_letter = FALSE; |
29406
979ce206409a
patch 9.0.0045: reading past end of completion with a long line
Bram Moolenaar <Bram@vim.org>
parents:
29355
diff
changeset
|
542 garray_T gap; |
26850
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
543 |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
544 IObuff[0] = NUL; |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
545 |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
546 // Allocate wide character array for the completion and fill it. |
29406
979ce206409a
patch 9.0.0045: reading past end of completion with a long line
Bram Moolenaar <Bram@vim.org>
parents:
29355
diff
changeset
|
547 wca = ALLOC_MULT(int, char_len); |
26850
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
548 if (wca == NULL) |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
549 return IObuff; |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
550 |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
551 p = str; |
29406
979ce206409a
patch 9.0.0045: reading past end of completion with a long line
Bram Moolenaar <Bram@vim.org>
parents:
29355
diff
changeset
|
552 for (i = 0; i < char_len; ++i) |
26850
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
553 if (has_mbyte) |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
554 wca[i] = mb_ptr2char_adv(&p); |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
555 else |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
556 wca[i] = *(p++); |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
557 |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
558 // Rule 1: Were any chars converted to lower? |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
559 p = compl_orig_text; |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
560 for (i = 0; i < min_len; ++i) |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
561 { |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
562 if (has_mbyte) |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
563 c = mb_ptr2char_adv(&p); |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
564 else |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
565 c = *(p++); |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
566 if (MB_ISLOWER(c)) |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
567 { |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
568 has_lower = TRUE; |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
569 if (MB_ISUPPER(wca[i])) |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
570 { |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
571 // Rule 1 is satisfied. |
29406
979ce206409a
patch 9.0.0045: reading past end of completion with a long line
Bram Moolenaar <Bram@vim.org>
parents:
29355
diff
changeset
|
572 for (i = compl_char_len; i < char_len; ++i) |
26850
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
573 wca[i] = MB_TOLOWER(wca[i]); |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
574 break; |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
575 } |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
576 } |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
577 } |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
578 |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
579 // Rule 2: No lower case, 2nd consecutive letter converted to |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
580 // upper case. |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
581 if (!has_lower) |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
582 { |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
583 p = compl_orig_text; |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
584 for (i = 0; i < min_len; ++i) |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
585 { |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
586 if (has_mbyte) |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
587 c = mb_ptr2char_adv(&p); |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
588 else |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
589 c = *(p++); |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
590 if (was_letter && MB_ISUPPER(c) && MB_ISLOWER(wca[i])) |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
591 { |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
592 // Rule 2 is satisfied. |
29406
979ce206409a
patch 9.0.0045: reading past end of completion with a long line
Bram Moolenaar <Bram@vim.org>
parents:
29355
diff
changeset
|
593 for (i = compl_char_len; i < char_len; ++i) |
26850
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
594 wca[i] = MB_TOUPPER(wca[i]); |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
595 break; |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
596 } |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
597 was_letter = MB_ISLOWER(c) || MB_ISUPPER(c); |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
598 } |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
599 } |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
600 |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
601 // Copy the original case of the part we typed. |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
602 p = compl_orig_text; |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
603 for (i = 0; i < min_len; ++i) |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
604 { |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
605 if (has_mbyte) |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
606 c = mb_ptr2char_adv(&p); |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
607 else |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
608 c = *(p++); |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
609 if (MB_ISLOWER(c)) |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
610 wca[i] = MB_TOLOWER(wca[i]); |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
611 else if (MB_ISUPPER(c)) |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
612 wca[i] = MB_TOUPPER(wca[i]); |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
613 } |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
614 |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
615 // Generate encoding specific output from wide character array. |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
616 p = IObuff; |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
617 i = 0; |
29406
979ce206409a
patch 9.0.0045: reading past end of completion with a long line
Bram Moolenaar <Bram@vim.org>
parents:
29355
diff
changeset
|
618 ga_init2(&gap, 1, 500); |
979ce206409a
patch 9.0.0045: reading past end of completion with a long line
Bram Moolenaar <Bram@vim.org>
parents:
29355
diff
changeset
|
619 while (i < char_len) |
979ce206409a
patch 9.0.0045: reading past end of completion with a long line
Bram Moolenaar <Bram@vim.org>
parents:
29355
diff
changeset
|
620 { |
979ce206409a
patch 9.0.0045: reading past end of completion with a long line
Bram Moolenaar <Bram@vim.org>
parents:
29355
diff
changeset
|
621 if (gap.ga_data != NULL) |
979ce206409a
patch 9.0.0045: reading past end of completion with a long line
Bram Moolenaar <Bram@vim.org>
parents:
29355
diff
changeset
|
622 { |
979ce206409a
patch 9.0.0045: reading past end of completion with a long line
Bram Moolenaar <Bram@vim.org>
parents:
29355
diff
changeset
|
623 if (ga_grow(&gap, 10) == FAIL) |
979ce206409a
patch 9.0.0045: reading past end of completion with a long line
Bram Moolenaar <Bram@vim.org>
parents:
29355
diff
changeset
|
624 { |
979ce206409a
patch 9.0.0045: reading past end of completion with a long line
Bram Moolenaar <Bram@vim.org>
parents:
29355
diff
changeset
|
625 ga_clear(&gap); |
979ce206409a
patch 9.0.0045: reading past end of completion with a long line
Bram Moolenaar <Bram@vim.org>
parents:
29355
diff
changeset
|
626 return (char_u *)"[failed]"; |
979ce206409a
patch 9.0.0045: reading past end of completion with a long line
Bram Moolenaar <Bram@vim.org>
parents:
29355
diff
changeset
|
627 } |
979ce206409a
patch 9.0.0045: reading past end of completion with a long line
Bram Moolenaar <Bram@vim.org>
parents:
29355
diff
changeset
|
628 p = (char_u *)gap.ga_data + gap.ga_len; |
979ce206409a
patch 9.0.0045: reading past end of completion with a long line
Bram Moolenaar <Bram@vim.org>
parents:
29355
diff
changeset
|
629 if (has_mbyte) |
979ce206409a
patch 9.0.0045: reading past end of completion with a long line
Bram Moolenaar <Bram@vim.org>
parents:
29355
diff
changeset
|
630 gap.ga_len += (*mb_char2bytes)(wca[i++], p); |
979ce206409a
patch 9.0.0045: reading past end of completion with a long line
Bram Moolenaar <Bram@vim.org>
parents:
29355
diff
changeset
|
631 else |
979ce206409a
patch 9.0.0045: reading past end of completion with a long line
Bram Moolenaar <Bram@vim.org>
parents:
29355
diff
changeset
|
632 { |
979ce206409a
patch 9.0.0045: reading past end of completion with a long line
Bram Moolenaar <Bram@vim.org>
parents:
29355
diff
changeset
|
633 *p = wca[i++]; |
979ce206409a
patch 9.0.0045: reading past end of completion with a long line
Bram Moolenaar <Bram@vim.org>
parents:
29355
diff
changeset
|
634 ++gap.ga_len; |
979ce206409a
patch 9.0.0045: reading past end of completion with a long line
Bram Moolenaar <Bram@vim.org>
parents:
29355
diff
changeset
|
635 } |
979ce206409a
patch 9.0.0045: reading past end of completion with a long line
Bram Moolenaar <Bram@vim.org>
parents:
29355
diff
changeset
|
636 } |
979ce206409a
patch 9.0.0045: reading past end of completion with a long line
Bram Moolenaar <Bram@vim.org>
parents:
29355
diff
changeset
|
637 else if ((p - IObuff) + 6 >= IOSIZE) |
979ce206409a
patch 9.0.0045: reading past end of completion with a long line
Bram Moolenaar <Bram@vim.org>
parents:
29355
diff
changeset
|
638 { |
979ce206409a
patch 9.0.0045: reading past end of completion with a long line
Bram Moolenaar <Bram@vim.org>
parents:
29355
diff
changeset
|
639 // Multi-byte characters can occupy up to five bytes more than |
979ce206409a
patch 9.0.0045: reading past end of completion with a long line
Bram Moolenaar <Bram@vim.org>
parents:
29355
diff
changeset
|
640 // ASCII characters, and we also need one byte for NUL, so when |
979ce206409a
patch 9.0.0045: reading past end of completion with a long line
Bram Moolenaar <Bram@vim.org>
parents:
29355
diff
changeset
|
641 // getting to six bytes from the edge of IObuff switch to using a |
979ce206409a
patch 9.0.0045: reading past end of completion with a long line
Bram Moolenaar <Bram@vim.org>
parents:
29355
diff
changeset
|
642 // growarray. Add the character in the next round. |
979ce206409a
patch 9.0.0045: reading past end of completion with a long line
Bram Moolenaar <Bram@vim.org>
parents:
29355
diff
changeset
|
643 if (ga_grow(&gap, IOSIZE) == FAIL) |
979ce206409a
patch 9.0.0045: reading past end of completion with a long line
Bram Moolenaar <Bram@vim.org>
parents:
29355
diff
changeset
|
644 return (char_u *)"[failed]"; |
29436
6888567953ca
patch 9.0.0060: accessing uninitialized memory when completing long line
Bram Moolenaar <Bram@vim.org>
parents:
29425
diff
changeset
|
645 *p = NUL; |
29406
979ce206409a
patch 9.0.0045: reading past end of completion with a long line
Bram Moolenaar <Bram@vim.org>
parents:
29355
diff
changeset
|
646 STRCPY(gap.ga_data, IObuff); |
29425
722a50132db9
patch 9.0.0054: compiler warning for size_t to int conversion
Bram Moolenaar <Bram@vim.org>
parents:
29408
diff
changeset
|
647 gap.ga_len = (int)STRLEN(IObuff); |
29406
979ce206409a
patch 9.0.0045: reading past end of completion with a long line
Bram Moolenaar <Bram@vim.org>
parents:
29355
diff
changeset
|
648 } |
979ce206409a
patch 9.0.0045: reading past end of completion with a long line
Bram Moolenaar <Bram@vim.org>
parents:
29355
diff
changeset
|
649 else if (has_mbyte) |
26850
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
650 p += (*mb_char2bytes)(wca[i++], p); |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
651 else |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
652 *(p++) = wca[i++]; |
29406
979ce206409a
patch 9.0.0045: reading past end of completion with a long line
Bram Moolenaar <Bram@vim.org>
parents:
29355
diff
changeset
|
653 } |
979ce206409a
patch 9.0.0045: reading past end of completion with a long line
Bram Moolenaar <Bram@vim.org>
parents:
29355
diff
changeset
|
654 vim_free(wca); |
979ce206409a
patch 9.0.0045: reading past end of completion with a long line
Bram Moolenaar <Bram@vim.org>
parents:
29355
diff
changeset
|
655 |
979ce206409a
patch 9.0.0045: reading past end of completion with a long line
Bram Moolenaar <Bram@vim.org>
parents:
29355
diff
changeset
|
656 if (gap.ga_data != NULL) |
979ce206409a
patch 9.0.0045: reading past end of completion with a long line
Bram Moolenaar <Bram@vim.org>
parents:
29355
diff
changeset
|
657 { |
979ce206409a
patch 9.0.0045: reading past end of completion with a long line
Bram Moolenaar <Bram@vim.org>
parents:
29355
diff
changeset
|
658 *tofree = gap.ga_data; |
979ce206409a
patch 9.0.0045: reading past end of completion with a long line
Bram Moolenaar <Bram@vim.org>
parents:
29355
diff
changeset
|
659 return gap.ga_data; |
979ce206409a
patch 9.0.0045: reading past end of completion with a long line
Bram Moolenaar <Bram@vim.org>
parents:
29355
diff
changeset
|
660 } |
979ce206409a
patch 9.0.0045: reading past end of completion with a long line
Bram Moolenaar <Bram@vim.org>
parents:
29355
diff
changeset
|
661 |
26850
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
662 *p = NUL; |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
663 return IObuff; |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
664 } |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
665 |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
666 /* |
16142
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
667 * This is like ins_compl_add(), but if 'ic' and 'inf' are set, then the |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
668 * case of the originally typed text is used, and the case of the completed |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
669 * text is inferred, ie this tries to work out what case you probably wanted |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
670 * the rest of the word to be in -- webb |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
671 */ |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
672 int |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
673 ins_compl_add_infercase( |
16237
56451a2677dc
patch 8.1.1123: no way to avoid filtering for autocomplete function
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
674 char_u *str_arg, |
16142
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
675 int len, |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
676 int icase, |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
677 char_u *fname, |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
678 int dir, |
16239
5df26b29e809
patch 8.1.1124: insert completion flags are mixed up
Bram Moolenaar <Bram@vim.org>
parents:
16237
diff
changeset
|
679 int cont_s_ipos) // next ^X<> will set initial_pos |
16142
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
680 { |
16237
56451a2677dc
patch 8.1.1123: no way to avoid filtering for autocomplete function
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
681 char_u *str = str_arg; |
16142
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
682 char_u *p; |
29406
979ce206409a
patch 9.0.0045: reading past end of completion with a long line
Bram Moolenaar <Bram@vim.org>
parents:
29355
diff
changeset
|
683 int char_len; // count multi-byte characters |
979ce206409a
patch 9.0.0045: reading past end of completion with a long line
Bram Moolenaar <Bram@vim.org>
parents:
29355
diff
changeset
|
684 int compl_char_len; |
16142
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
685 int min_len; |
16239
5df26b29e809
patch 8.1.1124: insert completion flags are mixed up
Bram Moolenaar <Bram@vim.org>
parents:
16237
diff
changeset
|
686 int flags = 0; |
29406
979ce206409a
patch 9.0.0045: reading past end of completion with a long line
Bram Moolenaar <Bram@vim.org>
parents:
29355
diff
changeset
|
687 int res; |
979ce206409a
patch 9.0.0045: reading past end of completion with a long line
Bram Moolenaar <Bram@vim.org>
parents:
29355
diff
changeset
|
688 char_u *tofree = NULL; |
16142
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
689 |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
690 if (p_ic && curbuf->b_p_inf && len > 0) |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
691 { |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
692 // Infer case of completed part. |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
693 |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
694 // Find actual length of completion. |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
695 if (has_mbyte) |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
696 { |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
697 p = str; |
29406
979ce206409a
patch 9.0.0045: reading past end of completion with a long line
Bram Moolenaar <Bram@vim.org>
parents:
29355
diff
changeset
|
698 char_len = 0; |
16142
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
699 while (*p != NUL) |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
700 { |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
701 MB_PTR_ADV(p); |
29406
979ce206409a
patch 9.0.0045: reading past end of completion with a long line
Bram Moolenaar <Bram@vim.org>
parents:
29355
diff
changeset
|
702 ++char_len; |
16142
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
703 } |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
704 } |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
705 else |
29406
979ce206409a
patch 9.0.0045: reading past end of completion with a long line
Bram Moolenaar <Bram@vim.org>
parents:
29355
diff
changeset
|
706 char_len = len; |
16142
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
707 |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
708 // Find actual length of original text. |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
709 if (has_mbyte) |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
710 { |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
711 p = compl_orig_text; |
29406
979ce206409a
patch 9.0.0045: reading past end of completion with a long line
Bram Moolenaar <Bram@vim.org>
parents:
29355
diff
changeset
|
712 compl_char_len = 0; |
16142
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
713 while (*p != NUL) |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
714 { |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
715 MB_PTR_ADV(p); |
29406
979ce206409a
patch 9.0.0045: reading past end of completion with a long line
Bram Moolenaar <Bram@vim.org>
parents:
29355
diff
changeset
|
716 ++compl_char_len; |
16142
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
717 } |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
718 } |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
719 else |
29406
979ce206409a
patch 9.0.0045: reading past end of completion with a long line
Bram Moolenaar <Bram@vim.org>
parents:
29355
diff
changeset
|
720 compl_char_len = compl_length; |
979ce206409a
patch 9.0.0045: reading past end of completion with a long line
Bram Moolenaar <Bram@vim.org>
parents:
29355
diff
changeset
|
721 |
979ce206409a
patch 9.0.0045: reading past end of completion with a long line
Bram Moolenaar <Bram@vim.org>
parents:
29355
diff
changeset
|
722 // "char_len" may be smaller than "compl_char_len" when using |
16142
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
723 // thesaurus, only use the minimum when comparing. |
29406
979ce206409a
patch 9.0.0045: reading past end of completion with a long line
Bram Moolenaar <Bram@vim.org>
parents:
29355
diff
changeset
|
724 min_len = char_len < compl_char_len ? char_len : compl_char_len; |
979ce206409a
patch 9.0.0045: reading past end of completion with a long line
Bram Moolenaar <Bram@vim.org>
parents:
29355
diff
changeset
|
725 |
979ce206409a
patch 9.0.0045: reading past end of completion with a long line
Bram Moolenaar <Bram@vim.org>
parents:
29355
diff
changeset
|
726 str = ins_compl_infercase_gettext(str, char_len, |
979ce206409a
patch 9.0.0045: reading past end of completion with a long line
Bram Moolenaar <Bram@vim.org>
parents:
29355
diff
changeset
|
727 compl_char_len, min_len, &tofree); |
16142
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
728 } |
16239
5df26b29e809
patch 8.1.1124: insert completion flags are mixed up
Bram Moolenaar <Bram@vim.org>
parents:
16237
diff
changeset
|
729 if (cont_s_ipos) |
5df26b29e809
patch 8.1.1124: insert completion flags are mixed up
Bram Moolenaar <Bram@vim.org>
parents:
16237
diff
changeset
|
730 flags |= CP_CONT_S_IPOS; |
5df26b29e809
patch 8.1.1124: insert completion flags are mixed up
Bram Moolenaar <Bram@vim.org>
parents:
16237
diff
changeset
|
731 if (icase) |
5df26b29e809
patch 8.1.1124: insert completion flags are mixed up
Bram Moolenaar <Bram@vim.org>
parents:
16237
diff
changeset
|
732 flags |= CP_ICASE; |
5df26b29e809
patch 8.1.1124: insert completion flags are mixed up
Bram Moolenaar <Bram@vim.org>
parents:
16237
diff
changeset
|
733 |
29406
979ce206409a
patch 9.0.0045: reading past end of completion with a long line
Bram Moolenaar <Bram@vim.org>
parents:
29355
diff
changeset
|
734 res = ins_compl_add(str, len, fname, NULL, NULL, dir, flags, FALSE); |
979ce206409a
patch 9.0.0045: reading past end of completion with a long line
Bram Moolenaar <Bram@vim.org>
parents:
29355
diff
changeset
|
735 vim_free(tofree); |
979ce206409a
patch 9.0.0045: reading past end of completion with a long line
Bram Moolenaar <Bram@vim.org>
parents:
29355
diff
changeset
|
736 return res; |
16142
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
737 } |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
738 |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
739 /* |
27016
1d9a7aa42744
patch 8.2.4037: Insert mode completion is insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
26962
diff
changeset
|
740 * Add a match to the list of matches. The arguments are: |
1d9a7aa42744
patch 8.2.4037: Insert mode completion is insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
26962
diff
changeset
|
741 * str - text of the match to add |
1d9a7aa42744
patch 8.2.4037: Insert mode completion is insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
26962
diff
changeset
|
742 * len - length of "str". If -1, then the length of "str" is |
1d9a7aa42744
patch 8.2.4037: Insert mode completion is insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
26962
diff
changeset
|
743 * computed. |
1d9a7aa42744
patch 8.2.4037: Insert mode completion is insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
26962
diff
changeset
|
744 * fname - file name to associate with this match. |
1d9a7aa42744
patch 8.2.4037: Insert mode completion is insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
26962
diff
changeset
|
745 * cptext - list of strings to use with this match (for abbr, menu, info |
1d9a7aa42744
patch 8.2.4037: Insert mode completion is insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
26962
diff
changeset
|
746 * and kind) |
1d9a7aa42744
patch 8.2.4037: Insert mode completion is insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
26962
diff
changeset
|
747 * user_data - user supplied data (any vim type) for this match |
1d9a7aa42744
patch 8.2.4037: Insert mode completion is insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
26962
diff
changeset
|
748 * cdir - match direction. If 0, use "compl_direction". |
1d9a7aa42744
patch 8.2.4037: Insert mode completion is insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
26962
diff
changeset
|
749 * flags_arg - match flags (cp_flags) |
1d9a7aa42744
patch 8.2.4037: Insert mode completion is insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
26962
diff
changeset
|
750 * adup - accept this match even if it is already present. |
1d9a7aa42744
patch 8.2.4037: Insert mode completion is insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
26962
diff
changeset
|
751 * If "cdir" is FORWARD, then the match is added after the current match. |
1d9a7aa42744
patch 8.2.4037: Insert mode completion is insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
26962
diff
changeset
|
752 * Otherwise, it is added before the current match. |
1d9a7aa42744
patch 8.2.4037: Insert mode completion is insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
26962
diff
changeset
|
753 * |
16142
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
754 * If the given string is already in the list of completions, then return |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
755 * NOTDONE, otherwise add it to the list and return OK. If there is an error, |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
756 * maybe because alloc() returns NULL, then FAIL is returned. |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
757 */ |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
758 static int |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
759 ins_compl_add( |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
760 char_u *str, |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
761 int len, |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
762 char_u *fname, |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19127
diff
changeset
|
763 char_u **cptext, // extra text for popup menu or NULL |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19127
diff
changeset
|
764 typval_T *user_data UNUSED, // "user_data" entry or NULL |
16142
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
765 int cdir, |
16239
5df26b29e809
patch 8.1.1124: insert completion flags are mixed up
Bram Moolenaar <Bram@vim.org>
parents:
16237
diff
changeset
|
766 int flags_arg, |
19047
a3fce2763e83
patch 8.2.0084: complete item "user_data" can only be a string
Bram Moolenaar <Bram@vim.org>
parents:
18933
diff
changeset
|
767 int adup) // accept duplicate match |
16142
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
768 { |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
769 compl_T *match; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
770 int dir = (cdir == 0 ? compl_direction : cdir); |
16239
5df26b29e809
patch 8.1.1124: insert completion flags are mixed up
Bram Moolenaar <Bram@vim.org>
parents:
16237
diff
changeset
|
771 int flags = flags_arg; |
16142
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
772 |
24333
47d55d8a93c9
patch 8.2.2707: adding a lot of completions can still be a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
24327
diff
changeset
|
773 if (flags & CP_FAST) |
47d55d8a93c9
patch 8.2.2707: adding a lot of completions can still be a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
24327
diff
changeset
|
774 fast_breakcheck(); |
47d55d8a93c9
patch 8.2.2707: adding a lot of completions can still be a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
24327
diff
changeset
|
775 else |
47d55d8a93c9
patch 8.2.2707: adding a lot of completions can still be a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
24327
diff
changeset
|
776 ui_breakcheck(); |
16142
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
777 if (got_int) |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
778 return FAIL; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
779 if (len < 0) |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
780 len = (int)STRLEN(str); |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
781 |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
782 // If the same match is already present, don't add it. |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
783 if (compl_first_match != NULL && !adup) |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
784 { |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
785 match = compl_first_match; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
786 do |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
787 { |
26944
8dbdd68627bd
patch 8.2.4001: insert complete code uses global variables
Bram Moolenaar <Bram@vim.org>
parents:
26921
diff
changeset
|
788 if (!match_at_original_text(match) |
16142
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
789 && STRNCMP(match->cp_str, str, len) == 0 |
29408
c12fb2c5b1b3
patch 9.0.0046: reading past end of completion with duplicate match
Bram Moolenaar <Bram@vim.org>
parents:
29406
diff
changeset
|
790 && ((int)STRLEN(match->cp_str) <= len |
c12fb2c5b1b3
patch 9.0.0046: reading past end of completion with duplicate match
Bram Moolenaar <Bram@vim.org>
parents:
29406
diff
changeset
|
791 || match->cp_str[len] == NUL)) |
16142
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
792 return NOTDONE; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
793 match = match->cp_next; |
26944
8dbdd68627bd
patch 8.2.4001: insert complete code uses global variables
Bram Moolenaar <Bram@vim.org>
parents:
26921
diff
changeset
|
794 } while (match != NULL && !is_first_match(match)); |
16142
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
795 } |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
796 |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
797 // Remove any popup menu before changing the list of matches. |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
798 ins_compl_del_pum(); |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
799 |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
800 // Allocate a new match structure. |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
801 // Copy the values to the new match structure. |
16825
ce04ebdf26b8
patch 8.1.1414: alloc() returning "char_u *" causes a lot of type casts
Bram Moolenaar <Bram@vim.org>
parents:
16768
diff
changeset
|
802 match = ALLOC_CLEAR_ONE(compl_T); |
16142
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
803 if (match == NULL) |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
804 return FAIL; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
805 match->cp_number = -1; |
16239
5df26b29e809
patch 8.1.1124: insert completion flags are mixed up
Bram Moolenaar <Bram@vim.org>
parents:
16237
diff
changeset
|
806 if (flags & CP_ORIGINAL_TEXT) |
16142
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
807 match->cp_number = 0; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
808 if ((match->cp_str = vim_strnsave(str, len)) == NULL) |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
809 { |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
810 vim_free(match); |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
811 return FAIL; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
812 } |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
813 |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
814 // match-fname is: |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
815 // - compl_curr_match->cp_fname if it is a string equal to fname. |
16239
5df26b29e809
patch 8.1.1124: insert completion flags are mixed up
Bram Moolenaar <Bram@vim.org>
parents:
16237
diff
changeset
|
816 // - a copy of fname, CP_FREE_FNAME is set to free later THE allocated mem. |
16142
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
817 // - NULL otherwise. --Acevedo |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
818 if (fname != NULL |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
819 && compl_curr_match != NULL |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
820 && compl_curr_match->cp_fname != NULL |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
821 && STRCMP(fname, compl_curr_match->cp_fname) == 0) |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
822 match->cp_fname = compl_curr_match->cp_fname; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
823 else if (fname != NULL) |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
824 { |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
825 match->cp_fname = vim_strsave(fname); |
16239
5df26b29e809
patch 8.1.1124: insert completion flags are mixed up
Bram Moolenaar <Bram@vim.org>
parents:
16237
diff
changeset
|
826 flags |= CP_FREE_FNAME; |
16142
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
827 } |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
828 else |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
829 match->cp_fname = NULL; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
830 match->cp_flags = flags; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
831 |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
832 if (cptext != NULL) |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
833 { |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
834 int i; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
835 |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
836 for (i = 0; i < CPT_COUNT; ++i) |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
837 if (cptext[i] != NULL && *cptext[i] != NUL) |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
838 match->cp_text[i] = vim_strsave(cptext[i]); |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
839 } |
19051
c6248ef5b41b
patch 8.2.0086: build error for small version
Bram Moolenaar <Bram@vim.org>
parents:
19047
diff
changeset
|
840 #ifdef FEAT_EVAL |
19047
a3fce2763e83
patch 8.2.0084: complete item "user_data" can only be a string
Bram Moolenaar <Bram@vim.org>
parents:
18933
diff
changeset
|
841 if (user_data != NULL) |
a3fce2763e83
patch 8.2.0084: complete item "user_data" can only be a string
Bram Moolenaar <Bram@vim.org>
parents:
18933
diff
changeset
|
842 match->cp_user_data = *user_data; |
19051
c6248ef5b41b
patch 8.2.0086: build error for small version
Bram Moolenaar <Bram@vim.org>
parents:
19047
diff
changeset
|
843 #endif |
16142
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
844 |
27016
1d9a7aa42744
patch 8.2.4037: Insert mode completion is insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
26962
diff
changeset
|
845 // Link the new match structure after (FORWARD) or before (BACKWARD) the |
1d9a7aa42744
patch 8.2.4037: Insert mode completion is insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
26962
diff
changeset
|
846 // current match in the list of matches . |
16142
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
847 if (compl_first_match == NULL) |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
848 match->cp_next = match->cp_prev = NULL; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
849 else if (dir == FORWARD) |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
850 { |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
851 match->cp_next = compl_curr_match->cp_next; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
852 match->cp_prev = compl_curr_match; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
853 } |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
854 else // BACKWARD |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
855 { |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
856 match->cp_next = compl_curr_match; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
857 match->cp_prev = compl_curr_match->cp_prev; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
858 } |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
859 if (match->cp_next) |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
860 match->cp_next->cp_prev = match; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
861 if (match->cp_prev) |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
862 match->cp_prev->cp_next = match; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
863 else // if there's nothing before, it is the first match |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
864 compl_first_match = match; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
865 compl_curr_match = match; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
866 |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
867 // Find the longest common string if still doing that. |
16239
5df26b29e809
patch 8.1.1124: insert completion flags are mixed up
Bram Moolenaar <Bram@vim.org>
parents:
16237
diff
changeset
|
868 if (compl_get_longest && (flags & CP_ORIGINAL_TEXT) == 0) |
16142
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
869 ins_compl_longest_match(match); |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
870 |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
871 return OK; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
872 } |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
873 |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
874 /* |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
875 * Return TRUE if "str[len]" matches with match->cp_str, considering |
16239
5df26b29e809
patch 8.1.1124: insert completion flags are mixed up
Bram Moolenaar <Bram@vim.org>
parents:
16237
diff
changeset
|
876 * match->cp_flags. |
16142
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
877 */ |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
878 static int |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
879 ins_compl_equal(compl_T *match, char_u *str, int len) |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
880 { |
16239
5df26b29e809
patch 8.1.1124: insert completion flags are mixed up
Bram Moolenaar <Bram@vim.org>
parents:
16237
diff
changeset
|
881 if (match->cp_flags & CP_EQUAL) |
16237
56451a2677dc
patch 8.1.1123: no way to avoid filtering for autocomplete function
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
882 return TRUE; |
16239
5df26b29e809
patch 8.1.1124: insert completion flags are mixed up
Bram Moolenaar <Bram@vim.org>
parents:
16237
diff
changeset
|
883 if (match->cp_flags & CP_ICASE) |
16142
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
884 return STRNICMP(match->cp_str, str, (size_t)len) == 0; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
885 return STRNCMP(match->cp_str, str, (size_t)len) == 0; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
886 } |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
887 |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
888 /* |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
889 * Reduce the longest common string for match "match". |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
890 */ |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
891 static void |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
892 ins_compl_longest_match(compl_T *match) |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
893 { |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
894 char_u *p, *s; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
895 int c1, c2; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
896 int had_match; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
897 |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
898 if (compl_leader == NULL) |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
899 { |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
900 // First match, use it as a whole. |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
901 compl_leader = vim_strsave(match->cp_str); |
26850
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
902 if (compl_leader == NULL) |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
903 return; |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
904 |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
905 had_match = (curwin->w_cursor.col > compl_col); |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
906 ins_compl_delete(); |
26944
8dbdd68627bd
patch 8.2.4001: insert complete code uses global variables
Bram Moolenaar <Bram@vim.org>
parents:
26921
diff
changeset
|
907 ins_bytes(compl_leader + get_compl_len()); |
26850
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
908 ins_redraw(FALSE); |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
909 |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
910 // When the match isn't there (to avoid matching itself) remove it |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
911 // again after redrawing. |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
912 if (!had_match) |
16142
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
913 ins_compl_delete(); |
26850
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
914 compl_used_match = FALSE; |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
915 |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
916 return; |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
917 } |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
918 |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
919 // Reduce the text if this match differs from compl_leader. |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
920 p = compl_leader; |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
921 s = match->cp_str; |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
922 while (*p != NUL) |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
923 { |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
924 if (has_mbyte) |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
925 { |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
926 c1 = mb_ptr2char(p); |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
927 c2 = mb_ptr2char(s); |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
928 } |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
929 else |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
930 { |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
931 c1 = *p; |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
932 c2 = *s; |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
933 } |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
934 if ((match->cp_flags & CP_ICASE) |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
935 ? (MB_TOLOWER(c1) != MB_TOLOWER(c2)) : (c1 != c2)) |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
936 break; |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
937 if (has_mbyte) |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
938 { |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
939 MB_PTR_ADV(p); |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
940 MB_PTR_ADV(s); |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
941 } |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
942 else |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
943 { |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
944 ++p; |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
945 ++s; |
16142
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
946 } |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
947 } |
26850
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
948 |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
949 if (*p != NUL) |
16142
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
950 { |
26850
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
951 // Leader was shortened, need to change the inserted text. |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
952 *p = NUL; |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
953 had_match = (curwin->w_cursor.col > compl_col); |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
954 ins_compl_delete(); |
26944
8dbdd68627bd
patch 8.2.4001: insert complete code uses global variables
Bram Moolenaar <Bram@vim.org>
parents:
26921
diff
changeset
|
955 ins_bytes(compl_leader + get_compl_len()); |
26850
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
956 ins_redraw(FALSE); |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
957 |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
958 // When the match isn't there (to avoid matching itself) remove it |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
959 // again after redrawing. |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
960 if (!had_match) |
16142
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
961 ins_compl_delete(); |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
962 } |
26850
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
963 |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
964 compl_used_match = FALSE; |
16142
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
965 } |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
966 |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
967 /* |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
968 * Add an array of matches to the list of matches. |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
969 * Frees matches[]. |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
970 */ |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
971 static void |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
972 ins_compl_add_matches( |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
973 int num_matches, |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
974 char_u **matches, |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
975 int icase) |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
976 { |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
977 int i; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
978 int add_r = OK; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
979 int dir = compl_direction; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
980 |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
981 for (i = 0; i < num_matches && add_r != FAIL; i++) |
19047
a3fce2763e83
patch 8.2.0084: complete item "user_data" can only be a string
Bram Moolenaar <Bram@vim.org>
parents:
18933
diff
changeset
|
982 if ((add_r = ins_compl_add(matches[i], -1, NULL, NULL, NULL, dir, |
24327
44e42eac77cb
patch 8.2.2704: adding a lot of completions can be a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
23772
diff
changeset
|
983 CP_FAST | (icase ? CP_ICASE : 0), FALSE)) == OK) |
16142
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
984 // if dir was BACKWARD then honor it just once |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
985 dir = FORWARD; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
986 FreeWild(num_matches, matches); |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
987 } |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
988 |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
989 /* |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
990 * Make the completion list cyclic. |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
991 * Return the number of matches (excluding the original). |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
992 */ |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
993 static int |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
994 ins_compl_make_cyclic(void) |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
995 { |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
996 compl_T *match; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
997 int count = 0; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
998 |
26850
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
999 if (compl_first_match == NULL) |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
1000 return 0; |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
1001 |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
1002 // Find the end of the list. |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
1003 match = compl_first_match; |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
1004 // there's always an entry for the compl_orig_text, it doesn't count. |
26944
8dbdd68627bd
patch 8.2.4001: insert complete code uses global variables
Bram Moolenaar <Bram@vim.org>
parents:
26921
diff
changeset
|
1005 while (match->cp_next != NULL && !is_first_match(match->cp_next)) |
16142
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1006 { |
26850
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
1007 match = match->cp_next; |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
1008 ++count; |
16142
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1009 } |
26850
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
1010 match->cp_next = compl_first_match; |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
1011 compl_first_match->cp_prev = match; |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
1012 |
16142
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1013 return count; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1014 } |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1015 |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1016 /* |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1017 * Return whether there currently is a shown match. |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1018 */ |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1019 int |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1020 ins_compl_has_shown_match(void) |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1021 { |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1022 return compl_shown_match == NULL |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1023 || compl_shown_match != compl_shown_match->cp_next; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1024 } |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1025 |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1026 /* |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1027 * Return whether the shown match is long enough. |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1028 */ |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1029 int |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1030 ins_compl_long_shown_match(void) |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1031 { |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1032 return (int)STRLEN(compl_shown_match->cp_str) |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1033 > curwin->w_cursor.col - compl_col; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1034 } |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1035 |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1036 /* |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1037 * Set variables that store noselect and noinsert behavior from the |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1038 * 'completeopt' value. |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1039 */ |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1040 void |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1041 completeopt_was_set(void) |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1042 { |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1043 compl_no_insert = FALSE; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1044 compl_no_select = FALSE; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1045 if (strstr((char *)p_cot, "noselect") != NULL) |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1046 compl_no_select = TRUE; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1047 if (strstr((char *)p_cot, "noinsert") != NULL) |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1048 compl_no_insert = TRUE; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1049 } |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1050 |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1051 |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1052 // "compl_match_array" points the currently displayed list of entries in the |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1053 // popup menu. It is NULL when there is no popup menu. |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1054 static pumitem_T *compl_match_array = NULL; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1055 static int compl_match_arraysize; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1056 |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1057 /* |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1058 * Update the screen and when there is any scrolling remove the popup menu. |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1059 */ |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1060 static void |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1061 ins_compl_upd_pum(void) |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1062 { |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1063 int h; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1064 |
26850
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
1065 if (compl_match_array == NULL) |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
1066 return; |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
1067 |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
1068 h = curwin->w_cline_height; |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
1069 // Update the screen later, before drawing the popup menu over it. |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
1070 pum_call_update_screen(); |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
1071 if (h != curwin->w_cline_height) |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
1072 ins_compl_del_pum(); |
16142
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1073 } |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1074 |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1075 /* |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1076 * Remove any popup menu. |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1077 */ |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1078 static void |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1079 ins_compl_del_pum(void) |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1080 { |
26850
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
1081 if (compl_match_array == NULL) |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
1082 return; |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
1083 |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
1084 pum_undisplay(); |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
1085 VIM_CLEAR(compl_match_array); |
16142
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1086 } |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1087 |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1088 /* |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1089 * Return TRUE if the popup menu should be displayed. |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1090 */ |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1091 int |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1092 pum_wanted(void) |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1093 { |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1094 // 'completeopt' must contain "menu" or "menuone" |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1095 if (vim_strchr(p_cot, 'm') == NULL) |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1096 return FALSE; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1097 |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1098 // The display looks bad on a B&W display. |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1099 if (t_colors < 8 |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1100 #ifdef FEAT_GUI |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1101 && !gui.in_use |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1102 #endif |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1103 ) |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1104 return FALSE; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1105 return TRUE; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1106 } |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1107 |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1108 /* |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1109 * Return TRUE if there are two or more matches to be shown in the popup menu. |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1110 * One if 'completopt' contains "menuone". |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1111 */ |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1112 static int |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1113 pum_enough_matches(void) |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1114 { |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1115 compl_T *compl; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1116 int i; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1117 |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1118 // Don't display the popup menu if there are no matches or there is only |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1119 // one (ignoring the original text). |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1120 compl = compl_first_match; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1121 i = 0; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1122 do |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1123 { |
26944
8dbdd68627bd
patch 8.2.4001: insert complete code uses global variables
Bram Moolenaar <Bram@vim.org>
parents:
26921
diff
changeset
|
1124 if (compl == NULL || (!match_at_original_text(compl) && ++i == 2)) |
16142
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1125 break; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1126 compl = compl->cp_next; |
26944
8dbdd68627bd
patch 8.2.4001: insert complete code uses global variables
Bram Moolenaar <Bram@vim.org>
parents:
26921
diff
changeset
|
1127 } while (!is_first_match(compl)); |
16142
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1128 |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1129 if (strstr((char *)p_cot, "menuone") != NULL) |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1130 return (i >= 1); |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1131 return (i >= 2); |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1132 } |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1133 |
26155
f2392648af3e
patch 8.2.3609: internal error when ModeChanged is triggered recursively
Bram Moolenaar <Bram@vim.org>
parents:
26042
diff
changeset
|
1134 #if defined(FEAT_EVAL) || defined(PROTO) |
17813
8ca20b0a3dc3
patch 8.1.1903: cannot build without the +eval feature
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
1135 /* |
8ca20b0a3dc3
patch 8.1.1903: cannot build without the +eval feature
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
1136 * Allocate Dict for the completed item. |
8ca20b0a3dc3
patch 8.1.1903: cannot build without the +eval feature
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
1137 * { word, abbr, menu, kind, info } |
8ca20b0a3dc3
patch 8.1.1903: cannot build without the +eval feature
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
1138 */ |
8ca20b0a3dc3
patch 8.1.1903: cannot build without the +eval feature
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
1139 static dict_T * |
8ca20b0a3dc3
patch 8.1.1903: cannot build without the +eval feature
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
1140 ins_compl_dict_alloc(compl_T *match) |
8ca20b0a3dc3
patch 8.1.1903: cannot build without the +eval feature
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
1141 { |
8ca20b0a3dc3
patch 8.1.1903: cannot build without the +eval feature
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
1142 dict_T *dict = dict_alloc_lock(VAR_FIXED); |
8ca20b0a3dc3
patch 8.1.1903: cannot build without the +eval feature
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
1143 |
26850
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
1144 if (dict == NULL) |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
1145 return NULL; |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
1146 |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
1147 dict_add_string(dict, "word", match->cp_str); |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
1148 dict_add_string(dict, "abbr", match->cp_text[CPT_ABBR]); |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
1149 dict_add_string(dict, "menu", match->cp_text[CPT_MENU]); |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
1150 dict_add_string(dict, "kind", match->cp_text[CPT_KIND]); |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
1151 dict_add_string(dict, "info", match->cp_text[CPT_INFO]); |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
1152 if (match->cp_user_data.v_type == VAR_UNKNOWN) |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
1153 dict_add_string(dict, "user_data", (char_u *)""); |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
1154 else |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
1155 dict_add_tv(dict, "user_data", &match->cp_user_data); |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
1156 |
17813
8ca20b0a3dc3
patch 8.1.1903: cannot build without the +eval feature
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
1157 return dict; |
8ca20b0a3dc3
patch 8.1.1903: cannot build without the +eval feature
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
1158 } |
8ca20b0a3dc3
patch 8.1.1903: cannot build without the +eval feature
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
1159 |
26921
b975b7c16ba1
patch 8.2.3989: some insert completion code is not tested
Bram Moolenaar <Bram@vim.org>
parents:
26883
diff
changeset
|
1160 /* |
b975b7c16ba1
patch 8.2.3989: some insert completion code is not tested
Bram Moolenaar <Bram@vim.org>
parents:
26883
diff
changeset
|
1161 * Trigger the CompleteChanged autocmd event. Invoked each time the Insert mode |
b975b7c16ba1
patch 8.2.3989: some insert completion code is not tested
Bram Moolenaar <Bram@vim.org>
parents:
26883
diff
changeset
|
1162 * completion menu is changed. |
b975b7c16ba1
patch 8.2.3989: some insert completion code is not tested
Bram Moolenaar <Bram@vim.org>
parents:
26883
diff
changeset
|
1163 */ |
16268
0f65f2808470
patch 8.1.1138: plugins don't get notified when the popup menu changes
Bram Moolenaar <Bram@vim.org>
parents:
16239
diff
changeset
|
1164 static void |
0f65f2808470
patch 8.1.1138: plugins don't get notified when the popup menu changes
Bram Moolenaar <Bram@vim.org>
parents:
16239
diff
changeset
|
1165 trigger_complete_changed_event(int cur) |
0f65f2808470
patch 8.1.1138: plugins don't get notified when the popup menu changes
Bram Moolenaar <Bram@vim.org>
parents:
16239
diff
changeset
|
1166 { |
0f65f2808470
patch 8.1.1138: plugins don't get notified when the popup menu changes
Bram Moolenaar <Bram@vim.org>
parents:
16239
diff
changeset
|
1167 dict_T *v_event; |
0f65f2808470
patch 8.1.1138: plugins don't get notified when the popup menu changes
Bram Moolenaar <Bram@vim.org>
parents:
16239
diff
changeset
|
1168 dict_T *item; |
0f65f2808470
patch 8.1.1138: plugins don't get notified when the popup menu changes
Bram Moolenaar <Bram@vim.org>
parents:
16239
diff
changeset
|
1169 static int recursive = FALSE; |
26155
f2392648af3e
patch 8.2.3609: internal error when ModeChanged is triggered recursively
Bram Moolenaar <Bram@vim.org>
parents:
26042
diff
changeset
|
1170 save_v_event_T save_v_event; |
16268
0f65f2808470
patch 8.1.1138: plugins don't get notified when the popup menu changes
Bram Moolenaar <Bram@vim.org>
parents:
16239
diff
changeset
|
1171 |
0f65f2808470
patch 8.1.1138: plugins don't get notified when the popup menu changes
Bram Moolenaar <Bram@vim.org>
parents:
16239
diff
changeset
|
1172 if (recursive) |
0f65f2808470
patch 8.1.1138: plugins don't get notified when the popup menu changes
Bram Moolenaar <Bram@vim.org>
parents:
16239
diff
changeset
|
1173 return; |
0f65f2808470
patch 8.1.1138: plugins don't get notified when the popup menu changes
Bram Moolenaar <Bram@vim.org>
parents:
16239
diff
changeset
|
1174 |
0f65f2808470
patch 8.1.1138: plugins don't get notified when the popup menu changes
Bram Moolenaar <Bram@vim.org>
parents:
16239
diff
changeset
|
1175 if (cur < 0) |
0f65f2808470
patch 8.1.1138: plugins don't get notified when the popup menu changes
Bram Moolenaar <Bram@vim.org>
parents:
16239
diff
changeset
|
1176 item = dict_alloc(); |
0f65f2808470
patch 8.1.1138: plugins don't get notified when the popup menu changes
Bram Moolenaar <Bram@vim.org>
parents:
16239
diff
changeset
|
1177 else |
0f65f2808470
patch 8.1.1138: plugins don't get notified when the popup menu changes
Bram Moolenaar <Bram@vim.org>
parents:
16239
diff
changeset
|
1178 item = ins_compl_dict_alloc(compl_curr_match); |
0f65f2808470
patch 8.1.1138: plugins don't get notified when the popup menu changes
Bram Moolenaar <Bram@vim.org>
parents:
16239
diff
changeset
|
1179 if (item == NULL) |
0f65f2808470
patch 8.1.1138: plugins don't get notified when the popup menu changes
Bram Moolenaar <Bram@vim.org>
parents:
16239
diff
changeset
|
1180 return; |
26155
f2392648af3e
patch 8.2.3609: internal error when ModeChanged is triggered recursively
Bram Moolenaar <Bram@vim.org>
parents:
26042
diff
changeset
|
1181 v_event = get_v_event(&save_v_event); |
16268
0f65f2808470
patch 8.1.1138: plugins don't get notified when the popup menu changes
Bram Moolenaar <Bram@vim.org>
parents:
16239
diff
changeset
|
1182 dict_add_dict(v_event, "completed_item", item); |
0f65f2808470
patch 8.1.1138: plugins don't get notified when the popup menu changes
Bram Moolenaar <Bram@vim.org>
parents:
16239
diff
changeset
|
1183 pum_set_event_info(v_event); |
0f65f2808470
patch 8.1.1138: plugins don't get notified when the popup menu changes
Bram Moolenaar <Bram@vim.org>
parents:
16239
diff
changeset
|
1184 dict_set_items_ro(v_event); |
0f65f2808470
patch 8.1.1138: plugins don't get notified when the popup menu changes
Bram Moolenaar <Bram@vim.org>
parents:
16239
diff
changeset
|
1185 |
0f65f2808470
patch 8.1.1138: plugins don't get notified when the popup menu changes
Bram Moolenaar <Bram@vim.org>
parents:
16239
diff
changeset
|
1186 recursive = TRUE; |
29014
45c182c4f7e9
patch 8.2.5029: "textlock" is always zero
Bram Moolenaar <Bram@vim.org>
parents:
29000
diff
changeset
|
1187 textlock++; |
16268
0f65f2808470
patch 8.1.1138: plugins don't get notified when the popup menu changes
Bram Moolenaar <Bram@vim.org>
parents:
16239
diff
changeset
|
1188 apply_autocmds(EVENT_COMPLETECHANGED, NULL, NULL, FALSE, curbuf); |
29014
45c182c4f7e9
patch 8.2.5029: "textlock" is always zero
Bram Moolenaar <Bram@vim.org>
parents:
29000
diff
changeset
|
1189 textlock--; |
16268
0f65f2808470
patch 8.1.1138: plugins don't get notified when the popup menu changes
Bram Moolenaar <Bram@vim.org>
parents:
16239
diff
changeset
|
1190 recursive = FALSE; |
0f65f2808470
patch 8.1.1138: plugins don't get notified when the popup menu changes
Bram Moolenaar <Bram@vim.org>
parents:
16239
diff
changeset
|
1191 |
26155
f2392648af3e
patch 8.2.3609: internal error when ModeChanged is triggered recursively
Bram Moolenaar <Bram@vim.org>
parents:
26042
diff
changeset
|
1192 restore_v_event(v_event, &save_v_event); |
16268
0f65f2808470
patch 8.1.1138: plugins don't get notified when the popup menu changes
Bram Moolenaar <Bram@vim.org>
parents:
16239
diff
changeset
|
1193 } |
17813
8ca20b0a3dc3
patch 8.1.1903: cannot build without the +eval feature
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
1194 #endif |
16268
0f65f2808470
patch 8.1.1138: plugins don't get notified when the popup menu changes
Bram Moolenaar <Bram@vim.org>
parents:
16239
diff
changeset
|
1195 |
16142
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1196 /* |
26850
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
1197 * Build a popup menu to show the completion matches. |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
1198 * Returns the popup menu entry that should be selected. Returns -1 if nothing |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
1199 * should be selected. |
16142
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1200 */ |
26850
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
1201 static int |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
1202 ins_compl_build_pum(void) |
16142
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1203 { |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1204 compl_T *compl; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1205 compl_T *shown_compl = NULL; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1206 int did_find_shown_match = FALSE; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1207 int shown_match_ok = FALSE; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1208 int i; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1209 int cur = -1; |
26850
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
1210 int lead_len = 0; |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
1211 |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
1212 // Need to build the popup menu list. |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
1213 compl_match_arraysize = 0; |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
1214 compl = compl_first_match; |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
1215 if (compl_leader != NULL) |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
1216 lead_len = (int)STRLEN(compl_leader); |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
1217 |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
1218 do |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
1219 { |
26944
8dbdd68627bd
patch 8.2.4001: insert complete code uses global variables
Bram Moolenaar <Bram@vim.org>
parents:
26921
diff
changeset
|
1220 if (!match_at_original_text(compl) |
26850
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
1221 && (compl_leader == NULL |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
1222 || ins_compl_equal(compl, compl_leader, lead_len))) |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
1223 ++compl_match_arraysize; |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
1224 compl = compl->cp_next; |
26944
8dbdd68627bd
patch 8.2.4001: insert complete code uses global variables
Bram Moolenaar <Bram@vim.org>
parents:
26921
diff
changeset
|
1225 } while (compl != NULL && !is_first_match(compl)); |
26850
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
1226 |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
1227 if (compl_match_arraysize == 0) |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
1228 return -1; |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
1229 |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
1230 compl_match_array = ALLOC_CLEAR_MULT(pumitem_T, compl_match_arraysize); |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
1231 if (compl_match_array == NULL) |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
1232 return -1; |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
1233 |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
1234 // If the current match is the original text don't find the first |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
1235 // match after it, don't highlight anything. |
26944
8dbdd68627bd
patch 8.2.4001: insert complete code uses global variables
Bram Moolenaar <Bram@vim.org>
parents:
26921
diff
changeset
|
1236 if (match_at_original_text(compl_shown_match)) |
26850
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
1237 shown_match_ok = TRUE; |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
1238 |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
1239 i = 0; |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
1240 compl = compl_first_match; |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
1241 do |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
1242 { |
26944
8dbdd68627bd
patch 8.2.4001: insert complete code uses global variables
Bram Moolenaar <Bram@vim.org>
parents:
26921
diff
changeset
|
1243 if (!match_at_original_text(compl) |
26850
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
1244 && (compl_leader == NULL |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
1245 || ins_compl_equal(compl, compl_leader, lead_len))) |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
1246 { |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
1247 if (!shown_match_ok) |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
1248 { |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
1249 if (compl == compl_shown_match || did_find_shown_match) |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
1250 { |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
1251 // This item is the shown match or this is the |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
1252 // first displayed item after the shown match. |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
1253 compl_shown_match = compl; |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
1254 did_find_shown_match = TRUE; |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
1255 shown_match_ok = TRUE; |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
1256 } |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
1257 else |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
1258 // Remember this displayed match for when the |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
1259 // shown match is just below it. |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
1260 shown_compl = compl; |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
1261 cur = i; |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
1262 } |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
1263 |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
1264 if (compl->cp_text[CPT_ABBR] != NULL) |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
1265 compl_match_array[i].pum_text = |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
1266 compl->cp_text[CPT_ABBR]; |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
1267 else |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
1268 compl_match_array[i].pum_text = compl->cp_str; |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
1269 compl_match_array[i].pum_kind = compl->cp_text[CPT_KIND]; |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
1270 compl_match_array[i].pum_info = compl->cp_text[CPT_INFO]; |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
1271 if (compl->cp_text[CPT_MENU] != NULL) |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
1272 compl_match_array[i++].pum_extra = |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
1273 compl->cp_text[CPT_MENU]; |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
1274 else |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
1275 compl_match_array[i++].pum_extra = compl->cp_fname; |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
1276 } |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
1277 |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
1278 if (compl == compl_shown_match) |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
1279 { |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
1280 did_find_shown_match = TRUE; |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
1281 |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
1282 // When the original text is the shown match don't set |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
1283 // compl_shown_match. |
26944
8dbdd68627bd
patch 8.2.4001: insert complete code uses global variables
Bram Moolenaar <Bram@vim.org>
parents:
26921
diff
changeset
|
1284 if (match_at_original_text(compl)) |
26850
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
1285 shown_match_ok = TRUE; |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
1286 |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
1287 if (!shown_match_ok && shown_compl != NULL) |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
1288 { |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
1289 // The shown match isn't displayed, set it to the |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
1290 // previously displayed match. |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
1291 compl_shown_match = shown_compl; |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
1292 shown_match_ok = TRUE; |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
1293 } |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
1294 } |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
1295 compl = compl->cp_next; |
26944
8dbdd68627bd
patch 8.2.4001: insert complete code uses global variables
Bram Moolenaar <Bram@vim.org>
parents:
26921
diff
changeset
|
1296 } while (compl != NULL && !is_first_match(compl)); |
26850
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
1297 |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
1298 if (!shown_match_ok) // no displayed match at all |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
1299 cur = -1; |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
1300 |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
1301 return cur; |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
1302 } |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
1303 |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
1304 /* |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
1305 * Show the popup menu for the list of matches. |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
1306 * Also adjusts "compl_shown_match" to an entry that is actually displayed. |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
1307 */ |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
1308 void |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
1309 ins_compl_show_pum(void) |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
1310 { |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
1311 int i; |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
1312 int cur = -1; |
16142
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1313 colnr_T col; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1314 |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1315 if (!pum_wanted() || !pum_enough_matches()) |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1316 return; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1317 |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1318 #if defined(FEAT_EVAL) |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1319 // Dirty hard-coded hack: remove any matchparen highlighting. |
23374
1371e21fdc3d
patch 8.2.2230: Vim9: insert completion runs into error
Bram Moolenaar <Bram@vim.org>
parents:
23272
diff
changeset
|
1320 do_cmdline_cmd((char_u *)"if exists('g:loaded_matchparen')|:3match none|endif"); |
16142
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1321 #endif |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1322 |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1323 // Update the screen later, before drawing the popup menu over it. |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1324 pum_call_update_screen(); |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1325 |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1326 if (compl_match_array == NULL) |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1327 // Need to build the popup menu list. |
26850
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
1328 cur = ins_compl_build_pum(); |
16142
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1329 else |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1330 { |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1331 // popup menu already exists, only need to find the current item. |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1332 for (i = 0; i < compl_match_arraysize; ++i) |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1333 if (compl_match_array[i].pum_text == compl_shown_match->cp_str |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1334 || compl_match_array[i].pum_text |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1335 == compl_shown_match->cp_text[CPT_ABBR]) |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1336 { |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1337 cur = i; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1338 break; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1339 } |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1340 } |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1341 |
26850
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
1342 if (compl_match_array == NULL) |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
1343 return; |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
1344 |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
1345 // In Replace mode when a $ is displayed at the end of the line only |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
1346 // part of the screen would be updated. We do need to redraw here. |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
1347 dollar_vcol = -1; |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
1348 |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
1349 // Compute the screen column of the start of the completed text. |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
1350 // Use the cursor to get all wrapping and other settings right. |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
1351 col = curwin->w_cursor.col; |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
1352 curwin->w_cursor.col = compl_col; |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
1353 pum_display(compl_match_array, compl_match_arraysize, cur); |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
1354 curwin->w_cursor.col = col; |
16268
0f65f2808470
patch 8.1.1138: plugins don't get notified when the popup menu changes
Bram Moolenaar <Bram@vim.org>
parents:
16239
diff
changeset
|
1355 |
17813
8ca20b0a3dc3
patch 8.1.1903: cannot build without the +eval feature
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
1356 #ifdef FEAT_EVAL |
26850
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
1357 if (has_completechanged()) |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
1358 trigger_complete_changed_event(cur); |
17813
8ca20b0a3dc3
patch 8.1.1903: cannot build without the +eval feature
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
1359 #endif |
16142
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1360 } |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1361 |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1362 #define DICT_FIRST (1) // use just first element in "dict" |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1363 #define DICT_EXACT (2) // "dict" is the exact name of a file |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1364 |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1365 /* |
26921
b975b7c16ba1
patch 8.2.3989: some insert completion code is not tested
Bram Moolenaar <Bram@vim.org>
parents:
26883
diff
changeset
|
1366 * Add any identifiers that match the given pattern "pat" in the list of |
b975b7c16ba1
patch 8.2.3989: some insert completion code is not tested
Bram Moolenaar <Bram@vim.org>
parents:
26883
diff
changeset
|
1367 * dictionary files "dict_start" to the list of completions. |
16142
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1368 */ |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1369 static void |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1370 ins_compl_dictionaries( |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1371 char_u *dict_start, |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1372 char_u *pat, |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1373 int flags, // DICT_FIRST and/or DICT_EXACT |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1374 int thesaurus) // Thesaurus completion |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1375 { |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1376 char_u *dict = dict_start; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1377 char_u *ptr; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1378 char_u *buf; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1379 regmatch_T regmatch; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1380 char_u **files; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1381 int count; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1382 int save_p_scs; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1383 int dir = compl_direction; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1384 |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1385 if (*dict == NUL) |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1386 { |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1387 #ifdef FEAT_SPELL |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1388 // When 'dictionary' is empty and spell checking is enabled use |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1389 // "spell". |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1390 if (!thesaurus && curwin->w_p_spell) |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1391 dict = (char_u *)"spell"; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1392 else |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1393 #endif |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1394 return; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1395 } |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1396 |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1397 buf = alloc(LSIZE); |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1398 if (buf == NULL) |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1399 return; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1400 regmatch.regprog = NULL; // so that we can goto theend |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1401 |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1402 // If 'infercase' is set, don't use 'smartcase' here |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1403 save_p_scs = p_scs; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1404 if (curbuf->b_p_inf) |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1405 p_scs = FALSE; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1406 |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1407 // When invoked to match whole lines for CTRL-X CTRL-L adjust the pattern |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1408 // to only match at the start of a line. Otherwise just match the |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1409 // pattern. Also need to double backslashes. |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1410 if (ctrl_x_mode_line_or_eval()) |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1411 { |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1412 char_u *pat_esc = vim_strsave_escaped(pat, (char_u *)"\\"); |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1413 size_t len; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1414 |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1415 if (pat_esc == NULL) |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1416 goto theend; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1417 len = STRLEN(pat_esc) + 10; |
16764
ef00b6bc186b
patch 8.1.1384: using "int" for alloc() often results in compiler warnings
Bram Moolenaar <Bram@vim.org>
parents:
16447
diff
changeset
|
1418 ptr = alloc(len); |
16142
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1419 if (ptr == NULL) |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1420 { |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1421 vim_free(pat_esc); |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1422 goto theend; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1423 } |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1424 vim_snprintf((char *)ptr, len, "^\\s*\\zs\\V%s", pat_esc); |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1425 regmatch.regprog = vim_regcomp(ptr, RE_MAGIC); |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1426 vim_free(pat_esc); |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1427 vim_free(ptr); |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1428 } |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1429 else |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1430 { |
23272
a84e7abb0c92
patch 8.2.2182: Vim9: value of 'magic' is still relevant
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
1431 regmatch.regprog = vim_regcomp(pat, magic_isset() ? RE_MAGIC : 0); |
16142
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1432 if (regmatch.regprog == NULL) |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1433 goto theend; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1434 } |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1435 |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1436 // ignore case depends on 'ignorecase', 'smartcase' and "pat" |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1437 regmatch.rm_ic = ignorecase(pat); |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1438 while (*dict != NUL && !got_int && !compl_interrupted) |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1439 { |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1440 // copy one dictionary file name into buf |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1441 if (flags == DICT_EXACT) |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1442 { |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1443 count = 1; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1444 files = &dict; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1445 } |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1446 else |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1447 { |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1448 // Expand wildcards in the dictionary name, but do not allow |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1449 // backticks (for security, the 'dict' option may have been set in |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1450 // a modeline). |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1451 copy_option_part(&dict, buf, LSIZE, ","); |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1452 # ifdef FEAT_SPELL |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1453 if (!thesaurus && STRCMP(buf, "spell") == 0) |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1454 count = -1; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1455 else |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1456 # endif |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1457 if (vim_strchr(buf, '`') != NULL |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1458 || expand_wildcards(1, &buf, &count, &files, |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1459 EW_FILE|EW_SILENT) != OK) |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1460 count = 0; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1461 } |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1462 |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1463 # ifdef FEAT_SPELL |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1464 if (count == -1) |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1465 { |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1466 // Complete from active spelling. Skip "\<" in the pattern, we |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1467 // don't use it as a RE. |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1468 if (pat[0] == '\\' && pat[1] == '<') |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1469 ptr = pat + 2; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1470 else |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1471 ptr = pat; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1472 spell_dump_compl(ptr, regmatch.rm_ic, &dir, 0); |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1473 } |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1474 else |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1475 # endif |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1476 if (count > 0) // avoid warning for using "files" uninit |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1477 { |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1478 ins_compl_files(count, files, thesaurus, flags, |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1479 ®match, buf, &dir); |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1480 if (flags != DICT_EXACT) |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1481 FreeWild(count, files); |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1482 } |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1483 if (flags != 0) |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1484 break; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1485 } |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1486 |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1487 theend: |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1488 p_scs = save_p_scs; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1489 vim_regfree(regmatch.regprog); |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1490 vim_free(buf); |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1491 } |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1492 |
26921
b975b7c16ba1
patch 8.2.3989: some insert completion code is not tested
Bram Moolenaar <Bram@vim.org>
parents:
26883
diff
changeset
|
1493 /* |
b975b7c16ba1
patch 8.2.3989: some insert completion code is not tested
Bram Moolenaar <Bram@vim.org>
parents:
26883
diff
changeset
|
1494 * Add all the words in the line "*buf_arg" from the thesaurus file "fname" |
b975b7c16ba1
patch 8.2.3989: some insert completion code is not tested
Bram Moolenaar <Bram@vim.org>
parents:
26883
diff
changeset
|
1495 * skipping the word at 'skip_word'. Returns OK on success. |
b975b7c16ba1
patch 8.2.3989: some insert completion code is not tested
Bram Moolenaar <Bram@vim.org>
parents:
26883
diff
changeset
|
1496 */ |
b975b7c16ba1
patch 8.2.3989: some insert completion code is not tested
Bram Moolenaar <Bram@vim.org>
parents:
26883
diff
changeset
|
1497 static int |
b975b7c16ba1
patch 8.2.3989: some insert completion code is not tested
Bram Moolenaar <Bram@vim.org>
parents:
26883
diff
changeset
|
1498 thesarurs_add_words_in_line( |
b975b7c16ba1
patch 8.2.3989: some insert completion code is not tested
Bram Moolenaar <Bram@vim.org>
parents:
26883
diff
changeset
|
1499 char_u *fname, |
b975b7c16ba1
patch 8.2.3989: some insert completion code is not tested
Bram Moolenaar <Bram@vim.org>
parents:
26883
diff
changeset
|
1500 char_u **buf_arg, |
b975b7c16ba1
patch 8.2.3989: some insert completion code is not tested
Bram Moolenaar <Bram@vim.org>
parents:
26883
diff
changeset
|
1501 int dir, |
b975b7c16ba1
patch 8.2.3989: some insert completion code is not tested
Bram Moolenaar <Bram@vim.org>
parents:
26883
diff
changeset
|
1502 char_u *skip_word) |
b975b7c16ba1
patch 8.2.3989: some insert completion code is not tested
Bram Moolenaar <Bram@vim.org>
parents:
26883
diff
changeset
|
1503 { |
b975b7c16ba1
patch 8.2.3989: some insert completion code is not tested
Bram Moolenaar <Bram@vim.org>
parents:
26883
diff
changeset
|
1504 int status = OK; |
b975b7c16ba1
patch 8.2.3989: some insert completion code is not tested
Bram Moolenaar <Bram@vim.org>
parents:
26883
diff
changeset
|
1505 char_u *ptr; |
b975b7c16ba1
patch 8.2.3989: some insert completion code is not tested
Bram Moolenaar <Bram@vim.org>
parents:
26883
diff
changeset
|
1506 char_u *wstart; |
b975b7c16ba1
patch 8.2.3989: some insert completion code is not tested
Bram Moolenaar <Bram@vim.org>
parents:
26883
diff
changeset
|
1507 |
b975b7c16ba1
patch 8.2.3989: some insert completion code is not tested
Bram Moolenaar <Bram@vim.org>
parents:
26883
diff
changeset
|
1508 // Add the other matches on the line |
b975b7c16ba1
patch 8.2.3989: some insert completion code is not tested
Bram Moolenaar <Bram@vim.org>
parents:
26883
diff
changeset
|
1509 ptr = *buf_arg; |
b975b7c16ba1
patch 8.2.3989: some insert completion code is not tested
Bram Moolenaar <Bram@vim.org>
parents:
26883
diff
changeset
|
1510 while (!got_int) |
b975b7c16ba1
patch 8.2.3989: some insert completion code is not tested
Bram Moolenaar <Bram@vim.org>
parents:
26883
diff
changeset
|
1511 { |
b975b7c16ba1
patch 8.2.3989: some insert completion code is not tested
Bram Moolenaar <Bram@vim.org>
parents:
26883
diff
changeset
|
1512 // Find start of the next word. Skip white |
b975b7c16ba1
patch 8.2.3989: some insert completion code is not tested
Bram Moolenaar <Bram@vim.org>
parents:
26883
diff
changeset
|
1513 // space and punctuation. |
b975b7c16ba1
patch 8.2.3989: some insert completion code is not tested
Bram Moolenaar <Bram@vim.org>
parents:
26883
diff
changeset
|
1514 ptr = find_word_start(ptr); |
b975b7c16ba1
patch 8.2.3989: some insert completion code is not tested
Bram Moolenaar <Bram@vim.org>
parents:
26883
diff
changeset
|
1515 if (*ptr == NUL || *ptr == NL) |
b975b7c16ba1
patch 8.2.3989: some insert completion code is not tested
Bram Moolenaar <Bram@vim.org>
parents:
26883
diff
changeset
|
1516 break; |
b975b7c16ba1
patch 8.2.3989: some insert completion code is not tested
Bram Moolenaar <Bram@vim.org>
parents:
26883
diff
changeset
|
1517 wstart = ptr; |
b975b7c16ba1
patch 8.2.3989: some insert completion code is not tested
Bram Moolenaar <Bram@vim.org>
parents:
26883
diff
changeset
|
1518 |
b975b7c16ba1
patch 8.2.3989: some insert completion code is not tested
Bram Moolenaar <Bram@vim.org>
parents:
26883
diff
changeset
|
1519 // Find end of the word. |
b975b7c16ba1
patch 8.2.3989: some insert completion code is not tested
Bram Moolenaar <Bram@vim.org>
parents:
26883
diff
changeset
|
1520 if (has_mbyte) |
b975b7c16ba1
patch 8.2.3989: some insert completion code is not tested
Bram Moolenaar <Bram@vim.org>
parents:
26883
diff
changeset
|
1521 // Japanese words may have characters in |
b975b7c16ba1
patch 8.2.3989: some insert completion code is not tested
Bram Moolenaar <Bram@vim.org>
parents:
26883
diff
changeset
|
1522 // different classes, only separate words |
b975b7c16ba1
patch 8.2.3989: some insert completion code is not tested
Bram Moolenaar <Bram@vim.org>
parents:
26883
diff
changeset
|
1523 // with single-byte non-word characters. |
b975b7c16ba1
patch 8.2.3989: some insert completion code is not tested
Bram Moolenaar <Bram@vim.org>
parents:
26883
diff
changeset
|
1524 while (*ptr != NUL) |
b975b7c16ba1
patch 8.2.3989: some insert completion code is not tested
Bram Moolenaar <Bram@vim.org>
parents:
26883
diff
changeset
|
1525 { |
b975b7c16ba1
patch 8.2.3989: some insert completion code is not tested
Bram Moolenaar <Bram@vim.org>
parents:
26883
diff
changeset
|
1526 int l = (*mb_ptr2len)(ptr); |
b975b7c16ba1
patch 8.2.3989: some insert completion code is not tested
Bram Moolenaar <Bram@vim.org>
parents:
26883
diff
changeset
|
1527 |
b975b7c16ba1
patch 8.2.3989: some insert completion code is not tested
Bram Moolenaar <Bram@vim.org>
parents:
26883
diff
changeset
|
1528 if (l < 2 && !vim_iswordc(*ptr)) |
b975b7c16ba1
patch 8.2.3989: some insert completion code is not tested
Bram Moolenaar <Bram@vim.org>
parents:
26883
diff
changeset
|
1529 break; |
b975b7c16ba1
patch 8.2.3989: some insert completion code is not tested
Bram Moolenaar <Bram@vim.org>
parents:
26883
diff
changeset
|
1530 ptr += l; |
b975b7c16ba1
patch 8.2.3989: some insert completion code is not tested
Bram Moolenaar <Bram@vim.org>
parents:
26883
diff
changeset
|
1531 } |
b975b7c16ba1
patch 8.2.3989: some insert completion code is not tested
Bram Moolenaar <Bram@vim.org>
parents:
26883
diff
changeset
|
1532 else |
b975b7c16ba1
patch 8.2.3989: some insert completion code is not tested
Bram Moolenaar <Bram@vim.org>
parents:
26883
diff
changeset
|
1533 ptr = find_word_end(ptr); |
b975b7c16ba1
patch 8.2.3989: some insert completion code is not tested
Bram Moolenaar <Bram@vim.org>
parents:
26883
diff
changeset
|
1534 |
b975b7c16ba1
patch 8.2.3989: some insert completion code is not tested
Bram Moolenaar <Bram@vim.org>
parents:
26883
diff
changeset
|
1535 // Add the word. Skip the regexp match. |
b975b7c16ba1
patch 8.2.3989: some insert completion code is not tested
Bram Moolenaar <Bram@vim.org>
parents:
26883
diff
changeset
|
1536 if (wstart != skip_word) |
b975b7c16ba1
patch 8.2.3989: some insert completion code is not tested
Bram Moolenaar <Bram@vim.org>
parents:
26883
diff
changeset
|
1537 { |
b975b7c16ba1
patch 8.2.3989: some insert completion code is not tested
Bram Moolenaar <Bram@vim.org>
parents:
26883
diff
changeset
|
1538 status = ins_compl_add_infercase(wstart, (int)(ptr - wstart), p_ic, |
b975b7c16ba1
patch 8.2.3989: some insert completion code is not tested
Bram Moolenaar <Bram@vim.org>
parents:
26883
diff
changeset
|
1539 fname, dir, FALSE); |
b975b7c16ba1
patch 8.2.3989: some insert completion code is not tested
Bram Moolenaar <Bram@vim.org>
parents:
26883
diff
changeset
|
1540 if (status == FAIL) |
b975b7c16ba1
patch 8.2.3989: some insert completion code is not tested
Bram Moolenaar <Bram@vim.org>
parents:
26883
diff
changeset
|
1541 break; |
b975b7c16ba1
patch 8.2.3989: some insert completion code is not tested
Bram Moolenaar <Bram@vim.org>
parents:
26883
diff
changeset
|
1542 } |
b975b7c16ba1
patch 8.2.3989: some insert completion code is not tested
Bram Moolenaar <Bram@vim.org>
parents:
26883
diff
changeset
|
1543 } |
b975b7c16ba1
patch 8.2.3989: some insert completion code is not tested
Bram Moolenaar <Bram@vim.org>
parents:
26883
diff
changeset
|
1544 |
b975b7c16ba1
patch 8.2.3989: some insert completion code is not tested
Bram Moolenaar <Bram@vim.org>
parents:
26883
diff
changeset
|
1545 *buf_arg = ptr; |
b975b7c16ba1
patch 8.2.3989: some insert completion code is not tested
Bram Moolenaar <Bram@vim.org>
parents:
26883
diff
changeset
|
1546 return status; |
b975b7c16ba1
patch 8.2.3989: some insert completion code is not tested
Bram Moolenaar <Bram@vim.org>
parents:
26883
diff
changeset
|
1547 } |
b975b7c16ba1
patch 8.2.3989: some insert completion code is not tested
Bram Moolenaar <Bram@vim.org>
parents:
26883
diff
changeset
|
1548 |
b975b7c16ba1
patch 8.2.3989: some insert completion code is not tested
Bram Moolenaar <Bram@vim.org>
parents:
26883
diff
changeset
|
1549 /* |
b975b7c16ba1
patch 8.2.3989: some insert completion code is not tested
Bram Moolenaar <Bram@vim.org>
parents:
26883
diff
changeset
|
1550 * Process "count" dictionary/thesaurus "files" and add the text matching |
b975b7c16ba1
patch 8.2.3989: some insert completion code is not tested
Bram Moolenaar <Bram@vim.org>
parents:
26883
diff
changeset
|
1551 * "regmatch". |
b975b7c16ba1
patch 8.2.3989: some insert completion code is not tested
Bram Moolenaar <Bram@vim.org>
parents:
26883
diff
changeset
|
1552 */ |
16142
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1553 static void |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1554 ins_compl_files( |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1555 int count, |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1556 char_u **files, |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1557 int thesaurus, |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1558 int flags, |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1559 regmatch_T *regmatch, |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1560 char_u *buf, |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1561 int *dir) |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1562 { |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1563 char_u *ptr; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1564 int i; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1565 FILE *fp; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1566 int add_r; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1567 |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1568 for (i = 0; i < count && !got_int && !compl_interrupted; i++) |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1569 { |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1570 fp = mch_fopen((char *)files[i], "r"); // open dictionary file |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1571 if (flags != DICT_EXACT) |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1572 { |
23169
5e6855ebc4ea
patch 8.2.2130: Insert mode completion messages end up in message history
Bram Moolenaar <Bram@vim.org>
parents:
22862
diff
changeset
|
1573 msg_hist_off = TRUE; // reset in msg_trunc_attr() |
16142
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1574 vim_snprintf((char *)IObuff, IOSIZE, |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1575 _("Scanning dictionary: %s"), (char *)files[i]); |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1576 (void)msg_trunc_attr((char *)IObuff, TRUE, HL_ATTR(HLF_R)); |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1577 } |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1578 |
26850
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
1579 if (fp == NULL) |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
1580 continue; |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
1581 |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
1582 // Read dictionary file line by line. |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
1583 // Check each line for a match. |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
1584 while (!got_int && !compl_interrupted && !vim_fgets(buf, LSIZE, fp)) |
16142
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1585 { |
26850
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
1586 ptr = buf; |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
1587 while (vim_regexec(regmatch, buf, (colnr_T)(ptr - buf))) |
16142
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1588 { |
26850
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
1589 ptr = regmatch->startp[0]; |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
1590 if (ctrl_x_mode_line_or_eval()) |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
1591 ptr = find_line_end(ptr); |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
1592 else |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
1593 ptr = find_word_end(ptr); |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
1594 add_r = ins_compl_add_infercase(regmatch->startp[0], |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
1595 (int)(ptr - regmatch->startp[0]), |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
1596 p_ic, files[i], *dir, FALSE); |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
1597 if (thesaurus) |
16142
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1598 { |
26921
b975b7c16ba1
patch 8.2.3989: some insert completion code is not tested
Bram Moolenaar <Bram@vim.org>
parents:
26883
diff
changeset
|
1599 // For a thesaurus, add all the words in the line |
26850
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
1600 ptr = buf; |
26921
b975b7c16ba1
patch 8.2.3989: some insert completion code is not tested
Bram Moolenaar <Bram@vim.org>
parents:
26883
diff
changeset
|
1601 add_r = thesarurs_add_words_in_line(files[i], &ptr, *dir, |
b975b7c16ba1
patch 8.2.3989: some insert completion code is not tested
Bram Moolenaar <Bram@vim.org>
parents:
26883
diff
changeset
|
1602 regmatch->startp[0]); |
16142
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1603 } |
26850
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
1604 if (add_r == OK) |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
1605 // if dir was BACKWARD then honor it just once |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
1606 *dir = FORWARD; |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
1607 else if (add_r == FAIL) |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
1608 break; |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
1609 // avoid expensive call to vim_regexec() when at end |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
1610 // of line |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
1611 if (*ptr == '\n' || got_int) |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
1612 break; |
16142
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1613 } |
26850
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
1614 line_breakcheck(); |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
1615 ins_compl_check_keys(50, FALSE); |
16142
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1616 } |
26850
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
1617 fclose(fp); |
16142
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1618 } |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1619 } |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1620 |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1621 /* |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1622 * Find the start of the next word. |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1623 * Returns a pointer to the first char of the word. Also stops at a NUL. |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1624 */ |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1625 char_u * |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1626 find_word_start(char_u *ptr) |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1627 { |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1628 if (has_mbyte) |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1629 while (*ptr != NUL && *ptr != '\n' && mb_get_class(ptr) <= 1) |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1630 ptr += (*mb_ptr2len)(ptr); |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1631 else |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1632 while (*ptr != NUL && *ptr != '\n' && !vim_iswordc(*ptr)) |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1633 ++ptr; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1634 return ptr; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1635 } |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1636 |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1637 /* |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1638 * Find the end of the word. Assumes it starts inside a word. |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1639 * Returns a pointer to just after the word. |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1640 */ |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1641 char_u * |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1642 find_word_end(char_u *ptr) |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1643 { |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1644 int start_class; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1645 |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1646 if (has_mbyte) |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1647 { |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1648 start_class = mb_get_class(ptr); |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1649 if (start_class > 1) |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1650 while (*ptr != NUL) |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1651 { |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1652 ptr += (*mb_ptr2len)(ptr); |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1653 if (mb_get_class(ptr) != start_class) |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1654 break; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1655 } |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1656 } |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1657 else |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1658 while (vim_iswordc(*ptr)) |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1659 ++ptr; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1660 return ptr; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1661 } |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1662 |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1663 /* |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1664 * Find the end of the line, omitting CR and NL at the end. |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1665 * Returns a pointer to just after the line. |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1666 */ |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1667 static char_u * |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1668 find_line_end(char_u *ptr) |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1669 { |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1670 char_u *s; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1671 |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1672 s = ptr + STRLEN(ptr); |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1673 while (s > ptr && (s[-1] == CAR || s[-1] == NL)) |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1674 --s; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1675 return s; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1676 } |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1677 |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1678 /* |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1679 * Free the list of completions |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1680 */ |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1681 static void |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1682 ins_compl_free(void) |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1683 { |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1684 compl_T *match; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1685 int i; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1686 |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1687 VIM_CLEAR(compl_pattern); |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1688 VIM_CLEAR(compl_leader); |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1689 |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1690 if (compl_first_match == NULL) |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1691 return; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1692 |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1693 ins_compl_del_pum(); |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1694 pum_clear(); |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1695 |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1696 compl_curr_match = compl_first_match; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1697 do |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1698 { |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1699 match = compl_curr_match; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1700 compl_curr_match = compl_curr_match->cp_next; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1701 vim_free(match->cp_str); |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1702 // several entries may use the same fname, free it just once. |
16239
5df26b29e809
patch 8.1.1124: insert completion flags are mixed up
Bram Moolenaar <Bram@vim.org>
parents:
16237
diff
changeset
|
1703 if (match->cp_flags & CP_FREE_FNAME) |
16142
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1704 vim_free(match->cp_fname); |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1705 for (i = 0; i < CPT_COUNT; ++i) |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1706 vim_free(match->cp_text[i]); |
19051
c6248ef5b41b
patch 8.2.0086: build error for small version
Bram Moolenaar <Bram@vim.org>
parents:
19047
diff
changeset
|
1707 #ifdef FEAT_EVAL |
19047
a3fce2763e83
patch 8.2.0084: complete item "user_data" can only be a string
Bram Moolenaar <Bram@vim.org>
parents:
18933
diff
changeset
|
1708 clear_tv(&match->cp_user_data); |
19051
c6248ef5b41b
patch 8.2.0086: build error for small version
Bram Moolenaar <Bram@vim.org>
parents:
19047
diff
changeset
|
1709 #endif |
16142
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1710 vim_free(match); |
26944
8dbdd68627bd
patch 8.2.4001: insert complete code uses global variables
Bram Moolenaar <Bram@vim.org>
parents:
26921
diff
changeset
|
1711 } while (compl_curr_match != NULL && !is_first_match(compl_curr_match)); |
16142
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1712 compl_first_match = compl_curr_match = NULL; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1713 compl_shown_match = NULL; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1714 compl_old_match = NULL; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1715 } |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1716 |
26944
8dbdd68627bd
patch 8.2.4001: insert complete code uses global variables
Bram Moolenaar <Bram@vim.org>
parents:
26921
diff
changeset
|
1717 /* |
8dbdd68627bd
patch 8.2.4001: insert complete code uses global variables
Bram Moolenaar <Bram@vim.org>
parents:
26921
diff
changeset
|
1718 * Reset/clear the completion state. |
8dbdd68627bd
patch 8.2.4001: insert complete code uses global variables
Bram Moolenaar <Bram@vim.org>
parents:
26921
diff
changeset
|
1719 */ |
16142
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1720 void |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1721 ins_compl_clear(void) |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1722 { |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1723 compl_cont_status = 0; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1724 compl_started = FALSE; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1725 compl_matches = 0; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1726 VIM_CLEAR(compl_pattern); |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1727 VIM_CLEAR(compl_leader); |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1728 edit_submode_extra = NULL; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1729 VIM_CLEAR(compl_orig_text); |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1730 compl_enter_selects = FALSE; |
17813
8ca20b0a3dc3
patch 8.1.1903: cannot build without the +eval feature
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
1731 #ifdef FEAT_EVAL |
16142
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1732 // clear v:completed_item |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1733 set_vim_var_dict(VV_COMPLETED_ITEM, dict_alloc_lock(VAR_FIXED)); |
17813
8ca20b0a3dc3
patch 8.1.1903: cannot build without the +eval feature
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
1734 #endif |
16142
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1735 } |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1736 |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1737 /* |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1738 * Return TRUE when Insert completion is active. |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1739 */ |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1740 int |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1741 ins_compl_active(void) |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1742 { |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1743 return compl_started; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1744 } |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1745 |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1746 /* |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1747 * Selected one of the matches. When FALSE the match was edited or using the |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1748 * longest common string. |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1749 */ |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1750 int |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1751 ins_compl_used_match(void) |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1752 { |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1753 return compl_used_match; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1754 } |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1755 |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1756 /* |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1757 * Initialize get longest common string. |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1758 */ |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1759 void |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1760 ins_compl_init_get_longest(void) |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1761 { |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1762 compl_get_longest = FALSE; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1763 } |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1764 |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1765 /* |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1766 * Returns TRUE when insert completion is interrupted. |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1767 */ |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1768 int |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1769 ins_compl_interrupted(void) |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1770 { |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1771 return compl_interrupted; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1772 } |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1773 |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1774 /* |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1775 * Returns TRUE if the <Enter> key selects a match in the completion popup |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1776 * menu. |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1777 */ |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1778 int |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1779 ins_compl_enter_selects(void) |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1780 { |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1781 return compl_enter_selects; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1782 } |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1783 |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1784 /* |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1785 * Return the column where the text starts that is being completed |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1786 */ |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1787 colnr_T |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1788 ins_compl_col(void) |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1789 { |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1790 return compl_col; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1791 } |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1792 |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1793 /* |
26944
8dbdd68627bd
patch 8.2.4001: insert complete code uses global variables
Bram Moolenaar <Bram@vim.org>
parents:
26921
diff
changeset
|
1794 * Return the length in bytes of the text being completed |
8dbdd68627bd
patch 8.2.4001: insert complete code uses global variables
Bram Moolenaar <Bram@vim.org>
parents:
26921
diff
changeset
|
1795 */ |
8dbdd68627bd
patch 8.2.4001: insert complete code uses global variables
Bram Moolenaar <Bram@vim.org>
parents:
26921
diff
changeset
|
1796 int |
8dbdd68627bd
patch 8.2.4001: insert complete code uses global variables
Bram Moolenaar <Bram@vim.org>
parents:
26921
diff
changeset
|
1797 ins_compl_len(void) |
8dbdd68627bd
patch 8.2.4001: insert complete code uses global variables
Bram Moolenaar <Bram@vim.org>
parents:
26921
diff
changeset
|
1798 { |
8dbdd68627bd
patch 8.2.4001: insert complete code uses global variables
Bram Moolenaar <Bram@vim.org>
parents:
26921
diff
changeset
|
1799 return compl_length; |
8dbdd68627bd
patch 8.2.4001: insert complete code uses global variables
Bram Moolenaar <Bram@vim.org>
parents:
26921
diff
changeset
|
1800 } |
8dbdd68627bd
patch 8.2.4001: insert complete code uses global variables
Bram Moolenaar <Bram@vim.org>
parents:
26921
diff
changeset
|
1801 |
8dbdd68627bd
patch 8.2.4001: insert complete code uses global variables
Bram Moolenaar <Bram@vim.org>
parents:
26921
diff
changeset
|
1802 /* |
16142
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1803 * Delete one character before the cursor and show the subset of the matches |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1804 * that match the word that is now before the cursor. |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1805 * Returns the character to be used, NUL if the work is done and another char |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1806 * to be got from the user. |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1807 */ |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1808 int |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1809 ins_compl_bs(void) |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1810 { |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1811 char_u *line; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1812 char_u *p; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1813 |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1814 line = ml_get_curline(); |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1815 p = line + curwin->w_cursor.col; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1816 MB_PTR_BACK(line, p); |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1817 |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1818 // Stop completion when the whole word was deleted. For Omni completion |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1819 // allow the word to be deleted, we won't match everything. |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1820 // Respect the 'backspace' option. |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1821 if ((int)(p - line) - (int)compl_col < 0 |
26944
8dbdd68627bd
patch 8.2.4001: insert complete code uses global variables
Bram Moolenaar <Bram@vim.org>
parents:
26921
diff
changeset
|
1822 || ((int)(p - line) - (int)compl_col == 0 && !ctrl_x_mode_omni()) |
8dbdd68627bd
patch 8.2.4001: insert complete code uses global variables
Bram Moolenaar <Bram@vim.org>
parents:
26921
diff
changeset
|
1823 || ctrl_x_mode_eval() |
16142
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1824 || (!can_bs(BS_START) && (int)(p - line) - (int)compl_col |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1825 - compl_length < 0)) |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1826 return K_BS; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1827 |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1828 // Deleted more than what was used to find matches or didn't finish |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1829 // finding all matches: need to look for matches all over again. |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1830 if (curwin->w_cursor.col <= compl_col + compl_length |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1831 || ins_compl_need_restart()) |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1832 ins_compl_restart(); |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1833 |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1834 vim_free(compl_leader); |
20830
9064044fd4f6
patch 8.2.0967: unnecessary type casts for vim_strnsave()
Bram Moolenaar <Bram@vim.org>
parents:
20392
diff
changeset
|
1835 compl_leader = vim_strnsave(line + compl_col, (p - line) - compl_col); |
26921
b975b7c16ba1
patch 8.2.3989: some insert completion code is not tested
Bram Moolenaar <Bram@vim.org>
parents:
26883
diff
changeset
|
1836 if (compl_leader == NULL) |
b975b7c16ba1
patch 8.2.3989: some insert completion code is not tested
Bram Moolenaar <Bram@vim.org>
parents:
26883
diff
changeset
|
1837 return K_BS; |
b975b7c16ba1
patch 8.2.3989: some insert completion code is not tested
Bram Moolenaar <Bram@vim.org>
parents:
26883
diff
changeset
|
1838 |
b975b7c16ba1
patch 8.2.3989: some insert completion code is not tested
Bram Moolenaar <Bram@vim.org>
parents:
26883
diff
changeset
|
1839 ins_compl_new_leader(); |
b975b7c16ba1
patch 8.2.3989: some insert completion code is not tested
Bram Moolenaar <Bram@vim.org>
parents:
26883
diff
changeset
|
1840 if (compl_shown_match != NULL) |
b975b7c16ba1
patch 8.2.3989: some insert completion code is not tested
Bram Moolenaar <Bram@vim.org>
parents:
26883
diff
changeset
|
1841 // Make sure current match is not a hidden item. |
b975b7c16ba1
patch 8.2.3989: some insert completion code is not tested
Bram Moolenaar <Bram@vim.org>
parents:
26883
diff
changeset
|
1842 compl_curr_match = compl_shown_match; |
b975b7c16ba1
patch 8.2.3989: some insert completion code is not tested
Bram Moolenaar <Bram@vim.org>
parents:
26883
diff
changeset
|
1843 return NUL; |
16142
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1844 } |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1845 |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1846 /* |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1847 * Return TRUE when we need to find matches again, ins_compl_restart() is to |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1848 * be called. |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1849 */ |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1850 static int |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1851 ins_compl_need_restart(void) |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1852 { |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1853 // Return TRUE if we didn't complete finding matches or when the |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1854 // 'completefunc' returned "always" in the "refresh" dictionary item. |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1855 return compl_was_interrupted |
26944
8dbdd68627bd
patch 8.2.4001: insert complete code uses global variables
Bram Moolenaar <Bram@vim.org>
parents:
26921
diff
changeset
|
1856 || ((ctrl_x_mode_function() || ctrl_x_mode_omni()) |
16142
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1857 && compl_opt_refresh_always); |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1858 } |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1859 |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1860 /* |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1861 * Called after changing "compl_leader". |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1862 * Show the popup menu with a different set of matches. |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1863 * May also search for matches again if the previous search was interrupted. |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1864 */ |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1865 static void |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1866 ins_compl_new_leader(void) |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1867 { |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1868 ins_compl_del_pum(); |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1869 ins_compl_delete(); |
26944
8dbdd68627bd
patch 8.2.4001: insert complete code uses global variables
Bram Moolenaar <Bram@vim.org>
parents:
26921
diff
changeset
|
1870 ins_bytes(compl_leader + get_compl_len()); |
16142
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1871 compl_used_match = FALSE; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1872 |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1873 if (compl_started) |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1874 ins_compl_set_original_text(compl_leader); |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1875 else |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1876 { |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1877 #ifdef FEAT_SPELL |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1878 spell_bad_len = 0; // need to redetect bad word |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1879 #endif |
18498
9e6d5a4abb1c
patch 8.1.2243: typos in comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
1880 // Matches were cleared, need to search for them now. Before drawing |
16142
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1881 // the popup menu display the changed text before the cursor. Set |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1882 // "compl_restarting" to avoid that the first match is inserted. |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1883 pum_call_update_screen(); |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1884 #ifdef FEAT_GUI |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1885 if (gui.in_use) |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1886 { |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1887 // Show the cursor after the match, not after the redrawn text. |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1888 setcursor(); |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1889 out_flush_cursor(FALSE, FALSE); |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1890 } |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1891 #endif |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1892 compl_restarting = TRUE; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1893 if (ins_complete(Ctrl_N, TRUE) == FAIL) |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1894 compl_cont_status = 0; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1895 compl_restarting = FALSE; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1896 } |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1897 |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1898 compl_enter_selects = !compl_used_match; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1899 |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1900 // Show the popup menu with a different set of matches. |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1901 ins_compl_show_pum(); |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1902 |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1903 // Don't let Enter select the original text when there is no popup menu. |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1904 if (compl_match_array == NULL) |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1905 compl_enter_selects = FALSE; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1906 } |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1907 |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1908 /* |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1909 * Return the length of the completion, from the completion start column to |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1910 * the cursor column. Making sure it never goes below zero. |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1911 */ |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1912 static int |
26944
8dbdd68627bd
patch 8.2.4001: insert complete code uses global variables
Bram Moolenaar <Bram@vim.org>
parents:
26921
diff
changeset
|
1913 get_compl_len(void) |
16142
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1914 { |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1915 int off = (int)curwin->w_cursor.col - (int)compl_col; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1916 |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1917 if (off < 0) |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1918 return 0; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1919 return off; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1920 } |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1921 |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1922 /* |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1923 * Append one character to the match leader. May reduce the number of |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1924 * matches. |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1925 */ |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1926 void |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1927 ins_compl_addleader(int c) |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1928 { |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1929 int cc; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1930 |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1931 if (stop_arrow() == FAIL) |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1932 return; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1933 if (has_mbyte && (cc = (*mb_char2len)(c)) > 1) |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1934 { |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1935 char_u buf[MB_MAXBYTES + 1]; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1936 |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1937 (*mb_char2bytes)(c, buf); |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1938 buf[cc] = NUL; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1939 ins_char_bytes(buf, cc); |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1940 if (compl_opt_refresh_always) |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1941 AppendToRedobuff(buf); |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1942 } |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1943 else |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1944 { |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1945 ins_char(c); |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1946 if (compl_opt_refresh_always) |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1947 AppendCharToRedobuff(c); |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1948 } |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1949 |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1950 // If we didn't complete finding matches we must search again. |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1951 if (ins_compl_need_restart()) |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1952 ins_compl_restart(); |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1953 |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1954 // When 'always' is set, don't reset compl_leader. While completing, |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1955 // cursor doesn't point original position, changing compl_leader would |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1956 // break redo. |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1957 if (!compl_opt_refresh_always) |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1958 { |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1959 vim_free(compl_leader); |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1960 compl_leader = vim_strnsave(ml_get_curline() + compl_col, |
20830
9064044fd4f6
patch 8.2.0967: unnecessary type casts for vim_strnsave()
Bram Moolenaar <Bram@vim.org>
parents:
20392
diff
changeset
|
1961 curwin->w_cursor.col - compl_col); |
16142
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1962 if (compl_leader != NULL) |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1963 ins_compl_new_leader(); |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1964 } |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1965 } |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1966 |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1967 /* |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1968 * Setup for finding completions again without leaving CTRL-X mode. Used when |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1969 * BS or a key was typed while still searching for matches. |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1970 */ |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1971 static void |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1972 ins_compl_restart(void) |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1973 { |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1974 ins_compl_free(); |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1975 compl_started = FALSE; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1976 compl_matches = 0; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1977 compl_cont_status = 0; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1978 compl_cont_mode = 0; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1979 } |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1980 |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1981 /* |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1982 * Set the first match, the original text. |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1983 */ |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1984 static void |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1985 ins_compl_set_original_text(char_u *str) |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1986 { |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1987 char_u *p; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1988 |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1989 // Replace the original text entry. |
26850
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
1990 // The CP_ORIGINAL_TEXT flag is either at the first item or might possibly |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
1991 // be at the last item for backward completion |
26944
8dbdd68627bd
patch 8.2.4001: insert complete code uses global variables
Bram Moolenaar <Bram@vim.org>
parents:
26921
diff
changeset
|
1992 if (match_at_original_text(compl_first_match)) // safety check |
16142
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1993 { |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1994 p = vim_strsave(str); |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1995 if (p != NULL) |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1996 { |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1997 vim_free(compl_first_match->cp_str); |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1998 compl_first_match->cp_str = p; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1999 } |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2000 } |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2001 else if (compl_first_match->cp_prev != NULL |
26944
8dbdd68627bd
patch 8.2.4001: insert complete code uses global variables
Bram Moolenaar <Bram@vim.org>
parents:
26921
diff
changeset
|
2002 && match_at_original_text(compl_first_match->cp_prev)) |
16142
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2003 { |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2004 p = vim_strsave(str); |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2005 if (p != NULL) |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2006 { |
28809
d0241e74bfdb
patch 8.2.4928: various white space and cosmetic mistakes
Bram Moolenaar <Bram@vim.org>
parents:
28773
diff
changeset
|
2007 vim_free(compl_first_match->cp_prev->cp_str); |
d0241e74bfdb
patch 8.2.4928: various white space and cosmetic mistakes
Bram Moolenaar <Bram@vim.org>
parents:
28773
diff
changeset
|
2008 compl_first_match->cp_prev->cp_str = p; |
16142
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2009 } |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2010 } |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2011 } |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2012 |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2013 /* |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2014 * Append one character to the match leader. May reduce the number of |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2015 * matches. |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2016 */ |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2017 void |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2018 ins_compl_addfrommatch(void) |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2019 { |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2020 char_u *p; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2021 int len = (int)curwin->w_cursor.col - (int)compl_col; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2022 int c; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2023 compl_T *cp; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2024 |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2025 p = compl_shown_match->cp_str; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2026 if ((int)STRLEN(p) <= len) // the match is too short |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2027 { |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2028 // When still at the original match use the first entry that matches |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2029 // the leader. |
26944
8dbdd68627bd
patch 8.2.4001: insert complete code uses global variables
Bram Moolenaar <Bram@vim.org>
parents:
26921
diff
changeset
|
2030 if (!match_at_original_text(compl_shown_match)) |
26850
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
2031 return; |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
2032 |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
2033 p = NULL; |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
2034 for (cp = compl_shown_match->cp_next; cp != NULL |
26944
8dbdd68627bd
patch 8.2.4001: insert complete code uses global variables
Bram Moolenaar <Bram@vim.org>
parents:
26921
diff
changeset
|
2035 && !is_first_match(cp); cp = cp->cp_next) |
16142
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2036 { |
26850
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
2037 if (compl_leader == NULL |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
2038 || ins_compl_equal(cp, compl_leader, |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
2039 (int)STRLEN(compl_leader))) |
16142
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2040 { |
26850
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
2041 p = cp->cp_str; |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
2042 break; |
16142
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2043 } |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2044 } |
26850
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
2045 if (p == NULL || (int)STRLEN(p) <= len) |
16142
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2046 return; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2047 } |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2048 p += len; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2049 c = PTR2CHAR(p); |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2050 ins_compl_addleader(c); |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2051 } |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2052 |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2053 /* |
26944
8dbdd68627bd
patch 8.2.4001: insert complete code uses global variables
Bram Moolenaar <Bram@vim.org>
parents:
26921
diff
changeset
|
2054 * Set the CTRL-X completion mode based on the key "c" typed after a CTRL-X. |
26831
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
2055 * Uses the global variables: ctrl_x_mode, edit_submode, edit_submode_pre, |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
2056 * compl_cont_mode and compl_cont_status. |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
2057 * Returns TRUE when the character is not to be inserted. |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
2058 */ |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
2059 static int |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
2060 set_ctrl_x_mode(int c) |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
2061 { |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
2062 int retval = FALSE; |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
2063 |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
2064 switch (c) |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
2065 { |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
2066 case Ctrl_E: |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
2067 case Ctrl_Y: |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
2068 // scroll the window one line up or down |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
2069 ctrl_x_mode = CTRL_X_SCROLL; |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
2070 if (!(State & REPLACE_FLAG)) |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
2071 edit_submode = (char_u *)_(" (insert) Scroll (^E/^Y)"); |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
2072 else |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
2073 edit_submode = (char_u *)_(" (replace) Scroll (^E/^Y)"); |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
2074 edit_submode_pre = NULL; |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
2075 showmode(); |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
2076 break; |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
2077 case Ctrl_L: |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
2078 // complete whole line |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
2079 ctrl_x_mode = CTRL_X_WHOLE_LINE; |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
2080 break; |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
2081 case Ctrl_F: |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
2082 // complete filenames |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
2083 ctrl_x_mode = CTRL_X_FILES; |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
2084 break; |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
2085 case Ctrl_K: |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
2086 // complete words from a dictinoary |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
2087 ctrl_x_mode = CTRL_X_DICTIONARY; |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
2088 break; |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
2089 case Ctrl_R: |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
2090 // Register insertion without exiting CTRL-X mode |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
2091 // Simply allow ^R to happen without affecting ^X mode |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
2092 break; |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
2093 case Ctrl_T: |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
2094 // complete words from a thesaurus |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
2095 ctrl_x_mode = CTRL_X_THESAURUS; |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
2096 break; |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
2097 #ifdef FEAT_COMPL_FUNC |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
2098 case Ctrl_U: |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
2099 // user defined completion |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
2100 ctrl_x_mode = CTRL_X_FUNCTION; |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
2101 break; |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
2102 case Ctrl_O: |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
2103 // omni completion |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
2104 ctrl_x_mode = CTRL_X_OMNI; |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
2105 break; |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
2106 #endif |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
2107 case 's': |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
2108 case Ctrl_S: |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
2109 // complete spelling suggestions |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
2110 ctrl_x_mode = CTRL_X_SPELL; |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
2111 #ifdef FEAT_SPELL |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
2112 ++emsg_off; // Avoid getting the E756 error twice. |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
2113 spell_back_to_badword(); |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
2114 --emsg_off; |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
2115 #endif |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
2116 break; |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
2117 case Ctrl_RSB: |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
2118 // complete tag names |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
2119 ctrl_x_mode = CTRL_X_TAGS; |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
2120 break; |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
2121 #ifdef FEAT_FIND_ID |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
2122 case Ctrl_I: |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
2123 case K_S_TAB: |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
2124 // complete keywords from included files |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
2125 ctrl_x_mode = CTRL_X_PATH_PATTERNS; |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
2126 break; |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
2127 case Ctrl_D: |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
2128 // complete definitions from included files |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
2129 ctrl_x_mode = CTRL_X_PATH_DEFINES; |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
2130 break; |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
2131 #endif |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
2132 case Ctrl_V: |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
2133 case Ctrl_Q: |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
2134 // complete vim commands |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
2135 ctrl_x_mode = CTRL_X_CMDLINE; |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
2136 break; |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
2137 case Ctrl_Z: |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
2138 // stop completion |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
2139 ctrl_x_mode = CTRL_X_NORMAL; |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
2140 edit_submode = NULL; |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
2141 showmode(); |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
2142 retval = TRUE; |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
2143 break; |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
2144 case Ctrl_P: |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
2145 case Ctrl_N: |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
2146 // ^X^P means LOCAL expansion if nothing interrupted (eg we |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
2147 // just started ^X mode, or there were enough ^X's to cancel |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
2148 // the previous mode, say ^X^F^X^X^P or ^P^X^X^X^P, see below) |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
2149 // do normal expansion when interrupting a different mode (say |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
2150 // ^X^F^X^P or ^P^X^X^P, see below) |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
2151 // nothing changes if interrupting mode 0, (eg, the flag |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
2152 // doesn't change when going to ADDING mode -- Acevedo |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
2153 if (!(compl_cont_status & CONT_INTRPT)) |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
2154 compl_cont_status |= CONT_LOCAL; |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
2155 else if (compl_cont_mode != 0) |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
2156 compl_cont_status &= ~CONT_LOCAL; |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
2157 // FALLTHROUGH |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
2158 default: |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
2159 // If we have typed at least 2 ^X's... for modes != 0, we set |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
2160 // compl_cont_status = 0 (eg, as if we had just started ^X |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
2161 // mode). |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
2162 // For mode 0, we set "compl_cont_mode" to an impossible |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
2163 // value, in both cases ^X^X can be used to restart the same |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
2164 // mode (avoiding ADDING mode). |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
2165 // Undocumented feature: In a mode != 0 ^X^P and ^X^X^P start |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
2166 // 'complete' and local ^P expansions respectively. |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
2167 // In mode 0 an extra ^X is needed since ^X^P goes to ADDING |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
2168 // mode -- Acevedo |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
2169 if (c == Ctrl_X) |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
2170 { |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
2171 if (compl_cont_mode != 0) |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
2172 compl_cont_status = 0; |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
2173 else |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
2174 compl_cont_mode = CTRL_X_NOT_DEFINED_YET; |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
2175 } |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
2176 ctrl_x_mode = CTRL_X_NORMAL; |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
2177 edit_submode = NULL; |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
2178 showmode(); |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
2179 break; |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
2180 } |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
2181 |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
2182 return retval; |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
2183 } |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
2184 |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
2185 /* |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
2186 * Stop insert completion mode |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
2187 */ |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
2188 static int |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
2189 ins_compl_stop(int c, int prev_mode, int retval) |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
2190 { |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
2191 char_u *ptr; |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
2192 int want_cindent; |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
2193 |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
2194 // Get here when we have finished typing a sequence of ^N and |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
2195 // ^P or other completion characters in CTRL-X mode. Free up |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
2196 // memory that was used, and make sure we can redo the insert. |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
2197 if (compl_curr_match != NULL || compl_leader != NULL || c == Ctrl_E) |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
2198 { |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
2199 // If any of the original typed text has been changed, eg when |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
2200 // ignorecase is set, we must add back-spaces to the redo |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
2201 // buffer. We add as few as necessary to delete just the part |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
2202 // of the original text that has changed. |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
2203 // When using the longest match, edited the match or used |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
2204 // CTRL-E then don't use the current match. |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
2205 if (compl_curr_match != NULL && compl_used_match && c != Ctrl_E) |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
2206 ptr = compl_curr_match->cp_str; |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
2207 else |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
2208 ptr = NULL; |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
2209 ins_compl_fixRedoBufForLeader(ptr); |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
2210 } |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
2211 |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
2212 want_cindent = (get_can_cindent() && cindent_on()); |
28942
6cdf55afaae9
patch 8.2.4993: smart/C/lisp indenting is optional
Bram Moolenaar <Bram@vim.org>
parents:
28809
diff
changeset
|
2213 |
26831
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
2214 // When completing whole lines: fix indent for 'cindent'. |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
2215 // Otherwise, break line if it's too long. |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
2216 if (compl_cont_mode == CTRL_X_WHOLE_LINE) |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
2217 { |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
2218 // re-indent the current line |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
2219 if (want_cindent) |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
2220 { |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
2221 do_c_expr_indent(); |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
2222 want_cindent = FALSE; // don't do it again |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
2223 } |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
2224 } |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
2225 else |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
2226 { |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
2227 int prev_col = curwin->w_cursor.col; |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
2228 |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
2229 // put the cursor on the last char, for 'tw' formatting |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
2230 if (prev_col > 0) |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
2231 dec_cursor(); |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
2232 // only format when something was inserted |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
2233 if (!arrow_used && !ins_need_undo_get() && c != Ctrl_E) |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
2234 insertchar(NUL, 0, -1); |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
2235 if (prev_col > 0 |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
2236 && ml_get_curline()[curwin->w_cursor.col] != NUL) |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
2237 inc_cursor(); |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
2238 } |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
2239 |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
2240 // If the popup menu is displayed pressing CTRL-Y means accepting |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
2241 // the selection without inserting anything. When |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
2242 // compl_enter_selects is set the Enter key does the same. |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
2243 if ((c == Ctrl_Y || (compl_enter_selects |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
2244 && (c == CAR || c == K_KENTER || c == NL))) |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
2245 && pum_visible()) |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
2246 retval = TRUE; |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
2247 |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
2248 // CTRL-E means completion is Ended, go back to the typed text. |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
2249 // but only do this, if the Popup is still visible |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
2250 if (c == Ctrl_E) |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
2251 { |
29355
796198629190
patch 9.0.0020: with some completion reading past end of string
Bram Moolenaar <Bram@vim.org>
parents:
29175
diff
changeset
|
2252 char_u *p = NULL; |
796198629190
patch 9.0.0020: with some completion reading past end of string
Bram Moolenaar <Bram@vim.org>
parents:
29175
diff
changeset
|
2253 |
26831
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
2254 ins_compl_delete(); |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
2255 if (compl_leader != NULL) |
29355
796198629190
patch 9.0.0020: with some completion reading past end of string
Bram Moolenaar <Bram@vim.org>
parents:
29175
diff
changeset
|
2256 p = compl_leader; |
26831
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
2257 else if (compl_first_match != NULL) |
29355
796198629190
patch 9.0.0020: with some completion reading past end of string
Bram Moolenaar <Bram@vim.org>
parents:
29175
diff
changeset
|
2258 p = compl_orig_text; |
796198629190
patch 9.0.0020: with some completion reading past end of string
Bram Moolenaar <Bram@vim.org>
parents:
29175
diff
changeset
|
2259 if (p != NULL) |
796198629190
patch 9.0.0020: with some completion reading past end of string
Bram Moolenaar <Bram@vim.org>
parents:
29175
diff
changeset
|
2260 { |
796198629190
patch 9.0.0020: with some completion reading past end of string
Bram Moolenaar <Bram@vim.org>
parents:
29175
diff
changeset
|
2261 int compl_len = get_compl_len(); |
796198629190
patch 9.0.0020: with some completion reading past end of string
Bram Moolenaar <Bram@vim.org>
parents:
29175
diff
changeset
|
2262 int len = (int)STRLEN(p); |
796198629190
patch 9.0.0020: with some completion reading past end of string
Bram Moolenaar <Bram@vim.org>
parents:
29175
diff
changeset
|
2263 |
796198629190
patch 9.0.0020: with some completion reading past end of string
Bram Moolenaar <Bram@vim.org>
parents:
29175
diff
changeset
|
2264 if (len > compl_len) |
796198629190
patch 9.0.0020: with some completion reading past end of string
Bram Moolenaar <Bram@vim.org>
parents:
29175
diff
changeset
|
2265 ins_bytes_len(p + compl_len, len - compl_len); |
796198629190
patch 9.0.0020: with some completion reading past end of string
Bram Moolenaar <Bram@vim.org>
parents:
29175
diff
changeset
|
2266 } |
26831
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
2267 retval = TRUE; |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
2268 } |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
2269 |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
2270 auto_format(FALSE, TRUE); |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
2271 |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
2272 // Trigger the CompleteDonePre event to give scripts a chance to |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
2273 // act upon the completion before clearing the info, and restore |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
2274 // ctrl_x_mode, so that complete_info() can be used. |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
2275 ctrl_x_mode = prev_mode; |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
2276 ins_apply_autocmds(EVENT_COMPLETEDONEPRE); |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
2277 |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
2278 ins_compl_free(); |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
2279 compl_started = FALSE; |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
2280 compl_matches = 0; |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
2281 if (!shortmess(SHM_COMPLETIONMENU)) |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
2282 msg_clr_cmdline(); // necessary for "noshowmode" |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
2283 ctrl_x_mode = CTRL_X_NORMAL; |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
2284 compl_enter_selects = FALSE; |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
2285 if (edit_submode != NULL) |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
2286 { |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
2287 edit_submode = NULL; |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
2288 showmode(); |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
2289 } |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
2290 |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
2291 #ifdef FEAT_CMDWIN |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
2292 if (c == Ctrl_C && cmdwin_type != 0) |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
2293 // Avoid the popup menu remains displayed when leaving the |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
2294 // command line window. |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
2295 update_screen(0); |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
2296 #endif |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
2297 // Indent now if a key was typed that is in 'cinkeys'. |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
2298 if (want_cindent && in_cinkeys(KEY_COMPLETE, ' ', inindent(0))) |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
2299 do_c_expr_indent(); |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
2300 // Trigger the CompleteDone event to give scripts a chance to act |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
2301 // upon the end of completion. |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
2302 ins_apply_autocmds(EVENT_COMPLETEDONE); |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
2303 |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
2304 return retval; |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
2305 } |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
2306 |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
2307 /* |
16142
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2308 * Prepare for Insert mode completion, or stop it. |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2309 * Called just after typing a character in Insert mode. |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2310 * Returns TRUE when the character is not to be inserted; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2311 */ |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2312 int |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2313 ins_compl_prep(int c) |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2314 { |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2315 int retval = FALSE; |
19127
0ee48dc3f8bc
patch 8.2.0123: complete_info() does not work when CompleteDone is triggered
Bram Moolenaar <Bram@vim.org>
parents:
19051
diff
changeset
|
2316 int prev_mode = ctrl_x_mode; |
16142
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2317 |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2318 // Forget any previous 'special' messages if this is actually |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2319 // a ^X mode key - bar ^R, in which case we wait to see what it gives us. |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2320 if (c != Ctrl_R && vim_is_ctrl_x_key(c)) |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2321 edit_submode_extra = NULL; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2322 |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2323 // Ignore end of Select mode mapping and mouse scroll buttons. |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2324 if (c == K_SELECT || c == K_MOUSEDOWN || c == K_MOUSEUP |
27140
a9eeb18e749c
patch 8.2.4099: Vim9: cannot use Vim9 syntax in mapping
Bram Moolenaar <Bram@vim.org>
parents:
27018
diff
changeset
|
2325 || c == K_MOUSELEFT || c == K_MOUSERIGHT |
a9eeb18e749c
patch 8.2.4099: Vim9: cannot use Vim9 syntax in mapping
Bram Moolenaar <Bram@vim.org>
parents:
27018
diff
changeset
|
2326 || c == K_COMMAND || c == K_SCRIPT_COMMAND) |
16142
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2327 return retval; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2328 |
18763
49b78d6465e5
patch 8.1.2371: FEAT_TEXT_PROP is a confusing name
Bram Moolenaar <Bram@vim.org>
parents:
18642
diff
changeset
|
2329 #ifdef FEAT_PROP_POPUP |
17775
b423bd231f33
patch 8.1.1884: cannot use mouse scroll wheel in popup in Insert mode
Bram Moolenaar <Bram@vim.org>
parents:
17704
diff
changeset
|
2330 // Ignore mouse events in a popup window |
b423bd231f33
patch 8.1.1884: cannot use mouse scroll wheel in popup in Insert mode
Bram Moolenaar <Bram@vim.org>
parents:
17704
diff
changeset
|
2331 if (is_mouse_key(c)) |
b423bd231f33
patch 8.1.1884: cannot use mouse scroll wheel in popup in Insert mode
Bram Moolenaar <Bram@vim.org>
parents:
17704
diff
changeset
|
2332 { |
b423bd231f33
patch 8.1.1884: cannot use mouse scroll wheel in popup in Insert mode
Bram Moolenaar <Bram@vim.org>
parents:
17704
diff
changeset
|
2333 // Ignore drag and release events, the position does not need to be in |
b423bd231f33
patch 8.1.1884: cannot use mouse scroll wheel in popup in Insert mode
Bram Moolenaar <Bram@vim.org>
parents:
17704
diff
changeset
|
2334 // the popup and it may have just closed. |
b423bd231f33
patch 8.1.1884: cannot use mouse scroll wheel in popup in Insert mode
Bram Moolenaar <Bram@vim.org>
parents:
17704
diff
changeset
|
2335 if (c == K_LEFTRELEASE |
b423bd231f33
patch 8.1.1884: cannot use mouse scroll wheel in popup in Insert mode
Bram Moolenaar <Bram@vim.org>
parents:
17704
diff
changeset
|
2336 || c == K_LEFTRELEASE_NM |
b423bd231f33
patch 8.1.1884: cannot use mouse scroll wheel in popup in Insert mode
Bram Moolenaar <Bram@vim.org>
parents:
17704
diff
changeset
|
2337 || c == K_MIDDLERELEASE |
b423bd231f33
patch 8.1.1884: cannot use mouse scroll wheel in popup in Insert mode
Bram Moolenaar <Bram@vim.org>
parents:
17704
diff
changeset
|
2338 || c == K_RIGHTRELEASE |
b423bd231f33
patch 8.1.1884: cannot use mouse scroll wheel in popup in Insert mode
Bram Moolenaar <Bram@vim.org>
parents:
17704
diff
changeset
|
2339 || c == K_X1RELEASE |
b423bd231f33
patch 8.1.1884: cannot use mouse scroll wheel in popup in Insert mode
Bram Moolenaar <Bram@vim.org>
parents:
17704
diff
changeset
|
2340 || c == K_X2RELEASE |
b423bd231f33
patch 8.1.1884: cannot use mouse scroll wheel in popup in Insert mode
Bram Moolenaar <Bram@vim.org>
parents:
17704
diff
changeset
|
2341 || c == K_LEFTDRAG |
b423bd231f33
patch 8.1.1884: cannot use mouse scroll wheel in popup in Insert mode
Bram Moolenaar <Bram@vim.org>
parents:
17704
diff
changeset
|
2342 || c == K_MIDDLEDRAG |
b423bd231f33
patch 8.1.1884: cannot use mouse scroll wheel in popup in Insert mode
Bram Moolenaar <Bram@vim.org>
parents:
17704
diff
changeset
|
2343 || c == K_RIGHTDRAG |
b423bd231f33
patch 8.1.1884: cannot use mouse scroll wheel in popup in Insert mode
Bram Moolenaar <Bram@vim.org>
parents:
17704
diff
changeset
|
2344 || c == K_X1DRAG |
b423bd231f33
patch 8.1.1884: cannot use mouse scroll wheel in popup in Insert mode
Bram Moolenaar <Bram@vim.org>
parents:
17704
diff
changeset
|
2345 || c == K_X2DRAG) |
b423bd231f33
patch 8.1.1884: cannot use mouse scroll wheel in popup in Insert mode
Bram Moolenaar <Bram@vim.org>
parents:
17704
diff
changeset
|
2346 return retval; |
b423bd231f33
patch 8.1.1884: cannot use mouse scroll wheel in popup in Insert mode
Bram Moolenaar <Bram@vim.org>
parents:
17704
diff
changeset
|
2347 if (popup_visible) |
b423bd231f33
patch 8.1.1884: cannot use mouse scroll wheel in popup in Insert mode
Bram Moolenaar <Bram@vim.org>
parents:
17704
diff
changeset
|
2348 { |
b423bd231f33
patch 8.1.1884: cannot use mouse scroll wheel in popup in Insert mode
Bram Moolenaar <Bram@vim.org>
parents:
17704
diff
changeset
|
2349 int row = mouse_row; |
b423bd231f33
patch 8.1.1884: cannot use mouse scroll wheel in popup in Insert mode
Bram Moolenaar <Bram@vim.org>
parents:
17704
diff
changeset
|
2350 int col = mouse_col; |
b423bd231f33
patch 8.1.1884: cannot use mouse scroll wheel in popup in Insert mode
Bram Moolenaar <Bram@vim.org>
parents:
17704
diff
changeset
|
2351 win_T *wp = mouse_find_win(&row, &col, FIND_POPUP); |
b423bd231f33
patch 8.1.1884: cannot use mouse scroll wheel in popup in Insert mode
Bram Moolenaar <Bram@vim.org>
parents:
17704
diff
changeset
|
2352 |
b423bd231f33
patch 8.1.1884: cannot use mouse scroll wheel in popup in Insert mode
Bram Moolenaar <Bram@vim.org>
parents:
17704
diff
changeset
|
2353 if (wp != NULL && WIN_IS_POPUP(wp)) |
b423bd231f33
patch 8.1.1884: cannot use mouse scroll wheel in popup in Insert mode
Bram Moolenaar <Bram@vim.org>
parents:
17704
diff
changeset
|
2354 return retval; |
b423bd231f33
patch 8.1.1884: cannot use mouse scroll wheel in popup in Insert mode
Bram Moolenaar <Bram@vim.org>
parents:
17704
diff
changeset
|
2355 } |
b423bd231f33
patch 8.1.1884: cannot use mouse scroll wheel in popup in Insert mode
Bram Moolenaar <Bram@vim.org>
parents:
17704
diff
changeset
|
2356 } |
b423bd231f33
patch 8.1.1884: cannot use mouse scroll wheel in popup in Insert mode
Bram Moolenaar <Bram@vim.org>
parents:
17704
diff
changeset
|
2357 #endif |
b423bd231f33
patch 8.1.1884: cannot use mouse scroll wheel in popup in Insert mode
Bram Moolenaar <Bram@vim.org>
parents:
17704
diff
changeset
|
2358 |
25707
31db9c6df4e3
patch 8.2.3389: cannot stop insert mode completion without side effects
Bram Moolenaar <Bram@vim.org>
parents:
25513
diff
changeset
|
2359 if (ctrl_x_mode == CTRL_X_CMDLINE_CTRL_X && c != Ctrl_X) |
31db9c6df4e3
patch 8.2.3389: cannot stop insert mode completion without side effects
Bram Moolenaar <Bram@vim.org>
parents:
25513
diff
changeset
|
2360 { |
31db9c6df4e3
patch 8.2.3389: cannot stop insert mode completion without side effects
Bram Moolenaar <Bram@vim.org>
parents:
25513
diff
changeset
|
2361 if (c == Ctrl_V || c == Ctrl_Q || c == Ctrl_Z || ins_compl_pum_key(c) |
31db9c6df4e3
patch 8.2.3389: cannot stop insert mode completion without side effects
Bram Moolenaar <Bram@vim.org>
parents:
25513
diff
changeset
|
2362 || !vim_is_ctrl_x_key(c)) |
31db9c6df4e3
patch 8.2.3389: cannot stop insert mode completion without side effects
Bram Moolenaar <Bram@vim.org>
parents:
25513
diff
changeset
|
2363 { |
31db9c6df4e3
patch 8.2.3389: cannot stop insert mode completion without side effects
Bram Moolenaar <Bram@vim.org>
parents:
25513
diff
changeset
|
2364 // Not starting another completion mode. |
31db9c6df4e3
patch 8.2.3389: cannot stop insert mode completion without side effects
Bram Moolenaar <Bram@vim.org>
parents:
25513
diff
changeset
|
2365 ctrl_x_mode = CTRL_X_CMDLINE; |
31db9c6df4e3
patch 8.2.3389: cannot stop insert mode completion without side effects
Bram Moolenaar <Bram@vim.org>
parents:
25513
diff
changeset
|
2366 |
31db9c6df4e3
patch 8.2.3389: cannot stop insert mode completion without side effects
Bram Moolenaar <Bram@vim.org>
parents:
25513
diff
changeset
|
2367 // CTRL-X CTRL-Z should stop completion without inserting anything |
31db9c6df4e3
patch 8.2.3389: cannot stop insert mode completion without side effects
Bram Moolenaar <Bram@vim.org>
parents:
25513
diff
changeset
|
2368 if (c == Ctrl_Z) |
31db9c6df4e3
patch 8.2.3389: cannot stop insert mode completion without side effects
Bram Moolenaar <Bram@vim.org>
parents:
25513
diff
changeset
|
2369 retval = TRUE; |
31db9c6df4e3
patch 8.2.3389: cannot stop insert mode completion without side effects
Bram Moolenaar <Bram@vim.org>
parents:
25513
diff
changeset
|
2370 } |
31db9c6df4e3
patch 8.2.3389: cannot stop insert mode completion without side effects
Bram Moolenaar <Bram@vim.org>
parents:
25513
diff
changeset
|
2371 else |
31db9c6df4e3
patch 8.2.3389: cannot stop insert mode completion without side effects
Bram Moolenaar <Bram@vim.org>
parents:
25513
diff
changeset
|
2372 { |
31db9c6df4e3
patch 8.2.3389: cannot stop insert mode completion without side effects
Bram Moolenaar <Bram@vim.org>
parents:
25513
diff
changeset
|
2373 ctrl_x_mode = CTRL_X_CMDLINE; |
31db9c6df4e3
patch 8.2.3389: cannot stop insert mode completion without side effects
Bram Moolenaar <Bram@vim.org>
parents:
25513
diff
changeset
|
2374 |
31db9c6df4e3
patch 8.2.3389: cannot stop insert mode completion without side effects
Bram Moolenaar <Bram@vim.org>
parents:
25513
diff
changeset
|
2375 // Other CTRL-X keys first stop completion, then start another |
31db9c6df4e3
patch 8.2.3389: cannot stop insert mode completion without side effects
Bram Moolenaar <Bram@vim.org>
parents:
25513
diff
changeset
|
2376 // completion mode. |
31db9c6df4e3
patch 8.2.3389: cannot stop insert mode completion without side effects
Bram Moolenaar <Bram@vim.org>
parents:
25513
diff
changeset
|
2377 ins_compl_prep(' '); |
31db9c6df4e3
patch 8.2.3389: cannot stop insert mode completion without side effects
Bram Moolenaar <Bram@vim.org>
parents:
25513
diff
changeset
|
2378 ctrl_x_mode = CTRL_X_NOT_DEFINED_YET; |
31db9c6df4e3
patch 8.2.3389: cannot stop insert mode completion without side effects
Bram Moolenaar <Bram@vim.org>
parents:
25513
diff
changeset
|
2379 } |
31db9c6df4e3
patch 8.2.3389: cannot stop insert mode completion without side effects
Bram Moolenaar <Bram@vim.org>
parents:
25513
diff
changeset
|
2380 } |
31db9c6df4e3
patch 8.2.3389: cannot stop insert mode completion without side effects
Bram Moolenaar <Bram@vim.org>
parents:
25513
diff
changeset
|
2381 |
16142
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2382 // Set "compl_get_longest" when finding the first matches. |
26944
8dbdd68627bd
patch 8.2.4001: insert complete code uses global variables
Bram Moolenaar <Bram@vim.org>
parents:
26921
diff
changeset
|
2383 if (ctrl_x_mode_not_defined_yet() |
8dbdd68627bd
patch 8.2.4001: insert complete code uses global variables
Bram Moolenaar <Bram@vim.org>
parents:
26921
diff
changeset
|
2384 || (ctrl_x_mode_normal() && !compl_started)) |
16142
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2385 { |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2386 compl_get_longest = (strstr((char *)p_cot, "longest") != NULL); |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2387 compl_used_match = TRUE; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2388 |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2389 } |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2390 |
26944
8dbdd68627bd
patch 8.2.4001: insert complete code uses global variables
Bram Moolenaar <Bram@vim.org>
parents:
26921
diff
changeset
|
2391 if (ctrl_x_mode_not_defined_yet()) |
16142
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2392 // We have just typed CTRL-X and aren't quite sure which CTRL-X mode |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2393 // it will be yet. Now we decide. |
26831
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
2394 retval = set_ctrl_x_mode(c); |
26944
8dbdd68627bd
patch 8.2.4001: insert complete code uses global variables
Bram Moolenaar <Bram@vim.org>
parents:
26921
diff
changeset
|
2395 else if (ctrl_x_mode_not_default()) |
16142
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2396 { |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2397 // We're already in CTRL-X mode, do we stay in it? |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2398 if (!vim_is_ctrl_x_key(c)) |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2399 { |
26944
8dbdd68627bd
patch 8.2.4001: insert complete code uses global variables
Bram Moolenaar <Bram@vim.org>
parents:
26921
diff
changeset
|
2400 if (ctrl_x_mode_scroll()) |
16142
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2401 ctrl_x_mode = CTRL_X_NORMAL; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2402 else |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2403 ctrl_x_mode = CTRL_X_FINISHED; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2404 edit_submode = NULL; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2405 } |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2406 showmode(); |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2407 } |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2408 |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2409 if (compl_started || ctrl_x_mode == CTRL_X_FINISHED) |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2410 { |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2411 // Show error message from attempted keyword completion (probably |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2412 // 'Pattern not found') until another key is hit, then go back to |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2413 // showing what mode we are in. |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2414 showmode(); |
26944
8dbdd68627bd
patch 8.2.4001: insert complete code uses global variables
Bram Moolenaar <Bram@vim.org>
parents:
26921
diff
changeset
|
2415 if ((ctrl_x_mode_normal() && c != Ctrl_N && c != Ctrl_P |
16142
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2416 && c != Ctrl_R && !ins_compl_pum_key(c)) |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2417 || ctrl_x_mode == CTRL_X_FINISHED) |
26831
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
2418 retval = ins_compl_stop(c, prev_mode, retval); |
16142
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2419 } |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2420 else if (ctrl_x_mode == CTRL_X_LOCAL_MSG) |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2421 // Trigger the CompleteDone event to give scripts a chance to act |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2422 // upon the (possibly failed) completion. |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2423 ins_apply_autocmds(EVENT_COMPLETEDONE); |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2424 |
28397
d1702731786c
patch 8.2.4723: the ModeChanged autocmd event is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
27140
diff
changeset
|
2425 may_trigger_modechanged(); |
26042
6b39ab99e367
patch 8.2.3555: ModeChanged is not triggered on every mode change
Bram Moolenaar <Bram@vim.org>
parents:
25990
diff
changeset
|
2426 |
16142
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2427 // reset continue_* if we left expansion-mode, if we stay they'll be |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2428 // (re)set properly in ins_complete() |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2429 if (!vim_is_ctrl_x_key(c)) |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2430 { |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2431 compl_cont_status = 0; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2432 compl_cont_mode = 0; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2433 } |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2434 |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2435 return retval; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2436 } |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2437 |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2438 /* |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2439 * Fix the redo buffer for the completion leader replacing some of the typed |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2440 * text. This inserts backspaces and appends the changed text. |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2441 * "ptr" is the known leader text or NUL. |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2442 */ |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2443 static void |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2444 ins_compl_fixRedoBufForLeader(char_u *ptr_arg) |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2445 { |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2446 int len; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2447 char_u *p; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2448 char_u *ptr = ptr_arg; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2449 |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2450 if (ptr == NULL) |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2451 { |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2452 if (compl_leader != NULL) |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2453 ptr = compl_leader; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2454 else |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2455 return; // nothing to do |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2456 } |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2457 if (compl_orig_text != NULL) |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2458 { |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2459 p = compl_orig_text; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2460 for (len = 0; p[len] != NUL && p[len] == ptr[len]; ++len) |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2461 ; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2462 if (len > 0) |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2463 len -= (*mb_head_off)(p, p + len); |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2464 for (p += len; *p != NUL; MB_PTR_ADV(p)) |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2465 AppendCharToRedobuff(K_BS); |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2466 } |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2467 else |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2468 len = 0; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2469 if (ptr != NULL) |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2470 AppendToRedobuffLit(ptr + len, -1); |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2471 } |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2472 |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2473 /* |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2474 * Loops through the list of windows, loaded-buffers or non-loaded-buffers |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2475 * (depending on flag) starting from buf and looking for a non-scanned |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2476 * buffer (other than curbuf). curbuf is special, if it is called with |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2477 * buf=curbuf then it has to be the first call for a given flag/expansion. |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2478 * |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2479 * Returns the buffer to scan, if any, otherwise returns curbuf -- Acevedo |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2480 */ |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2481 static buf_T * |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2482 ins_compl_next_buf(buf_T *buf, int flag) |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2483 { |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2484 static win_T *wp = NULL; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2485 |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2486 if (flag == 'w') // just windows |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2487 { |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2488 if (buf == curbuf || wp == NULL) // first call for this flag/expansion |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2489 wp = curwin; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2490 while ((wp = (wp->w_next != NULL ? wp->w_next : firstwin)) != curwin |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2491 && wp->w_buffer->b_scanned) |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2492 ; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2493 buf = wp->w_buffer; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2494 } |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2495 else |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2496 // 'b' (just loaded buffers), 'u' (just non-loaded buffers) or 'U' |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2497 // (unlisted buffers) |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2498 // When completing whole lines skip unloaded buffers. |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2499 while ((buf = (buf->b_next != NULL ? buf->b_next : firstbuf)) != curbuf |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2500 && ((flag == 'U' |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2501 ? buf->b_p_bl |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2502 : (!buf->b_p_bl |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2503 || (buf->b_ml.ml_mfp == NULL) != (flag == 'u'))) |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2504 || buf->b_scanned)) |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2505 ; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2506 return buf; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2507 } |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2508 |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2509 #ifdef FEAT_COMPL_FUNC |
26388
8aba638e91eb
patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents:
26362
diff
changeset
|
2510 |
8aba638e91eb
patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents:
26362
diff
changeset
|
2511 # ifdef FEAT_EVAL |
8aba638e91eb
patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents:
26362
diff
changeset
|
2512 static callback_T cfu_cb; // 'completefunc' callback function |
8aba638e91eb
patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents:
26362
diff
changeset
|
2513 static callback_T ofu_cb; // 'omnifunc' callback function |
8aba638e91eb
patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents:
26362
diff
changeset
|
2514 static callback_T tsrfu_cb; // 'thesaurusfunc' callback function |
8aba638e91eb
patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents:
26362
diff
changeset
|
2515 # endif |
8aba638e91eb
patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents:
26362
diff
changeset
|
2516 |
8aba638e91eb
patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents:
26362
diff
changeset
|
2517 /* |
8aba638e91eb
patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents:
26362
diff
changeset
|
2518 * Copy a global callback function to a buffer local callback. |
8aba638e91eb
patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents:
26362
diff
changeset
|
2519 */ |
8aba638e91eb
patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents:
26362
diff
changeset
|
2520 static void |
8aba638e91eb
patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents:
26362
diff
changeset
|
2521 copy_global_to_buflocal_cb(callback_T *globcb, callback_T *bufcb) |
8aba638e91eb
patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents:
26362
diff
changeset
|
2522 { |
8aba638e91eb
patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents:
26362
diff
changeset
|
2523 free_callback(bufcb); |
8aba638e91eb
patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents:
26362
diff
changeset
|
2524 if (globcb->cb_name != NULL && *globcb->cb_name != NUL) |
8aba638e91eb
patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents:
26362
diff
changeset
|
2525 copy_callback(bufcb, globcb); |
8aba638e91eb
patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents:
26362
diff
changeset
|
2526 } |
8aba638e91eb
patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents:
26362
diff
changeset
|
2527 |
8aba638e91eb
patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents:
26362
diff
changeset
|
2528 /* |
8aba638e91eb
patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents:
26362
diff
changeset
|
2529 * Parse the 'completefunc' option value and set the callback function. |
8aba638e91eb
patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents:
26362
diff
changeset
|
2530 * Invoked when the 'completefunc' option is set. The option value can be a |
8aba638e91eb
patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents:
26362
diff
changeset
|
2531 * name of a function (string), or function(<name>) or funcref(<name>) or a |
8aba638e91eb
patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents:
26362
diff
changeset
|
2532 * lambda expression. |
8aba638e91eb
patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents:
26362
diff
changeset
|
2533 */ |
8aba638e91eb
patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents:
26362
diff
changeset
|
2534 int |
8aba638e91eb
patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents:
26362
diff
changeset
|
2535 set_completefunc_option(void) |
8aba638e91eb
patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents:
26362
diff
changeset
|
2536 { |
8aba638e91eb
patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents:
26362
diff
changeset
|
2537 int retval; |
8aba638e91eb
patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents:
26362
diff
changeset
|
2538 |
8aba638e91eb
patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents:
26362
diff
changeset
|
2539 retval = option_set_callback_func(curbuf->b_p_cfu, &cfu_cb); |
8aba638e91eb
patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents:
26362
diff
changeset
|
2540 if (retval == OK) |
8aba638e91eb
patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents:
26362
diff
changeset
|
2541 set_buflocal_cfu_callback(curbuf); |
8aba638e91eb
patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents:
26362
diff
changeset
|
2542 |
8aba638e91eb
patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents:
26362
diff
changeset
|
2543 return retval; |
8aba638e91eb
patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents:
26362
diff
changeset
|
2544 } |
8aba638e91eb
patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents:
26362
diff
changeset
|
2545 |
8aba638e91eb
patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents:
26362
diff
changeset
|
2546 /* |
8aba638e91eb
patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents:
26362
diff
changeset
|
2547 * Copy the global 'completefunc' callback function to the buffer-local |
26944
8dbdd68627bd
patch 8.2.4001: insert complete code uses global variables
Bram Moolenaar <Bram@vim.org>
parents:
26921
diff
changeset
|
2548 * 'completefunc' callback for "buf". |
26388
8aba638e91eb
patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents:
26362
diff
changeset
|
2549 */ |
8aba638e91eb
patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents:
26362
diff
changeset
|
2550 void |
8aba638e91eb
patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents:
26362
diff
changeset
|
2551 set_buflocal_cfu_callback(buf_T *buf UNUSED) |
8aba638e91eb
patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents:
26362
diff
changeset
|
2552 { |
8aba638e91eb
patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents:
26362
diff
changeset
|
2553 # ifdef FEAT_EVAL |
8aba638e91eb
patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents:
26362
diff
changeset
|
2554 copy_global_to_buflocal_cb(&cfu_cb, &buf->b_cfu_cb); |
8aba638e91eb
patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents:
26362
diff
changeset
|
2555 # endif |
8aba638e91eb
patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents:
26362
diff
changeset
|
2556 } |
8aba638e91eb
patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents:
26362
diff
changeset
|
2557 |
8aba638e91eb
patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents:
26362
diff
changeset
|
2558 /* |
8aba638e91eb
patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents:
26362
diff
changeset
|
2559 * Parse the 'omnifunc' option value and set the callback function. |
8aba638e91eb
patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents:
26362
diff
changeset
|
2560 * Invoked when the 'omnifunc' option is set. The option value can be a |
8aba638e91eb
patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents:
26362
diff
changeset
|
2561 * name of a function (string), or function(<name>) or funcref(<name>) or a |
8aba638e91eb
patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents:
26362
diff
changeset
|
2562 * lambda expression. |
8aba638e91eb
patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents:
26362
diff
changeset
|
2563 */ |
8aba638e91eb
patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents:
26362
diff
changeset
|
2564 int |
8aba638e91eb
patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents:
26362
diff
changeset
|
2565 set_omnifunc_option(void) |
8aba638e91eb
patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents:
26362
diff
changeset
|
2566 { |
8aba638e91eb
patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents:
26362
diff
changeset
|
2567 int retval; |
8aba638e91eb
patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents:
26362
diff
changeset
|
2568 |
8aba638e91eb
patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents:
26362
diff
changeset
|
2569 retval = option_set_callback_func(curbuf->b_p_ofu, &ofu_cb); |
8aba638e91eb
patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents:
26362
diff
changeset
|
2570 if (retval == OK) |
8aba638e91eb
patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents:
26362
diff
changeset
|
2571 set_buflocal_ofu_callback(curbuf); |
8aba638e91eb
patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents:
26362
diff
changeset
|
2572 |
8aba638e91eb
patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents:
26362
diff
changeset
|
2573 return retval; |
8aba638e91eb
patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents:
26362
diff
changeset
|
2574 } |
8aba638e91eb
patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents:
26362
diff
changeset
|
2575 |
8aba638e91eb
patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents:
26362
diff
changeset
|
2576 /* |
8aba638e91eb
patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents:
26362
diff
changeset
|
2577 * Copy the global 'omnifunc' callback function to the buffer-local 'omnifunc' |
26944
8dbdd68627bd
patch 8.2.4001: insert complete code uses global variables
Bram Moolenaar <Bram@vim.org>
parents:
26921
diff
changeset
|
2578 * callback for "buf". |
26388
8aba638e91eb
patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents:
26362
diff
changeset
|
2579 */ |
8aba638e91eb
patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents:
26362
diff
changeset
|
2580 void |
8aba638e91eb
patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents:
26362
diff
changeset
|
2581 set_buflocal_ofu_callback(buf_T *buf UNUSED) |
8aba638e91eb
patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents:
26362
diff
changeset
|
2582 { |
8aba638e91eb
patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents:
26362
diff
changeset
|
2583 # ifdef FEAT_EVAL |
8aba638e91eb
patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents:
26362
diff
changeset
|
2584 copy_global_to_buflocal_cb(&ofu_cb, &buf->b_ofu_cb); |
8aba638e91eb
patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents:
26362
diff
changeset
|
2585 # endif |
8aba638e91eb
patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents:
26362
diff
changeset
|
2586 } |
8aba638e91eb
patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents:
26362
diff
changeset
|
2587 |
8aba638e91eb
patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents:
26362
diff
changeset
|
2588 /* |
8aba638e91eb
patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents:
26362
diff
changeset
|
2589 * Parse the 'thesaurusfunc' option value and set the callback function. |
8aba638e91eb
patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents:
26362
diff
changeset
|
2590 * Invoked when the 'thesaurusfunc' option is set. The option value can be a |
8aba638e91eb
patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents:
26362
diff
changeset
|
2591 * name of a function (string), or function(<name>) or funcref(<name>) or a |
8aba638e91eb
patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents:
26362
diff
changeset
|
2592 * lambda expression. |
8aba638e91eb
patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents:
26362
diff
changeset
|
2593 */ |
8aba638e91eb
patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents:
26362
diff
changeset
|
2594 int |
8aba638e91eb
patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents:
26362
diff
changeset
|
2595 set_thesaurusfunc_option(void) |
8aba638e91eb
patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents:
26362
diff
changeset
|
2596 { |
8aba638e91eb
patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents:
26362
diff
changeset
|
2597 int retval; |
8aba638e91eb
patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents:
26362
diff
changeset
|
2598 |
8aba638e91eb
patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents:
26362
diff
changeset
|
2599 if (*curbuf->b_p_tsrfu != NUL) |
8aba638e91eb
patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents:
26362
diff
changeset
|
2600 { |
8aba638e91eb
patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents:
26362
diff
changeset
|
2601 // buffer-local option set |
8aba638e91eb
patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents:
26362
diff
changeset
|
2602 retval = option_set_callback_func(curbuf->b_p_tsrfu, |
8aba638e91eb
patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents:
26362
diff
changeset
|
2603 &curbuf->b_tsrfu_cb); |
8aba638e91eb
patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents:
26362
diff
changeset
|
2604 } |
8aba638e91eb
patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents:
26362
diff
changeset
|
2605 else |
8aba638e91eb
patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents:
26362
diff
changeset
|
2606 { |
8aba638e91eb
patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents:
26362
diff
changeset
|
2607 // global option set |
8aba638e91eb
patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents:
26362
diff
changeset
|
2608 retval = option_set_callback_func(p_tsrfu, &tsrfu_cb); |
8aba638e91eb
patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents:
26362
diff
changeset
|
2609 } |
8aba638e91eb
patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents:
26362
diff
changeset
|
2610 |
8aba638e91eb
patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents:
26362
diff
changeset
|
2611 return retval; |
8aba638e91eb
patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents:
26362
diff
changeset
|
2612 } |
8aba638e91eb
patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents:
26362
diff
changeset
|
2613 |
26518
13ba00ef7687
patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents:
26452
diff
changeset
|
2614 /* |
13ba00ef7687
patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents:
26452
diff
changeset
|
2615 * Mark the global 'completefunc' 'omnifunc' and 'thesaurusfunc' callbacks with |
26944
8dbdd68627bd
patch 8.2.4001: insert complete code uses global variables
Bram Moolenaar <Bram@vim.org>
parents:
26921
diff
changeset
|
2616 * "copyID" so that they are not garbage collected. |
26518
13ba00ef7687
patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents:
26452
diff
changeset
|
2617 */ |
13ba00ef7687
patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents:
26452
diff
changeset
|
2618 int |
13ba00ef7687
patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents:
26452
diff
changeset
|
2619 set_ref_in_insexpand_funcs(int copyID) |
13ba00ef7687
patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents:
26452
diff
changeset
|
2620 { |
13ba00ef7687
patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents:
26452
diff
changeset
|
2621 int abort = FALSE; |
13ba00ef7687
patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents:
26452
diff
changeset
|
2622 |
13ba00ef7687
patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents:
26452
diff
changeset
|
2623 abort = set_ref_in_callback(&cfu_cb, copyID); |
13ba00ef7687
patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents:
26452
diff
changeset
|
2624 abort = abort || set_ref_in_callback(&ofu_cb, copyID); |
13ba00ef7687
patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents:
26452
diff
changeset
|
2625 abort = abort || set_ref_in_callback(&tsrfu_cb, copyID); |
13ba00ef7687
patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents:
26452
diff
changeset
|
2626 |
13ba00ef7687
patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents:
26452
diff
changeset
|
2627 return abort; |
13ba00ef7687
patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents:
26452
diff
changeset
|
2628 } |
26388
8aba638e91eb
patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents:
26362
diff
changeset
|
2629 |
16142
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2630 /* |
26944
8dbdd68627bd
patch 8.2.4001: insert complete code uses global variables
Bram Moolenaar <Bram@vim.org>
parents:
26921
diff
changeset
|
2631 * Get the user-defined completion function name for completion "type" |
25974
416237f1de22
patch 8.2.3520: cannot define a function for thesaurus completion
Bram Moolenaar <Bram@vim.org>
parents:
25862
diff
changeset
|
2632 */ |
416237f1de22
patch 8.2.3520: cannot define a function for thesaurus completion
Bram Moolenaar <Bram@vim.org>
parents:
25862
diff
changeset
|
2633 static char_u * |
416237f1de22
patch 8.2.3520: cannot define a function for thesaurus completion
Bram Moolenaar <Bram@vim.org>
parents:
25862
diff
changeset
|
2634 get_complete_funcname(int type) |
416237f1de22
patch 8.2.3520: cannot define a function for thesaurus completion
Bram Moolenaar <Bram@vim.org>
parents:
25862
diff
changeset
|
2635 { |
416237f1de22
patch 8.2.3520: cannot define a function for thesaurus completion
Bram Moolenaar <Bram@vim.org>
parents:
25862
diff
changeset
|
2636 switch (type) |
416237f1de22
patch 8.2.3520: cannot define a function for thesaurus completion
Bram Moolenaar <Bram@vim.org>
parents:
25862
diff
changeset
|
2637 { |
416237f1de22
patch 8.2.3520: cannot define a function for thesaurus completion
Bram Moolenaar <Bram@vim.org>
parents:
25862
diff
changeset
|
2638 case CTRL_X_FUNCTION: |
416237f1de22
patch 8.2.3520: cannot define a function for thesaurus completion
Bram Moolenaar <Bram@vim.org>
parents:
25862
diff
changeset
|
2639 return curbuf->b_p_cfu; |
416237f1de22
patch 8.2.3520: cannot define a function for thesaurus completion
Bram Moolenaar <Bram@vim.org>
parents:
25862
diff
changeset
|
2640 case CTRL_X_OMNI: |
416237f1de22
patch 8.2.3520: cannot define a function for thesaurus completion
Bram Moolenaar <Bram@vim.org>
parents:
25862
diff
changeset
|
2641 return curbuf->b_p_ofu; |
416237f1de22
patch 8.2.3520: cannot define a function for thesaurus completion
Bram Moolenaar <Bram@vim.org>
parents:
25862
diff
changeset
|
2642 case CTRL_X_THESAURUS: |
25990
ac330e2fecc4
patch 8.2.3528: 'thesaurus' and 'thesaurusfunc' do not have the same scope
Bram Moolenaar <Bram@vim.org>
parents:
25984
diff
changeset
|
2643 return *curbuf->b_p_tsrfu == NUL ? p_tsrfu : curbuf->b_p_tsrfu; |
25974
416237f1de22
patch 8.2.3520: cannot define a function for thesaurus completion
Bram Moolenaar <Bram@vim.org>
parents:
25862
diff
changeset
|
2644 default: |
416237f1de22
patch 8.2.3520: cannot define a function for thesaurus completion
Bram Moolenaar <Bram@vim.org>
parents:
25862
diff
changeset
|
2645 return (char_u *)""; |
416237f1de22
patch 8.2.3520: cannot define a function for thesaurus completion
Bram Moolenaar <Bram@vim.org>
parents:
25862
diff
changeset
|
2646 } |
416237f1de22
patch 8.2.3520: cannot define a function for thesaurus completion
Bram Moolenaar <Bram@vim.org>
parents:
25862
diff
changeset
|
2647 } |
416237f1de22
patch 8.2.3520: cannot define a function for thesaurus completion
Bram Moolenaar <Bram@vim.org>
parents:
25862
diff
changeset
|
2648 |
416237f1de22
patch 8.2.3520: cannot define a function for thesaurus completion
Bram Moolenaar <Bram@vim.org>
parents:
25862
diff
changeset
|
2649 /* |
26388
8aba638e91eb
patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents:
26362
diff
changeset
|
2650 * Get the callback to use for insert mode completion. |
8aba638e91eb
patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents:
26362
diff
changeset
|
2651 */ |
26944
8dbdd68627bd
patch 8.2.4001: insert complete code uses global variables
Bram Moolenaar <Bram@vim.org>
parents:
26921
diff
changeset
|
2652 static callback_T * |
26388
8aba638e91eb
patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents:
26362
diff
changeset
|
2653 get_insert_callback(int type) |
8aba638e91eb
patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents:
26362
diff
changeset
|
2654 { |
8aba638e91eb
patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents:
26362
diff
changeset
|
2655 if (type == CTRL_X_FUNCTION) |
8aba638e91eb
patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents:
26362
diff
changeset
|
2656 return &curbuf->b_cfu_cb; |
8aba638e91eb
patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents:
26362
diff
changeset
|
2657 if (type == CTRL_X_OMNI) |
8aba638e91eb
patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents:
26362
diff
changeset
|
2658 return &curbuf->b_ofu_cb; |
8aba638e91eb
patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents:
26362
diff
changeset
|
2659 // CTRL_X_THESAURUS |
8aba638e91eb
patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents:
26362
diff
changeset
|
2660 return (*curbuf->b_p_tsrfu != NUL) ? &curbuf->b_tsrfu_cb : &tsrfu_cb; |
8aba638e91eb
patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents:
26362
diff
changeset
|
2661 } |
8aba638e91eb
patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents:
26362
diff
changeset
|
2662 |
8aba638e91eb
patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents:
26362
diff
changeset
|
2663 /* |
26362
dbe615b75f15
patch 8.2.3712: cannot use Vim9 lambda for 'tagfunc'
Bram Moolenaar <Bram@vim.org>
parents:
26155
diff
changeset
|
2664 * Execute user defined complete function 'completefunc', 'omnifunc' or |
dbe615b75f15
patch 8.2.3712: cannot use Vim9 lambda for 'tagfunc'
Bram Moolenaar <Bram@vim.org>
parents:
26155
diff
changeset
|
2665 * 'thesaurusfunc', and get matches in "matches". |
dbe615b75f15
patch 8.2.3712: cannot use Vim9 lambda for 'tagfunc'
Bram Moolenaar <Bram@vim.org>
parents:
26155
diff
changeset
|
2666 * "type" is either CTRL_X_OMNI or CTRL_X_FUNCTION or CTRL_X_THESAURUS. |
16142
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2667 */ |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2668 static void |
26362
dbe615b75f15
patch 8.2.3712: cannot use Vim9 lambda for 'tagfunc'
Bram Moolenaar <Bram@vim.org>
parents:
26155
diff
changeset
|
2669 expand_by_function(int type, char_u *base) |
16142
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2670 { |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2671 list_T *matchlist = NULL; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2672 dict_T *matchdict = NULL; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2673 typval_T args[3]; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2674 char_u *funcname; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2675 pos_T pos; |
26388
8aba638e91eb
patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents:
26362
diff
changeset
|
2676 callback_T *cb; |
16142
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2677 typval_T rettv; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2678 int save_State = State; |
26388
8aba638e91eb
patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents:
26362
diff
changeset
|
2679 int retval; |
16142
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2680 |
25974
416237f1de22
patch 8.2.3520: cannot define a function for thesaurus completion
Bram Moolenaar <Bram@vim.org>
parents:
25862
diff
changeset
|
2681 funcname = get_complete_funcname(type); |
16142
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2682 if (*funcname == NUL) |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2683 return; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2684 |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2685 // Call 'completefunc' to obtain the list of matches. |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2686 args[0].v_type = VAR_NUMBER; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2687 args[0].vval.v_number = 0; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2688 args[1].v_type = VAR_STRING; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2689 args[1].vval.v_string = base != NULL ? base : (char_u *)""; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2690 args[2].v_type = VAR_UNKNOWN; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2691 |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2692 pos = curwin->w_cursor; |
23770
385d33dfb7df
patch 8.2.2426: allowing 'completefunc' to switch windows causes trouble
Bram Moolenaar <Bram@vim.org>
parents:
23374
diff
changeset
|
2693 // Lock the text to avoid weird things from happening. Also disallow |
385d33dfb7df
patch 8.2.2426: allowing 'completefunc' to switch windows causes trouble
Bram Moolenaar <Bram@vim.org>
parents:
23374
diff
changeset
|
2694 // switching to another window, it should not be needed and may end up in |
385d33dfb7df
patch 8.2.2426: allowing 'completefunc' to switch windows causes trouble
Bram Moolenaar <Bram@vim.org>
parents:
23374
diff
changeset
|
2695 // Insert mode in another buffer. |
29014
45c182c4f7e9
patch 8.2.5029: "textlock" is always zero
Bram Moolenaar <Bram@vim.org>
parents:
29000
diff
changeset
|
2696 ++textlock; |
16142
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2697 |
26388
8aba638e91eb
patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents:
26362
diff
changeset
|
2698 cb = get_insert_callback(type); |
8aba638e91eb
patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents:
26362
diff
changeset
|
2699 retval = call_callback(cb, 0, &rettv, 2, args); |
8aba638e91eb
patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents:
26362
diff
changeset
|
2700 |
16142
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2701 // Call a function, which returns a list or dict. |
26388
8aba638e91eb
patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents:
26362
diff
changeset
|
2702 if (retval == OK) |
16142
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2703 { |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2704 switch (rettv.v_type) |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2705 { |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2706 case VAR_LIST: |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2707 matchlist = rettv.vval.v_list; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2708 break; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2709 case VAR_DICT: |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2710 matchdict = rettv.vval.v_dict; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2711 break; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2712 case VAR_SPECIAL: |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2713 if (rettv.vval.v_number == VVAL_NONE) |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2714 compl_opt_suppress_empty = TRUE; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2715 // FALLTHROUGH |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2716 default: |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2717 // TODO: Give error message? |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2718 clear_tv(&rettv); |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2719 break; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2720 } |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2721 } |
29014
45c182c4f7e9
patch 8.2.5029: "textlock" is always zero
Bram Moolenaar <Bram@vim.org>
parents:
29000
diff
changeset
|
2722 --textlock; |
16142
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2723 |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2724 curwin->w_cursor = pos; // restore the cursor position |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2725 validate_cursor(); |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2726 if (!EQUAL_POS(curwin->w_cursor, pos)) |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2727 { |
26962
85866e069c24
patch 8.2.4010: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26958
diff
changeset
|
2728 emsg(_(e_complete_function_deleted_text)); |
16142
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2729 goto theend; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2730 } |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2731 |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2732 if (matchlist != NULL) |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2733 ins_compl_add_list(matchlist); |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2734 else if (matchdict != NULL) |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2735 ins_compl_add_dict(matchdict); |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2736 |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2737 theend: |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2738 // Restore State, it might have been changed. |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2739 State = save_State; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2740 |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2741 if (matchdict != NULL) |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2742 dict_unref(matchdict); |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2743 if (matchlist != NULL) |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2744 list_unref(matchlist); |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2745 } |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2746 #endif // FEAT_COMPL_FUNC |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2747 |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2748 #if defined(FEAT_COMPL_FUNC) || defined(FEAT_EVAL) || defined(PROTO) |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2749 /* |
17704 | 2750 * Add a match to the list of matches from a typeval_T. |
2751 * If the given string is already in the list of completions, then return | |
2752 * NOTDONE, otherwise add it to the list and return OK. If there is an error, | |
2753 * maybe because alloc() returns NULL, then FAIL is returned. | |
24327
44e42eac77cb
patch 8.2.2704: adding a lot of completions can be a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
23772
diff
changeset
|
2754 * When "fast" is TRUE use fast_breakcheck() instead of ui_breakcheck(). |
17704 | 2755 */ |
2756 static int | |
24327
44e42eac77cb
patch 8.2.2704: adding a lot of completions can be a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
23772
diff
changeset
|
2757 ins_compl_add_tv(typval_T *tv, int dir, int fast) |
17704 | 2758 { |
2759 char_u *word; | |
2760 int dup = FALSE; | |
2761 int empty = FALSE; | |
24327
44e42eac77cb
patch 8.2.2704: adding a lot of completions can be a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
23772
diff
changeset
|
2762 int flags = fast ? CP_FAST : 0; |
17704 | 2763 char_u *(cptext[CPT_COUNT]); |
19047
a3fce2763e83
patch 8.2.0084: complete item "user_data" can only be a string
Bram Moolenaar <Bram@vim.org>
parents:
18933
diff
changeset
|
2764 typval_T user_data; |
27016
1d9a7aa42744
patch 8.2.4037: Insert mode completion is insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
26962
diff
changeset
|
2765 int status; |
19047
a3fce2763e83
patch 8.2.0084: complete item "user_data" can only be a string
Bram Moolenaar <Bram@vim.org>
parents:
18933
diff
changeset
|
2766 |
a3fce2763e83
patch 8.2.0084: complete item "user_data" can only be a string
Bram Moolenaar <Bram@vim.org>
parents:
18933
diff
changeset
|
2767 user_data.v_type = VAR_UNKNOWN; |
17704 | 2768 if (tv->v_type == VAR_DICT && tv->vval.v_dict != NULL) |
2769 { | |
29442
827d9f2b7a71
patch 9.0.0063: too many type casts for dict_get functions
Bram Moolenaar <Bram@vim.org>
parents:
29436
diff
changeset
|
2770 word = dict_get_string(tv->vval.v_dict, "word", FALSE); |
827d9f2b7a71
patch 9.0.0063: too many type casts for dict_get functions
Bram Moolenaar <Bram@vim.org>
parents:
29436
diff
changeset
|
2771 cptext[CPT_ABBR] = dict_get_string(tv->vval.v_dict, "abbr", FALSE); |
827d9f2b7a71
patch 9.0.0063: too many type casts for dict_get functions
Bram Moolenaar <Bram@vim.org>
parents:
29436
diff
changeset
|
2772 cptext[CPT_MENU] = dict_get_string(tv->vval.v_dict, "menu", FALSE); |
827d9f2b7a71
patch 9.0.0063: too many type casts for dict_get functions
Bram Moolenaar <Bram@vim.org>
parents:
29436
diff
changeset
|
2773 cptext[CPT_KIND] = dict_get_string(tv->vval.v_dict, "kind", FALSE); |
827d9f2b7a71
patch 9.0.0063: too many type casts for dict_get functions
Bram Moolenaar <Bram@vim.org>
parents:
29436
diff
changeset
|
2774 cptext[CPT_INFO] = dict_get_string(tv->vval.v_dict, "info", FALSE); |
827d9f2b7a71
patch 9.0.0063: too many type casts for dict_get functions
Bram Moolenaar <Bram@vim.org>
parents:
29436
diff
changeset
|
2775 dict_get_tv(tv->vval.v_dict, "user_data", &user_data); |
827d9f2b7a71
patch 9.0.0063: too many type casts for dict_get functions
Bram Moolenaar <Bram@vim.org>
parents:
29436
diff
changeset
|
2776 if (dict_get_string(tv->vval.v_dict, "icase", FALSE) != NULL |
827d9f2b7a71
patch 9.0.0063: too many type casts for dict_get functions
Bram Moolenaar <Bram@vim.org>
parents:
29436
diff
changeset
|
2777 && dict_get_number(tv->vval.v_dict, "icase")) |
17704 | 2778 flags |= CP_ICASE; |
29442
827d9f2b7a71
patch 9.0.0063: too many type casts for dict_get functions
Bram Moolenaar <Bram@vim.org>
parents:
29436
diff
changeset
|
2779 if (dict_get_string(tv->vval.v_dict, "dup", FALSE) != NULL) |
827d9f2b7a71
patch 9.0.0063: too many type casts for dict_get functions
Bram Moolenaar <Bram@vim.org>
parents:
29436
diff
changeset
|
2780 dup = dict_get_number(tv->vval.v_dict, "dup"); |
827d9f2b7a71
patch 9.0.0063: too many type casts for dict_get functions
Bram Moolenaar <Bram@vim.org>
parents:
29436
diff
changeset
|
2781 if (dict_get_string(tv->vval.v_dict, "empty", FALSE) != NULL) |
827d9f2b7a71
patch 9.0.0063: too many type casts for dict_get functions
Bram Moolenaar <Bram@vim.org>
parents:
29436
diff
changeset
|
2782 empty = dict_get_number(tv->vval.v_dict, "empty"); |
827d9f2b7a71
patch 9.0.0063: too many type casts for dict_get functions
Bram Moolenaar <Bram@vim.org>
parents:
29436
diff
changeset
|
2783 if (dict_get_string(tv->vval.v_dict, "equal", FALSE) != NULL |
827d9f2b7a71
patch 9.0.0063: too many type casts for dict_get functions
Bram Moolenaar <Bram@vim.org>
parents:
29436
diff
changeset
|
2784 && dict_get_number(tv->vval.v_dict, "equal")) |
17704 | 2785 flags |= CP_EQUAL; |
2786 } | |
2787 else | |
2788 { | |
2789 word = tv_get_string_chk(tv); | |
20007
aadd1cae2ff5
patch 8.2.0559: clearing a struct is verbose
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
2790 CLEAR_FIELD(cptext); |
17704 | 2791 } |
2792 if (word == NULL || (!empty && *word == NUL)) | |
27016
1d9a7aa42744
patch 8.2.4037: Insert mode completion is insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
26962
diff
changeset
|
2793 { |
1d9a7aa42744
patch 8.2.4037: Insert mode completion is insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
26962
diff
changeset
|
2794 clear_tv(&user_data); |
17704 | 2795 return FAIL; |
27016
1d9a7aa42744
patch 8.2.4037: Insert mode completion is insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
26962
diff
changeset
|
2796 } |
1d9a7aa42744
patch 8.2.4037: Insert mode completion is insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
26962
diff
changeset
|
2797 status = ins_compl_add(word, -1, NULL, cptext, &user_data, dir, flags, dup); |
1d9a7aa42744
patch 8.2.4037: Insert mode completion is insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
26962
diff
changeset
|
2798 if (status != OK) |
1d9a7aa42744
patch 8.2.4037: Insert mode completion is insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
26962
diff
changeset
|
2799 clear_tv(&user_data); |
1d9a7aa42744
patch 8.2.4037: Insert mode completion is insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
26962
diff
changeset
|
2800 return status; |
17704 | 2801 } |
2802 | |
2803 /* | |
16142
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2804 * Add completions from a list. |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2805 */ |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2806 static void |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2807 ins_compl_add_list(list_T *list) |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2808 { |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2809 listitem_T *li; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2810 int dir = compl_direction; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2811 |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2812 // Go through the List with matches and add each of them. |
20392
4c317d8c1051
patch 8.2.0751: Vim9: performance can be improved
Bram Moolenaar <Bram@vim.org>
parents:
20229
diff
changeset
|
2813 CHECK_LIST_MATERIALIZE(list); |
19888
435726a03481
patch 8.2.0500: using the same loop in many places
Bram Moolenaar <Bram@vim.org>
parents:
19201
diff
changeset
|
2814 FOR_ALL_LIST_ITEMS(list, li) |
16142
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2815 { |
24327
44e42eac77cb
patch 8.2.2704: adding a lot of completions can be a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
23772
diff
changeset
|
2816 if (ins_compl_add_tv(&li->li_tv, dir, TRUE) == OK) |
16142
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2817 // if dir was BACKWARD then honor it just once |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2818 dir = FORWARD; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2819 else if (did_emsg) |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2820 break; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2821 } |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2822 } |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2823 |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2824 /* |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2825 * Add completions from a dict. |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2826 */ |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2827 static void |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2828 ins_compl_add_dict(dict_T *dict) |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2829 { |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2830 dictitem_T *di_refresh; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2831 dictitem_T *di_words; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2832 |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2833 // Check for optional "refresh" item. |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2834 compl_opt_refresh_always = FALSE; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2835 di_refresh = dict_find(dict, (char_u *)"refresh", 7); |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2836 if (di_refresh != NULL && di_refresh->di_tv.v_type == VAR_STRING) |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2837 { |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2838 char_u *v = di_refresh->di_tv.vval.v_string; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2839 |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2840 if (v != NULL && STRCMP(v, (char_u *)"always") == 0) |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2841 compl_opt_refresh_always = TRUE; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2842 } |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2843 |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2844 // Add completions from a "words" list. |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2845 di_words = dict_find(dict, (char_u *)"words", 5); |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2846 if (di_words != NULL && di_words->di_tv.v_type == VAR_LIST) |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2847 ins_compl_add_list(di_words->di_tv.vval.v_list); |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2848 } |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2849 |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2850 /* |
17813
8ca20b0a3dc3
patch 8.1.1903: cannot build without the +eval feature
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
2851 * Start completion for the complete() function. |
8ca20b0a3dc3
patch 8.1.1903: cannot build without the +eval feature
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
2852 * "startcol" is where the matched text starts (1 is first column). |
8ca20b0a3dc3
patch 8.1.1903: cannot build without the +eval feature
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
2853 * "list" is the list of matches. |
8ca20b0a3dc3
patch 8.1.1903: cannot build without the +eval feature
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
2854 */ |
8ca20b0a3dc3
patch 8.1.1903: cannot build without the +eval feature
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
2855 static void |
8ca20b0a3dc3
patch 8.1.1903: cannot build without the +eval feature
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
2856 set_completion(colnr_T startcol, list_T *list) |
8ca20b0a3dc3
patch 8.1.1903: cannot build without the +eval feature
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
2857 { |
8ca20b0a3dc3
patch 8.1.1903: cannot build without the +eval feature
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
2858 int save_w_wrow = curwin->w_wrow; |
8ca20b0a3dc3
patch 8.1.1903: cannot build without the +eval feature
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
2859 int save_w_leftcol = curwin->w_leftcol; |
8ca20b0a3dc3
patch 8.1.1903: cannot build without the +eval feature
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
2860 int flags = CP_ORIGINAL_TEXT; |
8ca20b0a3dc3
patch 8.1.1903: cannot build without the +eval feature
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
2861 |
8ca20b0a3dc3
patch 8.1.1903: cannot build without the +eval feature
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
2862 // If already doing completions stop it. |
26944
8dbdd68627bd
patch 8.2.4001: insert complete code uses global variables
Bram Moolenaar <Bram@vim.org>
parents:
26921
diff
changeset
|
2863 if (ctrl_x_mode_not_default()) |
17813
8ca20b0a3dc3
patch 8.1.1903: cannot build without the +eval feature
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
2864 ins_compl_prep(' '); |
8ca20b0a3dc3
patch 8.1.1903: cannot build without the +eval feature
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
2865 ins_compl_clear(); |
8ca20b0a3dc3
patch 8.1.1903: cannot build without the +eval feature
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
2866 ins_compl_free(); |
8ca20b0a3dc3
patch 8.1.1903: cannot build without the +eval feature
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
2867 |
8ca20b0a3dc3
patch 8.1.1903: cannot build without the +eval feature
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
2868 compl_direction = FORWARD; |
8ca20b0a3dc3
patch 8.1.1903: cannot build without the +eval feature
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
2869 if (startcol > curwin->w_cursor.col) |
8ca20b0a3dc3
patch 8.1.1903: cannot build without the +eval feature
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
2870 startcol = curwin->w_cursor.col; |
8ca20b0a3dc3
patch 8.1.1903: cannot build without the +eval feature
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
2871 compl_col = startcol; |
8ca20b0a3dc3
patch 8.1.1903: cannot build without the +eval feature
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
2872 compl_length = (int)curwin->w_cursor.col - (int)startcol; |
8ca20b0a3dc3
patch 8.1.1903: cannot build without the +eval feature
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
2873 // compl_pattern doesn't need to be set |
8ca20b0a3dc3
patch 8.1.1903: cannot build without the +eval feature
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
2874 compl_orig_text = vim_strnsave(ml_get_curline() + compl_col, compl_length); |
8ca20b0a3dc3
patch 8.1.1903: cannot build without the +eval feature
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
2875 if (p_ic) |
8ca20b0a3dc3
patch 8.1.1903: cannot build without the +eval feature
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
2876 flags |= CP_ICASE; |
8ca20b0a3dc3
patch 8.1.1903: cannot build without the +eval feature
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
2877 if (compl_orig_text == NULL || ins_compl_add(compl_orig_text, |
24327
44e42eac77cb
patch 8.2.2704: adding a lot of completions can be a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
23772
diff
changeset
|
2878 -1, NULL, NULL, NULL, 0, |
44e42eac77cb
patch 8.2.2704: adding a lot of completions can be a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
23772
diff
changeset
|
2879 flags | CP_FAST, FALSE) != OK) |
17813
8ca20b0a3dc3
patch 8.1.1903: cannot build without the +eval feature
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
2880 return; |
8ca20b0a3dc3
patch 8.1.1903: cannot build without the +eval feature
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
2881 |
8ca20b0a3dc3
patch 8.1.1903: cannot build without the +eval feature
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
2882 ctrl_x_mode = CTRL_X_EVAL; |
8ca20b0a3dc3
patch 8.1.1903: cannot build without the +eval feature
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
2883 |
8ca20b0a3dc3
patch 8.1.1903: cannot build without the +eval feature
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
2884 ins_compl_add_list(list); |
8ca20b0a3dc3
patch 8.1.1903: cannot build without the +eval feature
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
2885 compl_matches = ins_compl_make_cyclic(); |
8ca20b0a3dc3
patch 8.1.1903: cannot build without the +eval feature
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
2886 compl_started = TRUE; |
8ca20b0a3dc3
patch 8.1.1903: cannot build without the +eval feature
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
2887 compl_used_match = TRUE; |
8ca20b0a3dc3
patch 8.1.1903: cannot build without the +eval feature
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
2888 compl_cont_status = 0; |
8ca20b0a3dc3
patch 8.1.1903: cannot build without the +eval feature
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
2889 |
8ca20b0a3dc3
patch 8.1.1903: cannot build without the +eval feature
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
2890 compl_curr_match = compl_first_match; |
8ca20b0a3dc3
patch 8.1.1903: cannot build without the +eval feature
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
2891 if (compl_no_insert || compl_no_select) |
8ca20b0a3dc3
patch 8.1.1903: cannot build without the +eval feature
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
2892 { |
8ca20b0a3dc3
patch 8.1.1903: cannot build without the +eval feature
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
2893 ins_complete(K_DOWN, FALSE); |
8ca20b0a3dc3
patch 8.1.1903: cannot build without the +eval feature
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
2894 if (compl_no_select) |
8ca20b0a3dc3
patch 8.1.1903: cannot build without the +eval feature
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
2895 // Down/Up has no real effect. |
8ca20b0a3dc3
patch 8.1.1903: cannot build without the +eval feature
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
2896 ins_complete(K_UP, FALSE); |
8ca20b0a3dc3
patch 8.1.1903: cannot build without the +eval feature
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
2897 } |
8ca20b0a3dc3
patch 8.1.1903: cannot build without the +eval feature
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
2898 else |
8ca20b0a3dc3
patch 8.1.1903: cannot build without the +eval feature
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
2899 ins_complete(Ctrl_N, FALSE); |
8ca20b0a3dc3
patch 8.1.1903: cannot build without the +eval feature
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
2900 compl_enter_selects = compl_no_insert; |
8ca20b0a3dc3
patch 8.1.1903: cannot build without the +eval feature
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
2901 |
8ca20b0a3dc3
patch 8.1.1903: cannot build without the +eval feature
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
2902 // Lazily show the popup menu, unless we got interrupted. |
8ca20b0a3dc3
patch 8.1.1903: cannot build without the +eval feature
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
2903 if (!compl_interrupted) |
8ca20b0a3dc3
patch 8.1.1903: cannot build without the +eval feature
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
2904 show_pum(save_w_wrow, save_w_leftcol); |
28397
d1702731786c
patch 8.2.4723: the ModeChanged autocmd event is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
27140
diff
changeset
|
2905 may_trigger_modechanged(); |
17813
8ca20b0a3dc3
patch 8.1.1903: cannot build without the +eval feature
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
2906 out_flush(); |
8ca20b0a3dc3
patch 8.1.1903: cannot build without the +eval feature
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
2907 } |
8ca20b0a3dc3
patch 8.1.1903: cannot build without the +eval feature
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
2908 |
8ca20b0a3dc3
patch 8.1.1903: cannot build without the +eval feature
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
2909 /* |
17704 | 2910 * "complete()" function |
16142
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2911 */ |
17704 | 2912 void |
2913 f_complete(typval_T *argvars, typval_T *rettv UNUSED) | |
16142
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2914 { |
17704 | 2915 int startcol; |
2916 | |
25302
4d3c68196d05
patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
24333
diff
changeset
|
2917 if (in_vim9script() |
4d3c68196d05
patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
24333
diff
changeset
|
2918 && (check_for_number_arg(argvars, 0) == FAIL |
4d3c68196d05
patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
24333
diff
changeset
|
2919 || check_for_list_arg(argvars, 1) == FAIL)) |
4d3c68196d05
patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
24333
diff
changeset
|
2920 return; |
4d3c68196d05
patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
24333
diff
changeset
|
2921 |
28773
d770568e6c98
patch 8.2.4911: the mode #defines are not clearly named
Bram Moolenaar <Bram@vim.org>
parents:
28397
diff
changeset
|
2922 if ((State & MODE_INSERT) == 0) |
17704 | 2923 { |
26958
d92e0d85923f
patch 8.2.4008: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26944
diff
changeset
|
2924 emsg(_(e_complete_can_only_be_used_in_insert_mode)); |
17704 | 2925 return; |
2926 } | |
2927 | |
2928 // Check for undo allowed here, because if something was already inserted | |
2929 // the line was already saved for undo and this check isn't done. | |
2930 if (!undo_allowed()) | |
2931 return; | |
2932 | |
2933 if (argvars[1].v_type != VAR_LIST || argvars[1].vval.v_list == NULL) | |
26865
bce848ec8b1b
patch 8.2.3961: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26850
diff
changeset
|
2934 emsg(_(e_invalid_argument)); |
20118
252d2bb90394
patch 8.2.0614: get ml_get error when deleting a line in 'completefunc'
Bram Moolenaar <Bram@vim.org>
parents:
20007
diff
changeset
|
2935 else |
16142
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2936 { |
20118
252d2bb90394
patch 8.2.0614: get ml_get error when deleting a line in 'completefunc'
Bram Moolenaar <Bram@vim.org>
parents:
20007
diff
changeset
|
2937 startcol = (int)tv_get_number_chk(&argvars[0], NULL); |
252d2bb90394
patch 8.2.0614: get ml_get error when deleting a line in 'completefunc'
Bram Moolenaar <Bram@vim.org>
parents:
20007
diff
changeset
|
2938 if (startcol > 0) |
252d2bb90394
patch 8.2.0614: get ml_get error when deleting a line in 'completefunc'
Bram Moolenaar <Bram@vim.org>
parents:
20007
diff
changeset
|
2939 set_completion(startcol - 1, argvars[1].vval.v_list); |
16142
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2940 } |
17704 | 2941 } |
2942 | |
2943 /* | |
2944 * "complete_add()" function | |
2945 */ | |
2946 void | |
2947 f_complete_add(typval_T *argvars, typval_T *rettv) | |
2948 { | |
25384
e8e2c4d33b9b
patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents:
25302
diff
changeset
|
2949 if (in_vim9script() && check_for_string_or_dict_arg(argvars, 0) == FAIL) |
25302
4d3c68196d05
patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
24333
diff
changeset
|
2950 return; |
4d3c68196d05
patch 8.2.3188: Vim9: argument types are not checked at compile time
Bram Moolenaar <Bram@vim.org>
parents:
24333
diff
changeset
|
2951 |
24327
44e42eac77cb
patch 8.2.2704: adding a lot of completions can be a bit slow
Bram Moolenaar <Bram@vim.org>
parents:
23772
diff
changeset
|
2952 rettv->vval.v_number = ins_compl_add_tv(&argvars[0], 0, FALSE); |
17704 | 2953 } |
2954 | |
2955 /* | |
2956 * "complete_check()" function | |
2957 */ | |
2958 void | |
2959 f_complete_check(typval_T *argvars UNUSED, typval_T *rettv) | |
2960 { | |
2961 int saved = RedrawingDisabled; | |
2962 | |
2963 RedrawingDisabled = 0; | |
2964 ins_compl_check_keys(0, TRUE); | |
2965 rettv->vval.v_number = ins_compl_interrupted(); | |
2966 RedrawingDisabled = saved; | |
2967 } | |
2968 | |
2969 /* | |
17813
8ca20b0a3dc3
patch 8.1.1903: cannot build without the +eval feature
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
2970 * Return Insert completion mode name string |
8ca20b0a3dc3
patch 8.1.1903: cannot build without the +eval feature
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
2971 */ |
8ca20b0a3dc3
patch 8.1.1903: cannot build without the +eval feature
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
2972 static char_u * |
8ca20b0a3dc3
patch 8.1.1903: cannot build without the +eval feature
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
2973 ins_compl_mode(void) |
8ca20b0a3dc3
patch 8.1.1903: cannot build without the +eval feature
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
2974 { |
26944
8dbdd68627bd
patch 8.2.4001: insert complete code uses global variables
Bram Moolenaar <Bram@vim.org>
parents:
26921
diff
changeset
|
2975 if (ctrl_x_mode_not_defined_yet() || ctrl_x_mode_scroll() || compl_started) |
17813
8ca20b0a3dc3
patch 8.1.1903: cannot build without the +eval feature
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
2976 return (char_u *)ctrl_x_mode_names[ctrl_x_mode & ~CTRL_X_WANT_IDENT]; |
8ca20b0a3dc3
patch 8.1.1903: cannot build without the +eval feature
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
2977 |
8ca20b0a3dc3
patch 8.1.1903: cannot build without the +eval feature
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
2978 return (char_u *)""; |
8ca20b0a3dc3
patch 8.1.1903: cannot build without the +eval feature
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
2979 } |
8ca20b0a3dc3
patch 8.1.1903: cannot build without the +eval feature
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
2980 |
26921
b975b7c16ba1
patch 8.2.3989: some insert completion code is not tested
Bram Moolenaar <Bram@vim.org>
parents:
26883
diff
changeset
|
2981 /* |
b975b7c16ba1
patch 8.2.3989: some insert completion code is not tested
Bram Moolenaar <Bram@vim.org>
parents:
26883
diff
changeset
|
2982 * Assign the sequence number to all the completion matches which don't have |
b975b7c16ba1
patch 8.2.3989: some insert completion code is not tested
Bram Moolenaar <Bram@vim.org>
parents:
26883
diff
changeset
|
2983 * one assigned yet. |
b975b7c16ba1
patch 8.2.3989: some insert completion code is not tested
Bram Moolenaar <Bram@vim.org>
parents:
26883
diff
changeset
|
2984 */ |
22717
bd61aaf7f2a0
patch 8.2.1907: complete_info().selected may be wrong
Bram Moolenaar <Bram@vim.org>
parents:
22248
diff
changeset
|
2985 static void |
bd61aaf7f2a0
patch 8.2.1907: complete_info().selected may be wrong
Bram Moolenaar <Bram@vim.org>
parents:
22248
diff
changeset
|
2986 ins_compl_update_sequence_numbers() |
bd61aaf7f2a0
patch 8.2.1907: complete_info().selected may be wrong
Bram Moolenaar <Bram@vim.org>
parents:
22248
diff
changeset
|
2987 { |
bd61aaf7f2a0
patch 8.2.1907: complete_info().selected may be wrong
Bram Moolenaar <Bram@vim.org>
parents:
22248
diff
changeset
|
2988 int number = 0; |
bd61aaf7f2a0
patch 8.2.1907: complete_info().selected may be wrong
Bram Moolenaar <Bram@vim.org>
parents:
22248
diff
changeset
|
2989 compl_T *match; |
bd61aaf7f2a0
patch 8.2.1907: complete_info().selected may be wrong
Bram Moolenaar <Bram@vim.org>
parents:
22248
diff
changeset
|
2990 |
26944
8dbdd68627bd
patch 8.2.4001: insert complete code uses global variables
Bram Moolenaar <Bram@vim.org>
parents:
26921
diff
changeset
|
2991 if (compl_dir_forward()) |
22717
bd61aaf7f2a0
patch 8.2.1907: complete_info().selected may be wrong
Bram Moolenaar <Bram@vim.org>
parents:
22248
diff
changeset
|
2992 { |
bd61aaf7f2a0
patch 8.2.1907: complete_info().selected may be wrong
Bram Moolenaar <Bram@vim.org>
parents:
22248
diff
changeset
|
2993 // search backwards for the first valid (!= -1) number. |
bd61aaf7f2a0
patch 8.2.1907: complete_info().selected may be wrong
Bram Moolenaar <Bram@vim.org>
parents:
22248
diff
changeset
|
2994 // This should normally succeed already at the first loop |
bd61aaf7f2a0
patch 8.2.1907: complete_info().selected may be wrong
Bram Moolenaar <Bram@vim.org>
parents:
22248
diff
changeset
|
2995 // cycle, so it's fast! |
bd61aaf7f2a0
patch 8.2.1907: complete_info().selected may be wrong
Bram Moolenaar <Bram@vim.org>
parents:
22248
diff
changeset
|
2996 for (match = compl_curr_match->cp_prev; match != NULL |
26944
8dbdd68627bd
patch 8.2.4001: insert complete code uses global variables
Bram Moolenaar <Bram@vim.org>
parents:
26921
diff
changeset
|
2997 && !is_first_match(match); match = match->cp_prev) |
22717
bd61aaf7f2a0
patch 8.2.1907: complete_info().selected may be wrong
Bram Moolenaar <Bram@vim.org>
parents:
22248
diff
changeset
|
2998 if (match->cp_number != -1) |
bd61aaf7f2a0
patch 8.2.1907: complete_info().selected may be wrong
Bram Moolenaar <Bram@vim.org>
parents:
22248
diff
changeset
|
2999 { |
bd61aaf7f2a0
patch 8.2.1907: complete_info().selected may be wrong
Bram Moolenaar <Bram@vim.org>
parents:
22248
diff
changeset
|
3000 number = match->cp_number; |
bd61aaf7f2a0
patch 8.2.1907: complete_info().selected may be wrong
Bram Moolenaar <Bram@vim.org>
parents:
22248
diff
changeset
|
3001 break; |
bd61aaf7f2a0
patch 8.2.1907: complete_info().selected may be wrong
Bram Moolenaar <Bram@vim.org>
parents:
22248
diff
changeset
|
3002 } |
bd61aaf7f2a0
patch 8.2.1907: complete_info().selected may be wrong
Bram Moolenaar <Bram@vim.org>
parents:
22248
diff
changeset
|
3003 if (match != NULL) |
bd61aaf7f2a0
patch 8.2.1907: complete_info().selected may be wrong
Bram Moolenaar <Bram@vim.org>
parents:
22248
diff
changeset
|
3004 // go up and assign all numbers which are not assigned |
bd61aaf7f2a0
patch 8.2.1907: complete_info().selected may be wrong
Bram Moolenaar <Bram@vim.org>
parents:
22248
diff
changeset
|
3005 // yet |
bd61aaf7f2a0
patch 8.2.1907: complete_info().selected may be wrong
Bram Moolenaar <Bram@vim.org>
parents:
22248
diff
changeset
|
3006 for (match = match->cp_next; |
bd61aaf7f2a0
patch 8.2.1907: complete_info().selected may be wrong
Bram Moolenaar <Bram@vim.org>
parents:
22248
diff
changeset
|
3007 match != NULL && match->cp_number == -1; |
bd61aaf7f2a0
patch 8.2.1907: complete_info().selected may be wrong
Bram Moolenaar <Bram@vim.org>
parents:
22248
diff
changeset
|
3008 match = match->cp_next) |
bd61aaf7f2a0
patch 8.2.1907: complete_info().selected may be wrong
Bram Moolenaar <Bram@vim.org>
parents:
22248
diff
changeset
|
3009 match->cp_number = ++number; |
bd61aaf7f2a0
patch 8.2.1907: complete_info().selected may be wrong
Bram Moolenaar <Bram@vim.org>
parents:
22248
diff
changeset
|
3010 } |
bd61aaf7f2a0
patch 8.2.1907: complete_info().selected may be wrong
Bram Moolenaar <Bram@vim.org>
parents:
22248
diff
changeset
|
3011 else // BACKWARD |
bd61aaf7f2a0
patch 8.2.1907: complete_info().selected may be wrong
Bram Moolenaar <Bram@vim.org>
parents:
22248
diff
changeset
|
3012 { |
bd61aaf7f2a0
patch 8.2.1907: complete_info().selected may be wrong
Bram Moolenaar <Bram@vim.org>
parents:
22248
diff
changeset
|
3013 // search forwards (upwards) for the first valid (!= -1) |
bd61aaf7f2a0
patch 8.2.1907: complete_info().selected may be wrong
Bram Moolenaar <Bram@vim.org>
parents:
22248
diff
changeset
|
3014 // number. This should normally succeed already at the |
bd61aaf7f2a0
patch 8.2.1907: complete_info().selected may be wrong
Bram Moolenaar <Bram@vim.org>
parents:
22248
diff
changeset
|
3015 // first loop cycle, so it's fast! |
bd61aaf7f2a0
patch 8.2.1907: complete_info().selected may be wrong
Bram Moolenaar <Bram@vim.org>
parents:
22248
diff
changeset
|
3016 for (match = compl_curr_match->cp_next; match != NULL |
26944
8dbdd68627bd
patch 8.2.4001: insert complete code uses global variables
Bram Moolenaar <Bram@vim.org>
parents:
26921
diff
changeset
|
3017 && !is_first_match(match); match = match->cp_next) |
22717
bd61aaf7f2a0
patch 8.2.1907: complete_info().selected may be wrong
Bram Moolenaar <Bram@vim.org>
parents:
22248
diff
changeset
|
3018 if (match->cp_number != -1) |
bd61aaf7f2a0
patch 8.2.1907: complete_info().selected may be wrong
Bram Moolenaar <Bram@vim.org>
parents:
22248
diff
changeset
|
3019 { |
bd61aaf7f2a0
patch 8.2.1907: complete_info().selected may be wrong
Bram Moolenaar <Bram@vim.org>
parents:
22248
diff
changeset
|
3020 number = match->cp_number; |
bd61aaf7f2a0
patch 8.2.1907: complete_info().selected may be wrong
Bram Moolenaar <Bram@vim.org>
parents:
22248
diff
changeset
|
3021 break; |
bd61aaf7f2a0
patch 8.2.1907: complete_info().selected may be wrong
Bram Moolenaar <Bram@vim.org>
parents:
22248
diff
changeset
|
3022 } |
bd61aaf7f2a0
patch 8.2.1907: complete_info().selected may be wrong
Bram Moolenaar <Bram@vim.org>
parents:
22248
diff
changeset
|
3023 if (match != NULL) |
bd61aaf7f2a0
patch 8.2.1907: complete_info().selected may be wrong
Bram Moolenaar <Bram@vim.org>
parents:
22248
diff
changeset
|
3024 // go down and assign all numbers which are not |
bd61aaf7f2a0
patch 8.2.1907: complete_info().selected may be wrong
Bram Moolenaar <Bram@vim.org>
parents:
22248
diff
changeset
|
3025 // assigned yet |
bd61aaf7f2a0
patch 8.2.1907: complete_info().selected may be wrong
Bram Moolenaar <Bram@vim.org>
parents:
22248
diff
changeset
|
3026 for (match = match->cp_prev; match |
bd61aaf7f2a0
patch 8.2.1907: complete_info().selected may be wrong
Bram Moolenaar <Bram@vim.org>
parents:
22248
diff
changeset
|
3027 && match->cp_number == -1; |
bd61aaf7f2a0
patch 8.2.1907: complete_info().selected may be wrong
Bram Moolenaar <Bram@vim.org>
parents:
22248
diff
changeset
|
3028 match = match->cp_prev) |
bd61aaf7f2a0
patch 8.2.1907: complete_info().selected may be wrong
Bram Moolenaar <Bram@vim.org>
parents:
22248
diff
changeset
|
3029 match->cp_number = ++number; |
bd61aaf7f2a0
patch 8.2.1907: complete_info().selected may be wrong
Bram Moolenaar <Bram@vim.org>
parents:
22248
diff
changeset
|
3030 } |
bd61aaf7f2a0
patch 8.2.1907: complete_info().selected may be wrong
Bram Moolenaar <Bram@vim.org>
parents:
22248
diff
changeset
|
3031 } |
bd61aaf7f2a0
patch 8.2.1907: complete_info().selected may be wrong
Bram Moolenaar <Bram@vim.org>
parents:
22248
diff
changeset
|
3032 |
17813
8ca20b0a3dc3
patch 8.1.1903: cannot build without the +eval feature
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
3033 /* |
8ca20b0a3dc3
patch 8.1.1903: cannot build without the +eval feature
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
3034 * Get complete information |
8ca20b0a3dc3
patch 8.1.1903: cannot build without the +eval feature
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
3035 */ |
8ca20b0a3dc3
patch 8.1.1903: cannot build without the +eval feature
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
3036 static void |
8ca20b0a3dc3
patch 8.1.1903: cannot build without the +eval feature
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
3037 get_complete_info(list_T *what_list, dict_T *retdict) |
8ca20b0a3dc3
patch 8.1.1903: cannot build without the +eval feature
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
3038 { |
8ca20b0a3dc3
patch 8.1.1903: cannot build without the +eval feature
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
3039 int ret = OK; |
8ca20b0a3dc3
patch 8.1.1903: cannot build without the +eval feature
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
3040 listitem_T *item; |
8ca20b0a3dc3
patch 8.1.1903: cannot build without the +eval feature
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
3041 #define CI_WHAT_MODE 0x01 |
8ca20b0a3dc3
patch 8.1.1903: cannot build without the +eval feature
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
3042 #define CI_WHAT_PUM_VISIBLE 0x02 |
8ca20b0a3dc3
patch 8.1.1903: cannot build without the +eval feature
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
3043 #define CI_WHAT_ITEMS 0x04 |
8ca20b0a3dc3
patch 8.1.1903: cannot build without the +eval feature
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
3044 #define CI_WHAT_SELECTED 0x08 |
8ca20b0a3dc3
patch 8.1.1903: cannot build without the +eval feature
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
3045 #define CI_WHAT_INSERTED 0x10 |
8ca20b0a3dc3
patch 8.1.1903: cannot build without the +eval feature
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
3046 #define CI_WHAT_ALL 0xff |
8ca20b0a3dc3
patch 8.1.1903: cannot build without the +eval feature
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
3047 int what_flag; |
8ca20b0a3dc3
patch 8.1.1903: cannot build without the +eval feature
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
3048 |
8ca20b0a3dc3
patch 8.1.1903: cannot build without the +eval feature
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
3049 if (what_list == NULL) |
8ca20b0a3dc3
patch 8.1.1903: cannot build without the +eval feature
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
3050 what_flag = CI_WHAT_ALL; |
8ca20b0a3dc3
patch 8.1.1903: cannot build without the +eval feature
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
3051 else |
8ca20b0a3dc3
patch 8.1.1903: cannot build without the +eval feature
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
3052 { |
8ca20b0a3dc3
patch 8.1.1903: cannot build without the +eval feature
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
3053 what_flag = 0; |
20392
4c317d8c1051
patch 8.2.0751: Vim9: performance can be improved
Bram Moolenaar <Bram@vim.org>
parents:
20229
diff
changeset
|
3054 CHECK_LIST_MATERIALIZE(what_list); |
19888
435726a03481
patch 8.2.0500: using the same loop in many places
Bram Moolenaar <Bram@vim.org>
parents:
19201
diff
changeset
|
3055 FOR_ALL_LIST_ITEMS(what_list, item) |
17813
8ca20b0a3dc3
patch 8.1.1903: cannot build without the +eval feature
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
3056 { |
8ca20b0a3dc3
patch 8.1.1903: cannot build without the +eval feature
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
3057 char_u *what = tv_get_string(&item->li_tv); |
8ca20b0a3dc3
patch 8.1.1903: cannot build without the +eval feature
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
3058 |
8ca20b0a3dc3
patch 8.1.1903: cannot build without the +eval feature
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
3059 if (STRCMP(what, "mode") == 0) |
8ca20b0a3dc3
patch 8.1.1903: cannot build without the +eval feature
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
3060 what_flag |= CI_WHAT_MODE; |
8ca20b0a3dc3
patch 8.1.1903: cannot build without the +eval feature
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
3061 else if (STRCMP(what, "pum_visible") == 0) |
8ca20b0a3dc3
patch 8.1.1903: cannot build without the +eval feature
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
3062 what_flag |= CI_WHAT_PUM_VISIBLE; |
8ca20b0a3dc3
patch 8.1.1903: cannot build without the +eval feature
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
3063 else if (STRCMP(what, "items") == 0) |
8ca20b0a3dc3
patch 8.1.1903: cannot build without the +eval feature
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
3064 what_flag |= CI_WHAT_ITEMS; |
8ca20b0a3dc3
patch 8.1.1903: cannot build without the +eval feature
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
3065 else if (STRCMP(what, "selected") == 0) |
8ca20b0a3dc3
patch 8.1.1903: cannot build without the +eval feature
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
3066 what_flag |= CI_WHAT_SELECTED; |
8ca20b0a3dc3
patch 8.1.1903: cannot build without the +eval feature
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
3067 else if (STRCMP(what, "inserted") == 0) |
8ca20b0a3dc3
patch 8.1.1903: cannot build without the +eval feature
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
3068 what_flag |= CI_WHAT_INSERTED; |
8ca20b0a3dc3
patch 8.1.1903: cannot build without the +eval feature
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
3069 } |
8ca20b0a3dc3
patch 8.1.1903: cannot build without the +eval feature
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
3070 } |
8ca20b0a3dc3
patch 8.1.1903: cannot build without the +eval feature
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
3071 |
8ca20b0a3dc3
patch 8.1.1903: cannot build without the +eval feature
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
3072 if (ret == OK && (what_flag & CI_WHAT_MODE)) |
8ca20b0a3dc3
patch 8.1.1903: cannot build without the +eval feature
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
3073 ret = dict_add_string(retdict, "mode", ins_compl_mode()); |
8ca20b0a3dc3
patch 8.1.1903: cannot build without the +eval feature
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
3074 |
8ca20b0a3dc3
patch 8.1.1903: cannot build without the +eval feature
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
3075 if (ret == OK && (what_flag & CI_WHAT_PUM_VISIBLE)) |
8ca20b0a3dc3
patch 8.1.1903: cannot build without the +eval feature
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
3076 ret = dict_add_number(retdict, "pum_visible", pum_visible()); |
8ca20b0a3dc3
patch 8.1.1903: cannot build without the +eval feature
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
3077 |
8ca20b0a3dc3
patch 8.1.1903: cannot build without the +eval feature
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
3078 if (ret == OK && (what_flag & CI_WHAT_ITEMS)) |
8ca20b0a3dc3
patch 8.1.1903: cannot build without the +eval feature
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
3079 { |
8ca20b0a3dc3
patch 8.1.1903: cannot build without the +eval feature
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
3080 list_T *li; |
8ca20b0a3dc3
patch 8.1.1903: cannot build without the +eval feature
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
3081 dict_T *di; |
8ca20b0a3dc3
patch 8.1.1903: cannot build without the +eval feature
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
3082 compl_T *match; |
8ca20b0a3dc3
patch 8.1.1903: cannot build without the +eval feature
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
3083 |
8ca20b0a3dc3
patch 8.1.1903: cannot build without the +eval feature
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
3084 li = list_alloc(); |
8ca20b0a3dc3
patch 8.1.1903: cannot build without the +eval feature
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
3085 if (li == NULL) |
8ca20b0a3dc3
patch 8.1.1903: cannot build without the +eval feature
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
3086 return; |
8ca20b0a3dc3
patch 8.1.1903: cannot build without the +eval feature
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
3087 ret = dict_add_list(retdict, "items", li); |
8ca20b0a3dc3
patch 8.1.1903: cannot build without the +eval feature
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
3088 if (ret == OK && compl_first_match != NULL) |
8ca20b0a3dc3
patch 8.1.1903: cannot build without the +eval feature
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
3089 { |
8ca20b0a3dc3
patch 8.1.1903: cannot build without the +eval feature
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
3090 match = compl_first_match; |
8ca20b0a3dc3
patch 8.1.1903: cannot build without the +eval feature
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
3091 do |
8ca20b0a3dc3
patch 8.1.1903: cannot build without the +eval feature
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
3092 { |
26944
8dbdd68627bd
patch 8.2.4001: insert complete code uses global variables
Bram Moolenaar <Bram@vim.org>
parents:
26921
diff
changeset
|
3093 if (!match_at_original_text(match)) |
17813
8ca20b0a3dc3
patch 8.1.1903: cannot build without the +eval feature
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
3094 { |
8ca20b0a3dc3
patch 8.1.1903: cannot build without the +eval feature
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
3095 di = dict_alloc(); |
8ca20b0a3dc3
patch 8.1.1903: cannot build without the +eval feature
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
3096 if (di == NULL) |
8ca20b0a3dc3
patch 8.1.1903: cannot build without the +eval feature
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
3097 return; |
8ca20b0a3dc3
patch 8.1.1903: cannot build without the +eval feature
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
3098 ret = list_append_dict(li, di); |
8ca20b0a3dc3
patch 8.1.1903: cannot build without the +eval feature
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
3099 if (ret != OK) |
8ca20b0a3dc3
patch 8.1.1903: cannot build without the +eval feature
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
3100 return; |
8ca20b0a3dc3
patch 8.1.1903: cannot build without the +eval feature
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
3101 dict_add_string(di, "word", match->cp_str); |
8ca20b0a3dc3
patch 8.1.1903: cannot build without the +eval feature
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
3102 dict_add_string(di, "abbr", match->cp_text[CPT_ABBR]); |
8ca20b0a3dc3
patch 8.1.1903: cannot build without the +eval feature
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
3103 dict_add_string(di, "menu", match->cp_text[CPT_MENU]); |
8ca20b0a3dc3
patch 8.1.1903: cannot build without the +eval feature
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
3104 dict_add_string(di, "kind", match->cp_text[CPT_KIND]); |
8ca20b0a3dc3
patch 8.1.1903: cannot build without the +eval feature
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
3105 dict_add_string(di, "info", match->cp_text[CPT_INFO]); |
19047
a3fce2763e83
patch 8.2.0084: complete item "user_data" can only be a string
Bram Moolenaar <Bram@vim.org>
parents:
18933
diff
changeset
|
3106 if (match->cp_user_data.v_type == VAR_UNKNOWN) |
a3fce2763e83
patch 8.2.0084: complete item "user_data" can only be a string
Bram Moolenaar <Bram@vim.org>
parents:
18933
diff
changeset
|
3107 // Add an empty string for backwards compatibility |
a3fce2763e83
patch 8.2.0084: complete item "user_data" can only be a string
Bram Moolenaar <Bram@vim.org>
parents:
18933
diff
changeset
|
3108 dict_add_string(di, "user_data", (char_u *)""); |
a3fce2763e83
patch 8.2.0084: complete item "user_data" can only be a string
Bram Moolenaar <Bram@vim.org>
parents:
18933
diff
changeset
|
3109 else |
a3fce2763e83
patch 8.2.0084: complete item "user_data" can only be a string
Bram Moolenaar <Bram@vim.org>
parents:
18933
diff
changeset
|
3110 dict_add_tv(di, "user_data", &match->cp_user_data); |
17813
8ca20b0a3dc3
patch 8.1.1903: cannot build without the +eval feature
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
3111 } |
8ca20b0a3dc3
patch 8.1.1903: cannot build without the +eval feature
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
3112 match = match->cp_next; |
8ca20b0a3dc3
patch 8.1.1903: cannot build without the +eval feature
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
3113 } |
26944
8dbdd68627bd
patch 8.2.4001: insert complete code uses global variables
Bram Moolenaar <Bram@vim.org>
parents:
26921
diff
changeset
|
3114 while (match != NULL && !is_first_match(match)); |
17813
8ca20b0a3dc3
patch 8.1.1903: cannot build without the +eval feature
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
3115 } |
8ca20b0a3dc3
patch 8.1.1903: cannot build without the +eval feature
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
3116 } |
8ca20b0a3dc3
patch 8.1.1903: cannot build without the +eval feature
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
3117 |
8ca20b0a3dc3
patch 8.1.1903: cannot build without the +eval feature
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
3118 if (ret == OK && (what_flag & CI_WHAT_SELECTED)) |
22717
bd61aaf7f2a0
patch 8.2.1907: complete_info().selected may be wrong
Bram Moolenaar <Bram@vim.org>
parents:
22248
diff
changeset
|
3119 { |
bd61aaf7f2a0
patch 8.2.1907: complete_info().selected may be wrong
Bram Moolenaar <Bram@vim.org>
parents:
22248
diff
changeset
|
3120 if (compl_curr_match != NULL && compl_curr_match->cp_number == -1) |
bd61aaf7f2a0
patch 8.2.1907: complete_info().selected may be wrong
Bram Moolenaar <Bram@vim.org>
parents:
22248
diff
changeset
|
3121 ins_compl_update_sequence_numbers(); |
bd61aaf7f2a0
patch 8.2.1907: complete_info().selected may be wrong
Bram Moolenaar <Bram@vim.org>
parents:
22248
diff
changeset
|
3122 ret = dict_add_number(retdict, "selected", compl_curr_match != NULL |
bd61aaf7f2a0
patch 8.2.1907: complete_info().selected may be wrong
Bram Moolenaar <Bram@vim.org>
parents:
22248
diff
changeset
|
3123 ? compl_curr_match->cp_number - 1 : -1); |
bd61aaf7f2a0
patch 8.2.1907: complete_info().selected may be wrong
Bram Moolenaar <Bram@vim.org>
parents:
22248
diff
changeset
|
3124 } |
17813
8ca20b0a3dc3
patch 8.1.1903: cannot build without the +eval feature
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
3125 |
8ca20b0a3dc3
patch 8.1.1903: cannot build without the +eval feature
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
3126 // TODO |
8ca20b0a3dc3
patch 8.1.1903: cannot build without the +eval feature
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
3127 // if (ret == OK && (what_flag & CI_WHAT_INSERTED)) |
8ca20b0a3dc3
patch 8.1.1903: cannot build without the +eval feature
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
3128 } |
8ca20b0a3dc3
patch 8.1.1903: cannot build without the +eval feature
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
3129 |
8ca20b0a3dc3
patch 8.1.1903: cannot build without the +eval feature
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
3130 /* |
17704 | 3131 * "complete_info()" function |
3132 */ | |
3133 void | |
3134 f_complete_info(typval_T *argvars, typval_T *rettv) | |
3135 { | |
3136 list_T *what_list = NULL; | |
3137 | |
29175
755ab148288b
patch 8.2.5107: some callers of rettv_list_alloc() check for not OK
Bram Moolenaar <Bram@vim.org>
parents:
29014
diff
changeset
|
3138 if (rettv_dict_alloc(rettv) == FAIL) |
17704 | 3139 return; |
3140 | |
25384
e8e2c4d33b9b
patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents:
25302
diff
changeset
|
3141 if (in_vim9script() && check_for_opt_list_arg(argvars, 0) == FAIL) |
e8e2c4d33b9b
patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents:
25302
diff
changeset
|
3142 return; |
e8e2c4d33b9b
patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents:
25302
diff
changeset
|
3143 |
17704 | 3144 if (argvars[0].v_type != VAR_UNKNOWN) |
16142
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3145 { |
17704 | 3146 if (argvars[0].v_type != VAR_LIST) |
3147 { | |
26877
06a137af96f8
patch 8.2.3967: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26865
diff
changeset
|
3148 emsg(_(e_list_required)); |
17704 | 3149 return; |
3150 } | |
3151 what_list = argvars[0].vval.v_list; | |
16142
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3152 } |
17704 | 3153 get_complete_info(what_list, rettv->vval.v_dict); |
16142
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3154 } |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3155 #endif |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3156 |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3157 /* |
25974
416237f1de22
patch 8.2.3520: cannot define a function for thesaurus completion
Bram Moolenaar <Bram@vim.org>
parents:
25862
diff
changeset
|
3158 * Returns TRUE when using a user-defined function for thesaurus completion. |
416237f1de22
patch 8.2.3520: cannot define a function for thesaurus completion
Bram Moolenaar <Bram@vim.org>
parents:
25862
diff
changeset
|
3159 */ |
416237f1de22
patch 8.2.3520: cannot define a function for thesaurus completion
Bram Moolenaar <Bram@vim.org>
parents:
25862
diff
changeset
|
3160 static int |
416237f1de22
patch 8.2.3520: cannot define a function for thesaurus completion
Bram Moolenaar <Bram@vim.org>
parents:
25862
diff
changeset
|
3161 thesaurus_func_complete(int type UNUSED) |
416237f1de22
patch 8.2.3520: cannot define a function for thesaurus completion
Bram Moolenaar <Bram@vim.org>
parents:
25862
diff
changeset
|
3162 { |
416237f1de22
patch 8.2.3520: cannot define a function for thesaurus completion
Bram Moolenaar <Bram@vim.org>
parents:
25862
diff
changeset
|
3163 #ifdef FEAT_COMPL_FUNC |
25990
ac330e2fecc4
patch 8.2.3528: 'thesaurus' and 'thesaurusfunc' do not have the same scope
Bram Moolenaar <Bram@vim.org>
parents:
25984
diff
changeset
|
3164 return type == CTRL_X_THESAURUS |
ac330e2fecc4
patch 8.2.3528: 'thesaurus' and 'thesaurusfunc' do not have the same scope
Bram Moolenaar <Bram@vim.org>
parents:
25984
diff
changeset
|
3165 && (*curbuf->b_p_tsrfu != NUL || *p_tsrfu != NUL); |
25974
416237f1de22
patch 8.2.3520: cannot define a function for thesaurus completion
Bram Moolenaar <Bram@vim.org>
parents:
25862
diff
changeset
|
3166 #else |
416237f1de22
patch 8.2.3520: cannot define a function for thesaurus completion
Bram Moolenaar <Bram@vim.org>
parents:
25862
diff
changeset
|
3167 return FALSE; |
416237f1de22
patch 8.2.3520: cannot define a function for thesaurus completion
Bram Moolenaar <Bram@vim.org>
parents:
25862
diff
changeset
|
3168 #endif |
416237f1de22
patch 8.2.3520: cannot define a function for thesaurus completion
Bram Moolenaar <Bram@vim.org>
parents:
25862
diff
changeset
|
3169 } |
416237f1de22
patch 8.2.3520: cannot define a function for thesaurus completion
Bram Moolenaar <Bram@vim.org>
parents:
25862
diff
changeset
|
3170 |
416237f1de22
patch 8.2.3520: cannot define a function for thesaurus completion
Bram Moolenaar <Bram@vim.org>
parents:
25862
diff
changeset
|
3171 /* |
26817
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3172 * Return value of process_next_cpt_value() |
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3173 */ |
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3174 enum |
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3175 { |
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3176 INS_COMPL_CPT_OK = 1, |
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3177 INS_COMPL_CPT_CONT, |
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3178 INS_COMPL_CPT_END |
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3179 }; |
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3180 |
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3181 /* |
26850
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
3182 * state information used for getting the next set of insert completion |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
3183 * matches. |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
3184 */ |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
3185 typedef struct |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
3186 { |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
3187 char_u *e_cpt; // current entry in 'complete' |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
3188 buf_T *ins_buf; // buffer being scanned |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
3189 pos_T *cur_match_pos; // current match position |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
3190 pos_T prev_match_pos; // previous match position |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
3191 int set_match_pos; // save first_match_pos/last_match_pos |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
3192 pos_T first_match_pos; // first match position |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
3193 pos_T last_match_pos; // last match position |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
3194 int found_all; // found all matches of a certain type. |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
3195 char_u *dict; // dictionary file to search |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
3196 int dict_f; // "dict" is an exact file name or not |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
3197 } ins_compl_next_state_T; |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
3198 |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
3199 /* |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
3200 * Process the next 'complete' option value in st->e_cpt. |
26817
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3201 * |
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3202 * If successful, the arguments are set as below: |
26850
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
3203 * st->cpt - pointer to the next option value in "st->cpt" |
26817
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3204 * compl_type_arg - type of insert mode completion to use |
26850
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
3205 * st->found_all - all matches of this type are found |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
3206 * st->ins_buf - search for completions in this buffer |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
3207 * st->first_match_pos - position of the first completion match |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
3208 * st->last_match_pos - position of the last completion match |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
3209 * st->set_match_pos - TRUE if the first match position should be saved to |
28809
d0241e74bfdb
patch 8.2.4928: various white space and cosmetic mistakes
Bram Moolenaar <Bram@vim.org>
parents:
28773
diff
changeset
|
3210 * avoid loops after the search wraps around. |
26850
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
3211 * st->dict - name of the dictionary or thesaurus file to search |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
3212 * st->dict_f - flag specifying whether "dict" is an exact file name or not |
26817
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3213 * |
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3214 * Returns INS_COMPL_CPT_OK if the next value is processed successfully. |
27016
1d9a7aa42744
patch 8.2.4037: Insert mode completion is insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
26962
diff
changeset
|
3215 * Returns INS_COMPL_CPT_CONT to skip the current completion source matching |
1d9a7aa42744
patch 8.2.4037: Insert mode completion is insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
26962
diff
changeset
|
3216 * the "st->e_cpt" option value and process the next matching source. |
26850
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
3217 * Returns INS_COMPL_CPT_END if all the values in "st->e_cpt" are processed. |
26817
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3218 */ |
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3219 static int |
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3220 process_next_cpt_value( |
26850
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
3221 ins_compl_next_state_T *st, |
26817
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3222 int *compl_type_arg, |
26850
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
3223 pos_T *start_match_pos) |
26817
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3224 { |
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3225 int compl_type = -1; |
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3226 int status = INS_COMPL_CPT_OK; |
26850
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
3227 |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
3228 st->found_all = FALSE; |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
3229 |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
3230 while (*st->e_cpt == ',' || *st->e_cpt == ' ') |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
3231 st->e_cpt++; |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
3232 |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
3233 if (*st->e_cpt == '.' && !curbuf->b_scanned) |
26817
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3234 { |
26850
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
3235 st->ins_buf = curbuf; |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
3236 st->first_match_pos = *start_match_pos; |
26817
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3237 // Move the cursor back one character so that ^N can match the |
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3238 // word immediately after the cursor. |
26944
8dbdd68627bd
patch 8.2.4001: insert complete code uses global variables
Bram Moolenaar <Bram@vim.org>
parents:
26921
diff
changeset
|
3239 if (ctrl_x_mode_normal() && dec(&st->first_match_pos) < 0) |
26817
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3240 { |
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3241 // Move the cursor to after the last character in the |
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3242 // buffer, so that word at start of buffer is found |
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3243 // correctly. |
26850
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
3244 st->first_match_pos.lnum = st->ins_buf->b_ml.ml_line_count; |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
3245 st->first_match_pos.col = |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
3246 (colnr_T)STRLEN(ml_get(st->first_match_pos.lnum)); |
26817
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3247 } |
26850
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
3248 st->last_match_pos = st->first_match_pos; |
26817
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3249 compl_type = 0; |
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3250 |
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3251 // Remember the first match so that the loop stops when we |
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3252 // wrap and come back there a second time. |
26850
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
3253 st->set_match_pos = TRUE; |
26817
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3254 } |
26850
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
3255 else if (vim_strchr((char_u *)"buwU", *st->e_cpt) != NULL |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
3256 && (st->ins_buf = ins_compl_next_buf(st->ins_buf, *st->e_cpt)) != curbuf) |
26817
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3257 { |
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3258 // Scan a buffer, but not the current one. |
26850
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
3259 if (st->ins_buf->b_ml.ml_mfp != NULL) // loaded buffer |
26817
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3260 { |
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3261 compl_started = TRUE; |
26850
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
3262 st->first_match_pos.col = st->last_match_pos.col = 0; |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
3263 st->first_match_pos.lnum = st->ins_buf->b_ml.ml_line_count + 1; |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
3264 st->last_match_pos.lnum = 0; |
26817
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3265 compl_type = 0; |
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3266 } |
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3267 else // unloaded buffer, scan like dictionary |
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3268 { |
26850
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
3269 st->found_all = TRUE; |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
3270 if (st->ins_buf->b_fname == NULL) |
26817
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3271 { |
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3272 status = INS_COMPL_CPT_CONT; |
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3273 goto done; |
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3274 } |
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3275 compl_type = CTRL_X_DICTIONARY; |
26850
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
3276 st->dict = st->ins_buf->b_fname; |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
3277 st->dict_f = DICT_EXACT; |
26817
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3278 } |
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3279 msg_hist_off = TRUE; // reset in msg_trunc_attr() |
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3280 vim_snprintf((char *)IObuff, IOSIZE, _("Scanning: %s"), |
26850
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
3281 st->ins_buf->b_fname == NULL |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
3282 ? buf_spname(st->ins_buf) |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
3283 : st->ins_buf->b_sfname == NULL |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
3284 ? st->ins_buf->b_fname |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
3285 : st->ins_buf->b_sfname); |
26817
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3286 (void)msg_trunc_attr((char *)IObuff, TRUE, HL_ATTR(HLF_R)); |
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3287 } |
26850
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
3288 else if (*st->e_cpt == NUL) |
26817
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3289 status = INS_COMPL_CPT_END; |
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3290 else |
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3291 { |
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3292 if (ctrl_x_mode_line_or_eval()) |
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3293 compl_type = -1; |
26850
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
3294 else if (*st->e_cpt == 'k' || *st->e_cpt == 's') |
26817
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3295 { |
26850
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
3296 if (*st->e_cpt == 'k') |
26817
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3297 compl_type = CTRL_X_DICTIONARY; |
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3298 else |
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3299 compl_type = CTRL_X_THESAURUS; |
26850
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
3300 if (*++st->e_cpt != ',' && *st->e_cpt != NUL) |
26817
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3301 { |
26850
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
3302 st->dict = st->e_cpt; |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
3303 st->dict_f = DICT_FIRST; |
26817
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3304 } |
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3305 } |
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3306 #ifdef FEAT_FIND_ID |
26850
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
3307 else if (*st->e_cpt == 'i') |
26817
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3308 compl_type = CTRL_X_PATH_PATTERNS; |
26850
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
3309 else if (*st->e_cpt == 'd') |
26817
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3310 compl_type = CTRL_X_PATH_DEFINES; |
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3311 #endif |
26850
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
3312 else if (*st->e_cpt == ']' || *st->e_cpt == 't') |
26817
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3313 { |
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3314 msg_hist_off = TRUE; // reset in msg_trunc_attr() |
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3315 compl_type = CTRL_X_TAGS; |
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3316 vim_snprintf((char *)IObuff, IOSIZE, _("Scanning tags.")); |
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3317 (void)msg_trunc_attr((char *)IObuff, TRUE, HL_ATTR(HLF_R)); |
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3318 } |
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3319 else |
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3320 compl_type = -1; |
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3321 |
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3322 // in any case e_cpt is advanced to the next entry |
26850
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
3323 (void)copy_option_part(&st->e_cpt, IObuff, IOSIZE, ","); |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
3324 |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
3325 st->found_all = TRUE; |
26817
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3326 if (compl_type == -1) |
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3327 status = INS_COMPL_CPT_CONT; |
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3328 } |
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3329 |
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3330 done: |
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3331 *compl_type_arg = compl_type; |
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3332 return status; |
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3333 } |
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3334 |
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3335 #ifdef FEAT_FIND_ID |
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3336 /* |
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3337 * Get the next set of identifiers or defines matching "compl_pattern" in |
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3338 * included files. |
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3339 */ |
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3340 static void |
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3341 get_next_include_file_completion(int compl_type) |
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3342 { |
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3343 find_pattern_in_path(compl_pattern, compl_direction, |
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3344 (int)STRLEN(compl_pattern), FALSE, FALSE, |
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3345 (compl_type == CTRL_X_PATH_DEFINES |
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3346 && !(compl_cont_status & CONT_SOL)) |
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3347 ? FIND_DEFINE : FIND_ANY, 1L, ACTION_EXPAND, |
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3348 (linenr_T)1, (linenr_T)MAXLNUM); |
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3349 } |
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3350 #endif |
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3351 |
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3352 /* |
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3353 * Get the next set of words matching "compl_pattern" in dictionary or |
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3354 * thesaurus files. |
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3355 */ |
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3356 static void |
26850
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
3357 get_next_dict_tsr_completion(int compl_type, char_u *dict, int dict_f) |
26817
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3358 { |
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3359 #ifdef FEAT_COMPL_FUNC |
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3360 if (thesaurus_func_complete(compl_type)) |
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3361 expand_by_function(compl_type, compl_pattern); |
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3362 else |
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3363 #endif |
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3364 ins_compl_dictionaries( |
26850
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
3365 dict != NULL ? dict |
26817
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3366 : (compl_type == CTRL_X_THESAURUS |
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3367 ? (*curbuf->b_p_tsr == NUL ? p_tsr : curbuf->b_p_tsr) |
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3368 : (*curbuf->b_p_dict == NUL ? p_dict : curbuf->b_p_dict)), |
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3369 compl_pattern, |
26850
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
3370 dict != NULL ? dict_f : 0, |
26817
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3371 compl_type == CTRL_X_THESAURUS); |
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3372 } |
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3373 |
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3374 /* |
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3375 * Get the next set of tag names matching "compl_pattern". |
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3376 */ |
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3377 static void |
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3378 get_next_tag_completion(void) |
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3379 { |
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3380 int save_p_ic; |
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3381 char_u **matches; |
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3382 int num_matches; |
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3383 |
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3384 // set p_ic according to p_ic, p_scs and pat for find_tags(). |
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3385 save_p_ic = p_ic; |
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3386 p_ic = ignorecase(compl_pattern); |
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3387 |
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3388 // Find up to TAG_MANY matches. Avoids that an enormous number |
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3389 // of matches is found when compl_pattern is empty |
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3390 g_tag_at_cursor = TRUE; |
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3391 if (find_tags(compl_pattern, &num_matches, &matches, |
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3392 TAG_REGEXP | TAG_NAMES | TAG_NOIC | TAG_INS_COMP |
26944
8dbdd68627bd
patch 8.2.4001: insert complete code uses global variables
Bram Moolenaar <Bram@vim.org>
parents:
26921
diff
changeset
|
3393 | (ctrl_x_mode_not_default() ? TAG_VERBOSE : 0), |
26817
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3394 TAG_MANY, curbuf->b_ffname) == OK && num_matches > 0) |
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3395 ins_compl_add_matches(num_matches, matches, p_ic); |
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3396 g_tag_at_cursor = FALSE; |
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3397 p_ic = save_p_ic; |
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3398 } |
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3399 |
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3400 /* |
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3401 * Get the next set of filename matching "compl_pattern". |
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3402 */ |
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3403 static void |
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3404 get_next_filename_completion(void) |
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3405 { |
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3406 char_u **matches; |
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3407 int num_matches; |
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3408 |
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3409 if (expand_wildcards(1, &compl_pattern, &num_matches, &matches, |
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3410 EW_FILE|EW_DIR|EW_ADDSLASH|EW_SILENT) != OK) |
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3411 return; |
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3412 |
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3413 // May change home directory back to "~". |
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3414 tilde_replace(compl_pattern, num_matches, matches); |
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3415 #ifdef BACKSLASH_IN_FILENAME |
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3416 if (curbuf->b_p_csl[0] != NUL) |
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3417 { |
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3418 int i; |
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3419 |
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3420 for (i = 0; i < num_matches; ++i) |
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3421 { |
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3422 char_u *ptr = matches[i]; |
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3423 |
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3424 while (*ptr != NUL) |
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3425 { |
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3426 if (curbuf->b_p_csl[0] == 's' && *ptr == '\\') |
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3427 *ptr = '/'; |
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3428 else if (curbuf->b_p_csl[0] == 'b' && *ptr == '/') |
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3429 *ptr = '\\'; |
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3430 ptr += (*mb_ptr2len)(ptr); |
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3431 } |
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3432 } |
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3433 } |
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3434 #endif |
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3435 ins_compl_add_matches(num_matches, matches, p_fic || p_wic); |
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3436 } |
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3437 |
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3438 /* |
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3439 * Get the next set of command-line completions matching "compl_pattern". |
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3440 */ |
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3441 static void |
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3442 get_next_cmdline_completion() |
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3443 { |
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3444 char_u **matches; |
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3445 int num_matches; |
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3446 |
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3447 if (expand_cmdline(&compl_xp, compl_pattern, |
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3448 (int)STRLEN(compl_pattern), |
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3449 &num_matches, &matches) == EXPAND_OK) |
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3450 ins_compl_add_matches(num_matches, matches, FALSE); |
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3451 } |
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3452 |
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3453 /* |
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3454 * Get the next set of spell suggestions matching "compl_pattern". |
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3455 */ |
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3456 static void |
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3457 get_next_spell_completion(linenr_T lnum UNUSED) |
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3458 { |
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3459 #ifdef FEAT_SPELL |
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3460 char_u **matches; |
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3461 int num_matches; |
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3462 |
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3463 num_matches = expand_spelling(lnum, compl_pattern, &matches); |
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3464 if (num_matches > 0) |
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3465 ins_compl_add_matches(num_matches, matches, p_ic); |
26827
3949037c47f9
patch 8.2.3942: Coverity reports a possible memory leak
Bram Moolenaar <Bram@vim.org>
parents:
26817
diff
changeset
|
3466 else |
3949037c47f9
patch 8.2.3942: Coverity reports a possible memory leak
Bram Moolenaar <Bram@vim.org>
parents:
26817
diff
changeset
|
3467 vim_free(matches); |
26817
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3468 #endif |
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3469 } |
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3470 |
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3471 /* |
26831
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
3472 * Return the next word or line from buffer "ins_buf" at position |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
3473 * "cur_match_pos" for completion. The length of the match is set in "len". |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
3474 */ |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
3475 static char_u * |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
3476 ins_comp_get_next_word_or_line( |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
3477 buf_T *ins_buf, // buffer being scanned |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
3478 pos_T *cur_match_pos, // current match position |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
3479 int *match_len, |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
3480 int *cont_s_ipos) // next ^X<> will set initial_pos |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
3481 { |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
3482 char_u *ptr; |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
3483 int len; |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
3484 |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
3485 *match_len = 0; |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
3486 ptr = ml_get_buf(ins_buf, cur_match_pos->lnum, FALSE) + |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
3487 cur_match_pos->col; |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
3488 if (ctrl_x_mode_line_or_eval()) |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
3489 { |
26944
8dbdd68627bd
patch 8.2.4001: insert complete code uses global variables
Bram Moolenaar <Bram@vim.org>
parents:
26921
diff
changeset
|
3490 if (compl_status_adding()) |
26831
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
3491 { |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
3492 if (cur_match_pos->lnum >= ins_buf->b_ml.ml_line_count) |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
3493 return NULL; |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
3494 ptr = ml_get_buf(ins_buf, cur_match_pos->lnum + 1, FALSE); |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
3495 if (!p_paste) |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
3496 ptr = skipwhite(ptr); |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
3497 } |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
3498 len = (int)STRLEN(ptr); |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
3499 } |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
3500 else |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
3501 { |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
3502 char_u *tmp_ptr = ptr; |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
3503 |
29521
f538704ca03b
patch 9.0.0102: reading past end of line with insert mode completion
Bram Moolenaar <Bram@vim.org>
parents:
29442
diff
changeset
|
3504 if (compl_status_adding() && compl_length <= (int)STRLEN(tmp_ptr)) |
26831
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
3505 { |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
3506 tmp_ptr += compl_length; |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
3507 // Skip if already inside a word. |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
3508 if (vim_iswordp(tmp_ptr)) |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
3509 return NULL; |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
3510 // Find start of next word. |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
3511 tmp_ptr = find_word_start(tmp_ptr); |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
3512 } |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
3513 // Find end of this word. |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
3514 tmp_ptr = find_word_end(tmp_ptr); |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
3515 len = (int)(tmp_ptr - ptr); |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
3516 |
26944
8dbdd68627bd
patch 8.2.4001: insert complete code uses global variables
Bram Moolenaar <Bram@vim.org>
parents:
26921
diff
changeset
|
3517 if (compl_status_adding() && len == compl_length) |
26831
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
3518 { |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
3519 if (cur_match_pos->lnum < ins_buf->b_ml.ml_line_count) |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
3520 { |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
3521 // Try next line, if any. the new word will be |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
3522 // "join" as if the normal command "J" was used. |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
3523 // IOSIZE is always greater than |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
3524 // compl_length, so the next STRNCPY always |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
3525 // works -- Acevedo |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
3526 STRNCPY(IObuff, ptr, len); |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
3527 ptr = ml_get_buf(ins_buf, cur_match_pos->lnum + 1, FALSE); |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
3528 tmp_ptr = ptr = skipwhite(ptr); |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
3529 // Find start of next word. |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
3530 tmp_ptr = find_word_start(tmp_ptr); |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
3531 // Find end of next word. |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
3532 tmp_ptr = find_word_end(tmp_ptr); |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
3533 if (tmp_ptr > ptr) |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
3534 { |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
3535 if (*ptr != ')' && IObuff[len - 1] != TAB) |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
3536 { |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
3537 if (IObuff[len - 1] != ' ') |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
3538 IObuff[len++] = ' '; |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
3539 // IObuf =~ "\k.* ", thus len >= 2 |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
3540 if (p_js |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
3541 && (IObuff[len - 2] == '.' |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
3542 || (vim_strchr(p_cpo, CPO_JOINSP) |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
3543 == NULL |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
3544 && (IObuff[len - 2] == '?' |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
3545 || IObuff[len - 2] == '!')))) |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
3546 IObuff[len++] = ' '; |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
3547 } |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
3548 // copy as much as possible of the new word |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
3549 if (tmp_ptr - ptr >= IOSIZE - len) |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
3550 tmp_ptr = ptr + IOSIZE - len - 1; |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
3551 STRNCPY(IObuff + len, ptr, tmp_ptr - ptr); |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
3552 len += (int)(tmp_ptr - ptr); |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
3553 *cont_s_ipos = TRUE; |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
3554 } |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
3555 IObuff[len] = NUL; |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
3556 ptr = IObuff; |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
3557 } |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
3558 if (len == compl_length) |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
3559 return NULL; |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
3560 } |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
3561 } |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
3562 |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
3563 *match_len = len; |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
3564 return ptr; |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
3565 } |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
3566 |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
3567 /* |
26817
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3568 * Get the next set of words matching "compl_pattern" for default completion(s) |
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3569 * (normal ^P/^N and ^X^L). |
26850
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
3570 * Search for "compl_pattern" in the buffer "st->ins_buf" starting from the |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
3571 * position "st->start_pos" in the "compl_direction" direction. If |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
3572 * "st->set_match_pos" is TRUE, then set the "st->first_match_pos" and |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
3573 * "st->last_match_pos". |
26817
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3574 * Returns OK if a new next match is found, otherwise returns FAIL. |
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3575 */ |
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3576 static int |
26850
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
3577 get_next_default_completion(ins_compl_next_state_T *st, pos_T *start_pos) |
26817
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3578 { |
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3579 int found_new_match = FAIL; |
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3580 int save_p_scs; |
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3581 int save_p_ws; |
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3582 int looped_around = FALSE; |
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3583 char_u *ptr; |
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3584 int len; |
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3585 |
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3586 // If 'infercase' is set, don't use 'smartcase' here |
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3587 save_p_scs = p_scs; |
26850
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
3588 if (st->ins_buf->b_p_inf) |
26817
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3589 p_scs = FALSE; |
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3590 |
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3591 // Buffers other than curbuf are scanned from the beginning or the |
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3592 // end but never from the middle, thus setting nowrapscan in this |
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3593 // buffer is a good idea, on the other hand, we always set |
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3594 // wrapscan for curbuf to avoid missing matches -- Acevedo,Webb |
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3595 save_p_ws = p_ws; |
26850
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
3596 if (st->ins_buf != curbuf) |
26817
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3597 p_ws = FALSE; |
26850
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
3598 else if (*st->e_cpt == '.') |
26817
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3599 p_ws = TRUE; |
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3600 looped_around = FALSE; |
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3601 for (;;) |
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3602 { |
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3603 int cont_s_ipos = FALSE; |
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3604 |
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3605 ++msg_silent; // Don't want messages for wrapscan. |
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3606 |
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3607 // ctrl_x_mode_line_or_eval() || word-wise search that |
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3608 // has added a word that was at the beginning of the line |
26944
8dbdd68627bd
patch 8.2.4001: insert complete code uses global variables
Bram Moolenaar <Bram@vim.org>
parents:
26921
diff
changeset
|
3609 if (ctrl_x_mode_line_or_eval() || (compl_cont_status & CONT_SOL)) |
26850
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
3610 found_new_match = search_for_exact_line(st->ins_buf, |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
3611 st->cur_match_pos, compl_direction, compl_pattern); |
26817
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3612 else |
26850
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
3613 found_new_match = searchit(NULL, st->ins_buf, st->cur_match_pos, |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
3614 NULL, compl_direction, compl_pattern, 1L, |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
3615 SEARCH_KEEP + SEARCH_NFMSG, RE_LAST, NULL); |
26817
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3616 --msg_silent; |
26850
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
3617 if (!compl_started || st->set_match_pos) |
26817
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3618 { |
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3619 // set "compl_started" even on fail |
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3620 compl_started = TRUE; |
26850
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
3621 st->first_match_pos = *st->cur_match_pos; |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
3622 st->last_match_pos = *st->cur_match_pos; |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
3623 st->set_match_pos = FALSE; |
26817
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3624 } |
26850
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
3625 else if (st->first_match_pos.lnum == st->last_match_pos.lnum |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
3626 && st->first_match_pos.col == st->last_match_pos.col) |
26817
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3627 { |
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3628 found_new_match = FAIL; |
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3629 } |
26944
8dbdd68627bd
patch 8.2.4001: insert complete code uses global variables
Bram Moolenaar <Bram@vim.org>
parents:
26921
diff
changeset
|
3630 else if (compl_dir_forward() |
26850
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
3631 && (st->prev_match_pos.lnum > st->cur_match_pos->lnum |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
3632 || (st->prev_match_pos.lnum == st->cur_match_pos->lnum |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
3633 && st->prev_match_pos.col >= st->cur_match_pos->col))) |
26817
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3634 { |
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3635 if (looped_around) |
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3636 found_new_match = FAIL; |
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3637 else |
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3638 looped_around = TRUE; |
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3639 } |
26944
8dbdd68627bd
patch 8.2.4001: insert complete code uses global variables
Bram Moolenaar <Bram@vim.org>
parents:
26921
diff
changeset
|
3640 else if (!compl_dir_forward() |
26850
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
3641 && (st->prev_match_pos.lnum < st->cur_match_pos->lnum |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
3642 || (st->prev_match_pos.lnum == st->cur_match_pos->lnum |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
3643 && st->prev_match_pos.col <= st->cur_match_pos->col))) |
26817
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3644 { |
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3645 if (looped_around) |
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3646 found_new_match = FAIL; |
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3647 else |
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3648 looped_around = TRUE; |
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3649 } |
26850
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
3650 st->prev_match_pos = *st->cur_match_pos; |
26817
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3651 if (found_new_match == FAIL) |
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3652 break; |
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3653 |
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3654 // when ADDING, the text before the cursor matches, skip it |
26944
8dbdd68627bd
patch 8.2.4001: insert complete code uses global variables
Bram Moolenaar <Bram@vim.org>
parents:
26921
diff
changeset
|
3655 if (compl_status_adding() && st->ins_buf == curbuf |
26850
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
3656 && start_pos->lnum == st->cur_match_pos->lnum |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
3657 && start_pos->col == st->cur_match_pos->col) |
26817
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3658 continue; |
26831
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
3659 |
26850
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
3660 ptr = ins_comp_get_next_word_or_line(st->ins_buf, st->cur_match_pos, |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
3661 &len, &cont_s_ipos); |
26831
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
3662 if (ptr == NULL) |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
3663 continue; |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
3664 |
26817
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3665 if (ins_compl_add_infercase(ptr, len, p_ic, |
26850
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
3666 st->ins_buf == curbuf ? NULL : st->ins_buf->b_sfname, |
26817
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3667 0, cont_s_ipos) != NOTDONE) |
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3668 { |
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3669 found_new_match = OK; |
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3670 break; |
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3671 } |
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3672 } |
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3673 p_scs = save_p_scs; |
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3674 p_ws = save_p_ws; |
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3675 |
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3676 return found_new_match; |
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3677 } |
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3678 |
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3679 /* |
26944
8dbdd68627bd
patch 8.2.4001: insert complete code uses global variables
Bram Moolenaar <Bram@vim.org>
parents:
26921
diff
changeset
|
3680 * get the next set of completion matches for "type". |
26850
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
3681 * Returns TRUE if a new match is found. Otherwise returns FALSE. |
16142
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3682 */ |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3683 static int |
26850
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
3684 get_next_completion_match(int type, ins_compl_next_state_T *st, pos_T *ini) |
16142
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3685 { |
26850
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
3686 int found_new_match = FALSE; |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
3687 |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
3688 switch (type) |
16142
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3689 { |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3690 case -1: |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3691 break; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3692 #ifdef FEAT_FIND_ID |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3693 case CTRL_X_PATH_PATTERNS: |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3694 case CTRL_X_PATH_DEFINES: |
26817
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3695 get_next_include_file_completion(type); |
16142
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3696 break; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3697 #endif |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3698 |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3699 case CTRL_X_DICTIONARY: |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3700 case CTRL_X_THESAURUS: |
26850
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
3701 get_next_dict_tsr_completion(type, st->dict, st->dict_f); |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
3702 st->dict = NULL; |
16142
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3703 break; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3704 |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3705 case CTRL_X_TAGS: |
26817
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3706 get_next_tag_completion(); |
16142
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3707 break; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3708 |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3709 case CTRL_X_FILES: |
26817
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3710 get_next_filename_completion(); |
16142
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3711 break; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3712 |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3713 case CTRL_X_CMDLINE: |
25707
31db9c6df4e3
patch 8.2.3389: cannot stop insert mode completion without side effects
Bram Moolenaar <Bram@vim.org>
parents:
25513
diff
changeset
|
3714 case CTRL_X_CMDLINE_CTRL_X: |
26817
a8ded20a59e6
patch 8.2.3937: Insert mode completion function is too long
Bram Moolenaar <Bram@vim.org>
parents:
26773
diff
changeset
|
3715 get_next_cmdline_completion(); |
16142
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3716 break; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3717 |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3718 #ifdef FEAT_COMPL_FUNC |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3719 case CTRL_X_FUNCTION: |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3720 case CTRL_X_OMNI: |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3721 expand_by_function(type, compl_pattern); |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3722 break; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3723 #endif |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3724 |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3725 case CTRL_X_SPELL: |
26850
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
3726 get_next_spell_completion(st->first_match_pos.lnum); |
16142
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3727 break; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3728 |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3729 default: // normal ^P/^N and ^X^L |
26850
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
3730 found_new_match = get_next_default_completion(st, ini); |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
3731 if (found_new_match == FAIL && st->ins_buf == curbuf) |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
3732 st->found_all = TRUE; |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
3733 } |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
3734 |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
3735 // check if compl_curr_match has changed, (e.g. other type of |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
3736 // expansion added something) |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
3737 if (type != 0 && compl_curr_match != compl_old_match) |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
3738 found_new_match = OK; |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
3739 |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
3740 return found_new_match; |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
3741 } |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
3742 |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
3743 /* |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
3744 * Get the next expansion(s), using "compl_pattern". |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
3745 * The search starts at position "ini" in curbuf and in the direction |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
3746 * compl_direction. |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
3747 * When "compl_started" is FALSE start at that position, otherwise continue |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
3748 * where we stopped searching before. |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
3749 * This may return before finding all the matches. |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
3750 * Return the total number of matches or -1 if still unknown -- Acevedo |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
3751 */ |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
3752 static int |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
3753 ins_compl_get_exp(pos_T *ini) |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
3754 { |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
3755 static ins_compl_next_state_T st; |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
3756 int i; |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
3757 int found_new_match; |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
3758 int type = ctrl_x_mode; |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
3759 |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
3760 if (!compl_started) |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
3761 { |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
3762 FOR_ALL_BUFFERS(st.ins_buf) |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
3763 st.ins_buf->b_scanned = 0; |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
3764 st.found_all = FALSE; |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
3765 st.ins_buf = curbuf; |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
3766 st.e_cpt = (compl_cont_status & CONT_LOCAL) |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
3767 ? (char_u *)"." : curbuf->b_p_cpt; |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
3768 st.last_match_pos = st.first_match_pos = *ini; |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
3769 } |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
3770 else if (st.ins_buf != curbuf && !buf_valid(st.ins_buf)) |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
3771 st.ins_buf = curbuf; // In case the buffer was wiped out. |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
3772 |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
3773 compl_old_match = compl_curr_match; // remember the last current match |
26944
8dbdd68627bd
patch 8.2.4001: insert complete code uses global variables
Bram Moolenaar <Bram@vim.org>
parents:
26921
diff
changeset
|
3774 st.cur_match_pos = (compl_dir_forward()) |
26850
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
3775 ? &st.last_match_pos : &st.first_match_pos; |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
3776 |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
3777 // For ^N/^P loop over all the flags/windows/buffers in 'complete'. |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
3778 for (;;) |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
3779 { |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
3780 found_new_match = FAIL; |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
3781 st.set_match_pos = FALSE; |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
3782 |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
3783 // For ^N/^P pick a new entry from e_cpt if compl_started is off, |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
3784 // or if found_all says this entry is done. For ^X^L only use the |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
3785 // entries from 'complete' that look in loaded buffers. |
26944
8dbdd68627bd
patch 8.2.4001: insert complete code uses global variables
Bram Moolenaar <Bram@vim.org>
parents:
26921
diff
changeset
|
3786 if ((ctrl_x_mode_normal() || ctrl_x_mode_line_or_eval()) |
26850
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
3787 && (!compl_started || st.found_all)) |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
3788 { |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
3789 int status = process_next_cpt_value(&st, &type, ini); |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
3790 |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
3791 if (status == INS_COMPL_CPT_END) |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
3792 break; |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
3793 if (status == INS_COMPL_CPT_CONT) |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
3794 continue; |
16142
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3795 } |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3796 |
26850
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
3797 // If complete() was called then compl_pattern has been reset. The |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
3798 // following won't work then, bail out. |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
3799 if (compl_pattern == NULL) |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
3800 break; |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
3801 |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
3802 // get the next set of completion matches |
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
3803 found_new_match = get_next_completion_match(type, &st, ini); |
16142
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3804 |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3805 // break the loop for specialized modes (use 'complete' just for the |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3806 // generic ctrl_x_mode == CTRL_X_NORMAL) or when we've found a new |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3807 // match |
26944
8dbdd68627bd
patch 8.2.4001: insert complete code uses global variables
Bram Moolenaar <Bram@vim.org>
parents:
26921
diff
changeset
|
3808 if ((ctrl_x_mode_not_default() && !ctrl_x_mode_line_or_eval()) |
8dbdd68627bd
patch 8.2.4001: insert complete code uses global variables
Bram Moolenaar <Bram@vim.org>
parents:
26921
diff
changeset
|
3809 || found_new_match != FAIL) |
16142
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3810 { |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3811 if (got_int) |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3812 break; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3813 // Fill the popup menu as soon as possible. |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3814 if (type != -1) |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3815 ins_compl_check_keys(0, FALSE); |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3816 |
26944
8dbdd68627bd
patch 8.2.4001: insert complete code uses global variables
Bram Moolenaar <Bram@vim.org>
parents:
26921
diff
changeset
|
3817 if ((ctrl_x_mode_not_default() |
16142
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3818 && !ctrl_x_mode_line_or_eval()) || compl_interrupted) |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3819 break; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3820 compl_started = TRUE; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3821 } |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3822 else |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3823 { |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3824 // Mark a buffer scanned when it has been scanned completely |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3825 if (type == 0 || type == CTRL_X_PATH_PATTERNS) |
26850
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
3826 st.ins_buf->b_scanned = TRUE; |
16142
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3827 |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3828 compl_started = FALSE; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3829 } |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3830 } |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3831 compl_started = TRUE; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3832 |
26944
8dbdd68627bd
patch 8.2.4001: insert complete code uses global variables
Bram Moolenaar <Bram@vim.org>
parents:
26921
diff
changeset
|
3833 if ((ctrl_x_mode_normal() || ctrl_x_mode_line_or_eval()) |
26850
40c184a6b54b
patch 8.2.3953: insert completion code is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26831
diff
changeset
|
3834 && *st.e_cpt == NUL) // Got to end of 'complete' |
16142
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3835 found_new_match = FAIL; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3836 |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3837 i = -1; // total of matches, unknown |
26944
8dbdd68627bd
patch 8.2.4001: insert complete code uses global variables
Bram Moolenaar <Bram@vim.org>
parents:
26921
diff
changeset
|
3838 if (found_new_match == FAIL || (ctrl_x_mode_not_default() |
16142
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3839 && !ctrl_x_mode_line_or_eval())) |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3840 i = ins_compl_make_cyclic(); |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3841 |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3842 if (compl_old_match != NULL) |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3843 { |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3844 // If several matches were added (FORWARD) or the search failed and has |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3845 // just been made cyclic then we have to move compl_curr_match to the |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3846 // next or previous entry (if any) -- Acevedo |
26944
8dbdd68627bd
patch 8.2.4001: insert complete code uses global variables
Bram Moolenaar <Bram@vim.org>
parents:
26921
diff
changeset
|
3847 compl_curr_match = compl_dir_forward() ? compl_old_match->cp_next |
16142
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3848 : compl_old_match->cp_prev; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3849 if (compl_curr_match == NULL) |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3850 compl_curr_match = compl_old_match; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3851 } |
28397
d1702731786c
patch 8.2.4723: the ModeChanged autocmd event is inefficient
Bram Moolenaar <Bram@vim.org>
parents:
27140
diff
changeset
|
3852 may_trigger_modechanged(); |
26042
6b39ab99e367
patch 8.2.3555: ModeChanged is not triggered on every mode change
Bram Moolenaar <Bram@vim.org>
parents:
25990
diff
changeset
|
3853 |
16142
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3854 return i; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3855 } |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3856 |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3857 /* |
26831
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
3858 * Update "compl_shown_match" to the actually shown match, it may differ when |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
3859 * "compl_leader" is used to omit some of the matches. |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
3860 */ |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
3861 static void |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
3862 ins_compl_update_shown_match(void) |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
3863 { |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
3864 while (!ins_compl_equal(compl_shown_match, |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
3865 compl_leader, (int)STRLEN(compl_leader)) |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
3866 && compl_shown_match->cp_next != NULL |
26944
8dbdd68627bd
patch 8.2.4001: insert complete code uses global variables
Bram Moolenaar <Bram@vim.org>
parents:
26921
diff
changeset
|
3867 && !is_first_match(compl_shown_match->cp_next)) |
26831
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
3868 compl_shown_match = compl_shown_match->cp_next; |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
3869 |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
3870 // If we didn't find it searching forward, and compl_shows_dir is |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
3871 // backward, find the last match. |
26944
8dbdd68627bd
patch 8.2.4001: insert complete code uses global variables
Bram Moolenaar <Bram@vim.org>
parents:
26921
diff
changeset
|
3872 if (compl_shows_dir_backward() |
26831
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
3873 && !ins_compl_equal(compl_shown_match, |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
3874 compl_leader, (int)STRLEN(compl_leader)) |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
3875 && (compl_shown_match->cp_next == NULL |
26944
8dbdd68627bd
patch 8.2.4001: insert complete code uses global variables
Bram Moolenaar <Bram@vim.org>
parents:
26921
diff
changeset
|
3876 || is_first_match(compl_shown_match->cp_next))) |
26831
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
3877 { |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
3878 while (!ins_compl_equal(compl_shown_match, |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
3879 compl_leader, (int)STRLEN(compl_leader)) |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
3880 && compl_shown_match->cp_prev != NULL |
26944
8dbdd68627bd
patch 8.2.4001: insert complete code uses global variables
Bram Moolenaar <Bram@vim.org>
parents:
26921
diff
changeset
|
3881 && !is_first_match(compl_shown_match->cp_prev)) |
26831
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
3882 compl_shown_match = compl_shown_match->cp_prev; |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
3883 } |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
3884 } |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
3885 |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
3886 /* |
16142
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3887 * Delete the old text being completed. |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3888 */ |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3889 void |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3890 ins_compl_delete(void) |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3891 { |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3892 int col; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3893 |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3894 // In insert mode: Delete the typed part. |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3895 // In replace mode: Put the old characters back, if any. |
26944
8dbdd68627bd
patch 8.2.4001: insert complete code uses global variables
Bram Moolenaar <Bram@vim.org>
parents:
26921
diff
changeset
|
3896 col = compl_col + (compl_status_adding() ? compl_length : 0); |
16142
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3897 if ((int)curwin->w_cursor.col > col) |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3898 { |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3899 if (stop_arrow() == FAIL) |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3900 return; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3901 backspace_until_column(col); |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3902 } |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3903 |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3904 // TODO: is this sufficient for redrawing? Redrawing everything causes |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3905 // flicker, thus we can't do that. |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3906 changed_cline_bef_curs(); |
17813
8ca20b0a3dc3
patch 8.1.1903: cannot build without the +eval feature
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
3907 #ifdef FEAT_EVAL |
16142
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3908 // clear v:completed_item |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3909 set_vim_var_dict(VV_COMPLETED_ITEM, dict_alloc_lock(VAR_FIXED)); |
17813
8ca20b0a3dc3
patch 8.1.1903: cannot build without the +eval feature
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
3910 #endif |
16142
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3911 } |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3912 |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3913 /* |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3914 * Insert the new text being completed. |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3915 * "in_compl_func" is TRUE when called from complete_check(). |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3916 */ |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3917 void |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3918 ins_compl_insert(int in_compl_func) |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3919 { |
26944
8dbdd68627bd
patch 8.2.4001: insert complete code uses global variables
Bram Moolenaar <Bram@vim.org>
parents:
26921
diff
changeset
|
3920 int compl_len = get_compl_len(); |
26773
80e134cbee4b
patch 8.2.3915: illegal memory access when completing with invalid bytes
Bram Moolenaar <Bram@vim.org>
parents:
26767
diff
changeset
|
3921 |
80e134cbee4b
patch 8.2.3915: illegal memory access when completing with invalid bytes
Bram Moolenaar <Bram@vim.org>
parents:
26767
diff
changeset
|
3922 // Make sure we don't go over the end of the string, this can happen with |
80e134cbee4b
patch 8.2.3915: illegal memory access when completing with invalid bytes
Bram Moolenaar <Bram@vim.org>
parents:
26767
diff
changeset
|
3923 // illegal bytes. |
80e134cbee4b
patch 8.2.3915: illegal memory access when completing with invalid bytes
Bram Moolenaar <Bram@vim.org>
parents:
26767
diff
changeset
|
3924 if (compl_len < (int)STRLEN(compl_shown_match->cp_str)) |
80e134cbee4b
patch 8.2.3915: illegal memory access when completing with invalid bytes
Bram Moolenaar <Bram@vim.org>
parents:
26767
diff
changeset
|
3925 ins_bytes(compl_shown_match->cp_str + compl_len); |
26944
8dbdd68627bd
patch 8.2.4001: insert complete code uses global variables
Bram Moolenaar <Bram@vim.org>
parents:
26921
diff
changeset
|
3926 if (match_at_original_text(compl_shown_match)) |
16142
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3927 compl_used_match = FALSE; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3928 else |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3929 compl_used_match = TRUE; |
17813
8ca20b0a3dc3
patch 8.1.1903: cannot build without the +eval feature
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
3930 #ifdef FEAT_EVAL |
8ca20b0a3dc3
patch 8.1.1903: cannot build without the +eval feature
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
3931 { |
8ca20b0a3dc3
patch 8.1.1903: cannot build without the +eval feature
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
3932 dict_T *dict = ins_compl_dict_alloc(compl_shown_match); |
8ca20b0a3dc3
patch 8.1.1903: cannot build without the +eval feature
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
3933 |
8ca20b0a3dc3
patch 8.1.1903: cannot build without the +eval feature
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
3934 set_vim_var_dict(VV_COMPLETED_ITEM, dict); |
8ca20b0a3dc3
patch 8.1.1903: cannot build without the +eval feature
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
3935 } |
8ca20b0a3dc3
patch 8.1.1903: cannot build without the +eval feature
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
3936 #endif |
16142
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3937 if (!in_compl_func) |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3938 compl_curr_match = compl_shown_match; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3939 } |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3940 |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3941 /* |
26831
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
3942 * show the file name for the completion match (if any). Truncate the file |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
3943 * name to avoid a wait for return. |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
3944 */ |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
3945 static void |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
3946 ins_compl_show_filename(void) |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
3947 { |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
3948 char *lead = _("match in file"); |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
3949 int space = sc_col - vim_strsize((char_u *)lead) - 2; |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
3950 char_u *s; |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
3951 char_u *e; |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
3952 |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
3953 if (space <= 0) |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
3954 return; |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
3955 |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
3956 // We need the tail that fits. With double-byte encoding going |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
3957 // back from the end is very slow, thus go from the start and keep |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
3958 // the text that fits in "space" between "s" and "e". |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
3959 for (s = e = compl_shown_match->cp_fname; *e != NUL; MB_PTR_ADV(e)) |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
3960 { |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
3961 space -= ptr2cells(e); |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
3962 while (space < 0) |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
3963 { |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
3964 space += ptr2cells(s); |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
3965 MB_PTR_ADV(s); |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
3966 } |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
3967 } |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
3968 msg_hist_off = TRUE; |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
3969 vim_snprintf((char *)IObuff, IOSIZE, "%s %s%s", lead, |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
3970 s > compl_shown_match->cp_fname ? "<" : "", s); |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
3971 msg((char *)IObuff); |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
3972 msg_hist_off = FALSE; |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
3973 redraw_cmdline = FALSE; // don't overwrite! |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
3974 } |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
3975 |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
3976 /* |
26944
8dbdd68627bd
patch 8.2.4001: insert complete code uses global variables
Bram Moolenaar <Bram@vim.org>
parents:
26921
diff
changeset
|
3977 * Find the next set of matches for completion. Repeat the completion "todo" |
26831
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
3978 * times. The number of matches found is returned in 'num_matches'. |
16142
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3979 * |
26831
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
3980 * If "allow_get_expansion" is TRUE, then ins_compl_get_exp() may be called to |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
3981 * get more completions. If it is FALSE, then do nothing when there are no more |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
3982 * completions in the given direction. |
16142
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3983 * |
26831
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
3984 * If "advance" is TRUE, then completion will move to the first match. |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
3985 * Otherwise, the original text will be shown. |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
3986 * |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
3987 * Returns OK on success and -1 if the number of matches are unknown. |
16142
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3988 */ |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3989 static int |
26831
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
3990 find_next_completion_match( |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
3991 int allow_get_expansion, |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
3992 int todo, // repeat completion this many times |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
3993 int advance, |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
3994 int *num_matches) |
16142
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3995 { |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3996 int found_end = FALSE; |
26831
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
3997 compl_T *found_compl = NULL; |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
3998 |
16142
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3999 while (--todo >= 0) |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4000 { |
26944
8dbdd68627bd
patch 8.2.4001: insert complete code uses global variables
Bram Moolenaar <Bram@vim.org>
parents:
26921
diff
changeset
|
4001 if (compl_shows_dir_forward() && compl_shown_match->cp_next != NULL) |
16142
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4002 { |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4003 compl_shown_match = compl_shown_match->cp_next; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4004 found_end = (compl_first_match != NULL |
26944
8dbdd68627bd
patch 8.2.4001: insert complete code uses global variables
Bram Moolenaar <Bram@vim.org>
parents:
26921
diff
changeset
|
4005 && (is_first_match(compl_shown_match->cp_next) |
8dbdd68627bd
patch 8.2.4001: insert complete code uses global variables
Bram Moolenaar <Bram@vim.org>
parents:
26921
diff
changeset
|
4006 || is_first_match(compl_shown_match))); |
16142
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4007 } |
26944
8dbdd68627bd
patch 8.2.4001: insert complete code uses global variables
Bram Moolenaar <Bram@vim.org>
parents:
26921
diff
changeset
|
4008 else if (compl_shows_dir_backward() |
26831
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4009 && compl_shown_match->cp_prev != NULL) |
16142
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4010 { |
26944
8dbdd68627bd
patch 8.2.4001: insert complete code uses global variables
Bram Moolenaar <Bram@vim.org>
parents:
26921
diff
changeset
|
4011 found_end = is_first_match(compl_shown_match); |
16142
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4012 compl_shown_match = compl_shown_match->cp_prev; |
26944
8dbdd68627bd
patch 8.2.4001: insert complete code uses global variables
Bram Moolenaar <Bram@vim.org>
parents:
26921
diff
changeset
|
4013 found_end |= is_first_match(compl_shown_match); |
16142
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4014 } |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4015 else |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4016 { |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4017 if (!allow_get_expansion) |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4018 { |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4019 if (advance) |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4020 { |
26944
8dbdd68627bd
patch 8.2.4001: insert complete code uses global variables
Bram Moolenaar <Bram@vim.org>
parents:
26921
diff
changeset
|
4021 if (compl_shows_dir_backward()) |
16142
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4022 compl_pending -= todo + 1; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4023 else |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4024 compl_pending += todo + 1; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4025 } |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4026 return -1; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4027 } |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4028 |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4029 if (!compl_no_select && advance) |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4030 { |
26944
8dbdd68627bd
patch 8.2.4001: insert complete code uses global variables
Bram Moolenaar <Bram@vim.org>
parents:
26921
diff
changeset
|
4031 if (compl_shows_dir_backward()) |
16142
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4032 --compl_pending; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4033 else |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4034 ++compl_pending; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4035 } |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4036 |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4037 // Find matches. |
26831
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4038 *num_matches = ins_compl_get_exp(&compl_startpos); |
16142
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4039 |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4040 // handle any pending completions |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4041 while (compl_pending != 0 && compl_direction == compl_shows_dir |
26831
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4042 && advance) |
16142
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4043 { |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4044 if (compl_pending > 0 && compl_shown_match->cp_next != NULL) |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4045 { |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4046 compl_shown_match = compl_shown_match->cp_next; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4047 --compl_pending; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4048 } |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4049 if (compl_pending < 0 && compl_shown_match->cp_prev != NULL) |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4050 { |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4051 compl_shown_match = compl_shown_match->cp_prev; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4052 ++compl_pending; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4053 } |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4054 else |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4055 break; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4056 } |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4057 found_end = FALSE; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4058 } |
26944
8dbdd68627bd
patch 8.2.4001: insert complete code uses global variables
Bram Moolenaar <Bram@vim.org>
parents:
26921
diff
changeset
|
4059 if (!match_at_original_text(compl_shown_match) |
16142
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4060 && compl_leader != NULL |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4061 && !ins_compl_equal(compl_shown_match, |
26831
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4062 compl_leader, (int)STRLEN(compl_leader))) |
16142
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4063 ++todo; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4064 else |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4065 // Remember a matching item. |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4066 found_compl = compl_shown_match; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4067 |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4068 // Stop at the end of the list when we found a usable match. |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4069 if (found_end) |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4070 { |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4071 if (found_compl != NULL) |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4072 { |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4073 compl_shown_match = found_compl; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4074 break; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4075 } |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4076 todo = 1; // use first usable match after wrapping around |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4077 } |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4078 } |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4079 |
26831
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4080 return OK; |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4081 } |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4082 |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4083 /* |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4084 * Fill in the next completion in the current direction. |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4085 * If "allow_get_expansion" is TRUE, then we may call ins_compl_get_exp() to |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4086 * get more completions. If it is FALSE, then we just do nothing when there |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4087 * are no more completions in a given direction. The latter case is used when |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4088 * we are still in the middle of finding completions, to allow browsing |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4089 * through the ones found so far. |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4090 * Return the total number of matches, or -1 if still unknown -- webb. |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4091 * |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4092 * compl_curr_match is currently being used by ins_compl_get_exp(), so we use |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4093 * compl_shown_match here. |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4094 * |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4095 * Note that this function may be called recursively once only. First with |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4096 * "allow_get_expansion" TRUE, which calls ins_compl_get_exp(), which in turn |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4097 * calls this function with "allow_get_expansion" FALSE. |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4098 */ |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4099 static int |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4100 ins_compl_next( |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4101 int allow_get_expansion, |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4102 int count, // repeat completion this many times; should |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4103 // be at least 1 |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4104 int insert_match, // Insert the newly selected match |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4105 int in_compl_func) // called from complete_check() |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4106 { |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4107 int num_matches = -1; |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4108 int todo = count; |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4109 int advance; |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4110 int started = compl_started; |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4111 |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4112 // When user complete function return -1 for findstart which is next |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4113 // time of 'always', compl_shown_match become NULL. |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4114 if (compl_shown_match == NULL) |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4115 return -1; |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4116 |
26944
8dbdd68627bd
patch 8.2.4001: insert complete code uses global variables
Bram Moolenaar <Bram@vim.org>
parents:
26921
diff
changeset
|
4117 if (compl_leader != NULL && !match_at_original_text(compl_shown_match)) |
26831
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4118 // Update "compl_shown_match" to the actually shown match |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4119 ins_compl_update_shown_match(); |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4120 |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4121 if (allow_get_expansion && insert_match |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4122 && (!(compl_get_longest || compl_restarting) || compl_used_match)) |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4123 // Delete old text to be replaced |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4124 ins_compl_delete(); |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4125 |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4126 // When finding the longest common text we stick at the original text, |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4127 // don't let CTRL-N or CTRL-P move to the first match. |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4128 advance = count != 1 || !allow_get_expansion || !compl_get_longest; |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4129 |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4130 // When restarting the search don't insert the first match either. |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4131 if (compl_restarting) |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4132 { |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4133 advance = FALSE; |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4134 compl_restarting = FALSE; |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4135 } |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4136 |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4137 // Repeat this for when <PageUp> or <PageDown> is typed. But don't wrap |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4138 // around. |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4139 if (find_next_completion_match(allow_get_expansion, todo, advance, |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4140 &num_matches) == -1) |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4141 return -1; |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4142 |
16142
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4143 // Insert the text of the new completion, or the compl_leader. |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4144 if (compl_no_insert && !started) |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4145 { |
26944
8dbdd68627bd
patch 8.2.4001: insert complete code uses global variables
Bram Moolenaar <Bram@vim.org>
parents:
26921
diff
changeset
|
4146 ins_bytes(compl_orig_text + get_compl_len()); |
16142
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4147 compl_used_match = FALSE; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4148 } |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4149 else if (insert_match) |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4150 { |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4151 if (!compl_get_longest || compl_used_match) |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4152 ins_compl_insert(in_compl_func); |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4153 else |
26944
8dbdd68627bd
patch 8.2.4001: insert complete code uses global variables
Bram Moolenaar <Bram@vim.org>
parents:
26921
diff
changeset
|
4154 ins_bytes(compl_leader + get_compl_len()); |
16142
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4155 } |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4156 else |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4157 compl_used_match = FALSE; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4158 |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4159 if (!allow_get_expansion) |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4160 { |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4161 // may undisplay the popup menu first |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4162 ins_compl_upd_pum(); |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4163 |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4164 if (pum_enough_matches()) |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4165 // Will display the popup menu, don't redraw yet to avoid flicker. |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4166 pum_call_update_screen(); |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4167 else |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4168 // Not showing the popup menu yet, redraw to show the user what was |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4169 // inserted. |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4170 update_screen(0); |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4171 |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4172 // display the updated popup menu |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4173 ins_compl_show_pum(); |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4174 #ifdef FEAT_GUI |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4175 if (gui.in_use) |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4176 { |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4177 // Show the cursor after the match, not after the redrawn text. |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4178 setcursor(); |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4179 out_flush_cursor(FALSE, FALSE); |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4180 } |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4181 #endif |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4182 |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4183 // Delete old text to be replaced, since we're still searching and |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4184 // don't want to match ourselves! |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4185 ins_compl_delete(); |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4186 } |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4187 |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4188 // Enter will select a match when the match wasn't inserted and the popup |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4189 // menu is visible. |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4190 if (compl_no_insert && !started) |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4191 compl_enter_selects = TRUE; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4192 else |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4193 compl_enter_selects = !insert_match && compl_match_array != NULL; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4194 |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4195 // Show the file name for the match (if any) |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4196 if (compl_shown_match->cp_fname != NULL) |
26831
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4197 ins_compl_show_filename(); |
16142
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4198 |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4199 return num_matches; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4200 } |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4201 |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4202 /* |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4203 * Call this while finding completions, to check whether the user has hit a key |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4204 * that should change the currently displayed completion, or exit completion |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4205 * mode. Also, when compl_pending is not zero, show a completion as soon as |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4206 * possible. -- webb |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4207 * "frequency" specifies out of how many calls we actually check. |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4208 * "in_compl_func" is TRUE when called from complete_check(), don't set |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4209 * compl_curr_match. |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4210 */ |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4211 void |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4212 ins_compl_check_keys(int frequency, int in_compl_func) |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4213 { |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4214 static int count = 0; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4215 int c; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4216 |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4217 // Don't check when reading keys from a script, :normal or feedkeys(). |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4218 // That would break the test scripts. But do check for keys when called |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4219 // from complete_check(). |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4220 if (!in_compl_func && (using_script() || ex_normal_busy)) |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4221 return; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4222 |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4223 // Only do this at regular intervals |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4224 if (++count < frequency) |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4225 return; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4226 count = 0; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4227 |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4228 // Check for a typed key. Do use mappings, otherwise vim_is_ctrl_x_key() |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4229 // can't do its work correctly. |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4230 c = vpeekc_any(); |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4231 if (c != NUL) |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4232 { |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4233 if (vim_is_ctrl_x_key(c) && c != Ctrl_X && c != Ctrl_R) |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4234 { |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4235 c = safe_vgetc(); // Eat the character |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4236 compl_shows_dir = ins_compl_key2dir(c); |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4237 (void)ins_compl_next(FALSE, ins_compl_key2count(c), |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4238 c != K_UP && c != K_DOWN, in_compl_func); |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4239 } |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4240 else |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4241 { |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4242 // Need to get the character to have KeyTyped set. We'll put it |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4243 // back with vungetc() below. But skip K_IGNORE. |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4244 c = safe_vgetc(); |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4245 if (c != K_IGNORE) |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4246 { |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4247 // Don't interrupt completion when the character wasn't typed, |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4248 // e.g., when doing @q to replay keys. |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4249 if (c != Ctrl_R && KeyTyped) |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4250 compl_interrupted = TRUE; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4251 |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4252 vungetc(c); |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4253 } |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4254 } |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4255 } |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4256 if (compl_pending != 0 && !got_int && !compl_no_insert) |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4257 { |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4258 int todo = compl_pending > 0 ? compl_pending : -compl_pending; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4259 |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4260 compl_pending = 0; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4261 (void)ins_compl_next(FALSE, todo, TRUE, in_compl_func); |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4262 } |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4263 } |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4264 |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4265 /* |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4266 * Decide the direction of Insert mode complete from the key typed. |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4267 * Returns BACKWARD or FORWARD. |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4268 */ |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4269 static int |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4270 ins_compl_key2dir(int c) |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4271 { |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4272 if (c == Ctrl_P || c == Ctrl_L |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4273 || c == K_PAGEUP || c == K_KPAGEUP || c == K_S_UP || c == K_UP) |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4274 return BACKWARD; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4275 return FORWARD; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4276 } |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4277 |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4278 /* |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4279 * Return TRUE for keys that are used for completion only when the popup menu |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4280 * is visible. |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4281 */ |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4282 static int |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4283 ins_compl_pum_key(int c) |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4284 { |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4285 return pum_visible() && (c == K_PAGEUP || c == K_KPAGEUP || c == K_S_UP |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4286 || c == K_PAGEDOWN || c == K_KPAGEDOWN || c == K_S_DOWN |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4287 || c == K_UP || c == K_DOWN); |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4288 } |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4289 |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4290 /* |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4291 * Decide the number of completions to move forward. |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4292 * Returns 1 for most keys, height of the popup menu for page-up/down keys. |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4293 */ |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4294 static int |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4295 ins_compl_key2count(int c) |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4296 { |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4297 int h; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4298 |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4299 if (ins_compl_pum_key(c) && c != K_UP && c != K_DOWN) |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4300 { |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4301 h = pum_get_height(); |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4302 if (h > 3) |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4303 h -= 2; // keep some context |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4304 return h; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4305 } |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4306 return 1; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4307 } |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4308 |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4309 /* |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4310 * Return TRUE if completion with "c" should insert the match, FALSE if only |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4311 * to change the currently selected completion. |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4312 */ |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4313 static int |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4314 ins_compl_use_match(int c) |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4315 { |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4316 switch (c) |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4317 { |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4318 case K_UP: |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4319 case K_DOWN: |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4320 case K_PAGEDOWN: |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4321 case K_KPAGEDOWN: |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4322 case K_S_DOWN: |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4323 case K_PAGEUP: |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4324 case K_KPAGEUP: |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4325 case K_S_UP: |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4326 return FALSE; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4327 } |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4328 return TRUE; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4329 } |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4330 |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4331 /* |
26767
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4332 * Get the pattern, column and length for normal completion (CTRL-N CTRL-P |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4333 * completion) |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4334 * Sets the global variables: compl_col, compl_length and compl_pattern. |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4335 * Uses the global variables: compl_cont_status and ctrl_x_mode |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4336 */ |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4337 static int |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4338 get_normal_compl_info(char_u *line, int startcol, colnr_T curs_col) |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4339 { |
26944
8dbdd68627bd
patch 8.2.4001: insert complete code uses global variables
Bram Moolenaar <Bram@vim.org>
parents:
26921
diff
changeset
|
4340 if ((compl_cont_status & CONT_SOL) || ctrl_x_mode_path_defines()) |
26767
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4341 { |
26944
8dbdd68627bd
patch 8.2.4001: insert complete code uses global variables
Bram Moolenaar <Bram@vim.org>
parents:
26921
diff
changeset
|
4342 if (!compl_status_adding()) |
26767
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4343 { |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4344 while (--startcol >= 0 && vim_isIDc(line[startcol])) |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4345 ; |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4346 compl_col += ++startcol; |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4347 compl_length = curs_col - startcol; |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4348 } |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4349 if (p_ic) |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4350 compl_pattern = str_foldcase(line + compl_col, |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4351 compl_length, NULL, 0); |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4352 else |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4353 compl_pattern = vim_strnsave(line + compl_col, compl_length); |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4354 if (compl_pattern == NULL) |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4355 return FAIL; |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4356 } |
26944
8dbdd68627bd
patch 8.2.4001: insert complete code uses global variables
Bram Moolenaar <Bram@vim.org>
parents:
26921
diff
changeset
|
4357 else if (compl_status_adding()) |
26767
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4358 { |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4359 char_u *prefix = (char_u *)"\\<"; |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4360 |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4361 // we need up to 2 extra chars for the prefix |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4362 compl_pattern = alloc(quote_meta(NULL, line + compl_col, |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4363 compl_length) + 2); |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4364 if (compl_pattern == NULL) |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4365 return FAIL; |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4366 if (!vim_iswordp(line + compl_col) |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4367 || (compl_col > 0 |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4368 && (vim_iswordp(mb_prevptr(line, line + compl_col))))) |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4369 prefix = (char_u *)""; |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4370 STRCPY((char *)compl_pattern, prefix); |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4371 (void)quote_meta(compl_pattern + STRLEN(prefix), |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4372 line + compl_col, compl_length); |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4373 } |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4374 else if (--startcol < 0 |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4375 || !vim_iswordp(mb_prevptr(line, line + startcol + 1))) |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4376 { |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4377 // Match any word of at least two chars |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4378 compl_pattern = vim_strsave((char_u *)"\\<\\k\\k"); |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4379 if (compl_pattern == NULL) |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4380 return FAIL; |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4381 compl_col += curs_col; |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4382 compl_length = 0; |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4383 } |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4384 else |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4385 { |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4386 // Search the point of change class of multibyte character |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4387 // or not a word single byte character backward. |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4388 if (has_mbyte) |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4389 { |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4390 int base_class; |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4391 int head_off; |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4392 |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4393 startcol -= (*mb_head_off)(line, line + startcol); |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4394 base_class = mb_get_class(line + startcol); |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4395 while (--startcol >= 0) |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4396 { |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4397 head_off = (*mb_head_off)(line, line + startcol); |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4398 if (base_class != mb_get_class(line + startcol |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4399 - head_off)) |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4400 break; |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4401 startcol -= head_off; |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4402 } |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4403 } |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4404 else |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4405 while (--startcol >= 0 && vim_iswordc(line[startcol])) |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4406 ; |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4407 compl_col += ++startcol; |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4408 compl_length = (int)curs_col - startcol; |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4409 if (compl_length == 1) |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4410 { |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4411 // Only match word with at least two chars -- webb |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4412 // there's no need to call quote_meta, |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4413 // alloc(7) is enough -- Acevedo |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4414 compl_pattern = alloc(7); |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4415 if (compl_pattern == NULL) |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4416 return FAIL; |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4417 STRCPY((char *)compl_pattern, "\\<"); |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4418 (void)quote_meta(compl_pattern + 2, line + compl_col, 1); |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4419 STRCAT((char *)compl_pattern, "\\k"); |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4420 } |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4421 else |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4422 { |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4423 compl_pattern = alloc(quote_meta(NULL, line + compl_col, |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4424 compl_length) + 2); |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4425 if (compl_pattern == NULL) |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4426 return FAIL; |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4427 STRCPY((char *)compl_pattern, "\\<"); |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4428 (void)quote_meta(compl_pattern + 2, line + compl_col, |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4429 compl_length); |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4430 } |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4431 } |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4432 |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4433 return OK; |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4434 } |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4435 |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4436 /* |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4437 * Get the pattern, column and length for whole line completion or for the |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4438 * complete() function. |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4439 * Sets the global variables: compl_col, compl_length and compl_pattern. |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4440 */ |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4441 static int |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4442 get_wholeline_compl_info(char_u *line, colnr_T curs_col) |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4443 { |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4444 compl_col = (colnr_T)getwhitecols(line); |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4445 compl_length = (int)curs_col - (int)compl_col; |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4446 if (compl_length < 0) // cursor in indent: empty pattern |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4447 compl_length = 0; |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4448 if (p_ic) |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4449 compl_pattern = str_foldcase(line + compl_col, compl_length, |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4450 NULL, 0); |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4451 else |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4452 compl_pattern = vim_strnsave(line + compl_col, compl_length); |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4453 if (compl_pattern == NULL) |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4454 return FAIL; |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4455 |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4456 return OK; |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4457 } |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4458 |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4459 /* |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4460 * Get the pattern, column and length for filename completion. |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4461 * Sets the global variables: compl_col, compl_length and compl_pattern. |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4462 */ |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4463 static int |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4464 get_filename_compl_info(char_u *line, int startcol, colnr_T curs_col) |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4465 { |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4466 // Go back to just before the first filename character. |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4467 if (startcol > 0) |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4468 { |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4469 char_u *p = line + startcol; |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4470 |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4471 MB_PTR_BACK(line, p); |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4472 while (p > line && vim_isfilec(PTR2CHAR(p))) |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4473 MB_PTR_BACK(line, p); |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4474 if (p == line && vim_isfilec(PTR2CHAR(p))) |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4475 startcol = 0; |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4476 else |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4477 startcol = (int)(p - line) + 1; |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4478 } |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4479 |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4480 compl_col += startcol; |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4481 compl_length = (int)curs_col - startcol; |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4482 compl_pattern = addstar(line + compl_col, compl_length, EXPAND_FILES); |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4483 if (compl_pattern == NULL) |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4484 return FAIL; |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4485 |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4486 return OK; |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4487 } |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4488 |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4489 /* |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4490 * Get the pattern, column and length for command-line completion. |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4491 * Sets the global variables: compl_col, compl_length and compl_pattern. |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4492 */ |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4493 static int |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4494 get_cmdline_compl_info(char_u *line, colnr_T curs_col) |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4495 { |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4496 compl_pattern = vim_strnsave(line, curs_col); |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4497 if (compl_pattern == NULL) |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4498 return FAIL; |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4499 set_cmd_context(&compl_xp, compl_pattern, |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4500 (int)STRLEN(compl_pattern), curs_col, FALSE); |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4501 if (compl_xp.xp_context == EXPAND_UNSUCCESSFUL |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4502 || compl_xp.xp_context == EXPAND_NOTHING) |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4503 // No completion possible, use an empty pattern to get a |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4504 // "pattern not found" message. |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4505 compl_col = curs_col; |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4506 else |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4507 compl_col = (int)(compl_xp.xp_pattern - compl_pattern); |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4508 compl_length = curs_col - compl_col; |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4509 |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4510 return OK; |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4511 } |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4512 |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4513 /* |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4514 * Get the pattern, column and length for user defined completion ('omnifunc', |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4515 * 'completefunc' and 'thesaurusfunc') |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4516 * Sets the global variables: compl_col, compl_length and compl_pattern. |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4517 * Uses the global variable: spell_bad_len |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4518 */ |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4519 static int |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4520 get_userdefined_compl_info(colnr_T curs_col UNUSED) |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4521 { |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4522 int ret = FAIL; |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4523 |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4524 #ifdef FEAT_COMPL_FUNC |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4525 // Call user defined function 'completefunc' with "a:findstart" |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4526 // set to 1 to obtain the length of text to use for completion. |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4527 char_u *line; |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4528 typval_T args[3]; |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4529 int col; |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4530 char_u *funcname; |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4531 pos_T pos; |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4532 int save_State = State; |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4533 callback_T *cb; |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4534 |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4535 // Call 'completefunc' or 'omnifunc' or 'thesaurusfunc' and get pattern |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4536 // length as a string |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4537 funcname = get_complete_funcname(ctrl_x_mode); |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4538 if (*funcname == NUL) |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4539 { |
26944
8dbdd68627bd
patch 8.2.4001: insert complete code uses global variables
Bram Moolenaar <Bram@vim.org>
parents:
26921
diff
changeset
|
4540 semsg(_(e_option_str_is_not_set), ctrl_x_mode_function() |
26767
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4541 ? "completefunc" : "omnifunc"); |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4542 return FAIL; |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4543 } |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4544 |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4545 args[0].v_type = VAR_NUMBER; |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4546 args[0].vval.v_number = 1; |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4547 args[1].v_type = VAR_STRING; |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4548 args[1].vval.v_string = (char_u *)""; |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4549 args[2].v_type = VAR_UNKNOWN; |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4550 pos = curwin->w_cursor; |
29014
45c182c4f7e9
patch 8.2.5029: "textlock" is always zero
Bram Moolenaar <Bram@vim.org>
parents:
29000
diff
changeset
|
4551 ++textlock; |
26767
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4552 cb = get_insert_callback(ctrl_x_mode); |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4553 col = call_callback_retnr(cb, 2, args); |
29014
45c182c4f7e9
patch 8.2.5029: "textlock" is always zero
Bram Moolenaar <Bram@vim.org>
parents:
29000
diff
changeset
|
4554 --textlock; |
26767
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4555 |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4556 State = save_State; |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4557 curwin->w_cursor = pos; // restore the cursor position |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4558 validate_cursor(); |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4559 if (!EQUAL_POS(curwin->w_cursor, pos)) |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4560 { |
26962
85866e069c24
patch 8.2.4010: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26958
diff
changeset
|
4561 emsg(_(e_complete_function_deleted_text)); |
26767
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4562 return FAIL; |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4563 } |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4564 |
29000
7d28903e80df
patch 8.2.5022: 'completefunc'/'omnifunc' error does not end completion
Bram Moolenaar <Bram@vim.org>
parents:
28942
diff
changeset
|
4565 // Return value -2 means the user complete function wants to cancel the |
7d28903e80df
patch 8.2.5022: 'completefunc'/'omnifunc' error does not end completion
Bram Moolenaar <Bram@vim.org>
parents:
28942
diff
changeset
|
4566 // complete without an error, do the same if the function did not execute |
7d28903e80df
patch 8.2.5022: 'completefunc'/'omnifunc' error does not end completion
Bram Moolenaar <Bram@vim.org>
parents:
28942
diff
changeset
|
4567 // successfully. |
7d28903e80df
patch 8.2.5022: 'completefunc'/'omnifunc' error does not end completion
Bram Moolenaar <Bram@vim.org>
parents:
28942
diff
changeset
|
4568 if (col == -2 || aborting()) |
7d28903e80df
patch 8.2.5022: 'completefunc'/'omnifunc' error does not end completion
Bram Moolenaar <Bram@vim.org>
parents:
28942
diff
changeset
|
4569 return FAIL; |
26767
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4570 // Return value -3 does the same as -2 and leaves CTRL-X mode. |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4571 if (col == -3) |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4572 { |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4573 ctrl_x_mode = CTRL_X_NORMAL; |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4574 edit_submode = NULL; |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4575 if (!shortmess(SHM_COMPLETIONMENU)) |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4576 msg_clr_cmdline(); |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4577 return FAIL; |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4578 } |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4579 |
27016
1d9a7aa42744
patch 8.2.4037: Insert mode completion is insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
26962
diff
changeset
|
4580 // Reset extended parameters of completion, when starting new |
26767
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4581 // completion. |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4582 compl_opt_refresh_always = FALSE; |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4583 compl_opt_suppress_empty = FALSE; |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4584 |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4585 if (col < 0) |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4586 col = curs_col; |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4587 compl_col = col; |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4588 if (compl_col > curs_col) |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4589 compl_col = curs_col; |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4590 |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4591 // Setup variables for completion. Need to obtain "line" again, |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4592 // it may have become invalid. |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4593 line = ml_get(curwin->w_cursor.lnum); |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4594 compl_length = curs_col - compl_col; |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4595 compl_pattern = vim_strnsave(line + compl_col, compl_length); |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4596 if (compl_pattern == NULL) |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4597 return FAIL; |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4598 |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4599 ret = OK; |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4600 #endif |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4601 |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4602 return ret; |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4603 } |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4604 |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4605 /* |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4606 * Get the pattern, column and length for spell completion. |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4607 * Sets the global variables: compl_col, compl_length and compl_pattern. |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4608 * Uses the global variable: spell_bad_len |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4609 */ |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4610 static int |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4611 get_spell_compl_info(int startcol UNUSED, colnr_T curs_col UNUSED) |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4612 { |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4613 int ret = FAIL; |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4614 #ifdef FEAT_SPELL |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4615 char_u *line; |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4616 |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4617 if (spell_bad_len > 0) |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4618 compl_col = curs_col - spell_bad_len; |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4619 else |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4620 compl_col = spell_word_start(startcol); |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4621 if (compl_col >= (colnr_T)startcol) |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4622 { |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4623 compl_length = 0; |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4624 compl_col = curs_col; |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4625 } |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4626 else |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4627 { |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4628 spell_expand_check_cap(compl_col); |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4629 compl_length = (int)curs_col - compl_col; |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4630 } |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4631 // Need to obtain "line" again, it may have become invalid. |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4632 line = ml_get(curwin->w_cursor.lnum); |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4633 compl_pattern = vim_strnsave(line + compl_col, compl_length); |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4634 if (compl_pattern == NULL) |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4635 return FAIL; |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4636 |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4637 ret = OK; |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4638 #endif |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4639 |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4640 return ret; |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4641 } |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4642 |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4643 /* |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4644 * Get the completion pattern, column and length. |
26944
8dbdd68627bd
patch 8.2.4001: insert complete code uses global variables
Bram Moolenaar <Bram@vim.org>
parents:
26921
diff
changeset
|
4645 * "startcol" - start column number of the completion pattern/text |
8dbdd68627bd
patch 8.2.4001: insert complete code uses global variables
Bram Moolenaar <Bram@vim.org>
parents:
26921
diff
changeset
|
4646 * "cur_col" - current cursor column |
8dbdd68627bd
patch 8.2.4001: insert complete code uses global variables
Bram Moolenaar <Bram@vim.org>
parents:
26921
diff
changeset
|
4647 * On return, "line_invalid" is set to TRUE, if the current line may have |
8dbdd68627bd
patch 8.2.4001: insert complete code uses global variables
Bram Moolenaar <Bram@vim.org>
parents:
26921
diff
changeset
|
4648 * become invalid and needs to be fetched again. |
8dbdd68627bd
patch 8.2.4001: insert complete code uses global variables
Bram Moolenaar <Bram@vim.org>
parents:
26921
diff
changeset
|
4649 * Returns OK on success. |
26767
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4650 */ |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4651 static int |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4652 compl_get_info(char_u *line, int startcol, colnr_T curs_col, int *line_invalid) |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4653 { |
26944
8dbdd68627bd
patch 8.2.4001: insert complete code uses global variables
Bram Moolenaar <Bram@vim.org>
parents:
26921
diff
changeset
|
4654 if (ctrl_x_mode_normal() |
26767
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4655 || (ctrl_x_mode & CTRL_X_WANT_IDENT |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4656 && !thesaurus_func_complete(ctrl_x_mode))) |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4657 { |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4658 return get_normal_compl_info(line, startcol, curs_col); |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4659 } |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4660 else if (ctrl_x_mode_line_or_eval()) |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4661 { |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4662 return get_wholeline_compl_info(line, curs_col); |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4663 } |
26944
8dbdd68627bd
patch 8.2.4001: insert complete code uses global variables
Bram Moolenaar <Bram@vim.org>
parents:
26921
diff
changeset
|
4664 else if (ctrl_x_mode_files()) |
26767
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4665 { |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4666 return get_filename_compl_info(line, startcol, curs_col); |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4667 } |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4668 else if (ctrl_x_mode == CTRL_X_CMDLINE) |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4669 { |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4670 return get_cmdline_compl_info(line, curs_col); |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4671 } |
26944
8dbdd68627bd
patch 8.2.4001: insert complete code uses global variables
Bram Moolenaar <Bram@vim.org>
parents:
26921
diff
changeset
|
4672 else if (ctrl_x_mode_function() || ctrl_x_mode_omni() |
26767
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4673 || thesaurus_func_complete(ctrl_x_mode)) |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4674 { |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4675 if (get_userdefined_compl_info(curs_col) == FAIL) |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4676 return FAIL; |
26944
8dbdd68627bd
patch 8.2.4001: insert complete code uses global variables
Bram Moolenaar <Bram@vim.org>
parents:
26921
diff
changeset
|
4677 *line_invalid = TRUE; // "line" may have become invalid |
26767
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4678 } |
26944
8dbdd68627bd
patch 8.2.4001: insert complete code uses global variables
Bram Moolenaar <Bram@vim.org>
parents:
26921
diff
changeset
|
4679 else if (ctrl_x_mode_spell()) |
26767
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4680 { |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4681 if (get_spell_compl_info(startcol, curs_col) == FAIL) |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4682 return FAIL; |
26944
8dbdd68627bd
patch 8.2.4001: insert complete code uses global variables
Bram Moolenaar <Bram@vim.org>
parents:
26921
diff
changeset
|
4683 *line_invalid = TRUE; // "line" may have become invalid |
26767
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4684 } |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4685 else |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4686 { |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4687 internal_error("ins_complete()"); |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4688 return FAIL; |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4689 } |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4690 |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4691 return OK; |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4692 } |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4693 |
84d56c5b7f2b
patch 8.2.3912: the ins_complete() function is much too long
Bram Moolenaar <Bram@vim.org>
parents:
26518
diff
changeset
|
4694 /* |
26831
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4695 * Continue an interrupted completion mode search in "line". |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4696 * |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4697 * If this same ctrl_x_mode has been interrupted use the text from |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4698 * "compl_startpos" to the cursor as a pattern to add a new word instead of |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4699 * expand the one before the cursor, in word-wise if "compl_startpos" is not in |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4700 * the same line as the cursor then fix it (the line has been split because it |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4701 * was longer than 'tw'). if SOL is set then skip the previous pattern, a word |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4702 * at the beginning of the line has been inserted, we'll look for that. |
16142
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4703 */ |
26831
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4704 static void |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4705 ins_compl_continue_search(char_u *line) |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4706 { |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4707 // it is a continued search |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4708 compl_cont_status &= ~CONT_INTRPT; // remove INTRPT |
26944
8dbdd68627bd
patch 8.2.4001: insert complete code uses global variables
Bram Moolenaar <Bram@vim.org>
parents:
26921
diff
changeset
|
4709 if (ctrl_x_mode_normal() || ctrl_x_mode_path_patterns() |
8dbdd68627bd
patch 8.2.4001: insert complete code uses global variables
Bram Moolenaar <Bram@vim.org>
parents:
26921
diff
changeset
|
4710 || ctrl_x_mode_path_defines()) |
26831
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4711 { |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4712 if (compl_startpos.lnum != curwin->w_cursor.lnum) |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4713 { |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4714 // line (probably) wrapped, set compl_startpos to the |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4715 // first non_blank in the line, if it is not a wordchar |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4716 // include it to get a better pattern, but then we don't |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4717 // want the "\\<" prefix, check it below |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4718 compl_col = (colnr_T)getwhitecols(line); |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4719 compl_startpos.col = compl_col; |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4720 compl_startpos.lnum = curwin->w_cursor.lnum; |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4721 compl_cont_status &= ~CONT_SOL; // clear SOL if present |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4722 } |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4723 else |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4724 { |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4725 // S_IPOS was set when we inserted a word that was at the |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4726 // beginning of the line, which means that we'll go to SOL |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4727 // mode but first we need to redefine compl_startpos |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4728 if (compl_cont_status & CONT_S_IPOS) |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4729 { |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4730 compl_cont_status |= CONT_SOL; |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4731 compl_startpos.col = (colnr_T)(skipwhite( |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4732 line + compl_length |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4733 + compl_startpos.col) - line); |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4734 } |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4735 compl_col = compl_startpos.col; |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4736 } |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4737 compl_length = curwin->w_cursor.col - (int)compl_col; |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4738 // IObuff is used to add a "word from the next line" would we |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4739 // have enough space? just being paranoid |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4740 #define MIN_SPACE 75 |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4741 if (compl_length > (IOSIZE - MIN_SPACE)) |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4742 { |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4743 compl_cont_status &= ~CONT_SOL; |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4744 compl_length = (IOSIZE - MIN_SPACE); |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4745 compl_col = curwin->w_cursor.col - compl_length; |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4746 } |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4747 compl_cont_status |= CONT_ADDING | CONT_N_ADDS; |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4748 if (compl_length < 1) |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4749 compl_cont_status &= CONT_LOCAL; |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4750 } |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4751 else if (ctrl_x_mode_line_or_eval()) |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4752 compl_cont_status = CONT_ADDING | CONT_N_ADDS; |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4753 else |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4754 compl_cont_status = 0; |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4755 } |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4756 |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4757 /* |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4758 * start insert mode completion |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4759 */ |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4760 static int |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4761 ins_compl_start(void) |
16142
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4762 { |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4763 char_u *line; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4764 int startcol = 0; // column where searched text starts |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4765 colnr_T curs_col; // cursor column |
26831
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4766 int line_invalid = FALSE; |
16142
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4767 int save_did_ai = did_ai; |
16239
5df26b29e809
patch 8.1.1124: insert completion flags are mixed up
Bram Moolenaar <Bram@vim.org>
parents:
16237
diff
changeset
|
4768 int flags = CP_ORIGINAL_TEXT; |
26831
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4769 |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4770 // First time we hit ^N or ^P (in a row, I mean) |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4771 |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4772 did_ai = FALSE; |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4773 did_si = FALSE; |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4774 can_si = FALSE; |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4775 can_si_back = FALSE; |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4776 if (stop_arrow() == FAIL) |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4777 return FAIL; |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4778 |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4779 line = ml_get(curwin->w_cursor.lnum); |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4780 curs_col = curwin->w_cursor.col; |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4781 compl_pending = 0; |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4782 |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4783 if ((compl_cont_status & CONT_INTRPT) == CONT_INTRPT |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4784 && compl_cont_mode == ctrl_x_mode) |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4785 // this same ctrl-x_mode was interrupted previously. Continue the |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4786 // completion. |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4787 ins_compl_continue_search(line); |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4788 else |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4789 compl_cont_status &= CONT_LOCAL; |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4790 |
26944
8dbdd68627bd
patch 8.2.4001: insert complete code uses global variables
Bram Moolenaar <Bram@vim.org>
parents:
26921
diff
changeset
|
4791 if (!compl_status_adding()) // normal expansion |
26831
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4792 { |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4793 compl_cont_mode = ctrl_x_mode; |
26944
8dbdd68627bd
patch 8.2.4001: insert complete code uses global variables
Bram Moolenaar <Bram@vim.org>
parents:
26921
diff
changeset
|
4794 if (ctrl_x_mode_not_default()) |
26831
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4795 // Remove LOCAL if ctrl_x_mode != CTRL_X_NORMAL |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4796 compl_cont_status = 0; |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4797 compl_cont_status |= CONT_N_ADDS; |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4798 compl_startpos = curwin->w_cursor; |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4799 startcol = (int)curs_col; |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4800 compl_col = 0; |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4801 } |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4802 |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4803 // Work out completion pattern and original text -- webb |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4804 if (compl_get_info(line, startcol, curs_col, &line_invalid) == FAIL) |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4805 { |
26944
8dbdd68627bd
patch 8.2.4001: insert complete code uses global variables
Bram Moolenaar <Bram@vim.org>
parents:
26921
diff
changeset
|
4806 if (ctrl_x_mode_function() || ctrl_x_mode_omni() |
8dbdd68627bd
patch 8.2.4001: insert complete code uses global variables
Bram Moolenaar <Bram@vim.org>
parents:
26921
diff
changeset
|
4807 || thesaurus_func_complete(ctrl_x_mode)) |
26831
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4808 // restore did_ai, so that adding comment leader works |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4809 did_ai = save_did_ai; |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4810 return FAIL; |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4811 } |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4812 // If "line" was changed while getting completion info get it again. |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4813 if (line_invalid) |
16142
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4814 line = ml_get(curwin->w_cursor.lnum); |
26831
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4815 |
26944
8dbdd68627bd
patch 8.2.4001: insert complete code uses global variables
Bram Moolenaar <Bram@vim.org>
parents:
26921
diff
changeset
|
4816 if (compl_status_adding()) |
26831
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4817 { |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4818 edit_submode_pre = (char_u *)_(" Adding"); |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4819 if (ctrl_x_mode_line_or_eval()) |
16142
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4820 { |
26831
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4821 // Insert a new line, keep indentation but ignore 'comments'. |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4822 char_u *old = curbuf->b_p_com; |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4823 |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4824 curbuf->b_p_com = (char_u *)""; |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4825 compl_startpos.lnum = curwin->w_cursor.lnum; |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4826 compl_startpos.col = compl_col; |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4827 ins_eol('\r'); |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4828 curbuf->b_p_com = old; |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4829 compl_length = 0; |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4830 compl_col = curwin->w_cursor.col; |
16142
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4831 } |
26831
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4832 } |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4833 else |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4834 { |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4835 edit_submode_pre = NULL; |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4836 compl_startpos.col = compl_col; |
16142
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4837 } |
26831
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4838 |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4839 if (compl_cont_status & CONT_LOCAL) |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4840 edit_submode = (char_u *)_(ctrl_x_msgs[CTRL_X_LOCAL_MSG]); |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4841 else |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4842 edit_submode = (char_u *)_(CTRL_X_MSG(ctrl_x_mode)); |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4843 |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4844 // If any of the original typed text has been changed we need to fix |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4845 // the redo buffer. |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4846 ins_compl_fixRedoBufForLeader(NULL); |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4847 |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4848 // Always add completion for the original text. |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4849 vim_free(compl_orig_text); |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4850 compl_orig_text = vim_strnsave(line + compl_col, compl_length); |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4851 if (p_ic) |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4852 flags |= CP_ICASE; |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4853 if (compl_orig_text == NULL || ins_compl_add(compl_orig_text, |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4854 -1, NULL, NULL, NULL, 0, flags, FALSE) != OK) |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4855 { |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4856 VIM_CLEAR(compl_pattern); |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4857 VIM_CLEAR(compl_orig_text); |
16142
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4858 return FAIL; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4859 } |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4860 |
26831
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4861 // showmode might reset the internal line pointers, so it must |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4862 // be called before line = ml_get(), or when this address is no |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4863 // longer needed. -- Acevedo. |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4864 edit_submode_extra = (char_u *)_("-- Searching..."); |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4865 edit_submode_highl = HLF_COUNT; |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4866 showmode(); |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4867 edit_submode_extra = NULL; |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4868 out_flush(); |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4869 |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4870 return OK; |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4871 } |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4872 |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4873 /* |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4874 * display the completion status message |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4875 */ |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4876 static void |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4877 ins_compl_show_statusmsg(void) |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4878 { |
16142
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4879 // we found no match if the list has only the "compl_orig_text"-entry |
26944
8dbdd68627bd
patch 8.2.4001: insert complete code uses global variables
Bram Moolenaar <Bram@vim.org>
parents:
26921
diff
changeset
|
4880 if (is_first_match(compl_first_match->cp_next)) |
16142
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4881 { |
26944
8dbdd68627bd
patch 8.2.4001: insert complete code uses global variables
Bram Moolenaar <Bram@vim.org>
parents:
26921
diff
changeset
|
4882 edit_submode_extra = compl_status_adding() && compl_length > 1 |
26877
06a137af96f8
patch 8.2.3967: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26865
diff
changeset
|
4883 ? (char_u *)_(e_hitend) |
06a137af96f8
patch 8.2.3967: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26865
diff
changeset
|
4884 : (char_u *)_(e_pattern_not_found); |
16142
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4885 edit_submode_highl = HLF_E; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4886 } |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4887 |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4888 if (edit_submode_extra == NULL) |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4889 { |
26944
8dbdd68627bd
patch 8.2.4001: insert complete code uses global variables
Bram Moolenaar <Bram@vim.org>
parents:
26921
diff
changeset
|
4890 if (match_at_original_text(compl_curr_match)) |
16142
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4891 { |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4892 edit_submode_extra = (char_u *)_("Back at original"); |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4893 edit_submode_highl = HLF_W; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4894 } |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4895 else if (compl_cont_status & CONT_S_IPOS) |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4896 { |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4897 edit_submode_extra = (char_u *)_("Word from other line"); |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4898 edit_submode_highl = HLF_COUNT; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4899 } |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4900 else if (compl_curr_match->cp_next == compl_curr_match->cp_prev) |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4901 { |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4902 edit_submode_extra = (char_u *)_("The only match"); |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4903 edit_submode_highl = HLF_COUNT; |
22717
bd61aaf7f2a0
patch 8.2.1907: complete_info().selected may be wrong
Bram Moolenaar <Bram@vim.org>
parents:
22248
diff
changeset
|
4904 compl_curr_match->cp_number = 1; |
16142
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4905 } |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4906 else |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4907 { |
22726
768f72ca8872
patch 8.2.1911: tiny build fails
Bram Moolenaar <Bram@vim.org>
parents:
22717
diff
changeset
|
4908 #if defined(FEAT_COMPL_FUNC) || defined(FEAT_EVAL) |
16142
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4909 // Update completion sequence number when needed. |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4910 if (compl_curr_match->cp_number == -1) |
22717
bd61aaf7f2a0
patch 8.2.1907: complete_info().selected may be wrong
Bram Moolenaar <Bram@vim.org>
parents:
22248
diff
changeset
|
4911 ins_compl_update_sequence_numbers(); |
22726
768f72ca8872
patch 8.2.1911: tiny build fails
Bram Moolenaar <Bram@vim.org>
parents:
22717
diff
changeset
|
4912 #endif |
16142
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4913 // The match should always have a sequence number now, this is |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4914 // just a safety check. |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4915 if (compl_curr_match->cp_number != -1) |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4916 { |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4917 // Space for 10 text chars. + 2x10-digit no.s = 31. |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4918 // Translations may need more than twice that. |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4919 static char_u match_ref[81]; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4920 |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4921 if (compl_matches > 0) |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4922 vim_snprintf((char *)match_ref, sizeof(match_ref), |
26831
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4923 _("match %d of %d"), |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4924 compl_curr_match->cp_number, compl_matches); |
16142
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4925 else |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4926 vim_snprintf((char *)match_ref, sizeof(match_ref), |
26831
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4927 _("match %d"), |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4928 compl_curr_match->cp_number); |
16142
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4929 edit_submode_extra = match_ref; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4930 edit_submode_highl = HLF_R; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4931 if (dollar_vcol >= 0) |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4932 curs_columns(FALSE); |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4933 } |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4934 } |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4935 } |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4936 |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4937 // Show a message about what (completion) mode we're in. |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4938 if (!compl_opt_suppress_empty) |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4939 { |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4940 showmode(); |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4941 if (!shortmess(SHM_COMPLETIONMENU)) |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4942 { |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4943 if (edit_submode_extra != NULL) |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4944 { |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4945 if (!p_smd) |
23169
5e6855ebc4ea
patch 8.2.2130: Insert mode completion messages end up in message history
Bram Moolenaar <Bram@vim.org>
parents:
22862
diff
changeset
|
4946 { |
5e6855ebc4ea
patch 8.2.2130: Insert mode completion messages end up in message history
Bram Moolenaar <Bram@vim.org>
parents:
22862
diff
changeset
|
4947 msg_hist_off = TRUE; |
16142
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4948 msg_attr((char *)edit_submode_extra, |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4949 edit_submode_highl < HLF_COUNT |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4950 ? HL_ATTR(edit_submode_highl) : 0); |
23169
5e6855ebc4ea
patch 8.2.2130: Insert mode completion messages end up in message history
Bram Moolenaar <Bram@vim.org>
parents:
22862
diff
changeset
|
4951 msg_hist_off = FALSE; |
5e6855ebc4ea
patch 8.2.2130: Insert mode completion messages end up in message history
Bram Moolenaar <Bram@vim.org>
parents:
22862
diff
changeset
|
4952 } |
16142
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4953 } |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4954 else |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4955 msg_clr_cmdline(); // necessary for "noshowmode" |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4956 } |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4957 } |
26831
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4958 } |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4959 |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4960 /* |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4961 * Do Insert mode completion. |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4962 * Called when character "c" was typed, which has a meaning for completion. |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4963 * Returns OK if completion was done, FAIL if something failed (out of mem). |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4964 */ |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4965 int |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4966 ins_complete(int c, int enable_pum) |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4967 { |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4968 int n; |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4969 int save_w_wrow; |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4970 int save_w_leftcol; |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4971 int insert_match; |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4972 |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4973 compl_direction = ins_compl_key2dir(c); |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4974 insert_match = ins_compl_use_match(c); |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4975 |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4976 if (!compl_started) |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4977 { |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4978 if (ins_compl_start() == FAIL) |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4979 return FAIL; |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4980 } |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4981 else if (insert_match && stop_arrow() == FAIL) |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4982 return FAIL; |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4983 |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4984 compl_shown_match = compl_curr_match; |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4985 compl_shows_dir = compl_direction; |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4986 |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4987 // Find next match (and following matches). |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4988 save_w_wrow = curwin->w_wrow; |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4989 save_w_leftcol = curwin->w_leftcol; |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4990 n = ins_compl_next(TRUE, ins_compl_key2count(c), insert_match, FALSE); |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4991 |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4992 // may undisplay the popup menu |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4993 ins_compl_upd_pum(); |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4994 |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4995 if (n > 1) // all matches have been found |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4996 compl_matches = n; |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4997 compl_curr_match = compl_shown_match; |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4998 compl_direction = compl_shows_dir; |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
4999 |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
5000 // Eat the ESC that vgetc() returns after a CTRL-C to avoid leaving Insert |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
5001 // mode. |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
5002 if (got_int && !global_busy) |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
5003 { |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
5004 (void)vgetc(); |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
5005 got_int = FALSE; |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
5006 } |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
5007 |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
5008 // we found no match if the list has only the "compl_orig_text"-entry |
26944
8dbdd68627bd
patch 8.2.4001: insert complete code uses global variables
Bram Moolenaar <Bram@vim.org>
parents:
26921
diff
changeset
|
5009 if (is_first_match(compl_first_match->cp_next)) |
26831
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
5010 { |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
5011 // remove N_ADDS flag, so next ^X<> won't try to go to ADDING mode, |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
5012 // because we couldn't expand anything at first place, but if we used |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
5013 // ^P, ^N, ^X^I or ^X^D we might want to add-expand a single-char-word |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
5014 // (such as M in M'exico) if not tried already. -- Acevedo |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
5015 if (compl_length > 1 |
26944
8dbdd68627bd
patch 8.2.4001: insert complete code uses global variables
Bram Moolenaar <Bram@vim.org>
parents:
26921
diff
changeset
|
5016 || compl_status_adding() |
8dbdd68627bd
patch 8.2.4001: insert complete code uses global variables
Bram Moolenaar <Bram@vim.org>
parents:
26921
diff
changeset
|
5017 || (ctrl_x_mode_not_default() |
8dbdd68627bd
patch 8.2.4001: insert complete code uses global variables
Bram Moolenaar <Bram@vim.org>
parents:
26921
diff
changeset
|
5018 && !ctrl_x_mode_path_patterns() |
8dbdd68627bd
patch 8.2.4001: insert complete code uses global variables
Bram Moolenaar <Bram@vim.org>
parents:
26921
diff
changeset
|
5019 && !ctrl_x_mode_path_defines())) |
26831
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
5020 compl_cont_status &= ~CONT_N_ADDS; |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
5021 } |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
5022 |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
5023 if (compl_curr_match->cp_flags & CP_CONT_S_IPOS) |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
5024 compl_cont_status |= CONT_S_IPOS; |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
5025 else |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
5026 compl_cont_status &= ~CONT_S_IPOS; |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
5027 |
537fdb6653a9
patch 8.2.3944: insert mode completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
26827
diff
changeset
|
5028 ins_compl_show_statusmsg(); |
16142
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5029 |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5030 // Show the popup menu, unless we got interrupted. |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5031 if (enable_pum && !compl_interrupted) |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5032 show_pum(save_w_wrow, save_w_leftcol); |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5033 |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5034 compl_was_interrupted = compl_interrupted; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5035 compl_interrupted = FALSE; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5036 |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5037 return OK; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5038 } |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5039 |
26921
b975b7c16ba1
patch 8.2.3989: some insert completion code is not tested
Bram Moolenaar <Bram@vim.org>
parents:
26883
diff
changeset
|
5040 /* |
b975b7c16ba1
patch 8.2.3989: some insert completion code is not tested
Bram Moolenaar <Bram@vim.org>
parents:
26883
diff
changeset
|
5041 * Remove (if needed) and show the popup menu |
b975b7c16ba1
patch 8.2.3989: some insert completion code is not tested
Bram Moolenaar <Bram@vim.org>
parents:
26883
diff
changeset
|
5042 */ |
16142
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5043 static void |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5044 show_pum(int prev_w_wrow, int prev_w_leftcol) |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5045 { |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5046 // RedrawingDisabled may be set when invoked through complete(). |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5047 int n = RedrawingDisabled; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5048 |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5049 RedrawingDisabled = 0; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5050 |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5051 // If the cursor moved or the display scrolled we need to remove the pum |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5052 // first. |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5053 setcursor(); |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5054 if (prev_w_wrow != curwin->w_wrow || prev_w_leftcol != curwin->w_leftcol) |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5055 ins_compl_del_pum(); |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5056 |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5057 ins_compl_show_pum(); |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5058 setcursor(); |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5059 RedrawingDisabled = n; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5060 } |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5061 |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5062 /* |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5063 * Looks in the first "len" chars. of "src" for search-metachars. |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5064 * If dest is not NULL the chars. are copied there quoting (with |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5065 * a backslash) the metachars, and dest would be NUL terminated. |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5066 * Returns the length (needed) of dest |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5067 */ |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5068 static unsigned |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5069 quote_meta(char_u *dest, char_u *src, int len) |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5070 { |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5071 unsigned m = (unsigned)len + 1; // one extra for the NUL |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5072 |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5073 for ( ; --len >= 0; src++) |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5074 { |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5075 switch (*src) |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5076 { |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5077 case '.': |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5078 case '*': |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5079 case '[': |
26944
8dbdd68627bd
patch 8.2.4001: insert complete code uses global variables
Bram Moolenaar <Bram@vim.org>
parents:
26921
diff
changeset
|
5080 if (ctrl_x_mode_dictionary() || ctrl_x_mode_thesaurus()) |
16142
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5081 break; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5082 // FALLTHROUGH |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5083 case '~': |
23272
a84e7abb0c92
patch 8.2.2182: Vim9: value of 'magic' is still relevant
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
5084 if (!magic_isset()) // quote these only if magic is set |
16142
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5085 break; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5086 // FALLTHROUGH |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5087 case '\\': |
26944
8dbdd68627bd
patch 8.2.4001: insert complete code uses global variables
Bram Moolenaar <Bram@vim.org>
parents:
26921
diff
changeset
|
5088 if (ctrl_x_mode_dictionary() || ctrl_x_mode_thesaurus()) |
16142
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5089 break; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5090 // FALLTHROUGH |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5091 case '^': // currently it's not needed. |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5092 case '$': |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5093 m++; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5094 if (dest != NULL) |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5095 *dest++ = '\\'; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5096 break; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5097 } |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5098 if (dest != NULL) |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5099 *dest++ = *src; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5100 // Copy remaining bytes of a multibyte character. |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5101 if (has_mbyte) |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5102 { |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5103 int i, mb_len; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5104 |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5105 mb_len = (*mb_ptr2len)(src) - 1; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5106 if (mb_len > 0 && len >= mb_len) |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5107 for (i = 0; i < mb_len; ++i) |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5108 { |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5109 --len; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5110 ++src; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5111 if (dest != NULL) |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5112 *dest++ = *src; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5113 } |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5114 } |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5115 } |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5116 if (dest != NULL) |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5117 *dest = NUL; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5118 |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5119 return m; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5120 } |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5121 |
17809
59f8948b7590
patch 8.1.1901: the +insert_expand feature is not always available
Bram Moolenaar <Bram@vim.org>
parents:
17775
diff
changeset
|
5122 #if defined(EXITFREE) || defined(PROTO) |
16142
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5123 void |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5124 free_insexpand_stuff(void) |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5125 { |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5126 VIM_CLEAR(compl_orig_text); |
26388
8aba638e91eb
patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents:
26362
diff
changeset
|
5127 # ifdef FEAT_EVAL |
8aba638e91eb
patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents:
26362
diff
changeset
|
5128 free_callback(&cfu_cb); |
8aba638e91eb
patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents:
26362
diff
changeset
|
5129 free_callback(&ofu_cb); |
8aba638e91eb
patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents:
26362
diff
changeset
|
5130 free_callback(&tsrfu_cb); |
8aba638e91eb
patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents:
26362
diff
changeset
|
5131 # endif |
16142
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5132 } |
17809
59f8948b7590
patch 8.1.1901: the +insert_expand feature is not always available
Bram Moolenaar <Bram@vim.org>
parents:
17775
diff
changeset
|
5133 #endif |
59f8948b7590
patch 8.1.1901: the +insert_expand feature is not always available
Bram Moolenaar <Bram@vim.org>
parents:
17775
diff
changeset
|
5134 |
59f8948b7590
patch 8.1.1901: the +insert_expand feature is not always available
Bram Moolenaar <Bram@vim.org>
parents:
17775
diff
changeset
|
5135 #ifdef FEAT_SPELL |
16142
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5136 /* |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5137 * Called when starting CTRL_X_SPELL mode: Move backwards to a previous badly |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5138 * spelled word, if there is one. |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5139 */ |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5140 static void |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5141 spell_back_to_badword(void) |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5142 { |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5143 pos_T tpos = curwin->w_cursor; |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5144 |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5145 spell_bad_len = spell_move_to(curwin, BACKWARD, TRUE, TRUE, NULL); |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5146 if (curwin->w_cursor.col != tpos.col) |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5147 start_arrow(&tpos); |
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5148 } |
17809
59f8948b7590
patch 8.1.1901: the +insert_expand feature is not always available
Bram Moolenaar <Bram@vim.org>
parents:
17775
diff
changeset
|
5149 #endif |