annotate src/edit.c @ 1826:b9202c4cf847 v7.2.124

updated for version 7.2-124
author vimboss
date Sun, 22 Feb 2009 23:54:59 +0000
parents d88bdbabfbc6
children 720a59d79bcd
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1 /* vi:set ts=8 sts=4 sw=4:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3 * VIM - Vi IMproved by Bram Moolenaar
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5 * Do ":help uganda" in Vim to read copying and usage conditions.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6 * Do ":help credits" in Vim to see a list of people who contributed.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7 * See README.txt for an overview of the Vim source code.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
10 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
11 * edit.c: functions for Insert mode
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
12 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
13
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
14 #include "vim.h"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
15
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
16 #ifdef FEAT_INS_EXPAND
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
17 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
18 * definitions used for CTRL-X submode
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
19 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
20 #define CTRL_X_WANT_IDENT 0x100
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
21
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
22 #define CTRL_X_NOT_DEFINED_YET 1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
23 #define CTRL_X_SCROLL 2
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
24 #define CTRL_X_WHOLE_LINE 3
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
25 #define CTRL_X_FILES 4
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
26 #define CTRL_X_TAGS (5 + CTRL_X_WANT_IDENT)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
27 #define CTRL_X_PATH_PATTERNS (6 + CTRL_X_WANT_IDENT)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
28 #define CTRL_X_PATH_DEFINES (7 + CTRL_X_WANT_IDENT)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
29 #define CTRL_X_FINISHED 8
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
30 #define CTRL_X_DICTIONARY (9 + CTRL_X_WANT_IDENT)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
31 #define CTRL_X_THESAURUS (10 + CTRL_X_WANT_IDENT)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
32 #define CTRL_X_CMDLINE 11
12
bdeee1504ac1 updated for version 7.0004
vimboss
parents: 11
diff changeset
33 #define CTRL_X_FUNCTION 12
523
a7ae7e043e43 updated for version 7.0146
vimboss
parents: 502
diff changeset
34 #define CTRL_X_OMNI 13
477
f8b75b8f1988 updated for version 7.0128
vimboss
parents: 474
diff changeset
35 #define CTRL_X_SPELL 14
f8b75b8f1988 updated for version 7.0128
vimboss
parents: 474
diff changeset
36 #define CTRL_X_LOCAL_MSG 15 /* only used in "ctrl_x_msgs" */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
37
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
38 #define CTRL_X_MSG(i) ctrl_x_msgs[(i) & ~CTRL_X_WANT_IDENT]
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
39
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
40 static char *ctrl_x_msgs[] =
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
41 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
42 N_(" Keyword completion (^N^P)"), /* ctrl_x_mode == 0, ^P/^N compl. */
819
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 818
diff changeset
43 N_(" ^X mode (^]^D^E^F^I^K^L^N^O^Ps^U^V^Y)"),
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
44 NULL,
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
45 N_(" Whole line completion (^L^N^P)"),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
46 N_(" File name completion (^F^N^P)"),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
47 N_(" Tag completion (^]^N^P)"),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
48 N_(" Path pattern completion (^N^P)"),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
49 N_(" Definition completion (^D^N^P)"),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
50 NULL,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
51 N_(" Dictionary completion (^K^N^P)"),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
52 N_(" Thesaurus completion (^T^N^P)"),
12
bdeee1504ac1 updated for version 7.0004
vimboss
parents: 11
diff changeset
53 N_(" Command-line completion (^V^N^P)"),
bdeee1504ac1 updated for version 7.0004
vimboss
parents: 11
diff changeset
54 N_(" User defined completion (^U^N^P)"),
523
a7ae7e043e43 updated for version 7.0146
vimboss
parents: 502
diff changeset
55 N_(" Omni completion (^O^N^P)"),
819
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 818
diff changeset
56 N_(" Spelling suggestion (s^N^P)"),
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
57 N_(" Keyword Local completion (^N^P)"),
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
58 };
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
59
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
60 static char_u e_hitend[] = N_("Hit end of paragraph");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
61
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
62 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
63 * Structure used to store one match for insert completion.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
64 */
681
9364d114ed8d updated for version 7.0204
vimboss
parents: 677
diff changeset
65 typedef struct compl_S compl_T;
9364d114ed8d updated for version 7.0204
vimboss
parents: 677
diff changeset
66 struct compl_S
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
67 {
464
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
68 compl_T *cp_next;
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
69 compl_T *cp_prev;
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
70 char_u *cp_str; /* matched text */
681
9364d114ed8d updated for version 7.0204
vimboss
parents: 677
diff changeset
71 char cp_icase; /* TRUE or FALSE: ignore case */
786
8f6a426bc1e0 updated for version 7.0229
vimboss
parents: 782
diff changeset
72 char_u *(cp_text[CPT_COUNT]); /* text for the menu */
659
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
73 char_u *cp_fname; /* file containing the match, allocated when
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
74 * cp_flags has FREE_FNAME */
464
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
75 int cp_flags; /* ORIGINAL_TEXT, CONT_S_IPOS or FREE_FNAME */
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
76 int cp_number; /* sequence number */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
77 };
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
78
464
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
79 #define ORIGINAL_TEXT (1) /* the original text when the expansion begun */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
80 #define FREE_FNAME (2)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
81
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
82 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
83 * All the current matches are stored in a list.
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
84 * "compl_first_match" points to the start of the list.
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
85 * "compl_curr_match" points to the currently selected entry.
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
86 * "compl_shown_match" is different from compl_curr_match during
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
87 * ins_compl_get_exp().
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
88 */
464
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
89 static compl_T *compl_first_match = NULL;
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
90 static compl_T *compl_curr_match = NULL;
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
91 static compl_T *compl_shown_match = NULL;
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
92
825
6675076019ae updated for version 7.0d
vimboss
parents: 819
diff changeset
93 /* After using a cursor key <Enter> selects a match in the popup menu,
6675076019ae updated for version 7.0d
vimboss
parents: 819
diff changeset
94 * otherwise it inserts a line break. */
6675076019ae updated for version 7.0d
vimboss
parents: 819
diff changeset
95 static int compl_enter_selects = FALSE;
6675076019ae updated for version 7.0d
vimboss
parents: 819
diff changeset
96
657
b112ec5c73f0 updated for version 7.0193
vimboss
parents: 648
diff changeset
97 /* When "compl_leader" is not NULL only matches that start with this string
b112ec5c73f0 updated for version 7.0193
vimboss
parents: 648
diff changeset
98 * are used. */
b112ec5c73f0 updated for version 7.0193
vimboss
parents: 648
diff changeset
99 static char_u *compl_leader = NULL;
b112ec5c73f0 updated for version 7.0193
vimboss
parents: 648
diff changeset
100
665
21ab9abf0f08 updated for version 7.0196
vimboss
parents: 661
diff changeset
101 static int compl_get_longest = FALSE; /* put longest common string
21ab9abf0f08 updated for version 7.0196
vimboss
parents: 661
diff changeset
102 in compl_leader */
21ab9abf0f08 updated for version 7.0196
vimboss
parents: 661
diff changeset
103
657
b112ec5c73f0 updated for version 7.0193
vimboss
parents: 648
diff changeset
104 static int compl_used_match; /* Selected one of the matches. When
b112ec5c73f0 updated for version 7.0193
vimboss
parents: 648
diff changeset
105 FALSE the match was edited or using
b112ec5c73f0 updated for version 7.0193
vimboss
parents: 648
diff changeset
106 the longest common string. */
b112ec5c73f0 updated for version 7.0193
vimboss
parents: 648
diff changeset
107
874
4bac29d27e2f updated for version 7.0
vimboss
parents: 867
diff changeset
108 static int compl_was_interrupted = FALSE; /* didn't finish finding
4bac29d27e2f updated for version 7.0
vimboss
parents: 867
diff changeset
109 completions. */
4bac29d27e2f updated for version 7.0
vimboss
parents: 867
diff changeset
110
4bac29d27e2f updated for version 7.0
vimboss
parents: 867
diff changeset
111 static int compl_restarting = FALSE; /* don't insert match */
4bac29d27e2f updated for version 7.0
vimboss
parents: 867
diff changeset
112
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
113 /* When the first completion is done "compl_started" is set. When it's
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
114 * FALSE the word to be completed must be located. */
644
e4fa26ce8769 updated for version 7.0187
vimboss
parents: 634
diff changeset
115 static int compl_started = FALSE;
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
116
464
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
117 static int compl_matches = 0;
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
118 static char_u *compl_pattern = NULL;
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
119 static int compl_direction = FORWARD;
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
120 static int compl_shows_dir = FORWARD;
716
8ae24f338cab updated for version 7.0217
vimboss
parents: 714
diff changeset
121 static int compl_pending = 0; /* > 1 for postponed CTRL-N */
464
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
122 static pos_T compl_startpos;
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
123 static colnr_T compl_col = 0; /* column where the text starts
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
124 * that is being completed */
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
125 static char_u *compl_orig_text = NULL; /* text as it was before
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
126 * completion started */
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
127 static int compl_cont_mode = 0;
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
128 static expand_T compl_xp;
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
129
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
130 static void ins_ctrl_x __ARGS((void));
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
131 static int has_compl_option __ARGS((int dict_opt));
1430
342cf2a9f5cc updated for version 7.1-145
vimboss
parents: 1389
diff changeset
132 static int ins_compl_accept_char __ARGS((int c));
944
b2dcb8457067 updated for version 7.0-070
vimboss
parents: 942
diff changeset
133 static int ins_compl_add __ARGS((char_u *str, int len, int icase, char_u *fname, char_u **cptext, int cdir, int flags, int adup));
681
9364d114ed8d updated for version 7.0204
vimboss
parents: 677
diff changeset
134 static int ins_compl_equal __ARGS((compl_T *match, char_u *str, int len));
665
21ab9abf0f08 updated for version 7.0196
vimboss
parents: 661
diff changeset
135 static void ins_compl_longest_match __ARGS((compl_T *match));
681
9364d114ed8d updated for version 7.0204
vimboss
parents: 677
diff changeset
136 static void ins_compl_add_matches __ARGS((int num_matches, char_u **matches, int icase));
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
137 static int ins_compl_make_cyclic __ARGS((void));
540
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
138 static void ins_compl_upd_pum __ARGS((void));
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
139 static void ins_compl_del_pum __ARGS((void));
648
9032e4668296 updated for version 7.0189
vimboss
parents: 644
diff changeset
140 static int pum_wanted __ARGS((void));
707
111b7dcc8a17 updated for version 7.0213
vimboss
parents: 703
diff changeset
141 static int pum_enough_matches __ARGS((void));
659
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
142 static void ins_compl_dictionaries __ARGS((char_u *dict, char_u *pat, int flags, int thesaurus));
703
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
143 static void ins_compl_files __ARGS((int count, char_u **files, int thesaurus, int flags, regmatch_T *regmatch, char_u *buf, int *dir));
667
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
144 static char_u *find_line_end __ARGS((char_u *ptr));
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
145 static void ins_compl_free __ARGS((void));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
146 static void ins_compl_clear __ARGS((void));
657
b112ec5c73f0 updated for version 7.0193
vimboss
parents: 648
diff changeset
147 static int ins_compl_bs __ARGS((void));
874
4bac29d27e2f updated for version 7.0
vimboss
parents: 867
diff changeset
148 static void ins_compl_new_leader __ARGS((void));
657
b112ec5c73f0 updated for version 7.0193
vimboss
parents: 648
diff changeset
149 static void ins_compl_addleader __ARGS((int c));
1782
12cecc379574 updated for version 7.2-080
vimboss
parents: 1698
diff changeset
150 static int ins_compl_len __ARGS((void));
874
4bac29d27e2f updated for version 7.0
vimboss
parents: 867
diff changeset
151 static void ins_compl_restart __ARGS((void));
694
07d199fe02ed updated for version 7.0209
vimboss
parents: 692
diff changeset
152 static void ins_compl_set_original_text __ARGS((char_u *str));
659
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
153 static void ins_compl_addfrommatch __ARGS((void));
540
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
154 static int ins_compl_prep __ARGS((int c));
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
155 static buf_T *ins_compl_next_buf __ARGS((buf_T *buf, int flag));
724
a35dce0cabc5 updated for version 7.0220
vimboss
parents: 716
diff changeset
156 #if defined(FEAT_COMPL_FUNC) || defined(FEAT_EVAL)
a35dce0cabc5 updated for version 7.0220
vimboss
parents: 716
diff changeset
157 static void ins_compl_add_list __ARGS((list_T *list));
a35dce0cabc5 updated for version 7.0220
vimboss
parents: 716
diff changeset
158 #endif
659
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
159 static int ins_compl_get_exp __ARGS((pos_T *ini));
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
160 static void ins_compl_delete __ARGS((void));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
161 static void ins_compl_insert __ARGS((void));
665
21ab9abf0f08 updated for version 7.0196
vimboss
parents: 661
diff changeset
162 static int ins_compl_next __ARGS((int allow_get_expansion, int count, int insert_match));
610
cd3689efd90a updated for version 7.0173
vimboss
parents: 603
diff changeset
163 static int ins_compl_key2dir __ARGS((int c));
644
e4fa26ce8769 updated for version 7.0187
vimboss
parents: 634
diff changeset
164 static int ins_compl_pum_key __ARGS((int c));
610
cd3689efd90a updated for version 7.0173
vimboss
parents: 603
diff changeset
165 static int ins_compl_key2count __ARGS((int c));
681
9364d114ed8d updated for version 7.0204
vimboss
parents: 677
diff changeset
166 static int ins_compl_use_match __ARGS((int c));
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
167 static int ins_complete __ARGS((int c));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
168 static int quote_meta __ARGS((char_u *dest, char_u *str, int len));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
169 #endif /* FEAT_INS_EXPAND */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
170
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
171 #define BACKSPACE_CHAR 1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
172 #define BACKSPACE_WORD 2
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
173 #define BACKSPACE_WORD_NOT_SPACE 3
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
174 #define BACKSPACE_LINE 4
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
175
661
e93a99ef31d0 updated for version 7.0195
vimboss
parents: 659
diff changeset
176 static void ins_redraw __ARGS((int ready));
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
177 static void ins_ctrl_v __ARGS((void));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
178 static void undisplay_dollar __ARGS((void));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
179 static void insert_special __ARGS((int, int, int));
667
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
180 static void internal_format __ARGS((int textwidth, int second_indent, int flags, int format_only));
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
181 static void check_auto_format __ARGS((int));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
182 static void redo_literal __ARGS((int c));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
183 static void start_arrow __ARGS((pos_T *end_insert_pos));
744
07f7b4a7755c updated for version 7.0222
vimboss
parents: 732
diff changeset
184 #ifdef FEAT_SPELL
221
7fd4b5df33be updated for version 7.0062
vimboss
parents: 180
diff changeset
185 static void check_spell_redraw __ARGS((void));
484
f012c4ed8c38 updated for version 7.0132
vimboss
parents: 477
diff changeset
186 static void spell_back_to_badword __ARGS((void));
497
73f10d8124f4 updated for version 7.0136
vimboss
parents: 484
diff changeset
187 static int spell_bad_len = 0; /* length of located bad word */
221
7fd4b5df33be updated for version 7.0062
vimboss
parents: 180
diff changeset
188 #endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
189 static void stop_insert __ARGS((pos_T *end_insert_pos, int esc));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
190 static int echeck_abbr __ARGS((int));
840
2c885fab04e3 updated for version 7.0e06
vimboss
parents: 836
diff changeset
191 #if 0
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
192 static void replace_push_off __ARGS((int c));
840
2c885fab04e3 updated for version 7.0e06
vimboss
parents: 836
diff changeset
193 #endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
194 static int replace_pop __ARGS((void));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
195 static void replace_join __ARGS((int off));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
196 static void replace_pop_ins __ARGS((void));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
197 #ifdef FEAT_MBYTE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
198 static void mb_replace_pop_ins __ARGS((int cc));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
199 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
200 static void replace_flush __ARGS((void));
1782
12cecc379574 updated for version 7.2-080
vimboss
parents: 1698
diff changeset
201 static void replace_do_bs __ARGS((int limit_col));
12cecc379574 updated for version 7.2-080
vimboss
parents: 1698
diff changeset
202 static int del_char_after_col __ARGS((int limit_col));
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
203 #ifdef FEAT_CINDENT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
204 static int cindent_on __ARGS((void));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
205 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
206 static void ins_reg __ARGS((void));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
207 static void ins_ctrl_g __ARGS((void));
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
208 static void ins_ctrl_hat __ARGS((void));
477
f8b75b8f1988 updated for version 7.0128
vimboss
parents: 474
diff changeset
209 static int ins_esc __ARGS((long *count, int cmdchar, int nomove));
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
210 #ifdef FEAT_RIGHTLEFT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
211 static void ins_ctrl_ __ARGS((void));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
212 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
213 #ifdef FEAT_VISUAL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
214 static int ins_start_select __ARGS((int c));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
215 #endif
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
216 static void ins_insert __ARGS((int replaceState));
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
217 static void ins_ctrl_o __ARGS((void));
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
218 static void ins_shift __ARGS((int c, int lastc));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
219 static void ins_del __ARGS((void));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
220 static int ins_bs __ARGS((int c, int mode, int *inserted_space_p));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
221 #ifdef FEAT_MOUSE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
222 static void ins_mouse __ARGS((int c));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
223 static void ins_mousescroll __ARGS((int up));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
224 #endif
692
a28f83d37113 updated for version 7.0208
vimboss
parents: 683
diff changeset
225 #if defined(FEAT_GUI_TABLINE) || defined(PROTO)
a28f83d37113 updated for version 7.0208
vimboss
parents: 683
diff changeset
226 static void ins_tabline __ARGS((int c));
a28f83d37113 updated for version 7.0208
vimboss
parents: 683
diff changeset
227 #endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
228 static void ins_left __ARGS((void));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
229 static void ins_home __ARGS((int c));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
230 static void ins_end __ARGS((int c));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
231 static void ins_s_left __ARGS((void));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
232 static void ins_right __ARGS((void));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
233 static void ins_s_right __ARGS((void));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
234 static void ins_up __ARGS((int startcol));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
235 static void ins_pageup __ARGS((void));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
236 static void ins_down __ARGS((int startcol));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
237 static void ins_pagedown __ARGS((void));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
238 #ifdef FEAT_DND
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
239 static void ins_drop __ARGS((void));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
240 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
241 static int ins_tab __ARGS((void));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
242 static int ins_eol __ARGS((int c));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
243 #ifdef FEAT_DIGRAPHS
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
244 static int ins_digraph __ARGS((void));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
245 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
246 static int ins_copychar __ARGS((linenr_T lnum));
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
247 static int ins_ctrl_ey __ARGS((int tc));
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
248 #ifdef FEAT_SMARTINDENT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
249 static void ins_try_si __ARGS((int c));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
250 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
251 static colnr_T get_nolist_virtcol __ARGS((void));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
252
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
253 static colnr_T Insstart_textlen; /* length of line when insert started */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
254 static colnr_T Insstart_blank_vcol; /* vcol for first inserted blank */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
255
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
256 static char_u *last_insert = NULL; /* the text of the previous insert,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
257 K_SPECIAL and CSI are escaped */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
258 static int last_insert_skip; /* nr of chars in front of previous insert */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
259 static int new_insert_skip; /* nr of chars in front of current insert */
603
e4c00ec07598 updated for version 7.0171
vimboss
parents: 574
diff changeset
260 static int did_restart_edit; /* "restart_edit" when calling edit() */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
261
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
262 #ifdef FEAT_CINDENT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
263 static int can_cindent; /* may do cindenting on this line */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
264 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
265
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
266 static int old_indent = 0; /* for ^^D command in insert mode */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
267
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
268 #ifdef FEAT_RIGHTLEFT
298
f9de3e679a04 updated for version 7.0078
vimboss
parents: 278
diff changeset
269 static int revins_on; /* reverse insert mode on */
f9de3e679a04 updated for version 7.0078
vimboss
parents: 278
diff changeset
270 static int revins_chars; /* how much to skip after edit */
f9de3e679a04 updated for version 7.0078
vimboss
parents: 278
diff changeset
271 static int revins_legal; /* was the last char 'legal'? */
f9de3e679a04 updated for version 7.0078
vimboss
parents: 278
diff changeset
272 static int revins_scol; /* start column of revins session */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
273 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
274
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
275 static int ins_need_undo; /* call u_save() before inserting a
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
276 char. Set when edit() is called.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
277 after that arrow_used is used. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
278
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
279 static int did_add_space = FALSE; /* auto_format() added an extra space
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
280 under the cursor */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
281
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
282 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
283 * edit(): Start inserting text.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
284 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
285 * "cmdchar" can be:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
286 * 'i' normal insert command
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
287 * 'a' normal append command
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
288 * 'R' replace command
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
289 * 'r' "r<CR>" command: insert one <CR>. Note: count can be > 1, for redo,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
290 * but still only one <CR> is inserted. The <Esc> is not used for redo.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
291 * 'g' "gI" command.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
292 * 'V' "gR" command for Virtual Replace mode.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
293 * 'v' "gr" command for single character Virtual Replace mode.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
294 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
295 * This function is not called recursively. For CTRL-O commands, it returns
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
296 * and lets the caller handle the Normal-mode command.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
297 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
298 * Return TRUE if a CTRL-O command caused the return (insert mode pending).
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
299 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
300 int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
301 edit(cmdchar, startln, count)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
302 int cmdchar;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
303 int startln; /* if set, insert at start of line */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
304 long count;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
305 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
306 int c = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
307 char_u *ptr;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
308 int lastc;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
309 colnr_T mincol;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
310 static linenr_T o_lnum = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
311 int i;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
312 int did_backspace = TRUE; /* previous char was backspace */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
313 #ifdef FEAT_CINDENT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
314 int line_is_white = FALSE; /* line is empty before insert */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
315 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
316 linenr_T old_topline = 0; /* topline before insertion */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
317 #ifdef FEAT_DIFF
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
318 int old_topfill = -1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
319 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
320 int inserted_space = FALSE; /* just inserted a space */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
321 int replaceState = REPLACE;
477
f8b75b8f1988 updated for version 7.0128
vimboss
parents: 474
diff changeset
322 int nomove = FALSE; /* don't move cursor on return */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
323
603
e4c00ec07598 updated for version 7.0171
vimboss
parents: 574
diff changeset
324 /* Remember whether editing was restarted after CTRL-O. */
e4c00ec07598 updated for version 7.0171
vimboss
parents: 574
diff changeset
325 did_restart_edit = restart_edit;
e4c00ec07598 updated for version 7.0171
vimboss
parents: 574
diff changeset
326
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
327 /* sleep before redrawing, needed for "CTRL-O :" that results in an
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
328 * error message */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
329 check_for_delay(TRUE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
330
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
331 #ifdef HAVE_SANDBOX
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
332 /* Don't allow inserting in the sandbox. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
333 if (sandbox != 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
334 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
335 EMSG(_(e_sandbox));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
336 return FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
337 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
338 #endif
632
b6632d553df3 updated for version 7.0182
vimboss
parents: 626
diff changeset
339 /* Don't allow changes in the buffer while editing the cmdline. The
b6632d553df3 updated for version 7.0182
vimboss
parents: 626
diff changeset
340 * caller of getcmdline() may get confused. */
634
1c586ee8dd45 updated for version 7.0183
vimboss
parents: 632
diff changeset
341 if (textlock != 0)
632
b6632d553df3 updated for version 7.0182
vimboss
parents: 626
diff changeset
342 {
b6632d553df3 updated for version 7.0182
vimboss
parents: 626
diff changeset
343 EMSG(_(e_secure));
b6632d553df3 updated for version 7.0182
vimboss
parents: 626
diff changeset
344 return FALSE;
b6632d553df3 updated for version 7.0182
vimboss
parents: 626
diff changeset
345 }
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
346
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
347 #ifdef FEAT_INS_EXPAND
844
d3bbb5dd3913 updated for version 7.0f02
vimboss
parents: 842
diff changeset
348 /* Don't allow recursive insert mode when busy with completion. */
d3bbb5dd3913 updated for version 7.0f02
vimboss
parents: 842
diff changeset
349 if (compl_started || pum_visible())
d3bbb5dd3913 updated for version 7.0f02
vimboss
parents: 842
diff changeset
350 {
d3bbb5dd3913 updated for version 7.0f02
vimboss
parents: 842
diff changeset
351 EMSG(_(e_secure));
d3bbb5dd3913 updated for version 7.0f02
vimboss
parents: 842
diff changeset
352 return FALSE;
d3bbb5dd3913 updated for version 7.0f02
vimboss
parents: 842
diff changeset
353 }
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
354 ins_compl_clear(); /* clear stuff for CTRL-X mode */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
355 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
356
11
4424b47a0797 updated for version 7.0003
vimboss
parents: 10
diff changeset
357 #ifdef FEAT_AUTOCMD
4424b47a0797 updated for version 7.0003
vimboss
parents: 10
diff changeset
358 /*
4424b47a0797 updated for version 7.0003
vimboss
parents: 10
diff changeset
359 * Trigger InsertEnter autocommands. Do not do this for "r<CR>" or "grx".
4424b47a0797 updated for version 7.0003
vimboss
parents: 10
diff changeset
360 */
4424b47a0797 updated for version 7.0003
vimboss
parents: 10
diff changeset
361 if (cmdchar != 'r' && cmdchar != 'v')
4424b47a0797 updated for version 7.0003
vimboss
parents: 10
diff changeset
362 {
532
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 523
diff changeset
363 # ifdef FEAT_EVAL
11
4424b47a0797 updated for version 7.0003
vimboss
parents: 10
diff changeset
364 if (cmdchar == 'R')
4424b47a0797 updated for version 7.0003
vimboss
parents: 10
diff changeset
365 ptr = (char_u *)"r";
4424b47a0797 updated for version 7.0003
vimboss
parents: 10
diff changeset
366 else if (cmdchar == 'V')
4424b47a0797 updated for version 7.0003
vimboss
parents: 10
diff changeset
367 ptr = (char_u *)"v";
4424b47a0797 updated for version 7.0003
vimboss
parents: 10
diff changeset
368 else
4424b47a0797 updated for version 7.0003
vimboss
parents: 10
diff changeset
369 ptr = (char_u *)"i";
4424b47a0797 updated for version 7.0003
vimboss
parents: 10
diff changeset
370 set_vim_var_string(VV_INSERTMODE, ptr, 1);
532
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 523
diff changeset
371 # endif
11
4424b47a0797 updated for version 7.0003
vimboss
parents: 10
diff changeset
372 apply_autocmds(EVENT_INSERTENTER, NULL, NULL, FALSE, curbuf);
4424b47a0797 updated for version 7.0003
vimboss
parents: 10
diff changeset
373 }
4424b47a0797 updated for version 7.0003
vimboss
parents: 10
diff changeset
374 #endif
4424b47a0797 updated for version 7.0003
vimboss
parents: 10
diff changeset
375
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
376 #ifdef FEAT_MOUSE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
377 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
378 * When doing a paste with the middle mouse button, Insstart is set to
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
379 * where the paste started.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
380 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
381 if (where_paste_started.lnum != 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
382 Insstart = where_paste_started;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
383 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
384 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
385 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
386 Insstart = curwin->w_cursor;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
387 if (startln)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
388 Insstart.col = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
389 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
390 Insstart_textlen = linetabsize(ml_get_curline());
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
391 Insstart_blank_vcol = MAXCOL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
392 if (!did_ai)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
393 ai_col = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
394
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
395 if (cmdchar != NUL && restart_edit == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
396 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
397 ResetRedobuff();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
398 AppendNumberToRedobuff(count);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
399 #ifdef FEAT_VREPLACE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
400 if (cmdchar == 'V' || cmdchar == 'v')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
401 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
402 /* "gR" or "gr" command */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
403 AppendCharToRedobuff('g');
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
404 AppendCharToRedobuff((cmdchar == 'v') ? 'r' : 'R');
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
405 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
406 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
407 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
408 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
409 AppendCharToRedobuff(cmdchar);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
410 if (cmdchar == 'g') /* "gI" command */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
411 AppendCharToRedobuff('I');
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
412 else if (cmdchar == 'r') /* "r<CR>" command */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
413 count = 1; /* insert only one <CR> */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
414 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
415 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
416
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
417 if (cmdchar == 'R')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
418 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
419 #ifdef FEAT_FKMAP
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
420 if (p_fkmap && p_ri)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
421 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
422 beep_flush();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
423 EMSG(farsi_text_3); /* encoded in Farsi */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
424 State = INSERT;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
425 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
426 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
427 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
428 State = REPLACE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
429 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
430 #ifdef FEAT_VREPLACE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
431 else if (cmdchar == 'V' || cmdchar == 'v')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
432 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
433 State = VREPLACE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
434 replaceState = VREPLACE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
435 orig_line_count = curbuf->b_ml.ml_line_count;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
436 vr_lines_changed = 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
437 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
438 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
439 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
440 State = INSERT;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
441
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
442 stop_insert_mode = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
443
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
444 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
445 * Need to recompute the cursor position, it might move when the cursor is
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
446 * on a TAB or special character.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
447 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
448 curs_columns(TRUE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
449
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
450 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
451 * Enable langmap or IME, indicated by 'iminsert'.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
452 * Note that IME may enabled/disabled without us noticing here, thus the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
453 * 'iminsert' value may not reflect what is actually used. It is updated
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
454 * when hitting <Esc>.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
455 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
456 if (curbuf->b_p_iminsert == B_IMODE_LMAP)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
457 State |= LANGMAP;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
458 #ifdef USE_IM_CONTROL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
459 im_set_active(curbuf->b_p_iminsert == B_IMODE_IM);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
460 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
461
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
462 #ifdef FEAT_MOUSE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
463 setmouse();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
464 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
465 #ifdef FEAT_CMDL_INFO
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
466 clear_showcmd();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
467 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
468 #ifdef FEAT_RIGHTLEFT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
469 /* there is no reverse replace mode */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
470 revins_on = (State == INSERT && p_ri);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
471 if (revins_on)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
472 undisplay_dollar();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
473 revins_chars = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
474 revins_legal = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
475 revins_scol = -1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
476 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
477
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
478 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
479 * Handle restarting Insert mode.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
480 * Don't do this for "CTRL-O ." (repeat an insert): we get here with
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
481 * restart_edit non-zero, and something in the stuff buffer.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
482 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
483 if (restart_edit != 0 && stuff_empty())
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
484 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
485 #ifdef FEAT_MOUSE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
486 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
487 * After a paste we consider text typed to be part of the insert for
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
488 * the pasted text. You can backspace over the pasted text too.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
489 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
490 if (where_paste_started.lnum)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
491 arrow_used = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
492 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
493 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
494 arrow_used = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
495 restart_edit = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
496
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
497 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
498 * If the cursor was after the end-of-line before the CTRL-O and it is
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
499 * now at the end-of-line, put it after the end-of-line (this is not
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
500 * correct in very rare cases).
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
501 * Also do this if curswant is greater than the current virtual
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
502 * column. Eg after "^O$" or "^O80|".
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
503 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
504 validate_virtcol();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
505 update_curswant();
230
9281a51ca7a2 updated for version 7.0064
vimboss
parents: 221
diff changeset
506 if (((ins_at_eol && curwin->w_cursor.lnum == o_lnum)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
507 || curwin->w_curswant > curwin->w_virtcol)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
508 && *(ptr = ml_get_curline() + curwin->w_cursor.col) != NUL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
509 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
510 if (ptr[1] == NUL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
511 ++curwin->w_cursor.col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
512 #ifdef FEAT_MBYTE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
513 else if (has_mbyte)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
514 {
474
a5fcf36ef512 updated for version 7.0127
vimboss
parents: 470
diff changeset
515 i = (*mb_ptr2len)(ptr);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
516 if (ptr[i] == NUL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
517 curwin->w_cursor.col += i;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
518 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
519 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
520 }
230
9281a51ca7a2 updated for version 7.0064
vimboss
parents: 221
diff changeset
521 ins_at_eol = FALSE;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
522 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
523 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
524 arrow_used = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
525
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
526 /* we are in insert mode now, don't need to start it anymore */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
527 need_start_insertmode = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
528
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
529 /* Need to save the line for undo before inserting the first char. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
530 ins_need_undo = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
531
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
532 #ifdef FEAT_MOUSE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
533 where_paste_started.lnum = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
534 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
535 #ifdef FEAT_CINDENT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
536 can_cindent = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
537 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
538 #ifdef FEAT_FOLDING
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
539 /* The cursor line is not in a closed fold, unless 'insertmode' is set or
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
540 * restarting. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
541 if (!p_im && did_restart_edit == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
542 foldOpenCursor();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
543 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
544
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
545 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
546 * If 'showmode' is set, show the current (insert/replace/..) mode.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
547 * A warning message for changing a readonly file is given here, before
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
548 * actually changing anything. It's put after the mode, if any.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
549 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
550 i = 0;
644
e4fa26ce8769 updated for version 7.0187
vimboss
parents: 634
diff changeset
551 if (p_smd && msg_silent == 0)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
552 i = showmode();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
553
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
554 if (!p_im && did_restart_edit == 0)
1473
5ba8e25f7fc1 updated for version 7.1-188
vimboss
parents: 1470
diff changeset
555 change_warning(i == 0 ? 0 : i + 1);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
556
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
557 #ifdef CURSOR_SHAPE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
558 ui_cursor_shape(); /* may show different cursor shape */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
559 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
560 #ifdef FEAT_DIGRAPHS
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
561 do_digraph(-1); /* clear digraphs */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
562 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
563
603
e4c00ec07598 updated for version 7.0171
vimboss
parents: 574
diff changeset
564 /*
e4c00ec07598 updated for version 7.0171
vimboss
parents: 574
diff changeset
565 * Get the current length of the redo buffer, those characters have to be
e4c00ec07598 updated for version 7.0171
vimboss
parents: 574
diff changeset
566 * skipped if we want to get to the inserted characters.
e4c00ec07598 updated for version 7.0171
vimboss
parents: 574
diff changeset
567 */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
568 ptr = get_inserted();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
569 if (ptr == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
570 new_insert_skip = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
571 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
572 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
573 new_insert_skip = (int)STRLEN(ptr);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
574 vim_free(ptr);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
575 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
576
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
577 old_indent = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
578
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
579 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
580 * Main loop in Insert mode: repeat until Insert mode is left.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
581 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
582 for (;;)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
583 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
584 #ifdef FEAT_RIGHTLEFT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
585 if (!revins_legal)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
586 revins_scol = -1; /* reset on illegal motions */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
587 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
588 revins_legal = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
589 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
590 if (arrow_used) /* don't repeat insert when arrow key used */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
591 count = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
592
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
593 if (stop_insert_mode)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
594 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
595 /* ":stopinsert" used or 'insertmode' reset */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
596 count = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
597 goto doESCkey;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
598 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
599
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
600 /* set curwin->w_curswant for next K_DOWN or K_UP */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
601 if (!arrow_used)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
602 curwin->w_set_curswant = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
603
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
604 /* If there is no typeahead may check for timestamps (e.g., for when a
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
605 * menu invoked a shell command). */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
606 if (stuff_empty())
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
607 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
608 did_check_timestamps = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
609 if (need_check_timestamps)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
610 check_timestamps(FALSE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
611 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
612
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
613 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
614 * When emsg() was called msg_scroll will have been set.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
615 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
616 msg_scroll = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
617
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
618 #ifdef FEAT_GUI
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
619 /* When 'mousefocus' is set a mouse movement may have taken us to
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
620 * another window. "need_mouse_correct" may then be set because of an
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
621 * autocommand. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
622 if (need_mouse_correct)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
623 gui_mouse_correct();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
624 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
625
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
626 #ifdef FEAT_FOLDING
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
627 /* Open fold at the cursor line, according to 'foldopen'. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
628 if (fdo_flags & FDO_INSERT)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
629 foldOpenCursor();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
630 /* Close folds where the cursor isn't, according to 'foldclose' */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
631 if (!char_avail())
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
632 foldCheckClose();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
633 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
634
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
635 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
636 * If we inserted a character at the last position of the last line in
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
637 * the window, scroll the window one line up. This avoids an extra
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
638 * redraw.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
639 * This is detected when the cursor column is smaller after inserting
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
640 * something.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
641 * Don't do this when the topline changed already, it has
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
642 * already been adjusted (by insertchar() calling open_line())).
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
643 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
644 if (curbuf->b_mod_set
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
645 && curwin->w_p_wrap
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
646 && !did_backspace
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
647 && curwin->w_topline == old_topline
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
648 #ifdef FEAT_DIFF
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
649 && curwin->w_topfill == old_topfill
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
650 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
651 )
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
652 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
653 mincol = curwin->w_wcol;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
654 validate_cursor_col();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
655
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
656 if ((int)curwin->w_wcol < (int)mincol - curbuf->b_p_ts
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
657 && curwin->w_wrow == W_WINROW(curwin)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
658 + curwin->w_height - 1 - p_so
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
659 && (curwin->w_cursor.lnum != curwin->w_topline
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
660 #ifdef FEAT_DIFF
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
661 || curwin->w_topfill > 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
662 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
663 ))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
664 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
665 #ifdef FEAT_DIFF
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
666 if (curwin->w_topfill > 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
667 --curwin->w_topfill;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
668 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
669 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
670 #ifdef FEAT_FOLDING
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
671 if (hasFolding(curwin->w_topline, NULL, &old_topline))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
672 set_topline(curwin, old_topline + 1);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
673 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
674 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
675 set_topline(curwin, curwin->w_topline + 1);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
676 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
677 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
678
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
679 /* May need to adjust w_topline to show the cursor. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
680 update_topline();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
681
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
682 did_backspace = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
683
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
684 validate_cursor(); /* may set must_redraw */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
685
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
686 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
687 * Redraw the display when no characters are waiting.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
688 * Also shows mode, ruler and positions cursor.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
689 */
661
e93a99ef31d0 updated for version 7.0195
vimboss
parents: 659
diff changeset
690 ins_redraw(TRUE);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
691
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
692 #ifdef FEAT_SCROLLBIND
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
693 if (curwin->w_p_scb)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
694 do_check_scrollbind(TRUE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
695 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
696
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
697 update_curswant();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
698 old_topline = curwin->w_topline;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
699 #ifdef FEAT_DIFF
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
700 old_topfill = curwin->w_topfill;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
701 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
702
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
703 #ifdef USE_ON_FLY_SCROLL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
704 dont_scroll = FALSE; /* allow scrolling here */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
705 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
706
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
707 /*
1526
f79bb0320025 updated for version 7.1-241
vimboss
parents: 1516
diff changeset
708 * Get a character for Insert mode. Ignore K_IGNORE.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
709 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
710 lastc = c; /* remember previous char for CTRL-D */
1526
f79bb0320025 updated for version 7.1-241
vimboss
parents: 1516
diff changeset
711 do
f79bb0320025 updated for version 7.1-241
vimboss
parents: 1516
diff changeset
712 {
f79bb0320025 updated for version 7.1-241
vimboss
parents: 1516
diff changeset
713 c = safe_vgetc();
f79bb0320025 updated for version 7.1-241
vimboss
parents: 1516
diff changeset
714 } while (c == K_IGNORE);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
715
978
0e3e208b4b90 updated for version 7.0-104
vimboss
parents: 947
diff changeset
716 #ifdef FEAT_AUTOCMD
0e3e208b4b90 updated for version 7.0-104
vimboss
parents: 947
diff changeset
717 /* Don't want K_CURSORHOLD for the second key, e.g., after CTRL-V. */
0e3e208b4b90 updated for version 7.0-104
vimboss
parents: 947
diff changeset
718 did_cursorhold = TRUE;
0e3e208b4b90 updated for version 7.0-104
vimboss
parents: 947
diff changeset
719 #endif
0e3e208b4b90 updated for version 7.0-104
vimboss
parents: 947
diff changeset
720
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
721 #ifdef FEAT_RIGHTLEFT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
722 if (p_hkmap && KeyTyped)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
723 c = hkmap(c); /* Hebrew mode mapping */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
724 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
725 #ifdef FEAT_FKMAP
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
726 if (p_fkmap && KeyTyped)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
727 c = fkmap(c); /* Farsi mode mapping */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
728 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
729
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
730 #ifdef FEAT_INS_EXPAND
659
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
731 /*
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
732 * Special handling of keys while the popup menu is visible or wanted
897
2e1e9b708941 updated for version 7.0-023
vimboss
parents: 887
diff changeset
733 * and the cursor is still in the completed word. Only when there is
2e1e9b708941 updated for version 7.0-023
vimboss
parents: 887
diff changeset
734 * a match, skip this when no matches were found.
659
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
735 */
897
2e1e9b708941 updated for version 7.0-023
vimboss
parents: 887
diff changeset
736 if (compl_started
2e1e9b708941 updated for version 7.0-023
vimboss
parents: 887
diff changeset
737 && pum_wanted()
2e1e9b708941 updated for version 7.0-023
vimboss
parents: 887
diff changeset
738 && curwin->w_cursor.col >= compl_col
2e1e9b708941 updated for version 7.0-023
vimboss
parents: 887
diff changeset
739 && (compl_shown_match == NULL
2e1e9b708941 updated for version 7.0-023
vimboss
parents: 887
diff changeset
740 || compl_shown_match != compl_shown_match->cp_next))
659
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
741 {
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
742 /* BS: Delete one character from "compl_leader". */
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
743 if ((c == K_BS || c == Ctrl_H)
836
5a7843c57316 updated for version 7.0e02
vimboss
parents: 835
diff changeset
744 && curwin->w_cursor.col > compl_col
5a7843c57316 updated for version 7.0e02
vimboss
parents: 835
diff changeset
745 && (c = ins_compl_bs()) == NUL)
657
b112ec5c73f0 updated for version 7.0193
vimboss
parents: 648
diff changeset
746 continue;
b112ec5c73f0 updated for version 7.0193
vimboss
parents: 648
diff changeset
747
659
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
748 /* When no match was selected or it was edited. */
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
749 if (!compl_used_match)
657
b112ec5c73f0 updated for version 7.0193
vimboss
parents: 648
diff changeset
750 {
659
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
751 /* CTRL-L: Add one character from the current match to
836
5a7843c57316 updated for version 7.0e02
vimboss
parents: 835
diff changeset
752 * "compl_leader". Except when at the original match and
5a7843c57316 updated for version 7.0e02
vimboss
parents: 835
diff changeset
753 * there is nothing to add, CTRL-L works like CTRL-P then. */
5a7843c57316 updated for version 7.0e02
vimboss
parents: 835
diff changeset
754 if (c == Ctrl_L
5a7843c57316 updated for version 7.0e02
vimboss
parents: 835
diff changeset
755 && (ctrl_x_mode != CTRL_X_WHOLE_LINE
5a7843c57316 updated for version 7.0e02
vimboss
parents: 835
diff changeset
756 || STRLEN(compl_shown_match->cp_str)
5a7843c57316 updated for version 7.0e02
vimboss
parents: 835
diff changeset
757 > curwin->w_cursor.col - compl_col))
659
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
758 {
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
759 ins_compl_addfrommatch();
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
760 continue;
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
761 }
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
762
1430
342cf2a9f5cc updated for version 7.1-145
vimboss
parents: 1389
diff changeset
763 /* A non-white character that fits in with the current
342cf2a9f5cc updated for version 7.1-145
vimboss
parents: 1389
diff changeset
764 * completion: Add to "compl_leader". */
342cf2a9f5cc updated for version 7.1-145
vimboss
parents: 1389
diff changeset
765 if (ins_compl_accept_char(c))
659
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
766 {
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
767 ins_compl_addleader(c);
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
768 continue;
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
769 }
665
21ab9abf0f08 updated for version 7.0196
vimboss
parents: 661
diff changeset
770
887
9dc77520c6d3 updated for version 7.0-013
vimboss
parents: 874
diff changeset
771 /* Pressing CTRL-Y selects the current match. When
825
6675076019ae updated for version 7.0d
vimboss
parents: 819
diff changeset
772 * compl_enter_selects is set the Enter key does the same. */
6675076019ae updated for version 7.0d
vimboss
parents: 819
diff changeset
773 if (c == Ctrl_Y || (compl_enter_selects
6675076019ae updated for version 7.0d
vimboss
parents: 819
diff changeset
774 && (c == CAR || c == K_KENTER || c == NL)))
665
21ab9abf0f08 updated for version 7.0196
vimboss
parents: 661
diff changeset
775 {
21ab9abf0f08 updated for version 7.0196
vimboss
parents: 661
diff changeset
776 ins_compl_delete();
21ab9abf0f08 updated for version 7.0196
vimboss
parents: 661
diff changeset
777 ins_compl_insert();
21ab9abf0f08 updated for version 7.0196
vimboss
parents: 661
diff changeset
778 }
657
b112ec5c73f0 updated for version 7.0193
vimboss
parents: 648
diff changeset
779 }
b112ec5c73f0 updated for version 7.0193
vimboss
parents: 648
diff changeset
780 }
b112ec5c73f0 updated for version 7.0193
vimboss
parents: 648
diff changeset
781
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
782 /* Prepare for or stop CTRL-X mode. This doesn't do completion, but
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
783 * it does fix up the text when finishing completion. */
665
21ab9abf0f08 updated for version 7.0196
vimboss
parents: 661
diff changeset
784 compl_get_longest = FALSE;
1526
f79bb0320025 updated for version 7.1-241
vimboss
parents: 1516
diff changeset
785 if (ins_compl_prep(c))
657
b112ec5c73f0 updated for version 7.0193
vimboss
parents: 648
diff changeset
786 continue;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
787 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
788
477
f8b75b8f1988 updated for version 7.0128
vimboss
parents: 474
diff changeset
789 /* CTRL-\ CTRL-N goes to Normal mode,
f8b75b8f1988 updated for version 7.0128
vimboss
parents: 474
diff changeset
790 * CTRL-\ CTRL-G goes to mode selected with 'insertmode',
f8b75b8f1988 updated for version 7.0128
vimboss
parents: 474
diff changeset
791 * CTRL-\ CTRL-O is like CTRL-O but without moving the cursor. */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
792 if (c == Ctrl_BSL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
793 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
794 /* may need to redraw when no more chars available now */
661
e93a99ef31d0 updated for version 7.0195
vimboss
parents: 659
diff changeset
795 ins_redraw(FALSE);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
796 ++no_mapping;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
797 ++allow_keys;
1389
bdcfe793d49f updated for version 7.1-104
vimboss
parents: 1353
diff changeset
798 c = plain_vgetc();
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
799 --no_mapping;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
800 --allow_keys;
477
f8b75b8f1988 updated for version 7.0128
vimboss
parents: 474
diff changeset
801 if (c != Ctrl_N && c != Ctrl_G && c != Ctrl_O)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
802 {
477
f8b75b8f1988 updated for version 7.0128
vimboss
parents: 474
diff changeset
803 /* it's something else */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
804 vungetc(c);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
805 c = Ctrl_BSL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
806 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
807 else if (c == Ctrl_G && p_im)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
808 continue;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
809 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
810 {
477
f8b75b8f1988 updated for version 7.0128
vimboss
parents: 474
diff changeset
811 if (c == Ctrl_O)
f8b75b8f1988 updated for version 7.0128
vimboss
parents: 474
diff changeset
812 {
f8b75b8f1988 updated for version 7.0128
vimboss
parents: 474
diff changeset
813 ins_ctrl_o();
f8b75b8f1988 updated for version 7.0128
vimboss
parents: 474
diff changeset
814 ins_at_eol = FALSE; /* cursor keeps its column */
f8b75b8f1988 updated for version 7.0128
vimboss
parents: 474
diff changeset
815 nomove = TRUE;
f8b75b8f1988 updated for version 7.0128
vimboss
parents: 474
diff changeset
816 }
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
817 count = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
818 goto doESCkey;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
819 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
820 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
821
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
822 #ifdef FEAT_DIGRAPHS
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
823 c = do_digraph(c);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
824 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
825
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
826 #ifdef FEAT_INS_EXPAND
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
827 if ((c == Ctrl_V || c == Ctrl_Q) && ctrl_x_mode == CTRL_X_CMDLINE)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
828 goto docomplete;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
829 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
830 if (c == Ctrl_V || c == Ctrl_Q)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
831 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
832 ins_ctrl_v();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
833 c = Ctrl_V; /* pretend CTRL-V is last typed character */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
834 continue;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
835 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
836
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
837 #ifdef FEAT_CINDENT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
838 if (cindent_on()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
839 # ifdef FEAT_INS_EXPAND
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
840 && ctrl_x_mode == 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
841 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
842 )
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
843 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
844 /* A key name preceded by a bang means this key is not to be
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
845 * inserted. Skip ahead to the re-indenting below.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
846 * A key name preceded by a star means that indenting has to be
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
847 * done before inserting the key. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
848 line_is_white = inindent(0);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
849 if (in_cinkeys(c, '!', line_is_white))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
850 goto force_cindent;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
851 if (can_cindent && in_cinkeys(c, '*', line_is_white)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
852 && stop_arrow() == OK)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
853 do_c_expr_indent();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
854 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
855 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
856
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
857 #ifdef FEAT_RIGHTLEFT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
858 if (curwin->w_p_rl)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
859 switch (c)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
860 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
861 case K_LEFT: c = K_RIGHT; break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
862 case K_S_LEFT: c = K_S_RIGHT; break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
863 case K_C_LEFT: c = K_C_RIGHT; break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
864 case K_RIGHT: c = K_LEFT; break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
865 case K_S_RIGHT: c = K_S_LEFT; break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
866 case K_C_RIGHT: c = K_C_LEFT; break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
867 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
868 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
869
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
870 #ifdef FEAT_VISUAL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
871 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
872 * If 'keymodel' contains "startsel", may start selection. If it
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
873 * does, a CTRL-O and c will be stuffed, we need to get these
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
874 * characters.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
875 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
876 if (ins_start_select(c))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
877 continue;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
878 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
879
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
880 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
881 * The big switch to handle a character in insert mode.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
882 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
883 switch (c)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
884 {
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
885 case ESC: /* End input mode */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
886 if (echeck_abbr(ESC + ABBR_OFF))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
887 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
888 /*FALLTHROUGH*/
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
889
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
890 case Ctrl_C: /* End input mode */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
891 #ifdef FEAT_CMDWIN
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
892 if (c == Ctrl_C && cmdwin_type != 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
893 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
894 /* Close the cmdline window. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
895 cmdwin_result = K_IGNORE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
896 got_int = FALSE; /* don't stop executing autocommands et al. */
929
2448f4c8afc6 updated for version 7.0-055
vimboss
parents: 909
diff changeset
897 nomove = TRUE;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
898 goto doESCkey;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
899 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
900 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
901
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
902 #ifdef UNIX
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
903 do_intr:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
904 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
905 /* when 'insertmode' set, and not halfway a mapping, don't leave
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
906 * Insert mode */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
907 if (goto_im())
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
908 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
909 if (got_int)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
910 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
911 (void)vgetc(); /* flush all buffers */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
912 got_int = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
913 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
914 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
915 vim_beep();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
916 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
917 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
918 doESCkey:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
919 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
920 * This is the ONLY return from edit()!
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
921 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
922 /* Always update o_lnum, so that a "CTRL-O ." that adds a line
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
923 * still puts the cursor back after the inserted text. */
230
9281a51ca7a2 updated for version 7.0064
vimboss
parents: 221
diff changeset
924 if (ins_at_eol && gchar_cursor() == NUL)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
925 o_lnum = curwin->w_cursor.lnum;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
926
477
f8b75b8f1988 updated for version 7.0128
vimboss
parents: 474
diff changeset
927 if (ins_esc(&count, cmdchar, nomove))
11
4424b47a0797 updated for version 7.0003
vimboss
parents: 10
diff changeset
928 {
4424b47a0797 updated for version 7.0003
vimboss
parents: 10
diff changeset
929 #ifdef FEAT_AUTOCMD
4424b47a0797 updated for version 7.0003
vimboss
parents: 10
diff changeset
930 if (cmdchar != 'r' && cmdchar != 'v')
4424b47a0797 updated for version 7.0003
vimboss
parents: 10
diff changeset
931 apply_autocmds(EVENT_INSERTLEAVE, NULL, NULL,
4424b47a0797 updated for version 7.0003
vimboss
parents: 10
diff changeset
932 FALSE, curbuf);
993
cbc9c335ddb1 updated for version 7.0-119
vimboss
parents: 989
diff changeset
933 did_cursorhold = FALSE;
11
4424b47a0797 updated for version 7.0003
vimboss
parents: 10
diff changeset
934 #endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
935 return (c == Ctrl_O);
11
4424b47a0797 updated for version 7.0003
vimboss
parents: 10
diff changeset
936 }
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
937 continue;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
938
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
939 case Ctrl_Z: /* suspend when 'insertmode' set */
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
940 if (!p_im)
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
941 goto normalchar; /* insert CTRL-Z as normal char */
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
942 stuffReadbuff((char_u *)":st\r");
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
943 c = Ctrl_O;
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
944 /*FALLTHROUGH*/
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
945
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
946 case Ctrl_O: /* execute one command */
502
52e76e2b5b65 updated for version 7.0140
vimboss
parents: 499
diff changeset
947 #ifdef FEAT_COMPL_FUNC
523
a7ae7e043e43 updated for version 7.0146
vimboss
parents: 502
diff changeset
948 if (ctrl_x_mode == CTRL_X_OMNI)
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
949 goto docomplete;
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
950 #endif
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
951 if (echeck_abbr(Ctrl_O + ABBR_OFF))
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
952 break;
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
953 ins_ctrl_o();
853
d10fbefd3bc1 updated for version 7.0f05
vimboss
parents: 846
diff changeset
954
d10fbefd3bc1 updated for version 7.0f05
vimboss
parents: 846
diff changeset
955 #ifdef FEAT_VIRTUALEDIT
d10fbefd3bc1 updated for version 7.0f05
vimboss
parents: 846
diff changeset
956 /* don't move the cursor left when 'virtualedit' has "onemore". */
d10fbefd3bc1 updated for version 7.0f05
vimboss
parents: 846
diff changeset
957 if (ve_flags & VE_ONEMORE)
d10fbefd3bc1 updated for version 7.0f05
vimboss
parents: 846
diff changeset
958 {
d10fbefd3bc1 updated for version 7.0f05
vimboss
parents: 846
diff changeset
959 ins_at_eol = FALSE;
d10fbefd3bc1 updated for version 7.0f05
vimboss
parents: 846
diff changeset
960 nomove = TRUE;
d10fbefd3bc1 updated for version 7.0f05
vimboss
parents: 846
diff changeset
961 }
d10fbefd3bc1 updated for version 7.0f05
vimboss
parents: 846
diff changeset
962 #endif
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
963 count = 0;
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
964 goto doESCkey;
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
965
464
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
966 case K_INS: /* toggle insert/replace mode */
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
967 case K_KINS:
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
968 ins_insert(replaceState);
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
969 break;
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
970
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
971 case K_SELECT: /* end of Select mode mapping - ignore */
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
972 break;
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
973
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
974 #ifdef FEAT_SNIFF
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
975 case K_SNIFF: /* Sniff command received */
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
976 stuffcharReadbuff(K_SNIFF);
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
977 goto doESCkey;
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
978 #endif
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
979
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
980 case K_HELP: /* Help key works like <ESC> <Help> */
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
981 case K_F1:
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
982 case K_XF1:
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
983 stuffcharReadbuff(K_HELP);
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
984 if (p_im)
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
985 need_start_insertmode = TRUE;
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
986 goto doESCkey;
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
987
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
988 #ifdef FEAT_NETBEANS_INTG
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
989 case K_F21: /* NetBeans command */
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
990 ++no_mapping; /* don't map the next key hits */
1389
bdcfe793d49f updated for version 7.1-104
vimboss
parents: 1353
diff changeset
991 i = plain_vgetc();
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
992 --no_mapping;
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
993 netbeans_keycommand(i);
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
994 break;
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
995 #endif
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
996
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
997 case K_ZERO: /* Insert the previously inserted text. */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
998 case NUL:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
999 case Ctrl_A:
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
1000 /* For ^@ the trailing ESC will end the insert, unless there is an
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
1001 * error. */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1002 if (stuff_inserted(NUL, 1L, (c == Ctrl_A)) == FAIL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1003 && c != Ctrl_A && !p_im)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1004 goto doESCkey; /* quit insert mode */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1005 inserted_space = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1006 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1007
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
1008 case Ctrl_R: /* insert the contents of a register */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1009 ins_reg();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1010 auto_format(FALSE, TRUE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1011 inserted_space = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1012 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1013
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
1014 case Ctrl_G: /* commands starting with CTRL-G */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1015 ins_ctrl_g();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1016 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1017
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
1018 case Ctrl_HAT: /* switch input mode and/or langmap */
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
1019 ins_ctrl_hat();
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1020 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1021
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1022 #ifdef FEAT_RIGHTLEFT
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
1023 case Ctrl__: /* switch between languages */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1024 if (!p_ari)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1025 goto normalchar;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1026 ins_ctrl_();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1027 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1028 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1029
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
1030 case Ctrl_D: /* Make indent one shiftwidth smaller. */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1031 #if defined(FEAT_INS_EXPAND) && defined(FEAT_FIND_ID)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1032 if (ctrl_x_mode == CTRL_X_PATH_DEFINES)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1033 goto docomplete;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1034 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1035 /* FALLTHROUGH */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1036
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
1037 case Ctrl_T: /* Make indent one shiftwidth greater. */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1038 # ifdef FEAT_INS_EXPAND
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1039 if (c == Ctrl_T && ctrl_x_mode == CTRL_X_THESAURUS)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1040 {
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
1041 if (has_compl_option(FALSE))
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
1042 goto docomplete;
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
1043 break;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1044 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1045 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1046 ins_shift(c, lastc);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1047 auto_format(FALSE, TRUE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1048 inserted_space = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1049 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1050
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
1051 case K_DEL: /* delete character under the cursor */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1052 case K_KDEL:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1053 ins_del();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1054 auto_format(FALSE, TRUE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1055 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1056
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
1057 case K_BS: /* delete character before the cursor */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1058 case Ctrl_H:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1059 did_backspace = ins_bs(c, BACKSPACE_CHAR, &inserted_space);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1060 auto_format(FALSE, TRUE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1061 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1062
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
1063 case Ctrl_W: /* delete word before the cursor */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1064 did_backspace = ins_bs(c, BACKSPACE_WORD, &inserted_space);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1065 auto_format(FALSE, TRUE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1066 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1067
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
1068 case Ctrl_U: /* delete all inserted text in current line */
12
bdeee1504ac1 updated for version 7.0004
vimboss
parents: 11
diff changeset
1069 # ifdef FEAT_COMPL_FUNC
bdeee1504ac1 updated for version 7.0004
vimboss
parents: 11
diff changeset
1070 /* CTRL-X CTRL-U completes with 'completefunc'. */
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
1071 if (ctrl_x_mode == CTRL_X_FUNCTION)
12
bdeee1504ac1 updated for version 7.0004
vimboss
parents: 11
diff changeset
1072 goto docomplete;
bdeee1504ac1 updated for version 7.0004
vimboss
parents: 11
diff changeset
1073 # endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1074 did_backspace = ins_bs(c, BACKSPACE_LINE, &inserted_space);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1075 auto_format(FALSE, TRUE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1076 inserted_space = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1077 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1078
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1079 #ifdef FEAT_MOUSE
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
1080 case K_LEFTMOUSE: /* mouse keys */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1081 case K_LEFTMOUSE_NM:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1082 case K_LEFTDRAG:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1083 case K_LEFTRELEASE:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1084 case K_LEFTRELEASE_NM:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1085 case K_MIDDLEMOUSE:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1086 case K_MIDDLEDRAG:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1087 case K_MIDDLERELEASE:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1088 case K_RIGHTMOUSE:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1089 case K_RIGHTDRAG:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1090 case K_RIGHTRELEASE:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1091 case K_X1MOUSE:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1092 case K_X1DRAG:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1093 case K_X1RELEASE:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1094 case K_X2MOUSE:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1095 case K_X2DRAG:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1096 case K_X2RELEASE:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1097 ins_mouse(c);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1098 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1099
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
1100 case K_MOUSEDOWN: /* Default action for scroll wheel up: scroll up */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1101 ins_mousescroll(FALSE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1102 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1103
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
1104 case K_MOUSEUP: /* Default action for scroll wheel down: scroll down */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1105 ins_mousescroll(TRUE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1106 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1107 #endif
692
a28f83d37113 updated for version 7.0208
vimboss
parents: 683
diff changeset
1108 #ifdef FEAT_GUI_TABLINE
a28f83d37113 updated for version 7.0208
vimboss
parents: 683
diff changeset
1109 case K_TABLINE:
a28f83d37113 updated for version 7.0208
vimboss
parents: 683
diff changeset
1110 case K_TABMENU:
a28f83d37113 updated for version 7.0208
vimboss
parents: 683
diff changeset
1111 ins_tabline(c);
a28f83d37113 updated for version 7.0208
vimboss
parents: 683
diff changeset
1112 break;
a28f83d37113 updated for version 7.0208
vimboss
parents: 683
diff changeset
1113 #endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1114
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
1115 case K_IGNORE: /* Something mapped to nothing */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1116 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1117
661
e93a99ef31d0 updated for version 7.0195
vimboss
parents: 659
diff changeset
1118 #ifdef FEAT_AUTOCMD
e93a99ef31d0 updated for version 7.0195
vimboss
parents: 659
diff changeset
1119 case K_CURSORHOLD: /* Didn't type something for a while. */
e93a99ef31d0 updated for version 7.0195
vimboss
parents: 659
diff changeset
1120 apply_autocmds(EVENT_CURSORHOLDI, NULL, NULL, FALSE, curbuf);
e93a99ef31d0 updated for version 7.0195
vimboss
parents: 659
diff changeset
1121 did_cursorhold = TRUE;
e93a99ef31d0 updated for version 7.0195
vimboss
parents: 659
diff changeset
1122 break;
e93a99ef31d0 updated for version 7.0195
vimboss
parents: 659
diff changeset
1123 #endif
e93a99ef31d0 updated for version 7.0195
vimboss
parents: 659
diff changeset
1124
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 620
diff changeset
1125 #ifdef FEAT_GUI_W32
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 620
diff changeset
1126 /* On Win32 ignore <M-F4>, we get it when closing the window was
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 620
diff changeset
1127 * cancelled. */
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 620
diff changeset
1128 case K_F4:
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 620
diff changeset
1129 if (mod_mask != MOD_MASK_ALT)
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 620
diff changeset
1130 goto normalchar;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 620
diff changeset
1131 break;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 620
diff changeset
1132 #endif
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 620
diff changeset
1133
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1134 #ifdef FEAT_GUI
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1135 case K_VER_SCROLLBAR:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1136 ins_scroll();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1137 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1138
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1139 case K_HOR_SCROLLBAR:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1140 ins_horscroll();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1141 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1142 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1143
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
1144 case K_HOME: /* <Home> */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1145 case K_KHOME:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1146 case K_S_HOME:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1147 case K_C_HOME:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1148 ins_home(c);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1149 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1150
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
1151 case K_END: /* <End> */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1152 case K_KEND:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1153 case K_S_END:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1154 case K_C_END:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1155 ins_end(c);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1156 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1157
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
1158 case K_LEFT: /* <Left> */
180
7e70fc748752 updated for version 7.0056
vimboss
parents: 164
diff changeset
1159 if (mod_mask & (MOD_MASK_SHIFT|MOD_MASK_CTRL))
7e70fc748752 updated for version 7.0056
vimboss
parents: 164
diff changeset
1160 ins_s_left();
7e70fc748752 updated for version 7.0056
vimboss
parents: 164
diff changeset
1161 else
7e70fc748752 updated for version 7.0056
vimboss
parents: 164
diff changeset
1162 ins_left();
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1163 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1164
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
1165 case K_S_LEFT: /* <S-Left> */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1166 case K_C_LEFT:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1167 ins_s_left();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1168 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1169
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
1170 case K_RIGHT: /* <Right> */
180
7e70fc748752 updated for version 7.0056
vimboss
parents: 164
diff changeset
1171 if (mod_mask & (MOD_MASK_SHIFT|MOD_MASK_CTRL))
7e70fc748752 updated for version 7.0056
vimboss
parents: 164
diff changeset
1172 ins_s_right();
7e70fc748752 updated for version 7.0056
vimboss
parents: 164
diff changeset
1173 else
7e70fc748752 updated for version 7.0056
vimboss
parents: 164
diff changeset
1174 ins_right();
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1175 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1176
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
1177 case K_S_RIGHT: /* <S-Right> */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1178 case K_C_RIGHT:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1179 ins_s_right();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1180 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1181
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
1182 case K_UP: /* <Up> */
665
21ab9abf0f08 updated for version 7.0196
vimboss
parents: 661
diff changeset
1183 #ifdef FEAT_INS_EXPAND
21ab9abf0f08 updated for version 7.0196
vimboss
parents: 661
diff changeset
1184 if (pum_visible())
21ab9abf0f08 updated for version 7.0196
vimboss
parents: 661
diff changeset
1185 goto docomplete;
21ab9abf0f08 updated for version 7.0196
vimboss
parents: 661
diff changeset
1186 #endif
180
7e70fc748752 updated for version 7.0056
vimboss
parents: 164
diff changeset
1187 if (mod_mask & MOD_MASK_SHIFT)
7e70fc748752 updated for version 7.0056
vimboss
parents: 164
diff changeset
1188 ins_pageup();
7e70fc748752 updated for version 7.0056
vimboss
parents: 164
diff changeset
1189 else
7e70fc748752 updated for version 7.0056
vimboss
parents: 164
diff changeset
1190 ins_up(FALSE);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1191 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1192
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
1193 case K_S_UP: /* <S-Up> */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1194 case K_PAGEUP:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1195 case K_KPAGEUP:
613
53114ef7778f updated for version 7.0174
vimboss
parents: 610
diff changeset
1196 #ifdef FEAT_INS_EXPAND
610
cd3689efd90a updated for version 7.0173
vimboss
parents: 603
diff changeset
1197 if (pum_visible())
cd3689efd90a updated for version 7.0173
vimboss
parents: 603
diff changeset
1198 goto docomplete;
613
53114ef7778f updated for version 7.0174
vimboss
parents: 610
diff changeset
1199 #endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1200 ins_pageup();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1201 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1202
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
1203 case K_DOWN: /* <Down> */
665
21ab9abf0f08 updated for version 7.0196
vimboss
parents: 661
diff changeset
1204 #ifdef FEAT_INS_EXPAND
21ab9abf0f08 updated for version 7.0196
vimboss
parents: 661
diff changeset
1205 if (pum_visible())
21ab9abf0f08 updated for version 7.0196
vimboss
parents: 661
diff changeset
1206 goto docomplete;
21ab9abf0f08 updated for version 7.0196
vimboss
parents: 661
diff changeset
1207 #endif
180
7e70fc748752 updated for version 7.0056
vimboss
parents: 164
diff changeset
1208 if (mod_mask & MOD_MASK_SHIFT)
7e70fc748752 updated for version 7.0056
vimboss
parents: 164
diff changeset
1209 ins_pagedown();
7e70fc748752 updated for version 7.0056
vimboss
parents: 164
diff changeset
1210 else
7e70fc748752 updated for version 7.0056
vimboss
parents: 164
diff changeset
1211 ins_down(FALSE);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1212 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1213
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
1214 case K_S_DOWN: /* <S-Down> */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1215 case K_PAGEDOWN:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1216 case K_KPAGEDOWN:
613
53114ef7778f updated for version 7.0174
vimboss
parents: 610
diff changeset
1217 #ifdef FEAT_INS_EXPAND
610
cd3689efd90a updated for version 7.0173
vimboss
parents: 603
diff changeset
1218 if (pum_visible())
cd3689efd90a updated for version 7.0173
vimboss
parents: 603
diff changeset
1219 goto docomplete;
613
53114ef7778f updated for version 7.0174
vimboss
parents: 610
diff changeset
1220 #endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1221 ins_pagedown();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1222 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1223
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1224 #ifdef FEAT_DND
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
1225 case K_DROP: /* drag-n-drop event */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1226 ins_drop();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1227 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1228 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1229
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
1230 case K_S_TAB: /* When not mapped, use like a normal TAB */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1231 c = TAB;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1232 /* FALLTHROUGH */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1233
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
1234 case TAB: /* TAB or Complete patterns along path */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1235 #if defined(FEAT_INS_EXPAND) && defined(FEAT_FIND_ID)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1236 if (ctrl_x_mode == CTRL_X_PATH_PATTERNS)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1237 goto docomplete;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1238 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1239 inserted_space = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1240 if (ins_tab())
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1241 goto normalchar; /* insert TAB as a normal char */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1242 auto_format(FALSE, TRUE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1243 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1244
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
1245 case K_KENTER: /* <Enter> */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1246 c = CAR;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1247 /* FALLTHROUGH */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1248 case CAR:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1249 case NL:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1250 #if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1251 /* In a quickfix window a <CR> jumps to the error under the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1252 * cursor. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1253 if (bt_quickfix(curbuf) && c == CAR)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1254 {
644
e4fa26ce8769 updated for version 7.0187
vimboss
parents: 634
diff changeset
1255 if (curwin->w_llist_ref == NULL) /* quickfix window */
e4fa26ce8769 updated for version 7.0187
vimboss
parents: 634
diff changeset
1256 do_cmdline_cmd((char_u *)".cc");
e4fa26ce8769 updated for version 7.0187
vimboss
parents: 634
diff changeset
1257 else /* location list window */
e4fa26ce8769 updated for version 7.0187
vimboss
parents: 634
diff changeset
1258 do_cmdline_cmd((char_u *)".ll");
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1259 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1260 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1261 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1262 #ifdef FEAT_CMDWIN
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1263 if (cmdwin_type != 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1264 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1265 /* Execute the command in the cmdline window. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1266 cmdwin_result = CAR;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1267 goto doESCkey;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1268 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1269 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1270 if (ins_eol(c) && !p_im)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1271 goto doESCkey; /* out of memory */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1272 auto_format(FALSE, FALSE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1273 inserted_space = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1274 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1275
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1276 #if defined(FEAT_DIGRAPHS) || defined (FEAT_INS_EXPAND)
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
1277 case Ctrl_K: /* digraph or keyword completion */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1278 # ifdef FEAT_INS_EXPAND
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1279 if (ctrl_x_mode == CTRL_X_DICTIONARY)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1280 {
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
1281 if (has_compl_option(TRUE))
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
1282 goto docomplete;
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
1283 break;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1284 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1285 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1286 # ifdef FEAT_DIGRAPHS
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1287 c = ins_digraph();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1288 if (c == NUL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1289 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1290 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1291 goto normalchar;
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
1292 #endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1293
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1294 #ifdef FEAT_INS_EXPAND
464
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
1295 case Ctrl_X: /* Enter CTRL-X mode */
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
1296 ins_ctrl_x();
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
1297 break;
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
1298
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
1299 case Ctrl_RSB: /* Tag name completion after ^X */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1300 if (ctrl_x_mode != CTRL_X_TAGS)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1301 goto normalchar;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1302 goto docomplete;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1303
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
1304 case Ctrl_F: /* File name completion after ^X */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1305 if (ctrl_x_mode != CTRL_X_FILES)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1306 goto normalchar;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1307 goto docomplete;
477
f8b75b8f1988 updated for version 7.0128
vimboss
parents: 474
diff changeset
1308
f8b75b8f1988 updated for version 7.0128
vimboss
parents: 474
diff changeset
1309 case 's': /* Spelling completion after ^X */
f8b75b8f1988 updated for version 7.0128
vimboss
parents: 474
diff changeset
1310 case Ctrl_S:
f8b75b8f1988 updated for version 7.0128
vimboss
parents: 474
diff changeset
1311 if (ctrl_x_mode != CTRL_X_SPELL)
f8b75b8f1988 updated for version 7.0128
vimboss
parents: 474
diff changeset
1312 goto normalchar;
f8b75b8f1988 updated for version 7.0128
vimboss
parents: 474
diff changeset
1313 goto docomplete;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1314 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1315
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
1316 case Ctrl_L: /* Whole line completion after ^X */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1317 #ifdef FEAT_INS_EXPAND
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1318 if (ctrl_x_mode != CTRL_X_WHOLE_LINE)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1319 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1320 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1321 /* CTRL-L with 'insertmode' set: Leave Insert mode */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1322 if (p_im)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1323 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1324 if (echeck_abbr(Ctrl_L + ABBR_OFF))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1325 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1326 goto doESCkey;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1327 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1328 goto normalchar;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1329 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1330 #ifdef FEAT_INS_EXPAND
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1331 /* FALLTHROUGH */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1332
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
1333 case Ctrl_P: /* Do previous/next pattern completion */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1334 case Ctrl_N:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1335 /* if 'complete' is empty then plain ^P is no longer special,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1336 * but it is under other ^X modes */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1337 if (*curbuf->b_p_cpt == NUL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1338 && ctrl_x_mode != 0
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
1339 && !(compl_cont_status & CONT_LOCAL))
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1340 goto normalchar;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1341
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1342 docomplete:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1343 if (ins_complete(c) == FAIL)
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
1344 compl_cont_status = 0;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1345 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1346 #endif /* FEAT_INS_EXPAND */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1347
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
1348 case Ctrl_Y: /* copy from previous line or scroll down */
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
1349 case Ctrl_E: /* copy from next line or scroll up */
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
1350 c = ins_ctrl_ey(c);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1351 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1352
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1353 default:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1354 #ifdef UNIX
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1355 if (c == intr_char) /* special interrupt char */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1356 goto do_intr;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1357 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1358
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1359 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1360 * Insert a nomal character.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1361 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1362 normalchar:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1363 #ifdef FEAT_SMARTINDENT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1364 /* Try to perform smart-indenting. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1365 ins_try_si(c);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1366 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1367
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1368 if (c == ' ')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1369 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1370 inserted_space = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1371 #ifdef FEAT_CINDENT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1372 if (inindent(0))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1373 can_cindent = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1374 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1375 if (Insstart_blank_vcol == MAXCOL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1376 && curwin->w_cursor.lnum == Insstart.lnum)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1377 Insstart_blank_vcol = get_nolist_virtcol();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1378 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1379
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1380 if (vim_iswordc(c) || !echeck_abbr(
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1381 #ifdef FEAT_MBYTE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1382 /* Add ABBR_OFF for characters above 0x100, this is
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1383 * what check_abbr() expects. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1384 (has_mbyte && c >= 0x100) ? (c + ABBR_OFF) :
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1385 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1386 c))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1387 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1388 insert_special(c, FALSE, FALSE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1389 #ifdef FEAT_RIGHTLEFT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1390 revins_legal++;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1391 revins_chars++;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1392 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1393 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1394
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1395 auto_format(FALSE, TRUE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1396
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1397 #ifdef FEAT_FOLDING
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1398 /* When inserting a character the cursor line must never be in a
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1399 * closed fold. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1400 foldOpenCursor();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1401 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1402 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1403 } /* end of switch (c) */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1404
978
0e3e208b4b90 updated for version 7.0-104
vimboss
parents: 947
diff changeset
1405 #ifdef FEAT_AUTOCMD
0e3e208b4b90 updated for version 7.0-104
vimboss
parents: 947
diff changeset
1406 /* If typed something may trigger CursorHoldI again. */
0e3e208b4b90 updated for version 7.0-104
vimboss
parents: 947
diff changeset
1407 if (c != K_CURSORHOLD)
0e3e208b4b90 updated for version 7.0-104
vimboss
parents: 947
diff changeset
1408 did_cursorhold = FALSE;
0e3e208b4b90 updated for version 7.0-104
vimboss
parents: 947
diff changeset
1409 #endif
0e3e208b4b90 updated for version 7.0-104
vimboss
parents: 947
diff changeset
1410
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1411 /* If the cursor was moved we didn't just insert a space */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1412 if (arrow_used)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1413 inserted_space = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1414
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1415 #ifdef FEAT_CINDENT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1416 if (can_cindent && cindent_on()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1417 # ifdef FEAT_INS_EXPAND
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1418 && ctrl_x_mode == 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1419 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1420 )
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1421 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1422 force_cindent:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1423 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1424 * Indent now if a key was typed that is in 'cinkeys'.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1425 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1426 if (in_cinkeys(c, ' ', line_is_white))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1427 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1428 if (stop_arrow() == OK)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1429 /* re-indent the current line */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1430 do_c_expr_indent();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1431 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1432 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1433 #endif /* FEAT_CINDENT */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1434
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1435 } /* for (;;) */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1436 /* NOTREACHED */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1437 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1438
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1439 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1440 * Redraw for Insert mode.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1441 * This is postponed until getting the next character to make '$' in the 'cpo'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1442 * option work correctly.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1443 * Only redraw when there are no characters available. This speeds up
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1444 * inserting sequences of characters (e.g., for CTRL-R).
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1445 */
661
e93a99ef31d0 updated for version 7.0195
vimboss
parents: 659
diff changeset
1446 /*ARGSUSED*/
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1447 static void
661
e93a99ef31d0 updated for version 7.0195
vimboss
parents: 659
diff changeset
1448 ins_redraw(ready)
e93a99ef31d0 updated for version 7.0195
vimboss
parents: 659
diff changeset
1449 int ready; /* not busy with something */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1450 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1451 if (!char_avail())
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1452 {
661
e93a99ef31d0 updated for version 7.0195
vimboss
parents: 659
diff changeset
1453 #ifdef FEAT_AUTOCMD
794
f19994020dad updated for version 7.0231
vimboss
parents: 786
diff changeset
1454 /* Trigger CursorMoved if the cursor moved. Not when the popup menu is
f19994020dad updated for version 7.0231
vimboss
parents: 786
diff changeset
1455 * visible, the command might delete it. */
661
e93a99ef31d0 updated for version 7.0195
vimboss
parents: 659
diff changeset
1456 if (ready && has_cursormovedI()
794
f19994020dad updated for version 7.0231
vimboss
parents: 786
diff changeset
1457 && !equalpos(last_cursormoved, curwin->w_cursor)
f19994020dad updated for version 7.0231
vimboss
parents: 786
diff changeset
1458 # ifdef FEAT_INS_EXPAND
f19994020dad updated for version 7.0231
vimboss
parents: 786
diff changeset
1459 && !pum_visible()
f19994020dad updated for version 7.0231
vimboss
parents: 786
diff changeset
1460 # endif
f19994020dad updated for version 7.0231
vimboss
parents: 786
diff changeset
1461 )
661
e93a99ef31d0 updated for version 7.0195
vimboss
parents: 659
diff changeset
1462 {
1506
64ed4359d957 updated for version 7.1-221
vimboss
parents: 1497
diff changeset
1463 # ifdef FEAT_SYN_HL
64ed4359d957 updated for version 7.1-221
vimboss
parents: 1497
diff changeset
1464 /* Need to update the screen first, to make sure syntax
64ed4359d957 updated for version 7.1-221
vimboss
parents: 1497
diff changeset
1465 * highlighting is correct after making a change (e.g., inserting
64ed4359d957 updated for version 7.1-221
vimboss
parents: 1497
diff changeset
1466 * a "(". The autocommand may also require a redraw, so it's done
64ed4359d957 updated for version 7.1-221
vimboss
parents: 1497
diff changeset
1467 * again below, unfortunately. */
64ed4359d957 updated for version 7.1-221
vimboss
parents: 1497
diff changeset
1468 if (syntax_present(curbuf) && must_redraw)
64ed4359d957 updated for version 7.1-221
vimboss
parents: 1497
diff changeset
1469 update_screen(0);
64ed4359d957 updated for version 7.1-221
vimboss
parents: 1497
diff changeset
1470 # endif
661
e93a99ef31d0 updated for version 7.0195
vimboss
parents: 659
diff changeset
1471 apply_autocmds(EVENT_CURSORMOVEDI, NULL, NULL, FALSE, curbuf);
e93a99ef31d0 updated for version 7.0195
vimboss
parents: 659
diff changeset
1472 last_cursormoved = curwin->w_cursor;
e93a99ef31d0 updated for version 7.0195
vimboss
parents: 659
diff changeset
1473 }
e93a99ef31d0 updated for version 7.0195
vimboss
parents: 659
diff changeset
1474 #endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1475 if (must_redraw)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1476 update_screen(0);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1477 else if (clear_cmdline || redraw_cmdline)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1478 showmode(); /* clear cmdline and show mode */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1479 showruler(FALSE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1480 setcursor();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1481 emsg_on_display = FALSE; /* may remove error message now */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1482 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1483 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1484
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1485 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1486 * Handle a CTRL-V or CTRL-Q typed in Insert mode.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1487 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1488 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1489 ins_ctrl_v()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1490 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1491 int c;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1492
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1493 /* may need to redraw when no more chars available now */
661
e93a99ef31d0 updated for version 7.0195
vimboss
parents: 659
diff changeset
1494 ins_redraw(FALSE);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1495
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1496 if (redrawing() && !char_avail())
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1497 edit_putchar('^', TRUE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1498 AppendToRedobuff((char_u *)CTRL_V_STR); /* CTRL-V */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1499
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1500 #ifdef FEAT_CMDL_INFO
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1501 add_to_showcmd_c(Ctrl_V);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1502 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1503
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1504 c = get_literal();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1505 #ifdef FEAT_CMDL_INFO
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1506 clear_showcmd();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1507 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1508 insert_special(c, FALSE, TRUE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1509 #ifdef FEAT_RIGHTLEFT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1510 revins_chars++;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1511 revins_legal++;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1512 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1513 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1514
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1515 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1516 * Put a character directly onto the screen. It's not stored in a buffer.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1517 * Used while handling CTRL-K, CTRL-V, etc. in Insert mode.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1518 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1519 static int pc_status;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1520 #define PC_STATUS_UNSET 0 /* pc_bytes was not set */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1521 #define PC_STATUS_RIGHT 1 /* right halve of double-wide char */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1522 #define PC_STATUS_LEFT 2 /* left halve of double-wide char */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1523 #define PC_STATUS_SET 3 /* pc_bytes was filled */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1524 #ifdef FEAT_MBYTE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1525 static char_u pc_bytes[MB_MAXBYTES + 1]; /* saved bytes */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1526 #else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1527 static char_u pc_bytes[2]; /* saved bytes */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1528 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1529 static int pc_attr;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1530 static int pc_row;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1531 static int pc_col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1532
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1533 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1534 edit_putchar(c, highlight)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1535 int c;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1536 int highlight;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1537 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1538 int attr;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1539
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1540 if (ScreenLines != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1541 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1542 update_topline(); /* just in case w_topline isn't valid */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1543 validate_cursor();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1544 if (highlight)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1545 attr = hl_attr(HLF_8);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1546 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1547 attr = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1548 pc_row = W_WINROW(curwin) + curwin->w_wrow;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1549 pc_col = W_WINCOL(curwin);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1550 #if defined(FEAT_RIGHTLEFT) || defined(FEAT_MBYTE)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1551 pc_status = PC_STATUS_UNSET;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1552 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1553 #ifdef FEAT_RIGHTLEFT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1554 if (curwin->w_p_rl)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1555 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1556 pc_col += W_WIDTH(curwin) - 1 - curwin->w_wcol;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1557 # ifdef FEAT_MBYTE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1558 if (has_mbyte)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1559 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1560 int fix_col = mb_fix_col(pc_col, pc_row);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1561
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1562 if (fix_col != pc_col)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1563 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1564 screen_putchar(' ', pc_row, fix_col, attr);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1565 --curwin->w_wcol;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1566 pc_status = PC_STATUS_RIGHT;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1567 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1568 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1569 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1570 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1571 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1572 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1573 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1574 pc_col += curwin->w_wcol;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1575 #ifdef FEAT_MBYTE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1576 if (mb_lefthalve(pc_row, pc_col))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1577 pc_status = PC_STATUS_LEFT;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1578 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1579 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1580
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1581 /* save the character to be able to put it back */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1582 #if defined(FEAT_RIGHTLEFT) || defined(FEAT_MBYTE)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1583 if (pc_status == PC_STATUS_UNSET)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1584 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1585 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1586 screen_getbytes(pc_row, pc_col, pc_bytes, &pc_attr);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1587 pc_status = PC_STATUS_SET;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1588 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1589 screen_putchar(c, pc_row, pc_col, attr);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1590 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1591 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1592
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1593 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1594 * Undo the previous edit_putchar().
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1595 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1596 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1597 edit_unputchar()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1598 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1599 if (pc_status != PC_STATUS_UNSET && pc_row >= msg_scrolled)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1600 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1601 #if defined(FEAT_MBYTE)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1602 if (pc_status == PC_STATUS_RIGHT)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1603 ++curwin->w_wcol;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1604 if (pc_status == PC_STATUS_RIGHT || pc_status == PC_STATUS_LEFT)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1605 redrawWinline(curwin->w_cursor.lnum, FALSE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1606 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1607 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1608 screen_puts(pc_bytes, pc_row - msg_scrolled, pc_col, pc_attr);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1609 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1610 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1611
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1612 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1613 * Called when p_dollar is set: display a '$' at the end of the changed text
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1614 * Only works when cursor is in the line that changes.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1615 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1616 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1617 display_dollar(col)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1618 colnr_T col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1619 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1620 colnr_T save_col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1621
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1622 if (!redrawing())
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1623 return;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1624
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1625 cursor_off();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1626 save_col = curwin->w_cursor.col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1627 curwin->w_cursor.col = col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1628 #ifdef FEAT_MBYTE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1629 if (has_mbyte)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1630 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1631 char_u *p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1632
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1633 /* If on the last byte of a multi-byte move to the first byte. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1634 p = ml_get_curline();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1635 curwin->w_cursor.col -= (*mb_head_off)(p, p + col);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1636 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1637 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1638 curs_columns(FALSE); /* recompute w_wrow and w_wcol */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1639 if (curwin->w_wcol < W_WIDTH(curwin))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1640 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1641 edit_putchar('$', FALSE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1642 dollar_vcol = curwin->w_virtcol;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1643 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1644 curwin->w_cursor.col = save_col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1645 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1646
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1647 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1648 * Call this function before moving the cursor from the normal insert position
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1649 * in insert mode.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1650 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1651 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1652 undisplay_dollar()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1653 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1654 if (dollar_vcol)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1655 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1656 dollar_vcol = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1657 redrawWinline(curwin->w_cursor.lnum, FALSE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1658 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1659 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1660
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1661 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1662 * Insert an indent (for <Tab> or CTRL-T) or delete an indent (for CTRL-D).
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1663 * Keep the cursor on the same character.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1664 * type == INDENT_INC increase indent (for CTRL-T or <Tab>)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1665 * type == INDENT_DEC decrease indent (for CTRL-D)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1666 * type == INDENT_SET set indent to "amount"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1667 * if round is TRUE, round the indent to 'shiftwidth' (only with _INC and _Dec).
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1668 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1669 void
1516
ee9d2d24ea9b updated for version 7.1-231
vimboss
parents: 1514
diff changeset
1670 change_indent(type, amount, round, replaced, call_changed_bytes)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1671 int type;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1672 int amount;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1673 int round;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1674 int replaced; /* replaced character, put on replace stack */
1516
ee9d2d24ea9b updated for version 7.1-231
vimboss
parents: 1514
diff changeset
1675 int call_changed_bytes; /* call changed_bytes() */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1676 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1677 int vcol;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1678 int last_vcol;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1679 int insstart_less; /* reduction for Insstart.col */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1680 int new_cursor_col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1681 int i;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1682 char_u *ptr;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1683 int save_p_list;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1684 int start_col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1685 colnr_T vc;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1686 #ifdef FEAT_VREPLACE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1687 colnr_T orig_col = 0; /* init for GCC */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1688 char_u *new_line, *orig_line = NULL; /* init for GCC */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1689
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1690 /* VREPLACE mode needs to know what the line was like before changing */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1691 if (State & VREPLACE_FLAG)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1692 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1693 orig_line = vim_strsave(ml_get_curline()); /* Deal with NULL below */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1694 orig_col = curwin->w_cursor.col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1695 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1696 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1697
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1698 /* for the following tricks we don't want list mode */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1699 save_p_list = curwin->w_p_list;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1700 curwin->w_p_list = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1701 vc = getvcol_nolist(&curwin->w_cursor);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1702 vcol = vc;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1703
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1704 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1705 * For Replace mode we need to fix the replace stack later, which is only
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1706 * possible when the cursor is in the indent. Remember the number of
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1707 * characters before the cursor if it's possible.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1708 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1709 start_col = curwin->w_cursor.col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1710
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1711 /* determine offset from first non-blank */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1712 new_cursor_col = curwin->w_cursor.col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1713 beginline(BL_WHITE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1714 new_cursor_col -= curwin->w_cursor.col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1715
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1716 insstart_less = curwin->w_cursor.col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1717
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1718 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1719 * If the cursor is in the indent, compute how many screen columns the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1720 * cursor is to the left of the first non-blank.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1721 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1722 if (new_cursor_col < 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1723 vcol = get_indent() - vcol;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1724
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1725 if (new_cursor_col > 0) /* can't fix replace stack */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1726 start_col = -1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1727
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1728 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1729 * Set the new indent. The cursor will be put on the first non-blank.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1730 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1731 if (type == INDENT_SET)
1516
ee9d2d24ea9b updated for version 7.1-231
vimboss
parents: 1514
diff changeset
1732 (void)set_indent(amount, call_changed_bytes ? SIN_CHANGED : 0);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1733 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1734 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1735 #ifdef FEAT_VREPLACE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1736 int save_State = State;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1737
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1738 /* Avoid being called recursively. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1739 if (State & VREPLACE_FLAG)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1740 State = INSERT;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1741 #endif
1516
ee9d2d24ea9b updated for version 7.1-231
vimboss
parents: 1514
diff changeset
1742 shift_line(type == INDENT_DEC, round, 1, call_changed_bytes);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1743 #ifdef FEAT_VREPLACE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1744 State = save_State;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1745 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1746 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1747 insstart_less -= curwin->w_cursor.col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1748
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1749 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1750 * Try to put cursor on same character.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1751 * If the cursor is at or after the first non-blank in the line,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1752 * compute the cursor column relative to the column of the first
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1753 * non-blank character.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1754 * If we are not in insert mode, leave the cursor on the first non-blank.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1755 * If the cursor is before the first non-blank, position it relative
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1756 * to the first non-blank, counted in screen columns.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1757 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1758 if (new_cursor_col >= 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1759 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1760 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1761 * When changing the indent while the cursor is touching it, reset
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1762 * Insstart_col to 0.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1763 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1764 if (new_cursor_col == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1765 insstart_less = MAXCOL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1766 new_cursor_col += curwin->w_cursor.col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1767 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1768 else if (!(State & INSERT))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1769 new_cursor_col = curwin->w_cursor.col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1770 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1771 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1772 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1773 * Compute the screen column where the cursor should be.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1774 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1775 vcol = get_indent() - vcol;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1776 curwin->w_virtcol = (vcol < 0) ? 0 : vcol;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1777
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1778 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1779 * Advance the cursor until we reach the right screen column.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1780 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1781 vcol = last_vcol = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1782 new_cursor_col = -1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1783 ptr = ml_get_curline();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1784 while (vcol <= (int)curwin->w_virtcol)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1785 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1786 last_vcol = vcol;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1787 #ifdef FEAT_MBYTE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1788 if (has_mbyte && new_cursor_col >= 0)
474
a5fcf36ef512 updated for version 7.0127
vimboss
parents: 470
diff changeset
1789 new_cursor_col += (*mb_ptr2len)(ptr + new_cursor_col);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1790 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1791 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1792 ++new_cursor_col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1793 vcol += lbr_chartabsize(ptr + new_cursor_col, (colnr_T)vcol);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1794 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1795 vcol = last_vcol;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1796
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1797 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1798 * May need to insert spaces to be able to position the cursor on
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1799 * the right screen column.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1800 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1801 if (vcol != (int)curwin->w_virtcol)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1802 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1803 curwin->w_cursor.col = new_cursor_col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1804 i = (int)curwin->w_virtcol - vcol;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1805 ptr = alloc(i + 1);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1806 if (ptr != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1807 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1808 new_cursor_col += i;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1809 ptr[i] = NUL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1810 while (--i >= 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1811 ptr[i] = ' ';
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1812 ins_str(ptr);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1813 vim_free(ptr);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1814 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1815 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1816
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1817 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1818 * When changing the indent while the cursor is in it, reset
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1819 * Insstart_col to 0.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1820 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1821 insstart_less = MAXCOL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1822 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1823
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1824 curwin->w_p_list = save_p_list;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1825
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1826 if (new_cursor_col <= 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1827 curwin->w_cursor.col = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1828 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1829 curwin->w_cursor.col = new_cursor_col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1830 curwin->w_set_curswant = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1831 changed_cline_bef_curs();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1832
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1833 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1834 * May have to adjust the start of the insert.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1835 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1836 if (State & INSERT)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1837 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1838 if (curwin->w_cursor.lnum == Insstart.lnum && Insstart.col != 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1839 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1840 if ((int)Insstart.col <= insstart_less)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1841 Insstart.col = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1842 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1843 Insstart.col -= insstart_less;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1844 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1845 if ((int)ai_col <= insstart_less)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1846 ai_col = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1847 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1848 ai_col -= insstart_less;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1849 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1850
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1851 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1852 * For REPLACE mode, may have to fix the replace stack, if it's possible.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1853 * If the number of characters before the cursor decreased, need to pop a
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1854 * few characters from the replace stack.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1855 * If the number of characters before the cursor increased, need to push a
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1856 * few NULs onto the replace stack.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1857 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1858 if (REPLACE_NORMAL(State) && start_col >= 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1859 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1860 while (start_col > (int)curwin->w_cursor.col)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1861 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1862 replace_join(0); /* remove a NUL from the replace stack */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1863 --start_col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1864 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1865 while (start_col < (int)curwin->w_cursor.col || replaced)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1866 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1867 replace_push(NUL);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1868 if (replaced)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1869 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1870 replace_push(replaced);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1871 replaced = NUL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1872 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1873 ++start_col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1874 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1875 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1876
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1877 #ifdef FEAT_VREPLACE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1878 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1879 * For VREPLACE mode, we also have to fix the replace stack. In this case
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1880 * it is always possible because we backspace over the whole line and then
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1881 * put it back again the way we wanted it.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1882 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1883 if (State & VREPLACE_FLAG)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1884 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1885 /* If orig_line didn't allocate, just return. At least we did the job,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1886 * even if you can't backspace. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1887 if (orig_line == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1888 return;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1889
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1890 /* Save new line */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1891 new_line = vim_strsave(ml_get_curline());
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1892 if (new_line == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1893 return;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1894
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1895 /* We only put back the new line up to the cursor */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1896 new_line[curwin->w_cursor.col] = NUL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1897
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1898 /* Put back original line */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1899 ml_replace(curwin->w_cursor.lnum, orig_line, FALSE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1900 curwin->w_cursor.col = orig_col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1901
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1902 /* Backspace from cursor to start of line */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1903 backspace_until_column(0);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1904
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1905 /* Insert new stuff into line again */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1906 ins_bytes(new_line);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1907
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1908 vim_free(new_line);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1909 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1910 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1911 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1912
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1913 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1914 * Truncate the space at the end of a line. This is to be used only in an
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1915 * insert mode. It handles fixing the replace stack for REPLACE and VREPLACE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1916 * modes.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1917 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1918 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1919 truncate_spaces(line)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1920 char_u *line;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1921 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1922 int i;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1923
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1924 /* find start of trailing white space */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1925 for (i = (int)STRLEN(line) - 1; i >= 0 && vim_iswhite(line[i]); i--)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1926 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1927 if (State & REPLACE_FLAG)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1928 replace_join(0); /* remove a NUL from the replace stack */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1929 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1930 line[i + 1] = NUL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1931 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1932
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1933 #if defined(FEAT_VREPLACE) || defined(FEAT_INS_EXPAND) \
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1934 || defined(FEAT_COMMENTS) || defined(PROTO)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1935 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1936 * Backspace the cursor until the given column. Handles REPLACE and VREPLACE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1937 * modes correctly. May also be used when not in insert mode at all.
1782
12cecc379574 updated for version 7.2-080
vimboss
parents: 1698
diff changeset
1938 * Will attempt not to go before "col" even when there is a composing
12cecc379574 updated for version 7.2-080
vimboss
parents: 1698
diff changeset
1939 * character.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1940 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1941 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1942 backspace_until_column(col)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1943 int col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1944 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1945 while ((int)curwin->w_cursor.col > col)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1946 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1947 curwin->w_cursor.col--;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1948 if (State & REPLACE_FLAG)
1782
12cecc379574 updated for version 7.2-080
vimboss
parents: 1698
diff changeset
1949 replace_do_bs(col);
12cecc379574 updated for version 7.2-080
vimboss
parents: 1698
diff changeset
1950 else if (!del_char_after_col(col))
12cecc379574 updated for version 7.2-080
vimboss
parents: 1698
diff changeset
1951 break;
12cecc379574 updated for version 7.2-080
vimboss
parents: 1698
diff changeset
1952 }
12cecc379574 updated for version 7.2-080
vimboss
parents: 1698
diff changeset
1953 }
12cecc379574 updated for version 7.2-080
vimboss
parents: 1698
diff changeset
1954 #endif
12cecc379574 updated for version 7.2-080
vimboss
parents: 1698
diff changeset
1955
12cecc379574 updated for version 7.2-080
vimboss
parents: 1698
diff changeset
1956 /*
12cecc379574 updated for version 7.2-080
vimboss
parents: 1698
diff changeset
1957 * Like del_char(), but make sure not to go before column "limit_col".
12cecc379574 updated for version 7.2-080
vimboss
parents: 1698
diff changeset
1958 * Only matters when there are composing characters.
12cecc379574 updated for version 7.2-080
vimboss
parents: 1698
diff changeset
1959 * Return TRUE when something was deleted.
12cecc379574 updated for version 7.2-080
vimboss
parents: 1698
diff changeset
1960 */
1796
4589d1792c03 updated for version 7.2-094
vimboss
parents: 1782
diff changeset
1961 /*ARGSUSED*/
1782
12cecc379574 updated for version 7.2-080
vimboss
parents: 1698
diff changeset
1962 static int
12cecc379574 updated for version 7.2-080
vimboss
parents: 1698
diff changeset
1963 del_char_after_col(limit_col)
12cecc379574 updated for version 7.2-080
vimboss
parents: 1698
diff changeset
1964 int limit_col;
12cecc379574 updated for version 7.2-080
vimboss
parents: 1698
diff changeset
1965 {
12cecc379574 updated for version 7.2-080
vimboss
parents: 1698
diff changeset
1966 #ifdef FEAT_MBYTE
12cecc379574 updated for version 7.2-080
vimboss
parents: 1698
diff changeset
1967 if (enc_utf8 && limit_col >= 0)
12cecc379574 updated for version 7.2-080
vimboss
parents: 1698
diff changeset
1968 {
12cecc379574 updated for version 7.2-080
vimboss
parents: 1698
diff changeset
1969 int ecol = curwin->w_cursor.col + 1;
12cecc379574 updated for version 7.2-080
vimboss
parents: 1698
diff changeset
1970
12cecc379574 updated for version 7.2-080
vimboss
parents: 1698
diff changeset
1971 /* Make sure the cursor is at the start of a character, but
12cecc379574 updated for version 7.2-080
vimboss
parents: 1698
diff changeset
1972 * skip forward again when going too far back because of a
12cecc379574 updated for version 7.2-080
vimboss
parents: 1698
diff changeset
1973 * composing character. */
12cecc379574 updated for version 7.2-080
vimboss
parents: 1698
diff changeset
1974 mb_adjust_cursor();
1796
4589d1792c03 updated for version 7.2-094
vimboss
parents: 1782
diff changeset
1975 while (curwin->w_cursor.col < (colnr_T)limit_col)
1782
12cecc379574 updated for version 7.2-080
vimboss
parents: 1698
diff changeset
1976 {
12cecc379574 updated for version 7.2-080
vimboss
parents: 1698
diff changeset
1977 int l = utf_ptr2len(ml_get_cursor());
12cecc379574 updated for version 7.2-080
vimboss
parents: 1698
diff changeset
1978
12cecc379574 updated for version 7.2-080
vimboss
parents: 1698
diff changeset
1979 if (l == 0) /* end of line */
12cecc379574 updated for version 7.2-080
vimboss
parents: 1698
diff changeset
1980 break;
12cecc379574 updated for version 7.2-080
vimboss
parents: 1698
diff changeset
1981 curwin->w_cursor.col += l;
12cecc379574 updated for version 7.2-080
vimboss
parents: 1698
diff changeset
1982 }
12cecc379574 updated for version 7.2-080
vimboss
parents: 1698
diff changeset
1983 if (*ml_get_cursor() == NUL || curwin->w_cursor.col == ecol)
12cecc379574 updated for version 7.2-080
vimboss
parents: 1698
diff changeset
1984 return FALSE;
12cecc379574 updated for version 7.2-080
vimboss
parents: 1698
diff changeset
1985 del_bytes((long)(ecol - curwin->w_cursor.col), FALSE, TRUE);
12cecc379574 updated for version 7.2-080
vimboss
parents: 1698
diff changeset
1986 }
12cecc379574 updated for version 7.2-080
vimboss
parents: 1698
diff changeset
1987 else
12cecc379574 updated for version 7.2-080
vimboss
parents: 1698
diff changeset
1988 #endif
12cecc379574 updated for version 7.2-080
vimboss
parents: 1698
diff changeset
1989 (void)del_char(FALSE);
12cecc379574 updated for version 7.2-080
vimboss
parents: 1698
diff changeset
1990 return TRUE;
12cecc379574 updated for version 7.2-080
vimboss
parents: 1698
diff changeset
1991 }
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1992
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1993 #if defined(FEAT_INS_EXPAND) || defined(PROTO)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1994 /*
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
1995 * CTRL-X pressed in Insert mode.
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
1996 */
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
1997 static void
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
1998 ins_ctrl_x()
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
1999 {
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
2000 /* CTRL-X after CTRL-X CTRL-V doesn't do anything, so that CTRL-X
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
2001 * CTRL-V works like CTRL-N */
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
2002 if (ctrl_x_mode != CTRL_X_CMDLINE)
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
2003 {
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
2004 /* if the next ^X<> won't ADD nothing, then reset
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
2005 * compl_cont_status */
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
2006 if (compl_cont_status & CONT_N_ADDS)
665
21ab9abf0f08 updated for version 7.0196
vimboss
parents: 661
diff changeset
2007 compl_cont_status |= CONT_INTRPT;
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
2008 else
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
2009 compl_cont_status = 0;
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
2010 /* We're not sure which CTRL-X mode it will be yet */
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
2011 ctrl_x_mode = CTRL_X_NOT_DEFINED_YET;
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
2012 edit_submode = (char_u *)_(CTRL_X_MSG(ctrl_x_mode));
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
2013 edit_submode_pre = NULL;
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
2014 showmode();
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
2015 }
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
2016 }
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
2017
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
2018 /*
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
2019 * Return TRUE if the 'dict' or 'tsr' option can be used.
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
2020 */
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
2021 static int
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
2022 has_compl_option(dict_opt)
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
2023 int dict_opt;
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
2024 {
703
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
2025 if (dict_opt ? (*curbuf->b_p_dict == NUL && *p_dict == NUL
744
07f7b4a7755c updated for version 7.0222
vimboss
parents: 732
diff changeset
2026 # ifdef FEAT_SPELL
07f7b4a7755c updated for version 7.0222
vimboss
parents: 732
diff changeset
2027 && !curwin->w_p_spell
07f7b4a7755c updated for version 7.0222
vimboss
parents: 732
diff changeset
2028 # endif
07f7b4a7755c updated for version 7.0222
vimboss
parents: 732
diff changeset
2029 )
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
2030 : (*curbuf->b_p_tsr == NUL && *p_tsr == NUL))
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
2031 {
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
2032 ctrl_x_mode = 0;
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
2033 edit_submode = NULL;
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
2034 msg_attr(dict_opt ? (char_u *)_("'dictionary' option is empty")
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
2035 : (char_u *)_("'thesaurus' option is empty"),
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
2036 hl_attr(HLF_E));
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
2037 if (emsg_silent == 0)
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
2038 {
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
2039 vim_beep();
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
2040 setcursor();
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
2041 out_flush();
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
2042 ui_delay(2000L, FALSE);
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
2043 }
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
2044 return FALSE;
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
2045 }
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
2046 return TRUE;
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
2047 }
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
2048
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
2049 /*
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2050 * Is the character 'c' a valid key to go to or keep us in CTRL-X mode?
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2051 * This depends on the current mode.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2052 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2053 int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2054 vim_is_ctrl_x_key(c)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2055 int c;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2056 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2057 /* Always allow ^R - let it's results then be checked */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2058 if (c == Ctrl_R)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2059 return TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2060
610
cd3689efd90a updated for version 7.0173
vimboss
parents: 603
diff changeset
2061 /* Accept <PageUp> and <PageDown> if the popup menu is visible. */
644
e4fa26ce8769 updated for version 7.0187
vimboss
parents: 634
diff changeset
2062 if (ins_compl_pum_key(c))
610
cd3689efd90a updated for version 7.0173
vimboss
parents: 603
diff changeset
2063 return TRUE;
cd3689efd90a updated for version 7.0173
vimboss
parents: 603
diff changeset
2064
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2065 switch (ctrl_x_mode)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2066 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2067 case 0: /* Not in any CTRL-X mode */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2068 return (c == Ctrl_N || c == Ctrl_P || c == Ctrl_X);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2069 case CTRL_X_NOT_DEFINED_YET:
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
2070 return ( c == Ctrl_X || c == Ctrl_Y || c == Ctrl_E
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2071 || c == Ctrl_L || c == Ctrl_F || c == Ctrl_RSB
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2072 || c == Ctrl_I || c == Ctrl_D || c == Ctrl_P
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2073 || c == Ctrl_N || c == Ctrl_T || c == Ctrl_V
477
f8b75b8f1988 updated for version 7.0128
vimboss
parents: 474
diff changeset
2074 || c == Ctrl_Q || c == Ctrl_U || c == Ctrl_O
f8b75b8f1988 updated for version 7.0128
vimboss
parents: 474
diff changeset
2075 || c == Ctrl_S || c == 's');
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2076 case CTRL_X_SCROLL:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2077 return (c == Ctrl_Y || c == Ctrl_E);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2078 case CTRL_X_WHOLE_LINE:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2079 return (c == Ctrl_L || c == Ctrl_P || c == Ctrl_N);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2080 case CTRL_X_FILES:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2081 return (c == Ctrl_F || c == Ctrl_P || c == Ctrl_N);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2082 case CTRL_X_DICTIONARY:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2083 return (c == Ctrl_K || c == Ctrl_P || c == Ctrl_N);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2084 case CTRL_X_THESAURUS:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2085 return (c == Ctrl_T || c == Ctrl_P || c == Ctrl_N);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2086 case CTRL_X_TAGS:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2087 return (c == Ctrl_RSB || c == Ctrl_P || c == Ctrl_N);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2088 #ifdef FEAT_FIND_ID
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2089 case CTRL_X_PATH_PATTERNS:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2090 return (c == Ctrl_P || c == Ctrl_N);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2091 case CTRL_X_PATH_DEFINES:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2092 return (c == Ctrl_D || c == Ctrl_P || c == Ctrl_N);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2093 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2094 case CTRL_X_CMDLINE:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2095 return (c == Ctrl_V || c == Ctrl_Q || c == Ctrl_P || c == Ctrl_N
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2096 || c == Ctrl_X);
12
bdeee1504ac1 updated for version 7.0004
vimboss
parents: 11
diff changeset
2097 #ifdef FEAT_COMPL_FUNC
bdeee1504ac1 updated for version 7.0004
vimboss
parents: 11
diff changeset
2098 case CTRL_X_FUNCTION:
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
2099 return (c == Ctrl_U || c == Ctrl_P || c == Ctrl_N);
523
a7ae7e043e43 updated for version 7.0146
vimboss
parents: 502
diff changeset
2100 case CTRL_X_OMNI:
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
2101 return (c == Ctrl_O || c == Ctrl_P || c == Ctrl_N);
502
52e76e2b5b65 updated for version 7.0140
vimboss
parents: 499
diff changeset
2102 #endif
477
f8b75b8f1988 updated for version 7.0128
vimboss
parents: 474
diff changeset
2103 case CTRL_X_SPELL:
f8b75b8f1988 updated for version 7.0128
vimboss
parents: 474
diff changeset
2104 return (c == Ctrl_S || c == Ctrl_P || c == Ctrl_N);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2105 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2106 EMSG(_(e_internal));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2107 return FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2108 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2109
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2110 /*
1430
342cf2a9f5cc updated for version 7.1-145
vimboss
parents: 1389
diff changeset
2111 * Return TRUE when character "c" is part of the item currently being
342cf2a9f5cc updated for version 7.1-145
vimboss
parents: 1389
diff changeset
2112 * completed. Used to decide whether to abandon complete mode when the menu
342cf2a9f5cc updated for version 7.1-145
vimboss
parents: 1389
diff changeset
2113 * is visible.
342cf2a9f5cc updated for version 7.1-145
vimboss
parents: 1389
diff changeset
2114 */
342cf2a9f5cc updated for version 7.1-145
vimboss
parents: 1389
diff changeset
2115 static int
342cf2a9f5cc updated for version 7.1-145
vimboss
parents: 1389
diff changeset
2116 ins_compl_accept_char(c)
342cf2a9f5cc updated for version 7.1-145
vimboss
parents: 1389
diff changeset
2117 int c;
342cf2a9f5cc updated for version 7.1-145
vimboss
parents: 1389
diff changeset
2118 {
342cf2a9f5cc updated for version 7.1-145
vimboss
parents: 1389
diff changeset
2119 if (ctrl_x_mode & CTRL_X_WANT_IDENT)
342cf2a9f5cc updated for version 7.1-145
vimboss
parents: 1389
diff changeset
2120 /* When expanding an identifier only accept identifier chars. */
342cf2a9f5cc updated for version 7.1-145
vimboss
parents: 1389
diff changeset
2121 return vim_isIDc(c);
342cf2a9f5cc updated for version 7.1-145
vimboss
parents: 1389
diff changeset
2122
342cf2a9f5cc updated for version 7.1-145
vimboss
parents: 1389
diff changeset
2123 switch (ctrl_x_mode)
342cf2a9f5cc updated for version 7.1-145
vimboss
parents: 1389
diff changeset
2124 {
342cf2a9f5cc updated for version 7.1-145
vimboss
parents: 1389
diff changeset
2125 case CTRL_X_FILES:
342cf2a9f5cc updated for version 7.1-145
vimboss
parents: 1389
diff changeset
2126 /* When expanding file name only accept file name chars. But not
342cf2a9f5cc updated for version 7.1-145
vimboss
parents: 1389
diff changeset
2127 * path separators, so that "proto/<Tab>" expands files in
342cf2a9f5cc updated for version 7.1-145
vimboss
parents: 1389
diff changeset
2128 * "proto", not "proto/" as a whole */
342cf2a9f5cc updated for version 7.1-145
vimboss
parents: 1389
diff changeset
2129 return vim_isfilec(c) && !vim_ispathsep(c);
342cf2a9f5cc updated for version 7.1-145
vimboss
parents: 1389
diff changeset
2130
342cf2a9f5cc updated for version 7.1-145
vimboss
parents: 1389
diff changeset
2131 case CTRL_X_CMDLINE:
342cf2a9f5cc updated for version 7.1-145
vimboss
parents: 1389
diff changeset
2132 case CTRL_X_OMNI:
342cf2a9f5cc updated for version 7.1-145
vimboss
parents: 1389
diff changeset
2133 /* Command line and Omni completion can work with just about any
342cf2a9f5cc updated for version 7.1-145
vimboss
parents: 1389
diff changeset
2134 * printable character, but do stop at white space. */
342cf2a9f5cc updated for version 7.1-145
vimboss
parents: 1389
diff changeset
2135 return vim_isprintc(c) && !vim_iswhite(c);
342cf2a9f5cc updated for version 7.1-145
vimboss
parents: 1389
diff changeset
2136
342cf2a9f5cc updated for version 7.1-145
vimboss
parents: 1389
diff changeset
2137 case CTRL_X_WHOLE_LINE:
342cf2a9f5cc updated for version 7.1-145
vimboss
parents: 1389
diff changeset
2138 /* For while line completion a space can be part of the line. */
342cf2a9f5cc updated for version 7.1-145
vimboss
parents: 1389
diff changeset
2139 return vim_isprintc(c);
342cf2a9f5cc updated for version 7.1-145
vimboss
parents: 1389
diff changeset
2140 }
342cf2a9f5cc updated for version 7.1-145
vimboss
parents: 1389
diff changeset
2141 return vim_iswordc(c);
342cf2a9f5cc updated for version 7.1-145
vimboss
parents: 1389
diff changeset
2142 }
342cf2a9f5cc updated for version 7.1-145
vimboss
parents: 1389
diff changeset
2143
342cf2a9f5cc updated for version 7.1-145
vimboss
parents: 1389
diff changeset
2144 /*
659
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
2145 * This is like ins_compl_add(), but if 'ic' and 'inf' are set, then the
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2146 * case of the originally typed text is used, and the case of the completed
1219
aea597af5b4e updated for version 7.1b
vimboss
parents: 1159
diff changeset
2147 * text is inferred, ie this tries to work out what case you probably wanted
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2148 * the rest of the word to be in -- webb
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2149 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2150 int
681
9364d114ed8d updated for version 7.0204
vimboss
parents: 677
diff changeset
2151 ins_compl_add_infercase(str, len, icase, fname, dir, flags)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2152 char_u *str;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2153 int len;
681
9364d114ed8d updated for version 7.0204
vimboss
parents: 677
diff changeset
2154 int icase;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2155 char_u *fname;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2156 int dir;
464
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
2157 int flags;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2158 {
1353
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2159 char_u *p;
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2160 int i, c;
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2161 int actual_len; /* Take multi-byte characters */
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2162 int actual_compl_length; /* into account. */
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2163 int *wca; /* Wide character array. */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2164 int has_lower = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2165 int was_letter = FALSE;
1353
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2166
1436
77310929a1f9 updated for version 7.1-151
vimboss
parents: 1434
diff changeset
2167 if (p_ic && curbuf->b_p_inf && len > 0)
1353
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2168 {
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2169 /* Infer case of completed part. */
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2170
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2171 /* Find actual length of completion. */
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2172 #ifdef FEAT_MBYTE
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2173 if (has_mbyte)
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2174 {
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2175 p = str;
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2176 actual_len = 0;
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2177 while (*p != NUL)
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2178 {
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2179 mb_ptr_adv(p);
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2180 ++actual_len;
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2181 }
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2182 }
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2183 else
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2184 #endif
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2185 actual_len = len;
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2186
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2187 /* Find actual length of original text. */
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2188 #ifdef FEAT_MBYTE
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2189 if (has_mbyte)
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2190 {
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2191 p = compl_orig_text;
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2192 actual_compl_length = 0;
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2193 while (*p != NUL)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2194 {
1353
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2195 mb_ptr_adv(p);
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2196 ++actual_compl_length;
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2197 }
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2198 }
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2199 else
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2200 #endif
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2201 actual_compl_length = compl_length;
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2202
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2203 /* Allocate wide character array for the completion and fill it. */
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2204 wca = (int *)alloc(actual_len * sizeof(int));
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2205 if (wca != NULL)
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2206 {
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2207 p = str;
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2208 for (i = 0; i < actual_len; ++i)
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2209 #ifdef FEAT_MBYTE
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2210 if (has_mbyte)
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2211 wca[i] = mb_ptr2char_adv(&p);
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2212 else
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2213 #endif
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2214 wca[i] = *(p++);
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2215
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2216 /* Rule 1: Were any chars converted to lower? */
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2217 p = compl_orig_text;
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2218 for (i = 0; i < actual_compl_length; ++i)
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2219 {
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2220 #ifdef FEAT_MBYTE
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2221 if (has_mbyte)
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2222 c = mb_ptr2char_adv(&p);
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2223 else
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2224 #endif
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2225 c = *(p++);
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2226 if (MB_ISLOWER(c))
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2227 {
1353
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2228 has_lower = TRUE;
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2229 if (MB_ISUPPER(wca[i]))
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2230 {
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2231 /* Rule 1 is satisfied. */
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2232 for (i = actual_compl_length; i < actual_len; ++i)
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2233 wca[i] = MB_TOLOWER(wca[i]);
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2234 break;
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2235 }
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2236 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2237 }
1353
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2238
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2239 /*
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2240 * Rule 2: No lower case, 2nd consecutive letter converted to
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2241 * upper case.
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2242 */
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2243 if (!has_lower)
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2244 {
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2245 p = compl_orig_text;
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2246 for (i = 0; i < actual_compl_length; ++i)
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2247 {
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2248 #ifdef FEAT_MBYTE
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2249 if (has_mbyte)
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2250 c = mb_ptr2char_adv(&p);
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2251 else
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2252 #endif
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2253 c = *(p++);
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2254 if (was_letter && MB_ISUPPER(c) && MB_ISLOWER(wca[i]))
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2255 {
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2256 /* Rule 2 is satisfied. */
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2257 for (i = actual_compl_length; i < actual_len; ++i)
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2258 wca[i] = MB_TOUPPER(wca[i]);
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2259 break;
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2260 }
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2261 was_letter = MB_ISLOWER(c) || MB_ISUPPER(c);
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2262 }
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2263 }
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2264
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2265 /* Copy the original case of the part we typed. */
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2266 p = compl_orig_text;
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2267 for (i = 0; i < actual_compl_length; ++i)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2268 {
1353
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2269 #ifdef FEAT_MBYTE
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2270 if (has_mbyte)
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2271 c = mb_ptr2char_adv(&p);
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2272 else
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2273 #endif
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2274 c = *(p++);
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2275 if (MB_ISLOWER(c))
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2276 wca[i] = MB_TOLOWER(wca[i]);
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2277 else if (MB_ISUPPER(c))
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2278 wca[i] = MB_TOUPPER(wca[i]);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2279 }
1353
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2280
1436
77310929a1f9 updated for version 7.1-151
vimboss
parents: 1434
diff changeset
2281 /*
1353
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2282 * Generate encoding specific output from wide character array.
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2283 * Multi-byte characters can occupy up to five bytes more than
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2284 * ASCII characters, and we also need one byte for NUL, so stay
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2285 * six bytes away from the edge of IObuff.
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2286 */
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2287 p = IObuff;
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2288 i = 0;
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2289 while (i < actual_len && (p - IObuff + 6) < IOSIZE)
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2290 #ifdef FEAT_MBYTE
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2291 if (has_mbyte)
1446
f0b3b9ac2147 updated for version 7.1-161
vimboss
parents: 1436
diff changeset
2292 p += (*mb_char2bytes)(wca[i++], p);
1353
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2293 else
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2294 #endif
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2295 *(p++) = wca[i++];
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2296 *p = NUL;
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2297
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2298 vim_free(wca);
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
2299 }
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2300
841
c2cae213194d updated for version 7.0e07
vimboss
parents: 840
diff changeset
2301 return ins_compl_add(IObuff, len, icase, fname, NULL, dir,
c2cae213194d updated for version 7.0e07
vimboss
parents: 840
diff changeset
2302 flags, FALSE);
c2cae213194d updated for version 7.0e07
vimboss
parents: 840
diff changeset
2303 }
c2cae213194d updated for version 7.0e07
vimboss
parents: 840
diff changeset
2304 return ins_compl_add(str, len, icase, fname, NULL, dir, flags, FALSE);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2305 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2306
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2307 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2308 * Add a match to the list of matches.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2309 * If the given string is already in the list of completions, then return
464
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
2310 * NOTDONE, otherwise add it to the list and return OK. If there is an error,
681
9364d114ed8d updated for version 7.0204
vimboss
parents: 677
diff changeset
2311 * maybe because alloc() returns NULL, then FAIL is returned.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2312 */
841
c2cae213194d updated for version 7.0e07
vimboss
parents: 840
diff changeset
2313 static int
944
b2dcb8457067 updated for version 7.0-070
vimboss
parents: 942
diff changeset
2314 ins_compl_add(str, len, icase, fname, cptext, cdir, flags, adup)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2315 char_u *str;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2316 int len;
681
9364d114ed8d updated for version 7.0204
vimboss
parents: 677
diff changeset
2317 int icase;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2318 char_u *fname;
841
c2cae213194d updated for version 7.0e07
vimboss
parents: 840
diff changeset
2319 char_u **cptext; /* extra text for popup menu or NULL */
659
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
2320 int cdir;
464
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
2321 int flags;
944
b2dcb8457067 updated for version 7.0-070
vimboss
parents: 942
diff changeset
2322 int adup; /* accept duplicate match */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2323 {
464
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
2324 compl_T *match;
659
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
2325 int dir = (cdir == 0 ? compl_direction : cdir);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2326
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2327 ui_breakcheck();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2328 if (got_int)
464
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
2329 return FAIL;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2330 if (len < 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2331 len = (int)STRLEN(str);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2332
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2333 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2334 * If the same match is already present, don't add it.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2335 */
944
b2dcb8457067 updated for version 7.0-070
vimboss
parents: 942
diff changeset
2336 if (compl_first_match != NULL && !adup)
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
2337 {
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
2338 match = compl_first_match;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2339 do
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2340 {
464
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
2341 if ( !(match->cp_flags & ORIGINAL_TEXT)
989
3f8cf4c668c3 updated for version 7.0-115
vimboss
parents: 987
diff changeset
2342 && STRNCMP(match->cp_str, str, len) == 0
464
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
2343 && match->cp_str[len] == NUL)
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
2344 return NOTDONE;
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
2345 match = match->cp_next;
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
2346 } while (match != NULL && match != compl_first_match);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2347 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2348
540
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2349 /* Remove any popup menu before changing the list of matches. */
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2350 ins_compl_del_pum();
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2351
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2352 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2353 * Allocate a new match structure.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2354 * Copy the values to the new match structure.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2355 */
659
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
2356 match = (compl_T *)alloc_clear((unsigned)sizeof(compl_T));
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2357 if (match == NULL)
464
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
2358 return FAIL;
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
2359 match->cp_number = -1;
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
2360 if (flags & ORIGINAL_TEXT)
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
2361 match->cp_number = 0;
694
07d199fe02ed updated for version 7.0209
vimboss
parents: 692
diff changeset
2362 if ((match->cp_str = vim_strnsave(str, len)) == NULL)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2363 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2364 vim_free(match);
464
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
2365 return FAIL;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2366 }
681
9364d114ed8d updated for version 7.0204
vimboss
parents: 677
diff changeset
2367 match->cp_icase = icase;
659
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
2368
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2369 /* match-fname is:
464
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
2370 * - compl_curr_match->cp_fname if it is a string equal to fname.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2371 * - a copy of fname, FREE_FNAME is set to free later THE allocated mem.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2372 * - NULL otherwise. --Acevedo */
659
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
2373 if (fname != NULL
829
dc8197342755 updated for version 7.0d04
vimboss
parents: 828
diff changeset
2374 && compl_curr_match != NULL
659
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
2375 && compl_curr_match->cp_fname != NULL
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
2376 && STRCMP(fname, compl_curr_match->cp_fname) == 0)
464
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
2377 match->cp_fname = compl_curr_match->cp_fname;
659
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
2378 else if (fname != NULL)
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
2379 {
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
2380 match->cp_fname = vim_strsave(fname);
464
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
2381 flags |= FREE_FNAME;
659
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
2382 }
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2383 else
464
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
2384 match->cp_fname = NULL;
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
2385 match->cp_flags = flags;
786
8f6a426bc1e0 updated for version 7.0229
vimboss
parents: 782
diff changeset
2386
8f6a426bc1e0 updated for version 7.0229
vimboss
parents: 782
diff changeset
2387 if (cptext != NULL)
8f6a426bc1e0 updated for version 7.0229
vimboss
parents: 782
diff changeset
2388 {
8f6a426bc1e0 updated for version 7.0229
vimboss
parents: 782
diff changeset
2389 int i;
8f6a426bc1e0 updated for version 7.0229
vimboss
parents: 782
diff changeset
2390
8f6a426bc1e0 updated for version 7.0229
vimboss
parents: 782
diff changeset
2391 for (i = 0; i < CPT_COUNT; ++i)
8f6a426bc1e0 updated for version 7.0229
vimboss
parents: 782
diff changeset
2392 if (cptext[i] != NULL && *cptext[i] != NUL)
8f6a426bc1e0 updated for version 7.0229
vimboss
parents: 782
diff changeset
2393 match->cp_text[i] = vim_strsave(cptext[i]);
8f6a426bc1e0 updated for version 7.0229
vimboss
parents: 782
diff changeset
2394 }
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2395
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2396 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2397 * Link the new match structure in the list of matches.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2398 */
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
2399 if (compl_first_match == NULL)
464
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
2400 match->cp_next = match->cp_prev = NULL;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2401 else if (dir == FORWARD)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2402 {
464
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
2403 match->cp_next = compl_curr_match->cp_next;
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
2404 match->cp_prev = compl_curr_match;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2405 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2406 else /* BACKWARD */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2407 {
464
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
2408 match->cp_next = compl_curr_match;
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
2409 match->cp_prev = compl_curr_match->cp_prev;
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
2410 }
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
2411 if (match->cp_next)
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
2412 match->cp_next->cp_prev = match;
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
2413 if (match->cp_prev)
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
2414 match->cp_prev->cp_next = match;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2415 else /* if there's nothing before, it is the first match */
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
2416 compl_first_match = match;
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
2417 compl_curr_match = match;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2418
665
21ab9abf0f08 updated for version 7.0196
vimboss
parents: 661
diff changeset
2419 /*
21ab9abf0f08 updated for version 7.0196
vimboss
parents: 661
diff changeset
2420 * Find the longest common string if still doing that.
21ab9abf0f08 updated for version 7.0196
vimboss
parents: 661
diff changeset
2421 */
21ab9abf0f08 updated for version 7.0196
vimboss
parents: 661
diff changeset
2422 if (compl_get_longest && (flags & ORIGINAL_TEXT) == 0)
21ab9abf0f08 updated for version 7.0196
vimboss
parents: 661
diff changeset
2423 ins_compl_longest_match(match);
21ab9abf0f08 updated for version 7.0196
vimboss
parents: 661
diff changeset
2424
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2425 return OK;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2426 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2427
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2428 /*
681
9364d114ed8d updated for version 7.0204
vimboss
parents: 677
diff changeset
2429 * Return TRUE if "str[len]" matches with match->cp_str, considering
9364d114ed8d updated for version 7.0204
vimboss
parents: 677
diff changeset
2430 * match->cp_icase.
9364d114ed8d updated for version 7.0204
vimboss
parents: 677
diff changeset
2431 */
9364d114ed8d updated for version 7.0204
vimboss
parents: 677
diff changeset
2432 static int
9364d114ed8d updated for version 7.0204
vimboss
parents: 677
diff changeset
2433 ins_compl_equal(match, str, len)
9364d114ed8d updated for version 7.0204
vimboss
parents: 677
diff changeset
2434 compl_T *match;
9364d114ed8d updated for version 7.0204
vimboss
parents: 677
diff changeset
2435 char_u *str;
9364d114ed8d updated for version 7.0204
vimboss
parents: 677
diff changeset
2436 int len;
9364d114ed8d updated for version 7.0204
vimboss
parents: 677
diff changeset
2437 {
9364d114ed8d updated for version 7.0204
vimboss
parents: 677
diff changeset
2438 if (match->cp_icase)
9364d114ed8d updated for version 7.0204
vimboss
parents: 677
diff changeset
2439 return STRNICMP(match->cp_str, str, (size_t)len) == 0;
9364d114ed8d updated for version 7.0204
vimboss
parents: 677
diff changeset
2440 return STRNCMP(match->cp_str, str, (size_t)len) == 0;
9364d114ed8d updated for version 7.0204
vimboss
parents: 677
diff changeset
2441 }
9364d114ed8d updated for version 7.0204
vimboss
parents: 677
diff changeset
2442
9364d114ed8d updated for version 7.0204
vimboss
parents: 677
diff changeset
2443 /*
665
21ab9abf0f08 updated for version 7.0196
vimboss
parents: 661
diff changeset
2444 * Reduce the longest common string for match "match".
21ab9abf0f08 updated for version 7.0196
vimboss
parents: 661
diff changeset
2445 */
21ab9abf0f08 updated for version 7.0196
vimboss
parents: 661
diff changeset
2446 static void
21ab9abf0f08 updated for version 7.0196
vimboss
parents: 661
diff changeset
2447 ins_compl_longest_match(match)
21ab9abf0f08 updated for version 7.0196
vimboss
parents: 661
diff changeset
2448 compl_T *match;
21ab9abf0f08 updated for version 7.0196
vimboss
parents: 661
diff changeset
2449 {
21ab9abf0f08 updated for version 7.0196
vimboss
parents: 661
diff changeset
2450 char_u *p, *s;
681
9364d114ed8d updated for version 7.0204
vimboss
parents: 677
diff changeset
2451 int c1, c2;
665
21ab9abf0f08 updated for version 7.0196
vimboss
parents: 661
diff changeset
2452 int had_match;
21ab9abf0f08 updated for version 7.0196
vimboss
parents: 661
diff changeset
2453
21ab9abf0f08 updated for version 7.0196
vimboss
parents: 661
diff changeset
2454 if (compl_leader == NULL)
842
a209672376fd updated for version 7.0f
vimboss
parents: 841
diff changeset
2455 {
665
21ab9abf0f08 updated for version 7.0196
vimboss
parents: 661
diff changeset
2456 /* First match, use it as a whole. */
21ab9abf0f08 updated for version 7.0196
vimboss
parents: 661
diff changeset
2457 compl_leader = vim_strsave(match->cp_str);
842
a209672376fd updated for version 7.0f
vimboss
parents: 841
diff changeset
2458 if (compl_leader != NULL)
a209672376fd updated for version 7.0f
vimboss
parents: 841
diff changeset
2459 {
a209672376fd updated for version 7.0f
vimboss
parents: 841
diff changeset
2460 had_match = (curwin->w_cursor.col > compl_col);
a209672376fd updated for version 7.0f
vimboss
parents: 841
diff changeset
2461 ins_compl_delete();
1782
12cecc379574 updated for version 7.2-080
vimboss
parents: 1698
diff changeset
2462 ins_bytes(compl_leader + ins_compl_len());
842
a209672376fd updated for version 7.0f
vimboss
parents: 841
diff changeset
2463 ins_redraw(FALSE);
a209672376fd updated for version 7.0f
vimboss
parents: 841
diff changeset
2464
a209672376fd updated for version 7.0f
vimboss
parents: 841
diff changeset
2465 /* When the match isn't there (to avoid matching itself) remove it
a209672376fd updated for version 7.0f
vimboss
parents: 841
diff changeset
2466 * again after redrawing. */
a209672376fd updated for version 7.0f
vimboss
parents: 841
diff changeset
2467 if (!had_match)
a209672376fd updated for version 7.0f
vimboss
parents: 841
diff changeset
2468 ins_compl_delete();
a209672376fd updated for version 7.0f
vimboss
parents: 841
diff changeset
2469 compl_used_match = FALSE;
a209672376fd updated for version 7.0f
vimboss
parents: 841
diff changeset
2470 }
a209672376fd updated for version 7.0f
vimboss
parents: 841
diff changeset
2471 }
665
21ab9abf0f08 updated for version 7.0196
vimboss
parents: 661
diff changeset
2472 else
21ab9abf0f08 updated for version 7.0196
vimboss
parents: 661
diff changeset
2473 {
21ab9abf0f08 updated for version 7.0196
vimboss
parents: 661
diff changeset
2474 /* Reduce the text if this match differs from compl_leader. */
681
9364d114ed8d updated for version 7.0204
vimboss
parents: 677
diff changeset
2475 p = compl_leader;
9364d114ed8d updated for version 7.0204
vimboss
parents: 677
diff changeset
2476 s = match->cp_str;
9364d114ed8d updated for version 7.0204
vimboss
parents: 677
diff changeset
2477 while (*p != NUL)
665
21ab9abf0f08 updated for version 7.0196
vimboss
parents: 661
diff changeset
2478 {
21ab9abf0f08 updated for version 7.0196
vimboss
parents: 661
diff changeset
2479 #ifdef FEAT_MBYTE
21ab9abf0f08 updated for version 7.0196
vimboss
parents: 661
diff changeset
2480 if (has_mbyte)
21ab9abf0f08 updated for version 7.0196
vimboss
parents: 661
diff changeset
2481 {
681
9364d114ed8d updated for version 7.0204
vimboss
parents: 677
diff changeset
2482 c1 = mb_ptr2char(p);
9364d114ed8d updated for version 7.0204
vimboss
parents: 677
diff changeset
2483 c2 = mb_ptr2char(s);
665
21ab9abf0f08 updated for version 7.0196
vimboss
parents: 661
diff changeset
2484 }
21ab9abf0f08 updated for version 7.0196
vimboss
parents: 661
diff changeset
2485 else
21ab9abf0f08 updated for version 7.0196
vimboss
parents: 661
diff changeset
2486 #endif
21ab9abf0f08 updated for version 7.0196
vimboss
parents: 661
diff changeset
2487 {
681
9364d114ed8d updated for version 7.0204
vimboss
parents: 677
diff changeset
2488 c1 = *p;
9364d114ed8d updated for version 7.0204
vimboss
parents: 677
diff changeset
2489 c2 = *s;
9364d114ed8d updated for version 7.0204
vimboss
parents: 677
diff changeset
2490 }
9364d114ed8d updated for version 7.0204
vimboss
parents: 677
diff changeset
2491 if (match->cp_icase ? (MB_TOLOWER(c1) != MB_TOLOWER(c2))
9364d114ed8d updated for version 7.0204
vimboss
parents: 677
diff changeset
2492 : (c1 != c2))
9364d114ed8d updated for version 7.0204
vimboss
parents: 677
diff changeset
2493 break;
9364d114ed8d updated for version 7.0204
vimboss
parents: 677
diff changeset
2494 #ifdef FEAT_MBYTE
9364d114ed8d updated for version 7.0204
vimboss
parents: 677
diff changeset
2495 if (has_mbyte)
9364d114ed8d updated for version 7.0204
vimboss
parents: 677
diff changeset
2496 {
9364d114ed8d updated for version 7.0204
vimboss
parents: 677
diff changeset
2497 mb_ptr_adv(p);
9364d114ed8d updated for version 7.0204
vimboss
parents: 677
diff changeset
2498 mb_ptr_adv(s);
9364d114ed8d updated for version 7.0204
vimboss
parents: 677
diff changeset
2499 }
9364d114ed8d updated for version 7.0204
vimboss
parents: 677
diff changeset
2500 else
9364d114ed8d updated for version 7.0204
vimboss
parents: 677
diff changeset
2501 #endif
9364d114ed8d updated for version 7.0204
vimboss
parents: 677
diff changeset
2502 {
9364d114ed8d updated for version 7.0204
vimboss
parents: 677
diff changeset
2503 ++p;
9364d114ed8d updated for version 7.0204
vimboss
parents: 677
diff changeset
2504 ++s;
665
21ab9abf0f08 updated for version 7.0196
vimboss
parents: 661
diff changeset
2505 }
21ab9abf0f08 updated for version 7.0196
vimboss
parents: 661
diff changeset
2506 }
21ab9abf0f08 updated for version 7.0196
vimboss
parents: 661
diff changeset
2507
21ab9abf0f08 updated for version 7.0196
vimboss
parents: 661
diff changeset
2508 if (*p != NUL)
21ab9abf0f08 updated for version 7.0196
vimboss
parents: 661
diff changeset
2509 {
21ab9abf0f08 updated for version 7.0196
vimboss
parents: 661
diff changeset
2510 /* Leader was shortened, need to change the inserted text. */
21ab9abf0f08 updated for version 7.0196
vimboss
parents: 661
diff changeset
2511 *p = NUL;
21ab9abf0f08 updated for version 7.0196
vimboss
parents: 661
diff changeset
2512 had_match = (curwin->w_cursor.col > compl_col);
21ab9abf0f08 updated for version 7.0196
vimboss
parents: 661
diff changeset
2513 ins_compl_delete();
1782
12cecc379574 updated for version 7.2-080
vimboss
parents: 1698
diff changeset
2514 ins_bytes(compl_leader + ins_compl_len());
665
21ab9abf0f08 updated for version 7.0196
vimboss
parents: 661
diff changeset
2515 ins_redraw(FALSE);
21ab9abf0f08 updated for version 7.0196
vimboss
parents: 661
diff changeset
2516
21ab9abf0f08 updated for version 7.0196
vimboss
parents: 661
diff changeset
2517 /* When the match isn't there (to avoid matching itself) remove it
21ab9abf0f08 updated for version 7.0196
vimboss
parents: 661
diff changeset
2518 * again after redrawing. */
21ab9abf0f08 updated for version 7.0196
vimboss
parents: 661
diff changeset
2519 if (!had_match)
21ab9abf0f08 updated for version 7.0196
vimboss
parents: 661
diff changeset
2520 ins_compl_delete();
21ab9abf0f08 updated for version 7.0196
vimboss
parents: 661
diff changeset
2521 }
21ab9abf0f08 updated for version 7.0196
vimboss
parents: 661
diff changeset
2522
21ab9abf0f08 updated for version 7.0196
vimboss
parents: 661
diff changeset
2523 compl_used_match = FALSE;
21ab9abf0f08 updated for version 7.0196
vimboss
parents: 661
diff changeset
2524 }
21ab9abf0f08 updated for version 7.0196
vimboss
parents: 661
diff changeset
2525 }
21ab9abf0f08 updated for version 7.0196
vimboss
parents: 661
diff changeset
2526
21ab9abf0f08 updated for version 7.0196
vimboss
parents: 661
diff changeset
2527 /*
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2528 * Add an array of matches to the list of matches.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2529 * Frees matches[].
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2530 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2531 static void
681
9364d114ed8d updated for version 7.0204
vimboss
parents: 677
diff changeset
2532 ins_compl_add_matches(num_matches, matches, icase)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2533 int num_matches;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2534 char_u **matches;
681
9364d114ed8d updated for version 7.0204
vimboss
parents: 677
diff changeset
2535 int icase;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2536 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2537 int i;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2538 int add_r = OK;
659
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
2539 int dir = compl_direction;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2540
464
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
2541 for (i = 0; i < num_matches && add_r != FAIL; i++)
681
9364d114ed8d updated for version 7.0204
vimboss
parents: 677
diff changeset
2542 if ((add_r = ins_compl_add(matches[i], -1, icase,
841
c2cae213194d updated for version 7.0e07
vimboss
parents: 840
diff changeset
2543 NULL, NULL, dir, 0, FALSE)) == OK)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2544 /* if dir was BACKWARD then honor it just once */
659
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
2545 dir = FORWARD;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2546 FreeWild(num_matches, matches);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2547 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2548
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2549 /* Make the completion list cyclic.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2550 * Return the number of matches (excluding the original).
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2551 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2552 static int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2553 ins_compl_make_cyclic()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2554 {
464
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
2555 compl_T *match;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2556 int count = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2557
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
2558 if (compl_first_match != NULL)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2559 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2560 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2561 * Find the end of the list.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2562 */
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
2563 match = compl_first_match;
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
2564 /* there's always an entry for the compl_orig_text, it doesn't count. */
464
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
2565 while (match->cp_next != NULL && match->cp_next != compl_first_match)
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
2566 {
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
2567 match = match->cp_next;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2568 ++count;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2569 }
464
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
2570 match->cp_next = compl_first_match;
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
2571 compl_first_match->cp_prev = match;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2572 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2573 return count;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2574 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2575
724
a35dce0cabc5 updated for version 7.0220
vimboss
parents: 716
diff changeset
2576 /*
a35dce0cabc5 updated for version 7.0220
vimboss
parents: 716
diff changeset
2577 * Start completion for the complete() function.
a35dce0cabc5 updated for version 7.0220
vimboss
parents: 716
diff changeset
2578 * "startcol" is where the matched text starts (1 is first column).
a35dce0cabc5 updated for version 7.0220
vimboss
parents: 716
diff changeset
2579 * "list" is the list of matches.
a35dce0cabc5 updated for version 7.0220
vimboss
parents: 716
diff changeset
2580 */
a35dce0cabc5 updated for version 7.0220
vimboss
parents: 716
diff changeset
2581 void
a35dce0cabc5 updated for version 7.0220
vimboss
parents: 716
diff changeset
2582 set_completion(startcol, list)
a35dce0cabc5 updated for version 7.0220
vimboss
parents: 716
diff changeset
2583 int startcol;
a35dce0cabc5 updated for version 7.0220
vimboss
parents: 716
diff changeset
2584 list_T *list;
a35dce0cabc5 updated for version 7.0220
vimboss
parents: 716
diff changeset
2585 {
a35dce0cabc5 updated for version 7.0220
vimboss
parents: 716
diff changeset
2586 /* If already doing completions stop it. */
a35dce0cabc5 updated for version 7.0220
vimboss
parents: 716
diff changeset
2587 if (ctrl_x_mode != 0)
a35dce0cabc5 updated for version 7.0220
vimboss
parents: 716
diff changeset
2588 ins_compl_prep(' ');
a35dce0cabc5 updated for version 7.0220
vimboss
parents: 716
diff changeset
2589 ins_compl_clear();
a35dce0cabc5 updated for version 7.0220
vimboss
parents: 716
diff changeset
2590
a35dce0cabc5 updated for version 7.0220
vimboss
parents: 716
diff changeset
2591 if (stop_arrow() == FAIL)
a35dce0cabc5 updated for version 7.0220
vimboss
parents: 716
diff changeset
2592 return;
a35dce0cabc5 updated for version 7.0220
vimboss
parents: 716
diff changeset
2593
744
07f7b4a7755c updated for version 7.0222
vimboss
parents: 732
diff changeset
2594 if (startcol > (int)curwin->w_cursor.col)
724
a35dce0cabc5 updated for version 7.0220
vimboss
parents: 716
diff changeset
2595 startcol = curwin->w_cursor.col;
a35dce0cabc5 updated for version 7.0220
vimboss
parents: 716
diff changeset
2596 compl_col = startcol;
a35dce0cabc5 updated for version 7.0220
vimboss
parents: 716
diff changeset
2597 compl_length = curwin->w_cursor.col - startcol;
a35dce0cabc5 updated for version 7.0220
vimboss
parents: 716
diff changeset
2598 /* compl_pattern doesn't need to be set */
a35dce0cabc5 updated for version 7.0220
vimboss
parents: 716
diff changeset
2599 compl_orig_text = vim_strnsave(ml_get_curline() + compl_col, compl_length);
a35dce0cabc5 updated for version 7.0220
vimboss
parents: 716
diff changeset
2600 if (compl_orig_text == NULL || ins_compl_add(compl_orig_text,
942
29bf49bad20d updated for version 7.0-068
vimboss
parents: 941
diff changeset
2601 -1, p_ic, NULL, NULL, 0, ORIGINAL_TEXT, FALSE) != OK)
724
a35dce0cabc5 updated for version 7.0220
vimboss
parents: 716
diff changeset
2602 return;
a35dce0cabc5 updated for version 7.0220
vimboss
parents: 716
diff changeset
2603
a35dce0cabc5 updated for version 7.0220
vimboss
parents: 716
diff changeset
2604 /* Handle like dictionary completion. */
a35dce0cabc5 updated for version 7.0220
vimboss
parents: 716
diff changeset
2605 ctrl_x_mode = CTRL_X_WHOLE_LINE;
a35dce0cabc5 updated for version 7.0220
vimboss
parents: 716
diff changeset
2606
a35dce0cabc5 updated for version 7.0220
vimboss
parents: 716
diff changeset
2607 ins_compl_add_list(list);
a35dce0cabc5 updated for version 7.0220
vimboss
parents: 716
diff changeset
2608 compl_matches = ins_compl_make_cyclic();
a35dce0cabc5 updated for version 7.0220
vimboss
parents: 716
diff changeset
2609 compl_started = TRUE;
a35dce0cabc5 updated for version 7.0220
vimboss
parents: 716
diff changeset
2610 compl_used_match = TRUE;
929
2448f4c8afc6 updated for version 7.0-055
vimboss
parents: 909
diff changeset
2611 compl_cont_status = 0;
724
a35dce0cabc5 updated for version 7.0220
vimboss
parents: 716
diff changeset
2612
a35dce0cabc5 updated for version 7.0220
vimboss
parents: 716
diff changeset
2613 compl_curr_match = compl_first_match;
a35dce0cabc5 updated for version 7.0220
vimboss
parents: 716
diff changeset
2614 ins_complete(Ctrl_N);
a35dce0cabc5 updated for version 7.0220
vimboss
parents: 716
diff changeset
2615 out_flush();
a35dce0cabc5 updated for version 7.0220
vimboss
parents: 716
diff changeset
2616 }
a35dce0cabc5 updated for version 7.0220
vimboss
parents: 716
diff changeset
2617
a35dce0cabc5 updated for version 7.0220
vimboss
parents: 716
diff changeset
2618
574
25a70b1cd2da updated for version 7.0163
vimboss
parents: 548
diff changeset
2619 /* "compl_match_array" points the currently displayed list of entries in the
25a70b1cd2da updated for version 7.0163
vimboss
parents: 548
diff changeset
2620 * popup menu. It is NULL when there is no popup menu. */
659
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
2621 static pumitem_T *compl_match_array = NULL;
540
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2622 static int compl_match_arraysize;
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2623
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2624 /*
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2625 * Update the screen and when there is any scrolling remove the popup menu.
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2626 */
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2627 static void
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2628 ins_compl_upd_pum()
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2629 {
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2630 int h;
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2631
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2632 if (compl_match_array != NULL)
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2633 {
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2634 h = curwin->w_cline_height;
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2635 update_screen(0);
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2636 if (h != curwin->w_cline_height)
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2637 ins_compl_del_pum();
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2638 }
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2639 }
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2640
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2641 /*
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2642 * Remove any popup menu.
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2643 */
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2644 static void
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2645 ins_compl_del_pum()
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2646 {
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2647 if (compl_match_array != NULL)
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2648 {
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2649 pum_undisplay();
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2650 vim_free(compl_match_array);
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2651 compl_match_array = NULL;
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2652 }
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2653 }
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2654
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2655 /*
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2656 * Return TRUE if the popup menu should be displayed.
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2657 */
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2658 static int
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2659 pum_wanted()
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2660 {
707
111b7dcc8a17 updated for version 7.0213
vimboss
parents: 703
diff changeset
2661 /* 'completeopt' must contain "menu" or "menuone" */
665
21ab9abf0f08 updated for version 7.0196
vimboss
parents: 661
diff changeset
2662 if (vim_strchr(p_cot, 'm') == NULL)
540
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2663 return FALSE;
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2664
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2665 /* The display looks bad on a B&W display. */
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2666 if (t_colors < 8
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2667 #ifdef FEAT_GUI
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2668 && !gui.in_use
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2669 #endif
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2670 )
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2671 return FALSE;
657
b112ec5c73f0 updated for version 7.0193
vimboss
parents: 648
diff changeset
2672 return TRUE;
b112ec5c73f0 updated for version 7.0193
vimboss
parents: 648
diff changeset
2673 }
b112ec5c73f0 updated for version 7.0193
vimboss
parents: 648
diff changeset
2674
b112ec5c73f0 updated for version 7.0193
vimboss
parents: 648
diff changeset
2675 /*
b112ec5c73f0 updated for version 7.0193
vimboss
parents: 648
diff changeset
2676 * Return TRUE if there are two or more matches to be shown in the popup menu.
707
111b7dcc8a17 updated for version 7.0213
vimboss
parents: 703
diff changeset
2677 * One if 'completopt' contains "menuone".
657
b112ec5c73f0 updated for version 7.0193
vimboss
parents: 648
diff changeset
2678 */
b112ec5c73f0 updated for version 7.0193
vimboss
parents: 648
diff changeset
2679 static int
707
111b7dcc8a17 updated for version 7.0213
vimboss
parents: 703
diff changeset
2680 pum_enough_matches()
657
b112ec5c73f0 updated for version 7.0193
vimboss
parents: 648
diff changeset
2681 {
b112ec5c73f0 updated for version 7.0193
vimboss
parents: 648
diff changeset
2682 compl_T *compl;
b112ec5c73f0 updated for version 7.0193
vimboss
parents: 648
diff changeset
2683 int i;
540
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2684
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2685 /* Don't display the popup menu if there are no matches or there is only
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2686 * one (ignoring the original text). */
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2687 compl = compl_first_match;
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2688 i = 0;
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2689 do
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2690 {
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2691 if (compl == NULL
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2692 || ((compl->cp_flags & ORIGINAL_TEXT) == 0 && ++i == 2))
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2693 break;
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2694 compl = compl->cp_next;
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2695 } while (compl != compl_first_match);
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2696
707
111b7dcc8a17 updated for version 7.0213
vimboss
parents: 703
diff changeset
2697 if (strstr((char *)p_cot, "menuone") != NULL)
111b7dcc8a17 updated for version 7.0213
vimboss
parents: 703
diff changeset
2698 return (i >= 1);
540
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2699 return (i >= 2);
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2700 }
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2701
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2702 /*
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2703 * Show the popup menu for the list of matches.
659
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
2704 * Also adjusts "compl_shown_match" to an entry that is actually displayed.
540
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2705 */
648
9032e4668296 updated for version 7.0189
vimboss
parents: 644
diff changeset
2706 void
540
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2707 ins_compl_show_pum()
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2708 {
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2709 compl_T *compl;
659
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
2710 compl_T *shown_compl = NULL;
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
2711 int did_find_shown_match = FALSE;
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
2712 int shown_match_ok = FALSE;
540
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2713 int i;
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2714 int cur = -1;
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2715 colnr_T col;
657
b112ec5c73f0 updated for version 7.0193
vimboss
parents: 648
diff changeset
2716 int lead_len = 0;
b112ec5c73f0 updated for version 7.0193
vimboss
parents: 648
diff changeset
2717
707
111b7dcc8a17 updated for version 7.0213
vimboss
parents: 703
diff changeset
2718 if (!pum_wanted() || !pum_enough_matches())
540
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2719 return;
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2720
794
f19994020dad updated for version 7.0231
vimboss
parents: 786
diff changeset
2721 #if defined(FEAT_EVAL)
f19994020dad updated for version 7.0231
vimboss
parents: 786
diff changeset
2722 /* Dirty hard-coded hack: remove any matchparen highlighting. */
f19994020dad updated for version 7.0231
vimboss
parents: 786
diff changeset
2723 do_cmdline_cmd((char_u *)"if exists('g:loaded_matchparen')|3match none|endif");
f19994020dad updated for version 7.0231
vimboss
parents: 786
diff changeset
2724 #endif
f19994020dad updated for version 7.0231
vimboss
parents: 786
diff changeset
2725
540
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2726 /* Update the screen before drawing the popup menu over it. */
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2727 update_screen(0);
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2728
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2729 if (compl_match_array == NULL)
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2730 {
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2731 /* Need to build the popup menu list. */
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2732 compl_match_arraysize = 0;
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2733 compl = compl_first_match;
657
b112ec5c73f0 updated for version 7.0193
vimboss
parents: 648
diff changeset
2734 if (compl_leader != NULL)
835
8bebcabccc2c updated for version 7.0e01
vimboss
parents: 829
diff changeset
2735 lead_len = (int)STRLEN(compl_leader);
540
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2736 do
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2737 {
657
b112ec5c73f0 updated for version 7.0193
vimboss
parents: 648
diff changeset
2738 if ((compl->cp_flags & ORIGINAL_TEXT) == 0
b112ec5c73f0 updated for version 7.0193
vimboss
parents: 648
diff changeset
2739 && (compl_leader == NULL
681
9364d114ed8d updated for version 7.0204
vimboss
parents: 677
diff changeset
2740 || ins_compl_equal(compl, compl_leader, lead_len)))
540
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2741 ++compl_match_arraysize;
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2742 compl = compl->cp_next;
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2743 } while (compl != NULL && compl != compl_first_match);
657
b112ec5c73f0 updated for version 7.0193
vimboss
parents: 648
diff changeset
2744 if (compl_match_arraysize == 0)
b112ec5c73f0 updated for version 7.0193
vimboss
parents: 648
diff changeset
2745 return;
659
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
2746 compl_match_array = (pumitem_T *)alloc_clear(
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
2747 (unsigned)(sizeof(pumitem_T)
540
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2748 * compl_match_arraysize));
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2749 if (compl_match_array != NULL)
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2750 {
829
dc8197342755 updated for version 7.0d04
vimboss
parents: 828
diff changeset
2751 /* If the current match is the original text don't find the first
dc8197342755 updated for version 7.0d04
vimboss
parents: 828
diff changeset
2752 * match after it, don't highlight anything. */
dc8197342755 updated for version 7.0d04
vimboss
parents: 828
diff changeset
2753 if (compl_shown_match->cp_flags & ORIGINAL_TEXT)
dc8197342755 updated for version 7.0d04
vimboss
parents: 828
diff changeset
2754 shown_match_ok = TRUE;
dc8197342755 updated for version 7.0d04
vimboss
parents: 828
diff changeset
2755
540
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2756 i = 0;
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2757 compl = compl_first_match;
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2758 do
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2759 {
657
b112ec5c73f0 updated for version 7.0193
vimboss
parents: 648
diff changeset
2760 if ((compl->cp_flags & ORIGINAL_TEXT) == 0
b112ec5c73f0 updated for version 7.0193
vimboss
parents: 648
diff changeset
2761 && (compl_leader == NULL
681
9364d114ed8d updated for version 7.0204
vimboss
parents: 677
diff changeset
2762 || ins_compl_equal(compl, compl_leader, lead_len)))
540
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2763 {
659
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
2764 if (!shown_match_ok)
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
2765 {
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
2766 if (compl == compl_shown_match || did_find_shown_match)
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
2767 {
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
2768 /* This item is the shown match or this is the
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
2769 * first displayed item after the shown match. */
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
2770 compl_shown_match = compl;
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
2771 did_find_shown_match = TRUE;
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
2772 shown_match_ok = TRUE;
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
2773 }
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
2774 else
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
2775 /* Remember this displayed match for when the
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
2776 * shown match is just below it. */
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
2777 shown_compl = compl;
540
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2778 cur = i;
659
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
2779 }
786
8f6a426bc1e0 updated for version 7.0229
vimboss
parents: 782
diff changeset
2780
8f6a426bc1e0 updated for version 7.0229
vimboss
parents: 782
diff changeset
2781 if (compl->cp_text[CPT_ABBR] != NULL)
8f6a426bc1e0 updated for version 7.0229
vimboss
parents: 782
diff changeset
2782 compl_match_array[i].pum_text =
8f6a426bc1e0 updated for version 7.0229
vimboss
parents: 782
diff changeset
2783 compl->cp_text[CPT_ABBR];
8f6a426bc1e0 updated for version 7.0229
vimboss
parents: 782
diff changeset
2784 else
8f6a426bc1e0 updated for version 7.0229
vimboss
parents: 782
diff changeset
2785 compl_match_array[i].pum_text = compl->cp_str;
8f6a426bc1e0 updated for version 7.0229
vimboss
parents: 782
diff changeset
2786 compl_match_array[i].pum_kind = compl->cp_text[CPT_KIND];
8f6a426bc1e0 updated for version 7.0229
vimboss
parents: 782
diff changeset
2787 compl_match_array[i].pum_info = compl->cp_text[CPT_INFO];
8f6a426bc1e0 updated for version 7.0229
vimboss
parents: 782
diff changeset
2788 if (compl->cp_text[CPT_MENU] != NULL)
8f6a426bc1e0 updated for version 7.0229
vimboss
parents: 782
diff changeset
2789 compl_match_array[i++].pum_extra =
8f6a426bc1e0 updated for version 7.0229
vimboss
parents: 782
diff changeset
2790 compl->cp_text[CPT_MENU];
659
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
2791 else
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
2792 compl_match_array[i++].pum_extra = compl->cp_fname;
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
2793 }
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
2794
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
2795 if (compl == compl_shown_match)
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
2796 {
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
2797 did_find_shown_match = TRUE;
716
8ae24f338cab updated for version 7.0217
vimboss
parents: 714
diff changeset
2798
8ae24f338cab updated for version 7.0217
vimboss
parents: 714
diff changeset
2799 /* When the original text is the shown match don't set
8ae24f338cab updated for version 7.0217
vimboss
parents: 714
diff changeset
2800 * compl_shown_match. */
8ae24f338cab updated for version 7.0217
vimboss
parents: 714
diff changeset
2801 if (compl->cp_flags & ORIGINAL_TEXT)
8ae24f338cab updated for version 7.0217
vimboss
parents: 714
diff changeset
2802 shown_match_ok = TRUE;
8ae24f338cab updated for version 7.0217
vimboss
parents: 714
diff changeset
2803
659
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
2804 if (!shown_match_ok && shown_compl != NULL)
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
2805 {
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
2806 /* The shown match isn't displayed, set it to the
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
2807 * previously displayed match. */
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
2808 compl_shown_match = shown_compl;
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
2809 shown_match_ok = TRUE;
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
2810 }
540
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2811 }
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2812 compl = compl->cp_next;
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2813 } while (compl != NULL && compl != compl_first_match);
659
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
2814
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
2815 if (!shown_match_ok) /* no displayed match at all */
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
2816 cur = -1;
540
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2817 }
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2818 }
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2819 else
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2820 {
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2821 /* popup menu already exists, only need to find the current item.*/
657
b112ec5c73f0 updated for version 7.0193
vimboss
parents: 648
diff changeset
2822 for (i = 0; i < compl_match_arraysize; ++i)
786
8f6a426bc1e0 updated for version 7.0229
vimboss
parents: 782
diff changeset
2823 if (compl_match_array[i].pum_text == compl_shown_match->cp_str
8f6a426bc1e0 updated for version 7.0229
vimboss
parents: 782
diff changeset
2824 || compl_match_array[i].pum_text
8f6a426bc1e0 updated for version 7.0229
vimboss
parents: 782
diff changeset
2825 == compl_shown_match->cp_text[CPT_ABBR])
829
dc8197342755 updated for version 7.0d04
vimboss
parents: 828
diff changeset
2826 {
dc8197342755 updated for version 7.0d04
vimboss
parents: 828
diff changeset
2827 cur = i;
657
b112ec5c73f0 updated for version 7.0193
vimboss
parents: 648
diff changeset
2828 break;
829
dc8197342755 updated for version 7.0d04
vimboss
parents: 828
diff changeset
2829 }
540
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2830 }
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2831
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2832 if (compl_match_array != NULL)
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2833 {
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2834 /* Compute the screen column of the start of the completed text.
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2835 * Use the cursor to get all wrapping and other settings right. */
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2836 col = curwin->w_cursor.col;
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2837 curwin->w_cursor.col = compl_col;
732
f7034dd506fd updated for version 7.0221
vimboss
parents: 724
diff changeset
2838 pum_display(compl_match_array, compl_match_arraysize, cur);
540
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2839 curwin->w_cursor.col = col;
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2840 }
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2841 }
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2842
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2843 #define DICT_FIRST (1) /* use just first element in "dict" */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2844 #define DICT_EXACT (2) /* "dict" is the exact name of a file */
648
9032e4668296 updated for version 7.0189
vimboss
parents: 644
diff changeset
2845
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2846 /*
703
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
2847 * Add any identifiers that match the given pattern in the list of dictionary
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
2848 * files "dict_start" to the list of completions.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2849 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2850 static void
703
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
2851 ins_compl_dictionaries(dict_start, pat, flags, thesaurus)
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
2852 char_u *dict_start;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2853 char_u *pat;
667
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
2854 int flags; /* DICT_FIRST and/or DICT_EXACT */
703
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
2855 int thesaurus; /* Thesaurus completion */
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
2856 {
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
2857 char_u *dict = dict_start;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2858 char_u *ptr;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2859 char_u *buf;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2860 regmatch_T regmatch;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2861 char_u **files;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2862 int count;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2863 int i;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2864 int save_p_scs;
659
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
2865 int dir = compl_direction;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2866
703
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
2867 if (*dict == NUL)
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
2868 {
744
07f7b4a7755c updated for version 7.0222
vimboss
parents: 732
diff changeset
2869 #ifdef FEAT_SPELL
703
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
2870 /* When 'dictionary' is empty and spell checking is enabled use
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
2871 * "spell". */
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
2872 if (!thesaurus && curwin->w_p_spell)
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
2873 dict = (char_u *)"spell";
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
2874 else
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
2875 #endif
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
2876 return;
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
2877 }
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
2878
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2879 buf = alloc(LSIZE);
703
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
2880 if (buf == NULL)
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
2881 return;
1074
a112fdce9ebd updated for version 7.0-200
vimboss
parents: 1073
diff changeset
2882 regmatch.regprog = NULL; /* so that we can goto theend */
703
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
2883
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2884 /* If 'infercase' is set, don't use 'smartcase' here */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2885 save_p_scs = p_scs;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2886 if (curbuf->b_p_inf)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2887 p_scs = FALSE;
667
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
2888
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
2889 /* When invoked to match whole lines for CTRL-X CTRL-L adjust the pattern
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
2890 * to only match at the start of a line. Otherwise just match the
842
a209672376fd updated for version 7.0f
vimboss
parents: 841
diff changeset
2891 * pattern. Also need to double backslashes. */
667
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
2892 if (ctrl_x_mode == CTRL_X_WHOLE_LINE)
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
2893 {
842
a209672376fd updated for version 7.0f
vimboss
parents: 841
diff changeset
2894 char_u *pat_esc = vim_strsave_escaped(pat, (char_u *)"\\");
a209672376fd updated for version 7.0f
vimboss
parents: 841
diff changeset
2895
a209672376fd updated for version 7.0f
vimboss
parents: 841
diff changeset
2896 if (pat_esc == NULL)
1159
b5ee70fc4b0c updated for version 7.1a
vimboss
parents: 1085
diff changeset
2897 goto theend;
842
a209672376fd updated for version 7.0f
vimboss
parents: 841
diff changeset
2898 i = (int)STRLEN(pat_esc) + 10;
667
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
2899 ptr = alloc(i);
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
2900 if (ptr == NULL)
842
a209672376fd updated for version 7.0f
vimboss
parents: 841
diff changeset
2901 {
a209672376fd updated for version 7.0f
vimboss
parents: 841
diff changeset
2902 vim_free(pat_esc);
1074
a112fdce9ebd updated for version 7.0-200
vimboss
parents: 1073
diff changeset
2903 goto theend;
842
a209672376fd updated for version 7.0f
vimboss
parents: 841
diff changeset
2904 }
a209672376fd updated for version 7.0f
vimboss
parents: 841
diff changeset
2905 vim_snprintf((char *)ptr, i, "^\\s*\\zs\\V%s", pat_esc);
a209672376fd updated for version 7.0f
vimboss
parents: 841
diff changeset
2906 regmatch.regprog = vim_regcomp(ptr, RE_MAGIC);
a209672376fd updated for version 7.0f
vimboss
parents: 841
diff changeset
2907 vim_free(pat_esc);
667
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
2908 vim_free(ptr);
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
2909 }
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
2910 else
703
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
2911 {
667
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
2912 regmatch.regprog = vim_regcomp(pat, p_magic ? RE_MAGIC : 0);
703
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
2913 if (regmatch.regprog == NULL)
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
2914 goto theend;
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
2915 }
667
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
2916
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2917 /* ignore case depends on 'ignorecase', 'smartcase' and "pat" */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2918 regmatch.rm_ic = ignorecase(pat);
703
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
2919 while (*dict != NUL && !got_int && !compl_interrupted)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2920 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2921 /* copy one dictionary file name into buf */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2922 if (flags == DICT_EXACT)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2923 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2924 count = 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2925 files = &dict;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2926 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2927 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2928 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2929 /* Expand wildcards in the dictionary name, but do not allow
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2930 * backticks (for security, the 'dict' option may have been set in
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2931 * a modeline). */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2932 copy_option_part(&dict, buf, LSIZE, ",");
744
07f7b4a7755c updated for version 7.0222
vimboss
parents: 732
diff changeset
2933 # ifdef FEAT_SPELL
703
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
2934 if (!thesaurus && STRCMP(buf, "spell") == 0)
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
2935 count = -1;
744
07f7b4a7755c updated for version 7.0222
vimboss
parents: 732
diff changeset
2936 else
07f7b4a7755c updated for version 7.0222
vimboss
parents: 732
diff changeset
2937 # endif
07f7b4a7755c updated for version 7.0222
vimboss
parents: 732
diff changeset
2938 if (vim_strchr(buf, '`') != NULL
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2939 || expand_wildcards(1, &buf, &count, &files,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2940 EW_FILE|EW_SILENT) != OK)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2941 count = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2942 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2943
744
07f7b4a7755c updated for version 7.0222
vimboss
parents: 732
diff changeset
2944 # ifdef FEAT_SPELL
703
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
2945 if (count == -1)
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
2946 {
712
2e887dfa8917 updated for version 7.0214
vimboss
parents: 707
diff changeset
2947 /* Complete from active spelling. Skip "\<" in the pattern, we
2e887dfa8917 updated for version 7.0214
vimboss
parents: 707
diff changeset
2948 * don't use it as a RE. */
703
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
2949 if (pat[0] == '\\' && pat[1] == '<')
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
2950 ptr = pat + 2;
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
2951 else
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
2952 ptr = pat;
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
2953 spell_dump_compl(curbuf, ptr, regmatch.rm_ic, &dir, 0);
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
2954 }
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
2955 else
744
07f7b4a7755c updated for version 7.0222
vimboss
parents: 732
diff changeset
2956 # endif
938
fc0c566b9107 updated for version 7.0-064
vimboss
parents: 935
diff changeset
2957 if (count > 0) /* avoid warning for using "files" uninit */
703
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
2958 {
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
2959 ins_compl_files(count, files, thesaurus, flags,
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
2960 &regmatch, buf, &dir);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2961 if (flags != DICT_EXACT)
703
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
2962 FreeWild(count, files);
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
2963 }
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
2964 if (flags != 0)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2965 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2966 }
703
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
2967
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
2968 theend:
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2969 p_scs = save_p_scs;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2970 vim_free(regmatch.regprog);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2971 vim_free(buf);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2972 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2973
703
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
2974 static void
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
2975 ins_compl_files(count, files, thesaurus, flags, regmatch, buf, dir)
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
2976 int count;
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
2977 char_u **files;
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
2978 int thesaurus;
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
2979 int flags;
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
2980 regmatch_T *regmatch;
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
2981 char_u *buf;
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
2982 int *dir;
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
2983 {
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
2984 char_u *ptr;
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
2985 int i;
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
2986 FILE *fp;
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
2987 int add_r;
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
2988
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
2989 for (i = 0; i < count && !got_int && !compl_interrupted; i++)
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
2990 {
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
2991 fp = mch_fopen((char *)files[i], "r"); /* open dictionary file */
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
2992 if (flags != DICT_EXACT)
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
2993 {
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
2994 vim_snprintf((char *)IObuff, IOSIZE,
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
2995 _("Scanning dictionary: %s"), (char *)files[i]);
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
2996 msg_trunc_attr(IObuff, TRUE, hl_attr(HLF_R));
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
2997 }
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
2998
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
2999 if (fp != NULL)
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
3000 {
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
3001 /*
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
3002 * Read dictionary file line by line.
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
3003 * Check each line for a match.
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
3004 */
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
3005 while (!got_int && !compl_interrupted
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
3006 && !vim_fgets(buf, LSIZE, fp))
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
3007 {
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
3008 ptr = buf;
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
3009 while (vim_regexec(regmatch, buf, (colnr_T)(ptr - buf)))
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
3010 {
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
3011 ptr = regmatch->startp[0];
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
3012 if (ctrl_x_mode == CTRL_X_WHOLE_LINE)
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
3013 ptr = find_line_end(ptr);
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
3014 else
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
3015 ptr = find_word_end(ptr);
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
3016 add_r = ins_compl_add_infercase(regmatch->startp[0],
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
3017 (int)(ptr - regmatch->startp[0]),
942
29bf49bad20d updated for version 7.0-068
vimboss
parents: 941
diff changeset
3018 p_ic, files[i], *dir, 0);
703
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
3019 if (thesaurus)
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
3020 {
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
3021 char_u *wstart;
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
3022
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
3023 /*
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
3024 * Add the other matches on the line
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
3025 */
1353
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
3026 ptr = buf;
703
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
3027 while (!got_int)
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
3028 {
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
3029 /* Find start of the next word. Skip white
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
3030 * space and punctuation. */
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
3031 ptr = find_word_start(ptr);
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
3032 if (*ptr == NUL || *ptr == NL)
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
3033 break;
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
3034 wstart = ptr;
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
3035
1353
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
3036 /* Find end of the word. */
703
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
3037 #ifdef FEAT_MBYTE
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
3038 if (has_mbyte)
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
3039 /* Japanese words may have characters in
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
3040 * different classes, only separate words
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
3041 * with single-byte non-word characters. */
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
3042 while (*ptr != NUL)
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
3043 {
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
3044 int l = (*mb_ptr2len)(ptr);
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
3045
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
3046 if (l < 2 && !vim_iswordc(*ptr))
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
3047 break;
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
3048 ptr += l;
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
3049 }
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
3050 else
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
3051 #endif
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
3052 ptr = find_word_end(ptr);
1353
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
3053
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
3054 /* Add the word. Skip the regexp match. */
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
3055 if (wstart != regmatch->startp[0])
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
3056 add_r = ins_compl_add_infercase(wstart,
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
3057 (int)(ptr - wstart),
87401adbf5fc updated for version 7.1-067
vimboss
parents: 1330
diff changeset
3058 p_ic, files[i], *dir, 0);
703
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
3059 }
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
3060 }
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
3061 if (add_r == OK)
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
3062 /* if dir was BACKWARD then honor it just once */
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
3063 *dir = FORWARD;
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
3064 else if (add_r == FAIL)
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
3065 break;
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
3066 /* avoid expensive call to vim_regexec() when at end
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
3067 * of line */
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
3068 if (*ptr == '\n' || got_int)
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
3069 break;
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
3070 }
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
3071 line_breakcheck();
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
3072 ins_compl_check_keys(50);
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
3073 }
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
3074 fclose(fp);
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
3075 }
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
3076 }
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
3077 }
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
3078
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3079 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3080 * Find the start of the next word.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3081 * Returns a pointer to the first char of the word. Also stops at a NUL.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3082 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3083 char_u *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3084 find_word_start(ptr)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3085 char_u *ptr;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3086 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3087 #ifdef FEAT_MBYTE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3088 if (has_mbyte)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3089 while (*ptr != NUL && *ptr != '\n' && mb_get_class(ptr) <= 1)
474
a5fcf36ef512 updated for version 7.0127
vimboss
parents: 470
diff changeset
3090 ptr += (*mb_ptr2len)(ptr);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3091 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3092 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3093 while (*ptr != NUL && *ptr != '\n' && !vim_iswordc(*ptr))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3094 ++ptr;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3095 return ptr;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3096 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3097
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3098 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3099 * Find the end of the word. Assumes it starts inside a word.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3100 * Returns a pointer to just after the word.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3101 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3102 char_u *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3103 find_word_end(ptr)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3104 char_u *ptr;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3105 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3106 #ifdef FEAT_MBYTE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3107 int start_class;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3108
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3109 if (has_mbyte)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3110 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3111 start_class = mb_get_class(ptr);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3112 if (start_class > 1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3113 while (*ptr != NUL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3114 {
474
a5fcf36ef512 updated for version 7.0127
vimboss
parents: 470
diff changeset
3115 ptr += (*mb_ptr2len)(ptr);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3116 if (mb_get_class(ptr) != start_class)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3117 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3118 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3119 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3120 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3121 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3122 while (vim_iswordc(*ptr))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3123 ++ptr;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3124 return ptr;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3125 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3126
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3127 /*
667
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
3128 * Find the end of the line, omitting CR and NL at the end.
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
3129 * Returns a pointer to just after the line.
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
3130 */
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
3131 static char_u *
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
3132 find_line_end(ptr)
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
3133 char_u *ptr;
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
3134 {
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
3135 char_u *s;
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
3136
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
3137 s = ptr + STRLEN(ptr);
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
3138 while (s > ptr && (s[-1] == CAR || s[-1] == NL))
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
3139 --s;
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
3140 return s;
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
3141 }
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
3142
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
3143 /*
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3144 * Free the list of completions
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3145 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3146 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3147 ins_compl_free()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3148 {
464
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
3149 compl_T *match;
786
8f6a426bc1e0 updated for version 7.0229
vimboss
parents: 782
diff changeset
3150 int i;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3151
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3152 vim_free(compl_pattern);
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3153 compl_pattern = NULL;
657
b112ec5c73f0 updated for version 7.0193
vimboss
parents: 648
diff changeset
3154 vim_free(compl_leader);
b112ec5c73f0 updated for version 7.0193
vimboss
parents: 648
diff changeset
3155 compl_leader = NULL;
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3156
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3157 if (compl_first_match == NULL)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3158 return;
540
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
3159
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
3160 ins_compl_del_pum();
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
3161 pum_clear();
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
3162
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3163 compl_curr_match = compl_first_match;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3164 do
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3165 {
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3166 match = compl_curr_match;
464
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
3167 compl_curr_match = compl_curr_match->cp_next;
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
3168 vim_free(match->cp_str);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3169 /* several entries may use the same fname, free it just once. */
464
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
3170 if (match->cp_flags & FREE_FNAME)
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
3171 vim_free(match->cp_fname);
786
8f6a426bc1e0 updated for version 7.0229
vimboss
parents: 782
diff changeset
3172 for (i = 0; i < CPT_COUNT; ++i)
8f6a426bc1e0 updated for version 7.0229
vimboss
parents: 782
diff changeset
3173 vim_free(match->cp_text[i]);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3174 vim_free(match);
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3175 } while (compl_curr_match != NULL && compl_curr_match != compl_first_match);
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3176 compl_first_match = compl_curr_match = NULL;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3177 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3178
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3179 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3180 ins_compl_clear()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3181 {
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3182 compl_cont_status = 0;
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3183 compl_started = FALSE;
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3184 compl_matches = 0;
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3185 vim_free(compl_pattern);
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3186 compl_pattern = NULL;
657
b112ec5c73f0 updated for version 7.0193
vimboss
parents: 648
diff changeset
3187 vim_free(compl_leader);
b112ec5c73f0 updated for version 7.0193
vimboss
parents: 648
diff changeset
3188 compl_leader = NULL;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3189 edit_submode_extra = NULL;
724
a35dce0cabc5 updated for version 7.0220
vimboss
parents: 716
diff changeset
3190 vim_free(compl_orig_text);
a35dce0cabc5 updated for version 7.0220
vimboss
parents: 716
diff changeset
3191 compl_orig_text = NULL;
825
6675076019ae updated for version 7.0d
vimboss
parents: 819
diff changeset
3192 compl_enter_selects = FALSE;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3193 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3194
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3195 /*
674
4b8583e82cb8 updated for version 7.0201
vimboss
parents: 667
diff changeset
3196 * Return TRUE when Insert completion is active.
4b8583e82cb8 updated for version 7.0201
vimboss
parents: 667
diff changeset
3197 */
4b8583e82cb8 updated for version 7.0201
vimboss
parents: 667
diff changeset
3198 int
4b8583e82cb8 updated for version 7.0201
vimboss
parents: 667
diff changeset
3199 ins_compl_active()
4b8583e82cb8 updated for version 7.0201
vimboss
parents: 667
diff changeset
3200 {
4b8583e82cb8 updated for version 7.0201
vimboss
parents: 667
diff changeset
3201 return compl_started;
4b8583e82cb8 updated for version 7.0201
vimboss
parents: 667
diff changeset
3202 }
4b8583e82cb8 updated for version 7.0201
vimboss
parents: 667
diff changeset
3203
4b8583e82cb8 updated for version 7.0201
vimboss
parents: 667
diff changeset
3204 /*
659
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
3205 * Delete one character before the cursor and show the subset of the matches
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
3206 * that match the word that is now before the cursor.
836
5a7843c57316 updated for version 7.0e02
vimboss
parents: 835
diff changeset
3207 * Returns the character to be used, NUL if the work is done and another char
5a7843c57316 updated for version 7.0e02
vimboss
parents: 835
diff changeset
3208 * to be got from the user.
657
b112ec5c73f0 updated for version 7.0193
vimboss
parents: 648
diff changeset
3209 */
b112ec5c73f0 updated for version 7.0193
vimboss
parents: 648
diff changeset
3210 static int
b112ec5c73f0 updated for version 7.0193
vimboss
parents: 648
diff changeset
3211 ins_compl_bs()
b112ec5c73f0 updated for version 7.0193
vimboss
parents: 648
diff changeset
3212 {
b112ec5c73f0 updated for version 7.0193
vimboss
parents: 648
diff changeset
3213 char_u *line;
b112ec5c73f0 updated for version 7.0193
vimboss
parents: 648
diff changeset
3214 char_u *p;
b112ec5c73f0 updated for version 7.0193
vimboss
parents: 648
diff changeset
3215
836
5a7843c57316 updated for version 7.0e02
vimboss
parents: 835
diff changeset
3216 line = ml_get_curline();
5a7843c57316 updated for version 7.0e02
vimboss
parents: 835
diff changeset
3217 p = line + curwin->w_cursor.col;
5a7843c57316 updated for version 7.0e02
vimboss
parents: 835
diff changeset
3218 mb_ptr_back(line, p);
5a7843c57316 updated for version 7.0e02
vimboss
parents: 835
diff changeset
3219
1430
342cf2a9f5cc updated for version 7.1-145
vimboss
parents: 1389
diff changeset
3220 /* Stop completion when the whole word was deleted. For Omni completion
342cf2a9f5cc updated for version 7.1-145
vimboss
parents: 1389
diff changeset
3221 * allow the word to be deleted, we won't match everything. */
342cf2a9f5cc updated for version 7.1-145
vimboss
parents: 1389
diff changeset
3222 if ((int)(p - line) - (int)compl_col < 0
342cf2a9f5cc updated for version 7.1-145
vimboss
parents: 1389
diff changeset
3223 || ((int)(p - line) - (int)compl_col == 0
342cf2a9f5cc updated for version 7.1-145
vimboss
parents: 1389
diff changeset
3224 && (ctrl_x_mode & CTRL_X_OMNI) == 0))
836
5a7843c57316 updated for version 7.0e02
vimboss
parents: 835
diff changeset
3225 return K_BS;
5a7843c57316 updated for version 7.0e02
vimboss
parents: 835
diff changeset
3226
874
4bac29d27e2f updated for version 7.0
vimboss
parents: 867
diff changeset
3227 /* Deleted more than what was used to find matches or didn't finish
4bac29d27e2f updated for version 7.0
vimboss
parents: 867
diff changeset
3228 * finding all matches: need to look for matches all over again. */
4bac29d27e2f updated for version 7.0
vimboss
parents: 867
diff changeset
3229 if (curwin->w_cursor.col <= compl_col + compl_length
4bac29d27e2f updated for version 7.0
vimboss
parents: 867
diff changeset
3230 || compl_was_interrupted)
4bac29d27e2f updated for version 7.0
vimboss
parents: 867
diff changeset
3231 ins_compl_restart();
657
b112ec5c73f0 updated for version 7.0193
vimboss
parents: 648
diff changeset
3232
b112ec5c73f0 updated for version 7.0193
vimboss
parents: 648
diff changeset
3233 vim_free(compl_leader);
835
8bebcabccc2c updated for version 7.0e01
vimboss
parents: 829
diff changeset
3234 compl_leader = vim_strnsave(line + compl_col, (int)(p - line) - compl_col);
657
b112ec5c73f0 updated for version 7.0193
vimboss
parents: 648
diff changeset
3235 if (compl_leader != NULL)
b112ec5c73f0 updated for version 7.0193
vimboss
parents: 648
diff changeset
3236 {
874
4bac29d27e2f updated for version 7.0
vimboss
parents: 867
diff changeset
3237 ins_compl_new_leader();
4bac29d27e2f updated for version 7.0
vimboss
parents: 867
diff changeset
3238 return NUL;
4bac29d27e2f updated for version 7.0
vimboss
parents: 867
diff changeset
3239 }
4bac29d27e2f updated for version 7.0
vimboss
parents: 867
diff changeset
3240 return K_BS;
4bac29d27e2f updated for version 7.0
vimboss
parents: 867
diff changeset
3241 }
4bac29d27e2f updated for version 7.0
vimboss
parents: 867
diff changeset
3242
4bac29d27e2f updated for version 7.0
vimboss
parents: 867
diff changeset
3243 /*
4bac29d27e2f updated for version 7.0
vimboss
parents: 867
diff changeset
3244 * Called after changing "compl_leader".
4bac29d27e2f updated for version 7.0
vimboss
parents: 867
diff changeset
3245 * Show the popup menu with a different set of matches.
4bac29d27e2f updated for version 7.0
vimboss
parents: 867
diff changeset
3246 * May also search for matches again if the previous search was interrupted.
4bac29d27e2f updated for version 7.0
vimboss
parents: 867
diff changeset
3247 */
4bac29d27e2f updated for version 7.0
vimboss
parents: 867
diff changeset
3248 static void
4bac29d27e2f updated for version 7.0
vimboss
parents: 867
diff changeset
3249 ins_compl_new_leader()
4bac29d27e2f updated for version 7.0
vimboss
parents: 867
diff changeset
3250 {
4bac29d27e2f updated for version 7.0
vimboss
parents: 867
diff changeset
3251 ins_compl_del_pum();
4bac29d27e2f updated for version 7.0
vimboss
parents: 867
diff changeset
3252 ins_compl_delete();
1782
12cecc379574 updated for version 7.2-080
vimboss
parents: 1698
diff changeset
3253 ins_bytes(compl_leader + ins_compl_len());
874
4bac29d27e2f updated for version 7.0
vimboss
parents: 867
diff changeset
3254 compl_used_match = FALSE;
4bac29d27e2f updated for version 7.0
vimboss
parents: 867
diff changeset
3255
4bac29d27e2f updated for version 7.0
vimboss
parents: 867
diff changeset
3256 if (compl_started)
4bac29d27e2f updated for version 7.0
vimboss
parents: 867
diff changeset
3257 ins_compl_set_original_text(compl_leader);
4bac29d27e2f updated for version 7.0
vimboss
parents: 867
diff changeset
3258 else
4bac29d27e2f updated for version 7.0
vimboss
parents: 867
diff changeset
3259 {
826
1cdd2661f34c updated for version 7.0d01
vimboss
parents: 825
diff changeset
3260 #ifdef FEAT_SPELL
874
4bac29d27e2f updated for version 7.0
vimboss
parents: 867
diff changeset
3261 spell_bad_len = 0; /* need to redetect bad word */
4bac29d27e2f updated for version 7.0
vimboss
parents: 867
diff changeset
3262 #endif
4bac29d27e2f updated for version 7.0
vimboss
parents: 867
diff changeset
3263 /*
4bac29d27e2f updated for version 7.0
vimboss
parents: 867
diff changeset
3264 * Matches were cleared, need to search for them now. First display
4bac29d27e2f updated for version 7.0
vimboss
parents: 867
diff changeset
3265 * the changed text before the cursor. Set "compl_restarting" to
4bac29d27e2f updated for version 7.0
vimboss
parents: 867
diff changeset
3266 * avoid that the first match is inserted.
4bac29d27e2f updated for version 7.0
vimboss
parents: 867
diff changeset
3267 */
4bac29d27e2f updated for version 7.0
vimboss
parents: 867
diff changeset
3268 update_screen(0);
4bac29d27e2f updated for version 7.0
vimboss
parents: 867
diff changeset
3269 #ifdef FEAT_GUI
4bac29d27e2f updated for version 7.0
vimboss
parents: 867
diff changeset
3270 if (gui.in_use)
4bac29d27e2f updated for version 7.0
vimboss
parents: 867
diff changeset
3271 {
4bac29d27e2f updated for version 7.0
vimboss
parents: 867
diff changeset
3272 /* Show the cursor after the match, not after the redrawn text. */
4bac29d27e2f updated for version 7.0
vimboss
parents: 867
diff changeset
3273 setcursor();
4bac29d27e2f updated for version 7.0
vimboss
parents: 867
diff changeset
3274 out_flush();
4bac29d27e2f updated for version 7.0
vimboss
parents: 867
diff changeset
3275 gui_update_cursor(FALSE, FALSE);
4bac29d27e2f updated for version 7.0
vimboss
parents: 867
diff changeset
3276 }
4bac29d27e2f updated for version 7.0
vimboss
parents: 867
diff changeset
3277 #endif
4bac29d27e2f updated for version 7.0
vimboss
parents: 867
diff changeset
3278 compl_restarting = TRUE;
4bac29d27e2f updated for version 7.0
vimboss
parents: 867
diff changeset
3279 if (ins_complete(Ctrl_N) == FAIL)
4bac29d27e2f updated for version 7.0
vimboss
parents: 867
diff changeset
3280 compl_cont_status = 0;
4bac29d27e2f updated for version 7.0
vimboss
parents: 867
diff changeset
3281 compl_restarting = FALSE;
4bac29d27e2f updated for version 7.0
vimboss
parents: 867
diff changeset
3282 }
4bac29d27e2f updated for version 7.0
vimboss
parents: 867
diff changeset
3283
887
9dc77520c6d3 updated for version 7.0-013
vimboss
parents: 874
diff changeset
3284 #if 0 /* disabled, made CTRL-L, BS and typing char jump to original text. */
874
4bac29d27e2f updated for version 7.0
vimboss
parents: 867
diff changeset
3285 if (!compl_used_match)
4bac29d27e2f updated for version 7.0
vimboss
parents: 867
diff changeset
3286 {
829
dc8197342755 updated for version 7.0d04
vimboss
parents: 828
diff changeset
3287 /* Go to the original text, since none of the matches is inserted. */
dc8197342755 updated for version 7.0d04
vimboss
parents: 828
diff changeset
3288 if (compl_first_match->cp_prev != NULL
dc8197342755 updated for version 7.0d04
vimboss
parents: 828
diff changeset
3289 && (compl_first_match->cp_prev->cp_flags & ORIGINAL_TEXT))
dc8197342755 updated for version 7.0d04
vimboss
parents: 828
diff changeset
3290 compl_shown_match = compl_first_match->cp_prev;
dc8197342755 updated for version 7.0d04
vimboss
parents: 828
diff changeset
3291 else
dc8197342755 updated for version 7.0d04
vimboss
parents: 828
diff changeset
3292 compl_shown_match = compl_first_match;
dc8197342755 updated for version 7.0d04
vimboss
parents: 828
diff changeset
3293 compl_curr_match = compl_shown_match;
dc8197342755 updated for version 7.0d04
vimboss
parents: 828
diff changeset
3294 compl_shows_dir = compl_direction;
874
4bac29d27e2f updated for version 7.0
vimboss
parents: 867
diff changeset
3295 }
887
9dc77520c6d3 updated for version 7.0-013
vimboss
parents: 874
diff changeset
3296 #endif
9dc77520c6d3 updated for version 7.0-013
vimboss
parents: 874
diff changeset
3297 compl_enter_selects = !compl_used_match;
874
4bac29d27e2f updated for version 7.0
vimboss
parents: 867
diff changeset
3298
4bac29d27e2f updated for version 7.0
vimboss
parents: 867
diff changeset
3299 /* Show the popup menu with a different set of matches. */
4bac29d27e2f updated for version 7.0
vimboss
parents: 867
diff changeset
3300 ins_compl_show_pum();
947
a157c4786b79 updated for version 7.0-073
vimboss
parents: 944
diff changeset
3301
a157c4786b79 updated for version 7.0-073
vimboss
parents: 944
diff changeset
3302 /* Don't let Enter select the original text when there is no popup menu. */
a157c4786b79 updated for version 7.0-073
vimboss
parents: 944
diff changeset
3303 if (compl_match_array == NULL)
a157c4786b79 updated for version 7.0-073
vimboss
parents: 944
diff changeset
3304 compl_enter_selects = FALSE;
657
b112ec5c73f0 updated for version 7.0193
vimboss
parents: 648
diff changeset
3305 }
b112ec5c73f0 updated for version 7.0193
vimboss
parents: 648
diff changeset
3306
b112ec5c73f0 updated for version 7.0193
vimboss
parents: 648
diff changeset
3307 /*
1782
12cecc379574 updated for version 7.2-080
vimboss
parents: 1698
diff changeset
3308 * Return the length of the completion, from the completion start column to
12cecc379574 updated for version 7.2-080
vimboss
parents: 1698
diff changeset
3309 * the cursor column. Making sure it never goes below zero.
12cecc379574 updated for version 7.2-080
vimboss
parents: 1698
diff changeset
3310 */
12cecc379574 updated for version 7.2-080
vimboss
parents: 1698
diff changeset
3311 static int
12cecc379574 updated for version 7.2-080
vimboss
parents: 1698
diff changeset
3312 ins_compl_len()
12cecc379574 updated for version 7.2-080
vimboss
parents: 1698
diff changeset
3313 {
12cecc379574 updated for version 7.2-080
vimboss
parents: 1698
diff changeset
3314 int off = curwin->w_cursor.col - compl_col;
12cecc379574 updated for version 7.2-080
vimboss
parents: 1698
diff changeset
3315
12cecc379574 updated for version 7.2-080
vimboss
parents: 1698
diff changeset
3316 if (off < 0)
12cecc379574 updated for version 7.2-080
vimboss
parents: 1698
diff changeset
3317 return 0;
12cecc379574 updated for version 7.2-080
vimboss
parents: 1698
diff changeset
3318 return off;
12cecc379574 updated for version 7.2-080
vimboss
parents: 1698
diff changeset
3319 }
12cecc379574 updated for version 7.2-080
vimboss
parents: 1698
diff changeset
3320
12cecc379574 updated for version 7.2-080
vimboss
parents: 1698
diff changeset
3321 /*
657
b112ec5c73f0 updated for version 7.0193
vimboss
parents: 648
diff changeset
3322 * Append one character to the match leader. May reduce the number of
b112ec5c73f0 updated for version 7.0193
vimboss
parents: 648
diff changeset
3323 * matches.
b112ec5c73f0 updated for version 7.0193
vimboss
parents: 648
diff changeset
3324 */
b112ec5c73f0 updated for version 7.0193
vimboss
parents: 648
diff changeset
3325 static void
b112ec5c73f0 updated for version 7.0193
vimboss
parents: 648
diff changeset
3326 ins_compl_addleader(c)
b112ec5c73f0 updated for version 7.0193
vimboss
parents: 648
diff changeset
3327 int c;
b112ec5c73f0 updated for version 7.0193
vimboss
parents: 648
diff changeset
3328 {
b112ec5c73f0 updated for version 7.0193
vimboss
parents: 648
diff changeset
3329 #ifdef FEAT_MBYTE
b112ec5c73f0 updated for version 7.0193
vimboss
parents: 648
diff changeset
3330 int cc;
b112ec5c73f0 updated for version 7.0193
vimboss
parents: 648
diff changeset
3331
b112ec5c73f0 updated for version 7.0193
vimboss
parents: 648
diff changeset
3332 if (has_mbyte && (cc = (*mb_char2len)(c)) > 1)
b112ec5c73f0 updated for version 7.0193
vimboss
parents: 648
diff changeset
3333 {
b112ec5c73f0 updated for version 7.0193
vimboss
parents: 648
diff changeset
3334 char_u buf[MB_MAXBYTES + 1];
b112ec5c73f0 updated for version 7.0193
vimboss
parents: 648
diff changeset
3335
b112ec5c73f0 updated for version 7.0193
vimboss
parents: 648
diff changeset
3336 (*mb_char2bytes)(c, buf);
b112ec5c73f0 updated for version 7.0193
vimboss
parents: 648
diff changeset
3337 buf[cc] = NUL;
b112ec5c73f0 updated for version 7.0193
vimboss
parents: 648
diff changeset
3338 ins_char_bytes(buf, cc);
b112ec5c73f0 updated for version 7.0193
vimboss
parents: 648
diff changeset
3339 }
b112ec5c73f0 updated for version 7.0193
vimboss
parents: 648
diff changeset
3340 else
b112ec5c73f0 updated for version 7.0193
vimboss
parents: 648
diff changeset
3341 #endif
b112ec5c73f0 updated for version 7.0193
vimboss
parents: 648
diff changeset
3342 ins_char(c);
b112ec5c73f0 updated for version 7.0193
vimboss
parents: 648
diff changeset
3343
874
4bac29d27e2f updated for version 7.0
vimboss
parents: 867
diff changeset
3344 /* If we didn't complete finding matches we must search again. */
4bac29d27e2f updated for version 7.0
vimboss
parents: 867
diff changeset
3345 if (compl_was_interrupted)
4bac29d27e2f updated for version 7.0
vimboss
parents: 867
diff changeset
3346 ins_compl_restart();
4bac29d27e2f updated for version 7.0
vimboss
parents: 867
diff changeset
3347
657
b112ec5c73f0 updated for version 7.0193
vimboss
parents: 648
diff changeset
3348 vim_free(compl_leader);
b112ec5c73f0 updated for version 7.0193
vimboss
parents: 648
diff changeset
3349 compl_leader = vim_strnsave(ml_get_curline() + compl_col,
b112ec5c73f0 updated for version 7.0193
vimboss
parents: 648
diff changeset
3350 curwin->w_cursor.col - compl_col);
b112ec5c73f0 updated for version 7.0193
vimboss
parents: 648
diff changeset
3351 if (compl_leader != NULL)
874
4bac29d27e2f updated for version 7.0
vimboss
parents: 867
diff changeset
3352 ins_compl_new_leader();
4bac29d27e2f updated for version 7.0
vimboss
parents: 867
diff changeset
3353 }
4bac29d27e2f updated for version 7.0
vimboss
parents: 867
diff changeset
3354
4bac29d27e2f updated for version 7.0
vimboss
parents: 867
diff changeset
3355 /*
4bac29d27e2f updated for version 7.0
vimboss
parents: 867
diff changeset
3356 * Setup for finding completions again without leaving CTRL-X mode. Used when
4bac29d27e2f updated for version 7.0
vimboss
parents: 867
diff changeset
3357 * BS or a key was typed while still searching for matches.
4bac29d27e2f updated for version 7.0
vimboss
parents: 867
diff changeset
3358 */
4bac29d27e2f updated for version 7.0
vimboss
parents: 867
diff changeset
3359 static void
4bac29d27e2f updated for version 7.0
vimboss
parents: 867
diff changeset
3360 ins_compl_restart()
4bac29d27e2f updated for version 7.0
vimboss
parents: 867
diff changeset
3361 {
4bac29d27e2f updated for version 7.0
vimboss
parents: 867
diff changeset
3362 ins_compl_free();
4bac29d27e2f updated for version 7.0
vimboss
parents: 867
diff changeset
3363 compl_started = FALSE;
4bac29d27e2f updated for version 7.0
vimboss
parents: 867
diff changeset
3364 compl_matches = 0;
4bac29d27e2f updated for version 7.0
vimboss
parents: 867
diff changeset
3365 compl_cont_status = 0;
4bac29d27e2f updated for version 7.0
vimboss
parents: 867
diff changeset
3366 compl_cont_mode = 0;
694
07d199fe02ed updated for version 7.0209
vimboss
parents: 692
diff changeset
3367 }
07d199fe02ed updated for version 7.0209
vimboss
parents: 692
diff changeset
3368
07d199fe02ed updated for version 7.0209
vimboss
parents: 692
diff changeset
3369 /*
07d199fe02ed updated for version 7.0209
vimboss
parents: 692
diff changeset
3370 * Set the first match, the original text.
07d199fe02ed updated for version 7.0209
vimboss
parents: 692
diff changeset
3371 */
07d199fe02ed updated for version 7.0209
vimboss
parents: 692
diff changeset
3372 static void
07d199fe02ed updated for version 7.0209
vimboss
parents: 692
diff changeset
3373 ins_compl_set_original_text(str)
07d199fe02ed updated for version 7.0209
vimboss
parents: 692
diff changeset
3374 char_u *str;
07d199fe02ed updated for version 7.0209
vimboss
parents: 692
diff changeset
3375 {
07d199fe02ed updated for version 7.0209
vimboss
parents: 692
diff changeset
3376 char_u *p;
07d199fe02ed updated for version 7.0209
vimboss
parents: 692
diff changeset
3377
07d199fe02ed updated for version 7.0209
vimboss
parents: 692
diff changeset
3378 /* Replace the original text entry. */
07d199fe02ed updated for version 7.0209
vimboss
parents: 692
diff changeset
3379 if (compl_first_match->cp_flags & ORIGINAL_TEXT) /* safety check */
07d199fe02ed updated for version 7.0209
vimboss
parents: 692
diff changeset
3380 {
07d199fe02ed updated for version 7.0209
vimboss
parents: 692
diff changeset
3381 p = vim_strsave(str);
07d199fe02ed updated for version 7.0209
vimboss
parents: 692
diff changeset
3382 if (p != NULL)
07d199fe02ed updated for version 7.0209
vimboss
parents: 692
diff changeset
3383 {
07d199fe02ed updated for version 7.0209
vimboss
parents: 692
diff changeset
3384 vim_free(compl_first_match->cp_str);
07d199fe02ed updated for version 7.0209
vimboss
parents: 692
diff changeset
3385 compl_first_match->cp_str = p;
07d199fe02ed updated for version 7.0209
vimboss
parents: 692
diff changeset
3386 }
657
b112ec5c73f0 updated for version 7.0193
vimboss
parents: 648
diff changeset
3387 }
b112ec5c73f0 updated for version 7.0193
vimboss
parents: 648
diff changeset
3388 }
b112ec5c73f0 updated for version 7.0193
vimboss
parents: 648
diff changeset
3389
b112ec5c73f0 updated for version 7.0193
vimboss
parents: 648
diff changeset
3390 /*
659
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
3391 * Append one character to the match leader. May reduce the number of
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
3392 * matches.
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
3393 */
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
3394 static void
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
3395 ins_compl_addfrommatch()
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
3396 {
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
3397 char_u *p;
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
3398 int len = curwin->w_cursor.col - compl_col;
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
3399 int c;
887
9dc77520c6d3 updated for version 7.0-013
vimboss
parents: 874
diff changeset
3400 compl_T *cp;
659
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
3401
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
3402 p = compl_shown_match->cp_str;
677
e649c78407e6 updated for version 7.0202
vimboss
parents: 674
diff changeset
3403 if ((int)STRLEN(p) <= len) /* the match is too short */
887
9dc77520c6d3 updated for version 7.0-013
vimboss
parents: 874
diff changeset
3404 {
9dc77520c6d3 updated for version 7.0-013
vimboss
parents: 874
diff changeset
3405 /* When still at the original match use the first entry that matches
9dc77520c6d3 updated for version 7.0-013
vimboss
parents: 874
diff changeset
3406 * the leader. */
9dc77520c6d3 updated for version 7.0-013
vimboss
parents: 874
diff changeset
3407 if (compl_shown_match->cp_flags & ORIGINAL_TEXT)
9dc77520c6d3 updated for version 7.0-013
vimboss
parents: 874
diff changeset
3408 {
9dc77520c6d3 updated for version 7.0-013
vimboss
parents: 874
diff changeset
3409 p = NULL;
9dc77520c6d3 updated for version 7.0-013
vimboss
parents: 874
diff changeset
3410 for (cp = compl_shown_match->cp_next; cp != NULL
9dc77520c6d3 updated for version 7.0-013
vimboss
parents: 874
diff changeset
3411 && cp != compl_first_match; cp = cp->cp_next)
9dc77520c6d3 updated for version 7.0-013
vimboss
parents: 874
diff changeset
3412 {
987
e625dad74346 updated for version 7.0-113
vimboss
parents: 978
diff changeset
3413 if (compl_leader == NULL
e625dad74346 updated for version 7.0-113
vimboss
parents: 978
diff changeset
3414 || ins_compl_equal(cp, compl_leader,
887
9dc77520c6d3 updated for version 7.0-013
vimboss
parents: 874
diff changeset
3415 (int)STRLEN(compl_leader)))
9dc77520c6d3 updated for version 7.0-013
vimboss
parents: 874
diff changeset
3416 {
9dc77520c6d3 updated for version 7.0-013
vimboss
parents: 874
diff changeset
3417 p = cp->cp_str;
9dc77520c6d3 updated for version 7.0-013
vimboss
parents: 874
diff changeset
3418 break;
9dc77520c6d3 updated for version 7.0-013
vimboss
parents: 874
diff changeset
3419 }
9dc77520c6d3 updated for version 7.0-013
vimboss
parents: 874
diff changeset
3420 }
9dc77520c6d3 updated for version 7.0-013
vimboss
parents: 874
diff changeset
3421 if (p == NULL || (int)STRLEN(p) <= len)
9dc77520c6d3 updated for version 7.0-013
vimboss
parents: 874
diff changeset
3422 return;
9dc77520c6d3 updated for version 7.0-013
vimboss
parents: 874
diff changeset
3423 }
9dc77520c6d3 updated for version 7.0-013
vimboss
parents: 874
diff changeset
3424 else
9dc77520c6d3 updated for version 7.0-013
vimboss
parents: 874
diff changeset
3425 return;
9dc77520c6d3 updated for version 7.0-013
vimboss
parents: 874
diff changeset
3426 }
659
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
3427 p += len;
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
3428 #ifdef FEAT_MBYTE
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
3429 c = mb_ptr2char(p);
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
3430 #else
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
3431 c = *p;
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
3432 #endif
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
3433 ins_compl_addleader(c);
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
3434 }
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
3435
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
3436 /*
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3437 * Prepare for Insert mode completion, or stop it.
464
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
3438 * Called just after typing a character in Insert mode.
540
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
3439 * Returns TRUE when the character is not to be inserted;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3440 */
540
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
3441 static int
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3442 ins_compl_prep(c)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3443 int c;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3444 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3445 char_u *ptr;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3446 int want_cindent;
540
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
3447 int retval = FALSE;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3448
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3449 /* Forget any previous 'special' messages if this is actually
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3450 * a ^X mode key - bar ^R, in which case we wait to see what it gives us.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3451 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3452 if (c != Ctrl_R && vim_is_ctrl_x_key(c))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3453 edit_submode_extra = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3454
1434
40aa7ae37901 updated for version 7.1-149
vimboss
parents: 1430
diff changeset
3455 /* Ignore end of Select mode mapping and mouse scroll buttons. */
40aa7ae37901 updated for version 7.1-149
vimboss
parents: 1430
diff changeset
3456 if (c == K_SELECT || c == K_MOUSEDOWN || c == K_MOUSEUP)
540
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
3457 return retval;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3458
665
21ab9abf0f08 updated for version 7.0196
vimboss
parents: 661
diff changeset
3459 /* Set "compl_get_longest" when finding the first matches. */
21ab9abf0f08 updated for version 7.0196
vimboss
parents: 661
diff changeset
3460 if (ctrl_x_mode == CTRL_X_NOT_DEFINED_YET
21ab9abf0f08 updated for version 7.0196
vimboss
parents: 661
diff changeset
3461 || (ctrl_x_mode == 0 && !compl_started))
21ab9abf0f08 updated for version 7.0196
vimboss
parents: 661
diff changeset
3462 {
21ab9abf0f08 updated for version 7.0196
vimboss
parents: 661
diff changeset
3463 compl_get_longest = (vim_strchr(p_cot, 'l') != NULL);
21ab9abf0f08 updated for version 7.0196
vimboss
parents: 661
diff changeset
3464 compl_used_match = TRUE;
21ab9abf0f08 updated for version 7.0196
vimboss
parents: 661
diff changeset
3465 }
21ab9abf0f08 updated for version 7.0196
vimboss
parents: 661
diff changeset
3466
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3467 if (ctrl_x_mode == CTRL_X_NOT_DEFINED_YET)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3468 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3469 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3470 * We have just typed CTRL-X and aren't quite sure which CTRL-X mode
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3471 * it will be yet. Now we decide.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3472 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3473 switch (c)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3474 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3475 case Ctrl_E:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3476 case Ctrl_Y:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3477 ctrl_x_mode = CTRL_X_SCROLL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3478 if (!(State & REPLACE_FLAG))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3479 edit_submode = (char_u *)_(" (insert) Scroll (^E/^Y)");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3480 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3481 edit_submode = (char_u *)_(" (replace) Scroll (^E/^Y)");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3482 edit_submode_pre = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3483 showmode();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3484 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3485 case Ctrl_L:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3486 ctrl_x_mode = CTRL_X_WHOLE_LINE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3487 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3488 case Ctrl_F:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3489 ctrl_x_mode = CTRL_X_FILES;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3490 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3491 case Ctrl_K:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3492 ctrl_x_mode = CTRL_X_DICTIONARY;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3493 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3494 case Ctrl_R:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3495 /* Simply allow ^R to happen without affecting ^X mode */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3496 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3497 case Ctrl_T:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3498 ctrl_x_mode = CTRL_X_THESAURUS;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3499 break;
12
bdeee1504ac1 updated for version 7.0004
vimboss
parents: 11
diff changeset
3500 #ifdef FEAT_COMPL_FUNC
bdeee1504ac1 updated for version 7.0004
vimboss
parents: 11
diff changeset
3501 case Ctrl_U:
bdeee1504ac1 updated for version 7.0004
vimboss
parents: 11
diff changeset
3502 ctrl_x_mode = CTRL_X_FUNCTION;
bdeee1504ac1 updated for version 7.0004
vimboss
parents: 11
diff changeset
3503 break;
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3504 case Ctrl_O:
523
a7ae7e043e43 updated for version 7.0146
vimboss
parents: 502
diff changeset
3505 ctrl_x_mode = CTRL_X_OMNI;
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3506 break;
502
52e76e2b5b65 updated for version 7.0140
vimboss
parents: 499
diff changeset
3507 #endif
477
f8b75b8f1988 updated for version 7.0128
vimboss
parents: 474
diff changeset
3508 case 's':
f8b75b8f1988 updated for version 7.0128
vimboss
parents: 474
diff changeset
3509 case Ctrl_S:
f8b75b8f1988 updated for version 7.0128
vimboss
parents: 474
diff changeset
3510 ctrl_x_mode = CTRL_X_SPELL;
744
07f7b4a7755c updated for version 7.0222
vimboss
parents: 732
diff changeset
3511 #ifdef FEAT_SPELL
819
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 818
diff changeset
3512 ++emsg_off; /* Avoid getting the E756 error twice. */
484
f012c4ed8c38 updated for version 7.0132
vimboss
parents: 477
diff changeset
3513 spell_back_to_badword();
819
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 818
diff changeset
3514 --emsg_off;
484
f012c4ed8c38 updated for version 7.0132
vimboss
parents: 477
diff changeset
3515 #endif
477
f8b75b8f1988 updated for version 7.0128
vimboss
parents: 474
diff changeset
3516 break;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3517 case Ctrl_RSB:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3518 ctrl_x_mode = CTRL_X_TAGS;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3519 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3520 #ifdef FEAT_FIND_ID
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3521 case Ctrl_I:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3522 case K_S_TAB:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3523 ctrl_x_mode = CTRL_X_PATH_PATTERNS;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3524 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3525 case Ctrl_D:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3526 ctrl_x_mode = CTRL_X_PATH_DEFINES;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3527 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3528 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3529 case Ctrl_V:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3530 case Ctrl_Q:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3531 ctrl_x_mode = CTRL_X_CMDLINE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3532 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3533 case Ctrl_P:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3534 case Ctrl_N:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3535 /* ^X^P means LOCAL expansion if nothing interrupted (eg we
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3536 * just started ^X mode, or there were enough ^X's to cancel
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3537 * the previous mode, say ^X^F^X^X^P or ^P^X^X^X^P, see below)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3538 * do normal expansion when interrupting a different mode (say
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3539 * ^X^F^X^P or ^P^X^X^P, see below)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3540 * nothing changes if interrupting mode 0, (eg, the flag
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3541 * doesn't change when going to ADDING mode -- Acevedo */
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3542 if (!(compl_cont_status & CONT_INTRPT))
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3543 compl_cont_status |= CONT_LOCAL;
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3544 else if (compl_cont_mode != 0)
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3545 compl_cont_status &= ~CONT_LOCAL;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3546 /* FALLTHROUGH */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3547 default:
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3548 /* If we have typed at least 2 ^X's... for modes != 0, we set
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3549 * compl_cont_status = 0 (eg, as if we had just started ^X
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3550 * mode).
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3551 * For mode 0, we set "compl_cont_mode" to an impossible
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3552 * value, in both cases ^X^X can be used to restart the same
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3553 * mode (avoiding ADDING mode).
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3554 * Undocumented feature: In a mode != 0 ^X^P and ^X^X^P start
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3555 * 'complete' and local ^P expansions respectively.
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3556 * In mode 0 an extra ^X is needed since ^X^P goes to ADDING
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3557 * mode -- Acevedo */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3558 if (c == Ctrl_X)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3559 {
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3560 if (compl_cont_mode != 0)
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3561 compl_cont_status = 0;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3562 else
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3563 compl_cont_mode = CTRL_X_NOT_DEFINED_YET;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3564 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3565 ctrl_x_mode = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3566 edit_submode = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3567 showmode();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3568 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3569 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3570 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3571 else if (ctrl_x_mode != 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3572 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3573 /* We're already in CTRL-X mode, do we stay in it? */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3574 if (!vim_is_ctrl_x_key(c))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3575 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3576 if (ctrl_x_mode == CTRL_X_SCROLL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3577 ctrl_x_mode = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3578 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3579 ctrl_x_mode = CTRL_X_FINISHED;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3580 edit_submode = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3581 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3582 showmode();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3583 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3584
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3585 if (compl_started || ctrl_x_mode == CTRL_X_FINISHED)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3586 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3587 /* Show error message from attempted keyword completion (probably
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3588 * 'Pattern not found') until another key is hit, then go back to
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3589 * showing what mode we are in. */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3590 showmode();
644
e4fa26ce8769 updated for version 7.0187
vimboss
parents: 634
diff changeset
3591 if ((ctrl_x_mode == 0 && c != Ctrl_N && c != Ctrl_P && c != Ctrl_R
e4fa26ce8769 updated for version 7.0187
vimboss
parents: 634
diff changeset
3592 && !ins_compl_pum_key(c))
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3593 || ctrl_x_mode == CTRL_X_FINISHED)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3594 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3595 /* Get here when we have finished typing a sequence of ^N and
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3596 * ^P or other completion characters in CTRL-X mode. Free up
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3597 * memory that was used, and make sure we can redo the insert. */
836
5a7843c57316 updated for version 7.0e02
vimboss
parents: 835
diff changeset
3598 if (compl_curr_match != NULL || compl_leader != NULL || c == Ctrl_E)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3599 {
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3600 char_u *p;
938
fc0c566b9107 updated for version 7.0-064
vimboss
parents: 935
diff changeset
3601 int temp = 0;
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3602
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3603 /*
836
5a7843c57316 updated for version 7.0e02
vimboss
parents: 835
diff changeset
3604 * If any of the original typed text has been changed, eg when
5a7843c57316 updated for version 7.0e02
vimboss
parents: 835
diff changeset
3605 * ignorecase is set, we must add back-spaces to the redo
5a7843c57316 updated for version 7.0e02
vimboss
parents: 835
diff changeset
3606 * buffer. We add as few as necessary to delete just the part
5a7843c57316 updated for version 7.0e02
vimboss
parents: 835
diff changeset
3607 * of the original text that has changed.
5a7843c57316 updated for version 7.0e02
vimboss
parents: 835
diff changeset
3608 * When using the longest match, edited the match or used
5a7843c57316 updated for version 7.0e02
vimboss
parents: 835
diff changeset
3609 * CTRL-E then don't use the current match.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3610 */
836
5a7843c57316 updated for version 7.0e02
vimboss
parents: 835
diff changeset
3611 if (compl_curr_match != NULL && compl_used_match && c != Ctrl_E)
5a7843c57316 updated for version 7.0e02
vimboss
parents: 835
diff changeset
3612 ptr = compl_curr_match->cp_str;
5a7843c57316 updated for version 7.0e02
vimboss
parents: 835
diff changeset
3613 else if (compl_leader != NULL)
5a7843c57316 updated for version 7.0e02
vimboss
parents: 835
diff changeset
3614 ptr = compl_leader;
5a7843c57316 updated for version 7.0e02
vimboss
parents: 835
diff changeset
3615 else
5a7843c57316 updated for version 7.0e02
vimboss
parents: 835
diff changeset
3616 ptr = compl_orig_text;
897
2e1e9b708941 updated for version 7.0-023
vimboss
parents: 887
diff changeset
3617 if (compl_orig_text != NULL)
2e1e9b708941 updated for version 7.0-023
vimboss
parents: 887
diff changeset
3618 {
2e1e9b708941 updated for version 7.0-023
vimboss
parents: 887
diff changeset
3619 p = compl_orig_text;
2e1e9b708941 updated for version 7.0-023
vimboss
parents: 887
diff changeset
3620 for (temp = 0; p[temp] != NUL && p[temp] == ptr[temp];
2e1e9b708941 updated for version 7.0-023
vimboss
parents: 887
diff changeset
3621 ++temp)
2e1e9b708941 updated for version 7.0-023
vimboss
parents: 887
diff changeset
3622 ;
836
5a7843c57316 updated for version 7.0e02
vimboss
parents: 835
diff changeset
3623 #ifdef FEAT_MBYTE
897
2e1e9b708941 updated for version 7.0-023
vimboss
parents: 887
diff changeset
3624 if (temp > 0)
2e1e9b708941 updated for version 7.0-023
vimboss
parents: 887
diff changeset
3625 temp -= (*mb_head_off)(compl_orig_text, p + temp);
2e1e9b708941 updated for version 7.0-023
vimboss
parents: 887
diff changeset
3626 #endif
2e1e9b708941 updated for version 7.0-023
vimboss
parents: 887
diff changeset
3627 for (p += temp; *p != NUL; mb_ptr_adv(p))
2e1e9b708941 updated for version 7.0-023
vimboss
parents: 887
diff changeset
3628 AppendCharToRedobuff(K_BS);
2e1e9b708941 updated for version 7.0-023
vimboss
parents: 887
diff changeset
3629 }
2e1e9b708941 updated for version 7.0-023
vimboss
parents: 887
diff changeset
3630 if (ptr != NULL)
2e1e9b708941 updated for version 7.0-023
vimboss
parents: 887
diff changeset
3631 AppendToRedobuffLit(ptr + temp, -1);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3632 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3633
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3634 #ifdef FEAT_CINDENT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3635 want_cindent = (can_cindent && cindent_on());
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3636 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3637 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3638 * When completing whole lines: fix indent for 'cindent'.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3639 * Otherwise, break line if it's too long.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3640 */
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3641 if (compl_cont_mode == CTRL_X_WHOLE_LINE)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3642 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3643 #ifdef FEAT_CINDENT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3644 /* re-indent the current line */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3645 if (want_cindent)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3646 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3647 do_c_expr_indent();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3648 want_cindent = FALSE; /* don't do it again */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3649 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3650 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3651 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3652 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3653 {
1073
ec7a570696ac updated for version 7.0-199
vimboss
parents: 1063
diff changeset
3654 int prev_col = curwin->w_cursor.col;
ec7a570696ac updated for version 7.0-199
vimboss
parents: 1063
diff changeset
3655
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3656 /* put the cursor on the last char, for 'tw' formatting */
1073
ec7a570696ac updated for version 7.0-199
vimboss
parents: 1063
diff changeset
3657 if (prev_col > 0)
ec7a570696ac updated for version 7.0-199
vimboss
parents: 1063
diff changeset
3658 dec_cursor();
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3659 if (stop_arrow() == OK)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3660 insertchar(NUL, 0, -1);
1073
ec7a570696ac updated for version 7.0-199
vimboss
parents: 1063
diff changeset
3661 if (prev_col > 0
ec7a570696ac updated for version 7.0-199
vimboss
parents: 1063
diff changeset
3662 && ml_get_curline()[curwin->w_cursor.col] != NUL)
ec7a570696ac updated for version 7.0-199
vimboss
parents: 1063
diff changeset
3663 inc_cursor();
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3664 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3665
816
4a79d6d376f0 updated for version 7.0c02
vimboss
parents: 794
diff changeset
3666 /* If the popup menu is displayed pressing CTRL-Y means accepting
825
6675076019ae updated for version 7.0d
vimboss
parents: 819
diff changeset
3667 * the selection without inserting anything. When
6675076019ae updated for version 7.0d
vimboss
parents: 819
diff changeset
3668 * compl_enter_selects is set the Enter key does the same. */
6675076019ae updated for version 7.0d
vimboss
parents: 819
diff changeset
3669 if ((c == Ctrl_Y || (compl_enter_selects
6675076019ae updated for version 7.0d
vimboss
parents: 819
diff changeset
3670 && (c == CAR || c == K_KENTER || c == NL)))
6675076019ae updated for version 7.0d
vimboss
parents: 819
diff changeset
3671 && pum_visible())
540
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
3672 retval = TRUE;
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
3673
816
4a79d6d376f0 updated for version 7.0c02
vimboss
parents: 794
diff changeset
3674 /* CTRL-E means completion is Ended, go back to the typed text. */
4a79d6d376f0 updated for version 7.0c02
vimboss
parents: 794
diff changeset
3675 if (c == Ctrl_E)
4a79d6d376f0 updated for version 7.0c02
vimboss
parents: 794
diff changeset
3676 {
4a79d6d376f0 updated for version 7.0c02
vimboss
parents: 794
diff changeset
3677 ins_compl_delete();
4a79d6d376f0 updated for version 7.0c02
vimboss
parents: 794
diff changeset
3678 if (compl_leader != NULL)
1782
12cecc379574 updated for version 7.2-080
vimboss
parents: 1698
diff changeset
3679 ins_bytes(compl_leader + ins_compl_len());
816
4a79d6d376f0 updated for version 7.0c02
vimboss
parents: 794
diff changeset
3680 else if (compl_first_match != NULL)
1782
12cecc379574 updated for version 7.2-080
vimboss
parents: 1698
diff changeset
3681 ins_bytes(compl_orig_text + ins_compl_len());
816
4a79d6d376f0 updated for version 7.0c02
vimboss
parents: 794
diff changeset
3682 retval = TRUE;
4a79d6d376f0 updated for version 7.0c02
vimboss
parents: 794
diff changeset
3683 }
4a79d6d376f0 updated for version 7.0c02
vimboss
parents: 794
diff changeset
3684
1698
f4f8014d516e updated for version 7.2c-000
vimboss
parents: 1622
diff changeset
3685 auto_format(FALSE, TRUE);
f4f8014d516e updated for version 7.2c-000
vimboss
parents: 1622
diff changeset
3686
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3687 ins_compl_free();
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3688 compl_started = FALSE;
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3689 compl_matches = 0;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3690 msg_clr_cmdline(); /* necessary for "noshowmode" */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3691 ctrl_x_mode = 0;
825
6675076019ae updated for version 7.0d
vimboss
parents: 819
diff changeset
3692 compl_enter_selects = FALSE;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3693 if (edit_submode != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3694 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3695 edit_submode = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3696 showmode();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3697 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3698
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3699 #ifdef FEAT_CINDENT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3700 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3701 * Indent now if a key was typed that is in 'cinkeys'.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3702 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3703 if (want_cindent && in_cinkeys(KEY_COMPLETE, ' ', inindent(0)))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3704 do_c_expr_indent();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3705 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3706 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3707 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3708
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3709 /* reset continue_* if we left expansion-mode, if we stay they'll be
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3710 * (re)set properly in ins_complete() */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3711 if (!vim_is_ctrl_x_key(c))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3712 {
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3713 compl_cont_status = 0;
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3714 compl_cont_mode = 0;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3715 }
540
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
3716
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
3717 return retval;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3718 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3719
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3720 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3721 * Loops through the list of windows, loaded-buffers or non-loaded-buffers
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3722 * (depending on flag) starting from buf and looking for a non-scanned
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3723 * buffer (other than curbuf). curbuf is special, if it is called with
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3724 * buf=curbuf then it has to be the first call for a given flag/expansion.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3725 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3726 * Returns the buffer to scan, if any, otherwise returns curbuf -- Acevedo
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3727 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3728 static buf_T *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3729 ins_compl_next_buf(buf, flag)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3730 buf_T *buf;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3731 int flag;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3732 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3733 #ifdef FEAT_WINDOWS
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3734 static win_T *wp;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3735 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3736
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3737 if (flag == 'w') /* just windows */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3738 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3739 #ifdef FEAT_WINDOWS
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3740 if (buf == curbuf) /* first call for this flag/expansion */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3741 wp = curwin;
383
8c229eb52e34 updated for version 7.0099
vimboss
parents: 359
diff changeset
3742 while ((wp = (wp->w_next != NULL ? wp->w_next : firstwin)) != curwin
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3743 && wp->w_buffer->b_scanned)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3744 ;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3745 buf = wp->w_buffer;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3746 #else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3747 buf = curbuf;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3748 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3749 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3750 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3751 /* 'b' (just loaded buffers), 'u' (just non-loaded buffers) or 'U'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3752 * (unlisted buffers)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3753 * When completing whole lines skip unloaded buffers. */
383
8c229eb52e34 updated for version 7.0099
vimboss
parents: 359
diff changeset
3754 while ((buf = (buf->b_next != NULL ? buf->b_next : firstbuf)) != curbuf
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3755 && ((flag == 'U'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3756 ? buf->b_p_bl
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3757 : (!buf->b_p_bl
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3758 || (buf->b_ml.ml_mfp == NULL) != (flag == 'u')))
667
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
3759 || buf->b_scanned))
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3760 ;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3761 return buf;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3762 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3763
12
bdeee1504ac1 updated for version 7.0004
vimboss
parents: 11
diff changeset
3764 #ifdef FEAT_COMPL_FUNC
659
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
3765 static void expand_by_function __ARGS((int type, char_u *base));
12
bdeee1504ac1 updated for version 7.0004
vimboss
parents: 11
diff changeset
3766
bdeee1504ac1 updated for version 7.0004
vimboss
parents: 11
diff changeset
3767 /*
523
a7ae7e043e43 updated for version 7.0146
vimboss
parents: 502
diff changeset
3768 * Execute user defined complete function 'completefunc' or 'omnifunc', and
502
52e76e2b5b65 updated for version 7.0140
vimboss
parents: 499
diff changeset
3769 * get matches in "matches".
12
bdeee1504ac1 updated for version 7.0004
vimboss
parents: 11
diff changeset
3770 */
659
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
3771 static void
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
3772 expand_by_function(type, base)
523
a7ae7e043e43 updated for version 7.0146
vimboss
parents: 502
diff changeset
3773 int type; /* CTRL_X_OMNI or CTRL_X_FUNCTION */
12
bdeee1504ac1 updated for version 7.0004
vimboss
parents: 11
diff changeset
3774 char_u *base;
bdeee1504ac1 updated for version 7.0004
vimboss
parents: 11
diff changeset
3775 {
452
01af1008a8d8 updated for version 7.0120
vimboss
parents: 449
diff changeset
3776 list_T *matchlist;
502
52e76e2b5b65 updated for version 7.0140
vimboss
parents: 499
diff changeset
3777 char_u *args[2];
52e76e2b5b65 updated for version 7.0140
vimboss
parents: 499
diff changeset
3778 char_u *funcname;
52e76e2b5b65 updated for version 7.0140
vimboss
parents: 499
diff changeset
3779 pos_T pos;
52e76e2b5b65 updated for version 7.0140
vimboss
parents: 499
diff changeset
3780
52e76e2b5b65 updated for version 7.0140
vimboss
parents: 499
diff changeset
3781 funcname = (type == CTRL_X_FUNCTION) ? curbuf->b_p_cfu : curbuf->b_p_ofu;
52e76e2b5b65 updated for version 7.0140
vimboss
parents: 499
diff changeset
3782 if (*funcname == NUL)
659
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
3783 return;
452
01af1008a8d8 updated for version 7.0120
vimboss
parents: 449
diff changeset
3784
01af1008a8d8 updated for version 7.0120
vimboss
parents: 449
diff changeset
3785 /* Call 'completefunc' to obtain the list of matches. */
01af1008a8d8 updated for version 7.0120
vimboss
parents: 449
diff changeset
3786 args[0] = (char_u *)"0";
502
52e76e2b5b65 updated for version 7.0140
vimboss
parents: 499
diff changeset
3787 args[1] = base;
52e76e2b5b65 updated for version 7.0140
vimboss
parents: 499
diff changeset
3788
52e76e2b5b65 updated for version 7.0140
vimboss
parents: 499
diff changeset
3789 pos = curwin->w_cursor;
52e76e2b5b65 updated for version 7.0140
vimboss
parents: 499
diff changeset
3790 matchlist = call_func_retlist(funcname, 2, args, FALSE);
52e76e2b5b65 updated for version 7.0140
vimboss
parents: 499
diff changeset
3791 curwin->w_cursor = pos; /* restore the cursor position */
452
01af1008a8d8 updated for version 7.0120
vimboss
parents: 449
diff changeset
3792 if (matchlist == NULL)
659
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
3793 return;
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
3794
724
a35dce0cabc5 updated for version 7.0220
vimboss
parents: 716
diff changeset
3795 ins_compl_add_list(matchlist);
a35dce0cabc5 updated for version 7.0220
vimboss
parents: 716
diff changeset
3796 list_unref(matchlist);
a35dce0cabc5 updated for version 7.0220
vimboss
parents: 716
diff changeset
3797 }
a35dce0cabc5 updated for version 7.0220
vimboss
parents: 716
diff changeset
3798 #endif /* FEAT_COMPL_FUNC */
a35dce0cabc5 updated for version 7.0220
vimboss
parents: 716
diff changeset
3799
786
8f6a426bc1e0 updated for version 7.0229
vimboss
parents: 782
diff changeset
3800 #if defined(FEAT_COMPL_FUNC) || defined(FEAT_EVAL) || defined(PROTO)
724
a35dce0cabc5 updated for version 7.0220
vimboss
parents: 716
diff changeset
3801 /*
a35dce0cabc5 updated for version 7.0220
vimboss
parents: 716
diff changeset
3802 * Add completions from a list.
a35dce0cabc5 updated for version 7.0220
vimboss
parents: 716
diff changeset
3803 */
a35dce0cabc5 updated for version 7.0220
vimboss
parents: 716
diff changeset
3804 static void
a35dce0cabc5 updated for version 7.0220
vimboss
parents: 716
diff changeset
3805 ins_compl_add_list(list)
a35dce0cabc5 updated for version 7.0220
vimboss
parents: 716
diff changeset
3806 list_T *list;
a35dce0cabc5 updated for version 7.0220
vimboss
parents: 716
diff changeset
3807 {
a35dce0cabc5 updated for version 7.0220
vimboss
parents: 716
diff changeset
3808 listitem_T *li;
a35dce0cabc5 updated for version 7.0220
vimboss
parents: 716
diff changeset
3809 int dir = compl_direction;
a35dce0cabc5 updated for version 7.0220
vimboss
parents: 716
diff changeset
3810
659
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
3811 /* Go through the List with matches and add each of them. */
724
a35dce0cabc5 updated for version 7.0220
vimboss
parents: 716
diff changeset
3812 for (li = list->lv_first; li != NULL; li = li->li_next)
452
01af1008a8d8 updated for version 7.0120
vimboss
parents: 449
diff changeset
3813 {
786
8f6a426bc1e0 updated for version 7.0229
vimboss
parents: 782
diff changeset
3814 if (ins_compl_add_tv(&li->li_tv, dir) == OK)
8f6a426bc1e0 updated for version 7.0229
vimboss
parents: 782
diff changeset
3815 /* if dir was BACKWARD then honor it just once */
8f6a426bc1e0 updated for version 7.0229
vimboss
parents: 782
diff changeset
3816 dir = FORWARD;
648
9032e4668296 updated for version 7.0189
vimboss
parents: 644
diff changeset
3817 else if (did_emsg)
9032e4668296 updated for version 7.0189
vimboss
parents: 644
diff changeset
3818 break;
452
01af1008a8d8 updated for version 7.0120
vimboss
parents: 449
diff changeset
3819 }
724
a35dce0cabc5 updated for version 7.0220
vimboss
parents: 716
diff changeset
3820 }
786
8f6a426bc1e0 updated for version 7.0229
vimboss
parents: 782
diff changeset
3821
8f6a426bc1e0 updated for version 7.0229
vimboss
parents: 782
diff changeset
3822 /*
8f6a426bc1e0 updated for version 7.0229
vimboss
parents: 782
diff changeset
3823 * Add a match to the list of matches from a typeval_T.
8f6a426bc1e0 updated for version 7.0229
vimboss
parents: 782
diff changeset
3824 * If the given string is already in the list of completions, then return
8f6a426bc1e0 updated for version 7.0229
vimboss
parents: 782
diff changeset
3825 * NOTDONE, otherwise add it to the list and return OK. If there is an error,
8f6a426bc1e0 updated for version 7.0229
vimboss
parents: 782
diff changeset
3826 * maybe because alloc() returns NULL, then FAIL is returned.
8f6a426bc1e0 updated for version 7.0229
vimboss
parents: 782
diff changeset
3827 */
8f6a426bc1e0 updated for version 7.0229
vimboss
parents: 782
diff changeset
3828 int
8f6a426bc1e0 updated for version 7.0229
vimboss
parents: 782
diff changeset
3829 ins_compl_add_tv(tv, dir)
8f6a426bc1e0 updated for version 7.0229
vimboss
parents: 782
diff changeset
3830 typval_T *tv;
8f6a426bc1e0 updated for version 7.0229
vimboss
parents: 782
diff changeset
3831 int dir;
8f6a426bc1e0 updated for version 7.0229
vimboss
parents: 782
diff changeset
3832 {
8f6a426bc1e0 updated for version 7.0229
vimboss
parents: 782
diff changeset
3833 char_u *word;
867
a5677b7ce858 updated for version 7.0g04
vimboss
parents: 864
diff changeset
3834 int icase = FALSE;
944
b2dcb8457067 updated for version 7.0-070
vimboss
parents: 942
diff changeset
3835 int adup = FALSE;
786
8f6a426bc1e0 updated for version 7.0229
vimboss
parents: 782
diff changeset
3836 char_u *(cptext[CPT_COUNT]);
8f6a426bc1e0 updated for version 7.0229
vimboss
parents: 782
diff changeset
3837
8f6a426bc1e0 updated for version 7.0229
vimboss
parents: 782
diff changeset
3838 if (tv->v_type == VAR_DICT && tv->vval.v_dict != NULL)
8f6a426bc1e0 updated for version 7.0229
vimboss
parents: 782
diff changeset
3839 {
8f6a426bc1e0 updated for version 7.0229
vimboss
parents: 782
diff changeset
3840 word = get_dict_string(tv->vval.v_dict, (char_u *)"word", FALSE);
8f6a426bc1e0 updated for version 7.0229
vimboss
parents: 782
diff changeset
3841 cptext[CPT_ABBR] = get_dict_string(tv->vval.v_dict,
8f6a426bc1e0 updated for version 7.0229
vimboss
parents: 782
diff changeset
3842 (char_u *)"abbr", FALSE);
8f6a426bc1e0 updated for version 7.0229
vimboss
parents: 782
diff changeset
3843 cptext[CPT_MENU] = get_dict_string(tv->vval.v_dict,
8f6a426bc1e0 updated for version 7.0229
vimboss
parents: 782
diff changeset
3844 (char_u *)"menu", FALSE);
8f6a426bc1e0 updated for version 7.0229
vimboss
parents: 782
diff changeset
3845 cptext[CPT_KIND] = get_dict_string(tv->vval.v_dict,
8f6a426bc1e0 updated for version 7.0229
vimboss
parents: 782
diff changeset
3846 (char_u *)"kind", FALSE);
8f6a426bc1e0 updated for version 7.0229
vimboss
parents: 782
diff changeset
3847 cptext[CPT_INFO] = get_dict_string(tv->vval.v_dict,
8f6a426bc1e0 updated for version 7.0229
vimboss
parents: 782
diff changeset
3848 (char_u *)"info", FALSE);
8f6a426bc1e0 updated for version 7.0229
vimboss
parents: 782
diff changeset
3849 if (get_dict_string(tv->vval.v_dict, (char_u *)"icase", FALSE) != NULL)
8f6a426bc1e0 updated for version 7.0229
vimboss
parents: 782
diff changeset
3850 icase = get_dict_number(tv->vval.v_dict, (char_u *)"icase");
841
c2cae213194d updated for version 7.0e07
vimboss
parents: 840
diff changeset
3851 if (get_dict_string(tv->vval.v_dict, (char_u *)"dup", FALSE) != NULL)
944
b2dcb8457067 updated for version 7.0-070
vimboss
parents: 942
diff changeset
3852 adup = get_dict_number(tv->vval.v_dict, (char_u *)"dup");
786
8f6a426bc1e0 updated for version 7.0229
vimboss
parents: 782
diff changeset
3853 }
8f6a426bc1e0 updated for version 7.0229
vimboss
parents: 782
diff changeset
3854 else
8f6a426bc1e0 updated for version 7.0229
vimboss
parents: 782
diff changeset
3855 {
8f6a426bc1e0 updated for version 7.0229
vimboss
parents: 782
diff changeset
3856 word = get_tv_string_chk(tv);
8f6a426bc1e0 updated for version 7.0229
vimboss
parents: 782
diff changeset
3857 vim_memset(cptext, 0, sizeof(cptext));
8f6a426bc1e0 updated for version 7.0229
vimboss
parents: 782
diff changeset
3858 }
8f6a426bc1e0 updated for version 7.0229
vimboss
parents: 782
diff changeset
3859 if (word == NULL || *word == NUL)
8f6a426bc1e0 updated for version 7.0229
vimboss
parents: 782
diff changeset
3860 return FAIL;
944
b2dcb8457067 updated for version 7.0-070
vimboss
parents: 942
diff changeset
3861 return ins_compl_add(word, -1, icase, NULL, cptext, dir, 0, adup);
786
8f6a426bc1e0 updated for version 7.0229
vimboss
parents: 782
diff changeset
3862 }
724
a35dce0cabc5 updated for version 7.0220
vimboss
parents: 716
diff changeset
3863 #endif
12
bdeee1504ac1 updated for version 7.0004
vimboss
parents: 11
diff changeset
3864
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3865 /*
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3866 * Get the next expansion(s), using "compl_pattern".
659
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
3867 * The search starts at position "ini" in curbuf and in the direction
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
3868 * compl_direction.
667
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
3869 * When "compl_started" is FALSE start at that position, otherwise continue
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
3870 * where we stopped searching before.
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3871 * This may return before finding all the matches.
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3872 * Return the total number of matches or -1 if still unknown -- Acevedo
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3873 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3874 static int
659
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
3875 ins_compl_get_exp(ini)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3876 pos_T *ini;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3877 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3878 static pos_T first_match_pos;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3879 static pos_T last_match_pos;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3880 static char_u *e_cpt = (char_u *)""; /* curr. entry in 'complete' */
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3881 static int found_all = FALSE; /* Found all matches of a
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3882 certain type. */
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3883 static buf_T *ins_buf = NULL; /* buffer being scanned */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3884
464
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
3885 pos_T *pos;
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
3886 char_u **matches;
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
3887 int save_p_scs;
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
3888 int save_p_ws;
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
3889 int save_p_ic;
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
3890 int i;
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
3891 int num_matches;
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
3892 int len;
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
3893 int found_new_match;
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
3894 int type = ctrl_x_mode;
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
3895 char_u *ptr;
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
3896 char_u *dict = NULL;
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
3897 int dict_f = 0;
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
3898 compl_T *old_match;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3899
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3900 if (!compl_started)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3901 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3902 for (ins_buf = firstbuf; ins_buf != NULL; ins_buf = ins_buf->b_next)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3903 ins_buf->b_scanned = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3904 found_all = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3905 ins_buf = curbuf;
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3906 e_cpt = (compl_cont_status & CONT_LOCAL)
12
bdeee1504ac1 updated for version 7.0004
vimboss
parents: 11
diff changeset
3907 ? (char_u *)"." : curbuf->b_p_cpt;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3908 last_match_pos = first_match_pos = *ini;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3909 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3910
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3911 old_match = compl_curr_match; /* remember the last current match */
659
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
3912 pos = (compl_direction == FORWARD) ? &last_match_pos : &first_match_pos;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3913 /* For ^N/^P loop over all the flags/windows/buffers in 'complete' */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3914 for (;;)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3915 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3916 found_new_match = FAIL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3917
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3918 /* For ^N/^P pick a new entry from e_cpt if compl_started is off,
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3919 * or if found_all says this entry is done. For ^X^L only use the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3920 * entries from 'complete' that look in loaded buffers. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3921 if ((ctrl_x_mode == 0 || ctrl_x_mode == CTRL_X_WHOLE_LINE)
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3922 && (!compl_started || found_all))
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3923 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3924 found_all = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3925 while (*e_cpt == ',' || *e_cpt == ' ')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3926 e_cpt++;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3927 if (*e_cpt == '.' && !curbuf->b_scanned)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3928 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3929 ins_buf = curbuf;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3930 first_match_pos = *ini;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3931 /* So that ^N can match word immediately after cursor */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3932 if (ctrl_x_mode == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3933 dec(&first_match_pos);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3934 last_match_pos = first_match_pos;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3935 type = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3936 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3937 else if (vim_strchr((char_u *)"buwU", *e_cpt) != NULL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3938 && (ins_buf = ins_compl_next_buf(ins_buf, *e_cpt)) != curbuf)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3939 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3940 /* Scan a buffer, but not the current one. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3941 if (ins_buf->b_ml.ml_mfp != NULL) /* loaded buffer */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3942 {
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3943 compl_started = TRUE;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3944 first_match_pos.col = last_match_pos.col = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3945 first_match_pos.lnum = ins_buf->b_ml.ml_line_count + 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3946 last_match_pos.lnum = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3947 type = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3948 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3949 else /* unloaded buffer, scan like dictionary */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3950 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3951 found_all = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3952 if (ins_buf->b_fname == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3953 continue;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3954 type = CTRL_X_DICTIONARY;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3955 dict = ins_buf->b_fname;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3956 dict_f = DICT_EXACT;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3957 }
274
8fa8d7964cf1 updated for version 7.0073
vimboss
parents: 237
diff changeset
3958 vim_snprintf((char *)IObuff, IOSIZE, _("Scanning: %s"),
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3959 ins_buf->b_fname == NULL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3960 ? buf_spname(ins_buf)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3961 : ins_buf->b_sfname == NULL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3962 ? (char *)ins_buf->b_fname
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3963 : (char *)ins_buf->b_sfname);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3964 msg_trunc_attr(IObuff, TRUE, hl_attr(HLF_R));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3965 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3966 else if (*e_cpt == NUL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3967 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3968 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3969 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3970 if (ctrl_x_mode == CTRL_X_WHOLE_LINE)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3971 type = -1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3972 else if (*e_cpt == 'k' || *e_cpt == 's')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3973 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3974 if (*e_cpt == 'k')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3975 type = CTRL_X_DICTIONARY;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3976 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3977 type = CTRL_X_THESAURUS;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3978 if (*++e_cpt != ',' && *e_cpt != NUL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3979 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3980 dict = e_cpt;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3981 dict_f = DICT_FIRST;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3982 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3983 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3984 #ifdef FEAT_FIND_ID
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3985 else if (*e_cpt == 'i')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3986 type = CTRL_X_PATH_PATTERNS;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3987 else if (*e_cpt == 'd')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3988 type = CTRL_X_PATH_DEFINES;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3989 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3990 else if (*e_cpt == ']' || *e_cpt == 't')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3991 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3992 type = CTRL_X_TAGS;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3993 sprintf((char*)IObuff, _("Scanning tags."));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3994 msg_trunc_attr(IObuff, TRUE, hl_attr(HLF_R));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3995 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3996 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3997 type = -1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3998
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3999 /* in any case e_cpt is advanced to the next entry */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4000 (void)copy_option_part(&e_cpt, IObuff, IOSIZE, ",");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4001
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4002 found_all = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4003 if (type == -1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4004 continue;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4005 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4006 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4007
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4008 switch (type)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4009 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4010 case -1:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4011 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4012 #ifdef FEAT_FIND_ID
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4013 case CTRL_X_PATH_PATTERNS:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4014 case CTRL_X_PATH_DEFINES:
659
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
4015 find_pattern_in_path(compl_pattern, compl_direction,
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4016 (int)STRLEN(compl_pattern), FALSE, FALSE,
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4017 (type == CTRL_X_PATH_DEFINES
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4018 && !(compl_cont_status & CONT_SOL))
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4019 ? FIND_DEFINE : FIND_ANY, 1L, ACTION_EXPAND,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4020 (linenr_T)1, (linenr_T)MAXLNUM);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4021 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4022 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4023
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4024 case CTRL_X_DICTIONARY:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4025 case CTRL_X_THESAURUS:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4026 ins_compl_dictionaries(
703
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
4027 dict != NULL ? dict
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4028 : (type == CTRL_X_THESAURUS
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4029 ? (*curbuf->b_p_tsr == NUL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4030 ? p_tsr
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4031 : curbuf->b_p_tsr)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4032 : (*curbuf->b_p_dict == NUL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4033 ? p_dict
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4034 : curbuf->b_p_dict)),
659
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
4035 compl_pattern,
703
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
4036 dict != NULL ? dict_f
2fae45239fb3 updated for version 7.0212
vimboss
parents: 697
diff changeset
4037 : 0, type == CTRL_X_THESAURUS);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4038 dict = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4039 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4040
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4041 case CTRL_X_TAGS:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4042 /* set p_ic according to p_ic, p_scs and pat for find_tags(). */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4043 save_p_ic = p_ic;
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4044 p_ic = ignorecase(compl_pattern);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4045
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4046 /* Find up to TAG_MANY matches. Avoids that an enourmous number
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4047 * of matches is found when compl_pattern is empty */
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4048 if (find_tags(compl_pattern, &num_matches, &matches,
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4049 TAG_REGEXP | TAG_NAMES | TAG_NOIC |
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4050 TAG_INS_COMP | (ctrl_x_mode ? TAG_VERBOSE : 0),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4051 TAG_MANY, curbuf->b_ffname) == OK && num_matches > 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4052 {
942
29bf49bad20d updated for version 7.0-068
vimboss
parents: 941
diff changeset
4053 ins_compl_add_matches(num_matches, matches, p_ic);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4054 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4055 p_ic = save_p_ic;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4056 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4057
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4058 case CTRL_X_FILES:
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4059 if (expand_wildcards(1, &compl_pattern, &num_matches, &matches,
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4060 EW_FILE|EW_DIR|EW_ADDSLASH|EW_SILENT) == OK)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4061 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4062
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4063 /* May change home directory back to "~". */
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4064 tilde_replace(compl_pattern, num_matches, matches);
681
9364d114ed8d updated for version 7.0204
vimboss
parents: 677
diff changeset
4065 ins_compl_add_matches(num_matches, matches,
9364d114ed8d updated for version 7.0204
vimboss
parents: 677
diff changeset
4066 #ifdef CASE_INSENSITIVE_FILENAME
9364d114ed8d updated for version 7.0204
vimboss
parents: 677
diff changeset
4067 TRUE
9364d114ed8d updated for version 7.0204
vimboss
parents: 677
diff changeset
4068 #else
9364d114ed8d updated for version 7.0204
vimboss
parents: 677
diff changeset
4069 FALSE
9364d114ed8d updated for version 7.0204
vimboss
parents: 677
diff changeset
4070 #endif
9364d114ed8d updated for version 7.0204
vimboss
parents: 677
diff changeset
4071 );
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4072 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4073 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4074
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4075 case CTRL_X_CMDLINE:
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4076 if (expand_cmdline(&compl_xp, compl_pattern,
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4077 (int)STRLEN(compl_pattern),
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4078 &num_matches, &matches) == EXPAND_OK)
681
9364d114ed8d updated for version 7.0204
vimboss
parents: 677
diff changeset
4079 ins_compl_add_matches(num_matches, matches, FALSE);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4080 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4081
12
bdeee1504ac1 updated for version 7.0004
vimboss
parents: 11
diff changeset
4082 #ifdef FEAT_COMPL_FUNC
bdeee1504ac1 updated for version 7.0004
vimboss
parents: 11
diff changeset
4083 case CTRL_X_FUNCTION:
523
a7ae7e043e43 updated for version 7.0146
vimboss
parents: 502
diff changeset
4084 case CTRL_X_OMNI:
659
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
4085 expand_by_function(type, compl_pattern);
12
bdeee1504ac1 updated for version 7.0004
vimboss
parents: 11
diff changeset
4086 break;
bdeee1504ac1 updated for version 7.0004
vimboss
parents: 11
diff changeset
4087 #endif
bdeee1504ac1 updated for version 7.0004
vimboss
parents: 11
diff changeset
4088
477
f8b75b8f1988 updated for version 7.0128
vimboss
parents: 474
diff changeset
4089 case CTRL_X_SPELL:
744
07f7b4a7755c updated for version 7.0222
vimboss
parents: 732
diff changeset
4090 #ifdef FEAT_SPELL
477
f8b75b8f1988 updated for version 7.0128
vimboss
parents: 474
diff changeset
4091 num_matches = expand_spelling(first_match_pos.lnum,
f8b75b8f1988 updated for version 7.0128
vimboss
parents: 474
diff changeset
4092 first_match_pos.col, compl_pattern, &matches);
f8b75b8f1988 updated for version 7.0128
vimboss
parents: 474
diff changeset
4093 if (num_matches > 0)
942
29bf49bad20d updated for version 7.0-068
vimboss
parents: 941
diff changeset
4094 ins_compl_add_matches(num_matches, matches, p_ic);
477
f8b75b8f1988 updated for version 7.0128
vimboss
parents: 474
diff changeset
4095 #endif
f8b75b8f1988 updated for version 7.0128
vimboss
parents: 474
diff changeset
4096 break;
f8b75b8f1988 updated for version 7.0128
vimboss
parents: 474
diff changeset
4097
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4098 default: /* normal ^P/^N and ^X^L */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4099 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4100 * If 'infercase' is set, don't use 'smartcase' here
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4101 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4102 save_p_scs = p_scs;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4103 if (ins_buf->b_p_inf)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4104 p_scs = FALSE;
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4105
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4106 /* buffers other than curbuf are scanned from the beginning or the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4107 * end but never from the middle, thus setting nowrapscan in this
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4108 * buffers is a good idea, on the other hand, we always set
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4109 * wrapscan for curbuf to avoid missing matches -- Acevedo,Webb */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4110 save_p_ws = p_ws;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4111 if (ins_buf != curbuf)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4112 p_ws = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4113 else if (*e_cpt == '.')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4114 p_ws = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4115 for (;;)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4116 {
464
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
4117 int flags = 0;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4118
1007
7d29124f77f5 updated for version 7.0-133
vimboss
parents: 1000
diff changeset
4119 ++msg_silent; /* Don't want messages for wrapscan. */
7d29124f77f5 updated for version 7.0-133
vimboss
parents: 1000
diff changeset
4120
540
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
4121 /* ctrl_x_mode == CTRL_X_WHOLE_LINE || word-wise search that
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
4122 * has added a word that was at the beginning of the line */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4123 if ( ctrl_x_mode == CTRL_X_WHOLE_LINE
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4124 || (compl_cont_status & CONT_SOL))
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4125 found_new_match = search_for_exact_line(ins_buf, pos,
659
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
4126 compl_direction, compl_pattern);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4127 else
659
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
4128 found_new_match = searchit(NULL, ins_buf, pos,
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
4129 compl_direction,
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4130 compl_pattern, 1L, SEARCH_KEEP + SEARCH_NFMSG,
1496
29c09fa57168 updated for version 7.1-211
vimboss
parents: 1473
diff changeset
4131 RE_LAST, (linenr_T)0, NULL);
1007
7d29124f77f5 updated for version 7.0-133
vimboss
parents: 1000
diff changeset
4132 --msg_silent;
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4133 if (!compl_started)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4134 {
667
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
4135 /* set "compl_started" even on fail */
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4136 compl_started = TRUE;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4137 first_match_pos = *pos;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4138 last_match_pos = *pos;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4139 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4140 else if (first_match_pos.lnum == last_match_pos.lnum
665
21ab9abf0f08 updated for version 7.0196
vimboss
parents: 661
diff changeset
4141 && first_match_pos.col == last_match_pos.col)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4142 found_new_match = FAIL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4143 if (found_new_match == FAIL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4144 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4145 if (ins_buf == curbuf)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4146 found_all = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4147 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4148 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4149
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4150 /* when ADDING, the text before the cursor matches, skip it */
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4151 if ( (compl_cont_status & CONT_ADDING) && ins_buf == curbuf
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4152 && ini->lnum == pos->lnum
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4153 && ini->col == pos->col)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4154 continue;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4155 ptr = ml_get_buf(ins_buf, pos->lnum, FALSE) + pos->col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4156 if (ctrl_x_mode == CTRL_X_WHOLE_LINE)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4157 {
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4158 if (compl_cont_status & CONT_ADDING)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4159 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4160 if (pos->lnum >= ins_buf->b_ml.ml_line_count)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4161 continue;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4162 ptr = ml_get_buf(ins_buf, pos->lnum + 1, FALSE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4163 if (!p_paste)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4164 ptr = skipwhite(ptr);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4165 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4166 len = (int)STRLEN(ptr);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4167 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4168 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4169 {
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4170 char_u *tmp_ptr = ptr;
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4171
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4172 if (compl_cont_status & CONT_ADDING)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4173 {
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4174 tmp_ptr += compl_length;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4175 /* Skip if already inside a word. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4176 if (vim_iswordp(tmp_ptr))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4177 continue;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4178 /* Find start of next word. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4179 tmp_ptr = find_word_start(tmp_ptr);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4180 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4181 /* Find end of this word. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4182 tmp_ptr = find_word_end(tmp_ptr);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4183 len = (int)(tmp_ptr - ptr);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4184
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4185 if ((compl_cont_status & CONT_ADDING)
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4186 && len == compl_length)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4187 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4188 if (pos->lnum < ins_buf->b_ml.ml_line_count)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4189 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4190 /* Try next line, if any. the new word will be
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4191 * "join" as if the normal command "J" was used.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4192 * IOSIZE is always greater than
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4193 * compl_length, so the next STRNCPY always
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4194 * works -- Acevedo */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4195 STRNCPY(IObuff, ptr, len);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4196 ptr = ml_get_buf(ins_buf, pos->lnum + 1, FALSE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4197 tmp_ptr = ptr = skipwhite(ptr);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4198 /* Find start of next word. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4199 tmp_ptr = find_word_start(tmp_ptr);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4200 /* Find end of next word. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4201 tmp_ptr = find_word_end(tmp_ptr);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4202 if (tmp_ptr > ptr)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4203 {
419
f713fc55bf7b updated for version 7.0109
vimboss
parents: 408
diff changeset
4204 if (*ptr != ')' && IObuff[len - 1] != TAB)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4205 {
419
f713fc55bf7b updated for version 7.0109
vimboss
parents: 408
diff changeset
4206 if (IObuff[len - 1] != ' ')
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4207 IObuff[len++] = ' ';
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4208 /* IObuf =~ "\k.* ", thus len >= 2 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4209 if (p_js
419
f713fc55bf7b updated for version 7.0109
vimboss
parents: 408
diff changeset
4210 && (IObuff[len - 2] == '.'
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4211 || (vim_strchr(p_cpo, CPO_JOINSP)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4212 == NULL
419
f713fc55bf7b updated for version 7.0109
vimboss
parents: 408
diff changeset
4213 && (IObuff[len - 2] == '?'
f713fc55bf7b updated for version 7.0109
vimboss
parents: 408
diff changeset
4214 || IObuff[len - 2] == '!'))))
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4215 IObuff[len++] = ' ';
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4216 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4217 /* copy as much as posible of the new word */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4218 if (tmp_ptr - ptr >= IOSIZE - len)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4219 tmp_ptr = ptr + IOSIZE - len - 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4220 STRNCPY(IObuff + len, ptr, tmp_ptr - ptr);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4221 len += (int)(tmp_ptr - ptr);
464
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
4222 flags |= CONT_S_IPOS;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4223 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4224 IObuff[len] = NUL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4225 ptr = IObuff;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4226 }
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4227 if (len == compl_length)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4228 continue;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4229 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4230 }
942
29bf49bad20d updated for version 7.0-068
vimboss
parents: 941
diff changeset
4231 if (ins_compl_add_infercase(ptr, len, p_ic,
540
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
4232 ins_buf == curbuf ? NULL : ins_buf->b_sfname,
659
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
4233 0, flags) != NOTDONE)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4234 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4235 found_new_match = OK;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4236 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4237 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4238 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4239 p_scs = save_p_scs;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4240 p_ws = save_p_ws;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4241 }
540
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
4242
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4243 /* check if compl_curr_match has changed, (e.g. other type of
1796
4589d1792c03 updated for version 7.2-094
vimboss
parents: 1782
diff changeset
4244 * expansion added something) */
540
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
4245 if (type != 0 && compl_curr_match != old_match)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4246 found_new_match = OK;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4247
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4248 /* break the loop for specialized modes (use 'complete' just for the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4249 * generic ctrl_x_mode == 0) or when we've found a new match */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4250 if ((ctrl_x_mode != 0 && ctrl_x_mode != CTRL_X_WHOLE_LINE)
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4251 || found_new_match != FAIL)
540
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
4252 {
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
4253 if (got_int)
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
4254 break;
665
21ab9abf0f08 updated for version 7.0196
vimboss
parents: 661
diff changeset
4255 /* Fill the popup menu as soon as possible. */
989
3f8cf4c668c3 updated for version 7.0-115
vimboss
parents: 987
diff changeset
4256 if (type != -1)
540
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
4257 ins_compl_check_keys(0);
665
21ab9abf0f08 updated for version 7.0196
vimboss
parents: 661
diff changeset
4258
540
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
4259 if ((ctrl_x_mode != 0 && ctrl_x_mode != CTRL_X_WHOLE_LINE)
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
4260 || compl_interrupted)
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
4261 break;
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
4262 compl_started = TRUE;
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
4263 }
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
4264 else
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
4265 {
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
4266 /* Mark a buffer scanned when it has been scanned completely */
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
4267 if (type == 0 || type == CTRL_X_PATH_PATTERNS)
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
4268 ins_buf->b_scanned = TRUE;
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
4269
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
4270 compl_started = FALSE;
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
4271 }
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4272 }
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4273 compl_started = TRUE;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4274
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4275 if ((ctrl_x_mode == 0 || ctrl_x_mode == CTRL_X_WHOLE_LINE)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4276 && *e_cpt == NUL) /* Got to end of 'complete' */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4277 found_new_match = FAIL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4278
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4279 i = -1; /* total of matches, unknown */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4280 if (found_new_match == FAIL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4281 || (ctrl_x_mode != 0 && ctrl_x_mode != CTRL_X_WHOLE_LINE))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4282 i = ins_compl_make_cyclic();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4283
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4284 /* If several matches were added (FORWARD) or the search failed and has
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4285 * just been made cyclic then we have to move compl_curr_match to the next
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4286 * or previous entry (if any) -- Acevedo */
724
a35dce0cabc5 updated for version 7.0220
vimboss
parents: 716
diff changeset
4287 compl_curr_match = compl_direction == FORWARD ? old_match->cp_next
a35dce0cabc5 updated for version 7.0220
vimboss
parents: 716
diff changeset
4288 : old_match->cp_prev;
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4289 if (compl_curr_match == NULL)
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4290 compl_curr_match = old_match;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4291 return i;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4292 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4293
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4294 /* Delete the old text being completed. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4295 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4296 ins_compl_delete()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4297 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4298 int i;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4299
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4300 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4301 * In insert mode: Delete the typed part.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4302 * In replace mode: Put the old characters back, if any.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4303 */
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4304 i = compl_col + (compl_cont_status & CONT_ADDING ? compl_length : 0);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4305 backspace_until_column(i);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4306 changed_cline_bef_curs();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4307 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4308
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4309 /* Insert the new text being completed. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4310 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4311 ins_compl_insert()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4312 {
1782
12cecc379574 updated for version 7.2-080
vimboss
parents: 1698
diff changeset
4313 ins_bytes(compl_shown_match->cp_str + ins_compl_len());
683
a39b8af64334 updated for version 7.0205
vimboss
parents: 681
diff changeset
4314 if (compl_shown_match->cp_flags & ORIGINAL_TEXT)
a39b8af64334 updated for version 7.0205
vimboss
parents: 681
diff changeset
4315 compl_used_match = FALSE;
a39b8af64334 updated for version 7.0205
vimboss
parents: 681
diff changeset
4316 else
a39b8af64334 updated for version 7.0205
vimboss
parents: 681
diff changeset
4317 compl_used_match = TRUE;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4318 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4319
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4320 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4321 * Fill in the next completion in the current direction.
464
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
4322 * If "allow_get_expansion" is TRUE, then we may call ins_compl_get_exp() to
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
4323 * get more completions. If it is FALSE, then we just do nothing when there
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
4324 * are no more completions in a given direction. The latter case is used when
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
4325 * we are still in the middle of finding completions, to allow browsing
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
4326 * through the ones found so far.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4327 * Return the total number of matches, or -1 if still unknown -- webb.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4328 *
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4329 * compl_curr_match is currently being used by ins_compl_get_exp(), so we use
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4330 * compl_shown_match here.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4331 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4332 * Note that this function may be called recursively once only. First with
464
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
4333 * "allow_get_expansion" TRUE, which calls ins_compl_get_exp(), which in turn
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
4334 * calls this function with "allow_get_expansion" FALSE.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4335 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4336 static int
665
21ab9abf0f08 updated for version 7.0196
vimboss
parents: 661
diff changeset
4337 ins_compl_next(allow_get_expansion, count, insert_match)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4338 int allow_get_expansion;
610
cd3689efd90a updated for version 7.0173
vimboss
parents: 603
diff changeset
4339 int count; /* repeat completion this many times; should
cd3689efd90a updated for version 7.0173
vimboss
parents: 603
diff changeset
4340 be at least 1 */
665
21ab9abf0f08 updated for version 7.0196
vimboss
parents: 661
diff changeset
4341 int insert_match; /* Insert the newly selected match */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4342 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4343 int num_matches = -1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4344 int i;
610
cd3689efd90a updated for version 7.0173
vimboss
parents: 603
diff changeset
4345 int todo = count;
657
b112ec5c73f0 updated for version 7.0193
vimboss
parents: 648
diff changeset
4346 compl_T *found_compl = NULL;
b112ec5c73f0 updated for version 7.0193
vimboss
parents: 648
diff changeset
4347 int found_end = FALSE;
836
5a7843c57316 updated for version 7.0e02
vimboss
parents: 835
diff changeset
4348 int advance;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4349
665
21ab9abf0f08 updated for version 7.0196
vimboss
parents: 661
diff changeset
4350 if (compl_leader != NULL
21ab9abf0f08 updated for version 7.0196
vimboss
parents: 661
diff changeset
4351 && (compl_shown_match->cp_flags & ORIGINAL_TEXT) == 0)
21ab9abf0f08 updated for version 7.0196
vimboss
parents: 661
diff changeset
4352 {
21ab9abf0f08 updated for version 7.0196
vimboss
parents: 661
diff changeset
4353 /* Set "compl_shown_match" to the actually shown match, it may differ
21ab9abf0f08 updated for version 7.0196
vimboss
parents: 661
diff changeset
4354 * when "compl_leader" is used to omit some of the matches. */
681
9364d114ed8d updated for version 7.0204
vimboss
parents: 677
diff changeset
4355 while (!ins_compl_equal(compl_shown_match,
835
8bebcabccc2c updated for version 7.0e01
vimboss
parents: 829
diff changeset
4356 compl_leader, (int)STRLEN(compl_leader))
665
21ab9abf0f08 updated for version 7.0196
vimboss
parents: 661
diff changeset
4357 && compl_shown_match->cp_next != NULL
21ab9abf0f08 updated for version 7.0196
vimboss
parents: 661
diff changeset
4358 && compl_shown_match->cp_next != compl_first_match)
21ab9abf0f08 updated for version 7.0196
vimboss
parents: 661
diff changeset
4359 compl_shown_match = compl_shown_match->cp_next;
887
9dc77520c6d3 updated for version 7.0-013
vimboss
parents: 874
diff changeset
4360
9dc77520c6d3 updated for version 7.0-013
vimboss
parents: 874
diff changeset
4361 /* If we didn't find it searching forward, and compl_shows_dir is
9dc77520c6d3 updated for version 7.0-013
vimboss
parents: 874
diff changeset
4362 * backward, find the last match. */
9dc77520c6d3 updated for version 7.0-013
vimboss
parents: 874
diff changeset
4363 if (compl_shows_dir == BACKWARD
9dc77520c6d3 updated for version 7.0-013
vimboss
parents: 874
diff changeset
4364 && !ins_compl_equal(compl_shown_match,
9dc77520c6d3 updated for version 7.0-013
vimboss
parents: 874
diff changeset
4365 compl_leader, (int)STRLEN(compl_leader))
9dc77520c6d3 updated for version 7.0-013
vimboss
parents: 874
diff changeset
4366 && (compl_shown_match->cp_next == NULL
9dc77520c6d3 updated for version 7.0-013
vimboss
parents: 874
diff changeset
4367 || compl_shown_match->cp_next == compl_first_match))
9dc77520c6d3 updated for version 7.0-013
vimboss
parents: 874
diff changeset
4368 {
9dc77520c6d3 updated for version 7.0-013
vimboss
parents: 874
diff changeset
4369 while (!ins_compl_equal(compl_shown_match,
9dc77520c6d3 updated for version 7.0-013
vimboss
parents: 874
diff changeset
4370 compl_leader, (int)STRLEN(compl_leader))
9dc77520c6d3 updated for version 7.0-013
vimboss
parents: 874
diff changeset
4371 && compl_shown_match->cp_prev != NULL
9dc77520c6d3 updated for version 7.0-013
vimboss
parents: 874
diff changeset
4372 && compl_shown_match->cp_prev != compl_first_match)
9dc77520c6d3 updated for version 7.0-013
vimboss
parents: 874
diff changeset
4373 compl_shown_match = compl_shown_match->cp_prev;
9dc77520c6d3 updated for version 7.0-013
vimboss
parents: 874
diff changeset
4374 }
665
21ab9abf0f08 updated for version 7.0196
vimboss
parents: 661
diff changeset
4375 }
21ab9abf0f08 updated for version 7.0196
vimboss
parents: 661
diff changeset
4376
21ab9abf0f08 updated for version 7.0196
vimboss
parents: 661
diff changeset
4377 if (allow_get_expansion && insert_match
874
4bac29d27e2f updated for version 7.0
vimboss
parents: 867
diff changeset
4378 && (!(compl_get_longest || compl_restarting) || compl_used_match))
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4379 /* Delete old text to be replaced */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4380 ins_compl_delete();
665
21ab9abf0f08 updated for version 7.0196
vimboss
parents: 661
diff changeset
4381
836
5a7843c57316 updated for version 7.0e02
vimboss
parents: 835
diff changeset
4382 /* When finding the longest common text we stick at the original text,
5a7843c57316 updated for version 7.0e02
vimboss
parents: 835
diff changeset
4383 * don't let CTRL-N or CTRL-P move to the first match. */
5a7843c57316 updated for version 7.0e02
vimboss
parents: 835
diff changeset
4384 advance = count != 1 || !allow_get_expansion || !compl_get_longest;
5a7843c57316 updated for version 7.0e02
vimboss
parents: 835
diff changeset
4385
874
4bac29d27e2f updated for version 7.0
vimboss
parents: 867
diff changeset
4386 /* When restarting the search don't insert the first match either. */
4bac29d27e2f updated for version 7.0
vimboss
parents: 867
diff changeset
4387 if (compl_restarting)
4bac29d27e2f updated for version 7.0
vimboss
parents: 867
diff changeset
4388 {
4bac29d27e2f updated for version 7.0
vimboss
parents: 867
diff changeset
4389 advance = FALSE;
4bac29d27e2f updated for version 7.0
vimboss
parents: 867
diff changeset
4390 compl_restarting = FALSE;
4bac29d27e2f updated for version 7.0
vimboss
parents: 867
diff changeset
4391 }
4bac29d27e2f updated for version 7.0
vimboss
parents: 867
diff changeset
4392
610
cd3689efd90a updated for version 7.0173
vimboss
parents: 603
diff changeset
4393 /* Repeat this for when <PageUp> or <PageDown> is typed. But don't wrap
cd3689efd90a updated for version 7.0173
vimboss
parents: 603
diff changeset
4394 * around. */
cd3689efd90a updated for version 7.0173
vimboss
parents: 603
diff changeset
4395 while (--todo >= 0)
cd3689efd90a updated for version 7.0173
vimboss
parents: 603
diff changeset
4396 {
cd3689efd90a updated for version 7.0173
vimboss
parents: 603
diff changeset
4397 if (compl_shows_dir == FORWARD && compl_shown_match->cp_next != NULL)
cd3689efd90a updated for version 7.0173
vimboss
parents: 603
diff changeset
4398 {
cd3689efd90a updated for version 7.0173
vimboss
parents: 603
diff changeset
4399 compl_shown_match = compl_shown_match->cp_next;
657
b112ec5c73f0 updated for version 7.0193
vimboss
parents: 648
diff changeset
4400 found_end = (compl_first_match != NULL
b112ec5c73f0 updated for version 7.0193
vimboss
parents: 648
diff changeset
4401 && (compl_shown_match->cp_next == compl_first_match
b112ec5c73f0 updated for version 7.0193
vimboss
parents: 648
diff changeset
4402 || compl_shown_match == compl_first_match));
610
cd3689efd90a updated for version 7.0173
vimboss
parents: 603
diff changeset
4403 }
cd3689efd90a updated for version 7.0173
vimboss
parents: 603
diff changeset
4404 else if (compl_shows_dir == BACKWARD
cd3689efd90a updated for version 7.0173
vimboss
parents: 603
diff changeset
4405 && compl_shown_match->cp_prev != NULL)
cd3689efd90a updated for version 7.0173
vimboss
parents: 603
diff changeset
4406 {
657
b112ec5c73f0 updated for version 7.0193
vimboss
parents: 648
diff changeset
4407 found_end = (compl_shown_match == compl_first_match);
610
cd3689efd90a updated for version 7.0173
vimboss
parents: 603
diff changeset
4408 compl_shown_match = compl_shown_match->cp_prev;
657
b112ec5c73f0 updated for version 7.0193
vimboss
parents: 648
diff changeset
4409 found_end |= (compl_shown_match == compl_first_match);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4410 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4411 else
610
cd3689efd90a updated for version 7.0173
vimboss
parents: 603
diff changeset
4412 {
909
073f98f45a44 updated for version 7.0-035
vimboss
parents: 908
diff changeset
4413 if (!allow_get_expansion)
073f98f45a44 updated for version 7.0-035
vimboss
parents: 908
diff changeset
4414 {
073f98f45a44 updated for version 7.0-035
vimboss
parents: 908
diff changeset
4415 if (advance)
073f98f45a44 updated for version 7.0-035
vimboss
parents: 908
diff changeset
4416 {
073f98f45a44 updated for version 7.0-035
vimboss
parents: 908
diff changeset
4417 if (compl_shows_dir == BACKWARD)
073f98f45a44 updated for version 7.0-035
vimboss
parents: 908
diff changeset
4418 compl_pending -= todo + 1;
073f98f45a44 updated for version 7.0-035
vimboss
parents: 908
diff changeset
4419 else
073f98f45a44 updated for version 7.0-035
vimboss
parents: 908
diff changeset
4420 compl_pending += todo + 1;
073f98f45a44 updated for version 7.0-035
vimboss
parents: 908
diff changeset
4421 }
073f98f45a44 updated for version 7.0-035
vimboss
parents: 908
diff changeset
4422 return -1;
073f98f45a44 updated for version 7.0-035
vimboss
parents: 908
diff changeset
4423 }
073f98f45a44 updated for version 7.0-035
vimboss
parents: 908
diff changeset
4424
836
5a7843c57316 updated for version 7.0e02
vimboss
parents: 835
diff changeset
4425 if (advance)
5a7843c57316 updated for version 7.0e02
vimboss
parents: 835
diff changeset
4426 {
5a7843c57316 updated for version 7.0e02
vimboss
parents: 835
diff changeset
4427 if (compl_shows_dir == BACKWARD)
5a7843c57316 updated for version 7.0e02
vimboss
parents: 835
diff changeset
4428 --compl_pending;
5a7843c57316 updated for version 7.0e02
vimboss
parents: 835
diff changeset
4429 else
5a7843c57316 updated for version 7.0e02
vimboss
parents: 835
diff changeset
4430 ++compl_pending;
5a7843c57316 updated for version 7.0e02
vimboss
parents: 835
diff changeset
4431 }
657
b112ec5c73f0 updated for version 7.0193
vimboss
parents: 648
diff changeset
4432
874
4bac29d27e2f updated for version 7.0
vimboss
parents: 867
diff changeset
4433 /* Find matches. */
659
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
4434 num_matches = ins_compl_get_exp(&compl_startpos);
909
073f98f45a44 updated for version 7.0-035
vimboss
parents: 908
diff changeset
4435
073f98f45a44 updated for version 7.0-035
vimboss
parents: 908
diff changeset
4436 /* handle any pending completions */
073f98f45a44 updated for version 7.0-035
vimboss
parents: 908
diff changeset
4437 while (compl_pending != 0 && compl_direction == compl_shows_dir
836
5a7843c57316 updated for version 7.0e02
vimboss
parents: 835
diff changeset
4438 && advance)
909
073f98f45a44 updated for version 7.0-035
vimboss
parents: 908
diff changeset
4439 {
073f98f45a44 updated for version 7.0-035
vimboss
parents: 908
diff changeset
4440 if (compl_pending > 0 && compl_shown_match->cp_next != NULL)
073f98f45a44 updated for version 7.0-035
vimboss
parents: 908
diff changeset
4441 {
073f98f45a44 updated for version 7.0-035
vimboss
parents: 908
diff changeset
4442 compl_shown_match = compl_shown_match->cp_next;
073f98f45a44 updated for version 7.0-035
vimboss
parents: 908
diff changeset
4443 --compl_pending;
073f98f45a44 updated for version 7.0-035
vimboss
parents: 908
diff changeset
4444 }
073f98f45a44 updated for version 7.0-035
vimboss
parents: 908
diff changeset
4445 if (compl_pending < 0 && compl_shown_match->cp_prev != NULL)
073f98f45a44 updated for version 7.0-035
vimboss
parents: 908
diff changeset
4446 {
073f98f45a44 updated for version 7.0-035
vimboss
parents: 908
diff changeset
4447 compl_shown_match = compl_shown_match->cp_prev;
073f98f45a44 updated for version 7.0-035
vimboss
parents: 908
diff changeset
4448 ++compl_pending;
073f98f45a44 updated for version 7.0-035
vimboss
parents: 908
diff changeset
4449 }
073f98f45a44 updated for version 7.0-035
vimboss
parents: 908
diff changeset
4450 else
073f98f45a44 updated for version 7.0-035
vimboss
parents: 908
diff changeset
4451 break;
073f98f45a44 updated for version 7.0-035
vimboss
parents: 908
diff changeset
4452 }
657
b112ec5c73f0 updated for version 7.0193
vimboss
parents: 648
diff changeset
4453 found_end = FALSE;
b112ec5c73f0 updated for version 7.0193
vimboss
parents: 648
diff changeset
4454 }
b112ec5c73f0 updated for version 7.0193
vimboss
parents: 648
diff changeset
4455 if ((compl_shown_match->cp_flags & ORIGINAL_TEXT) == 0
b112ec5c73f0 updated for version 7.0193
vimboss
parents: 648
diff changeset
4456 && compl_leader != NULL
681
9364d114ed8d updated for version 7.0204
vimboss
parents: 677
diff changeset
4457 && !ins_compl_equal(compl_shown_match,
835
8bebcabccc2c updated for version 7.0e01
vimboss
parents: 829
diff changeset
4458 compl_leader, (int)STRLEN(compl_leader)))
657
b112ec5c73f0 updated for version 7.0193
vimboss
parents: 648
diff changeset
4459 ++todo;
b112ec5c73f0 updated for version 7.0193
vimboss
parents: 648
diff changeset
4460 else
b112ec5c73f0 updated for version 7.0193
vimboss
parents: 648
diff changeset
4461 /* Remember a matching item. */
b112ec5c73f0 updated for version 7.0193
vimboss
parents: 648
diff changeset
4462 found_compl = compl_shown_match;
b112ec5c73f0 updated for version 7.0193
vimboss
parents: 648
diff changeset
4463
b112ec5c73f0 updated for version 7.0193
vimboss
parents: 648
diff changeset
4464 /* Stop at the end of the list when we found a usable match. */
b112ec5c73f0 updated for version 7.0193
vimboss
parents: 648
diff changeset
4465 if (found_end)
b112ec5c73f0 updated for version 7.0193
vimboss
parents: 648
diff changeset
4466 {
b112ec5c73f0 updated for version 7.0193
vimboss
parents: 648
diff changeset
4467 if (found_compl != NULL)
610
cd3689efd90a updated for version 7.0173
vimboss
parents: 603
diff changeset
4468 {
657
b112ec5c73f0 updated for version 7.0193
vimboss
parents: 648
diff changeset
4469 compl_shown_match = found_compl;
b112ec5c73f0 updated for version 7.0193
vimboss
parents: 648
diff changeset
4470 break;
610
cd3689efd90a updated for version 7.0173
vimboss
parents: 603
diff changeset
4471 }
657
b112ec5c73f0 updated for version 7.0193
vimboss
parents: 648
diff changeset
4472 todo = 1; /* use first usable match after wrapping around */
610
cd3689efd90a updated for version 7.0173
vimboss
parents: 603
diff changeset
4473 }
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4474 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4475
665
21ab9abf0f08 updated for version 7.0196
vimboss
parents: 661
diff changeset
4476 /* Insert the text of the new completion, or the compl_leader. */
21ab9abf0f08 updated for version 7.0196
vimboss
parents: 661
diff changeset
4477 if (insert_match)
21ab9abf0f08 updated for version 7.0196
vimboss
parents: 661
diff changeset
4478 {
21ab9abf0f08 updated for version 7.0196
vimboss
parents: 661
diff changeset
4479 if (!compl_get_longest || compl_used_match)
21ab9abf0f08 updated for version 7.0196
vimboss
parents: 661
diff changeset
4480 ins_compl_insert();
21ab9abf0f08 updated for version 7.0196
vimboss
parents: 661
diff changeset
4481 else
1782
12cecc379574 updated for version 7.2-080
vimboss
parents: 1698
diff changeset
4482 ins_bytes(compl_leader + ins_compl_len());
665
21ab9abf0f08 updated for version 7.0196
vimboss
parents: 661
diff changeset
4483 }
21ab9abf0f08 updated for version 7.0196
vimboss
parents: 661
diff changeset
4484 else
21ab9abf0f08 updated for version 7.0196
vimboss
parents: 661
diff changeset
4485 compl_used_match = FALSE;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4486
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4487 if (!allow_get_expansion)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4488 {
540
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
4489 /* may undisplay the popup menu first */
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
4490 ins_compl_upd_pum();
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
4491
665
21ab9abf0f08 updated for version 7.0196
vimboss
parents: 661
diff changeset
4492 /* redraw to show the user what was inserted */
21ab9abf0f08 updated for version 7.0196
vimboss
parents: 661
diff changeset
4493 update_screen(0);
21ab9abf0f08 updated for version 7.0196
vimboss
parents: 661
diff changeset
4494
540
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
4495 /* display the updated popup menu */
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
4496 ins_compl_show_pum();
864
bc620d6bdf06 updated for version 7.0g03
vimboss
parents: 857
diff changeset
4497 #ifdef FEAT_GUI
bc620d6bdf06 updated for version 7.0g03
vimboss
parents: 857
diff changeset
4498 if (gui.in_use)
bc620d6bdf06 updated for version 7.0g03
vimboss
parents: 857
diff changeset
4499 {
bc620d6bdf06 updated for version 7.0g03
vimboss
parents: 857
diff changeset
4500 /* Show the cursor after the match, not after the redrawn text. */
bc620d6bdf06 updated for version 7.0g03
vimboss
parents: 857
diff changeset
4501 setcursor();
bc620d6bdf06 updated for version 7.0g03
vimboss
parents: 857
diff changeset
4502 out_flush();
bc620d6bdf06 updated for version 7.0g03
vimboss
parents: 857
diff changeset
4503 gui_update_cursor(FALSE, FALSE);
bc620d6bdf06 updated for version 7.0g03
vimboss
parents: 857
diff changeset
4504 }
bc620d6bdf06 updated for version 7.0g03
vimboss
parents: 857
diff changeset
4505 #endif
540
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
4506
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4507 /* Delete old text to be replaced, since we're still searching and
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4508 * don't want to match ourselves! */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4509 ins_compl_delete();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4510 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4511
825
6675076019ae updated for version 7.0d
vimboss
parents: 819
diff changeset
4512 /* Enter will select a match when the match wasn't inserted and the popup
1219
aea597af5b4e updated for version 7.1b
vimboss
parents: 1159
diff changeset
4513 * menu is visible. */
825
6675076019ae updated for version 7.0d
vimboss
parents: 819
diff changeset
4514 compl_enter_selects = !insert_match && compl_match_array != NULL;
6675076019ae updated for version 7.0d
vimboss
parents: 819
diff changeset
4515
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4516 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4517 * Show the file name for the match (if any)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4518 * Truncate the file name to avoid a wait for return.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4519 */
464
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
4520 if (compl_shown_match->cp_fname != NULL)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4521 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4522 STRCPY(IObuff, "match in file ");
464
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
4523 i = (vim_strsize(compl_shown_match->cp_fname) + 16) - sc_col;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4524 if (i <= 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4525 i = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4526 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4527 STRCAT(IObuff, "<");
464
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
4528 STRCAT(IObuff, compl_shown_match->cp_fname + i);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4529 msg(IObuff);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4530 redraw_cmdline = FALSE; /* don't overwrite! */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4531 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4532
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4533 return num_matches;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4534 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4535
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4536 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4537 * Call this while finding completions, to check whether the user has hit a key
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4538 * that should change the currently displayed completion, or exit completion
716
8ae24f338cab updated for version 7.0217
vimboss
parents: 714
diff changeset
4539 * mode. Also, when compl_pending is not zero, show a completion as soon as
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4540 * possible. -- webb
464
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
4541 * "frequency" specifies out of how many calls we actually check.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4542 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4543 void
464
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
4544 ins_compl_check_keys(frequency)
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
4545 int frequency;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4546 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4547 static int count = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4548
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4549 int c;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4550
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4551 /* Don't check when reading keys from a script. That would break the test
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4552 * scripts */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4553 if (using_script())
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4554 return;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4555
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4556 /* Only do this at regular intervals */
464
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
4557 if (++count < frequency)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4558 return;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4559 count = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4560
909
073f98f45a44 updated for version 7.0-035
vimboss
parents: 908
diff changeset
4561 /* Check for a typed key. Do use mappings, otherwise vim_is_ctrl_x_key()
073f98f45a44 updated for version 7.0-035
vimboss
parents: 908
diff changeset
4562 * can't do its work correctly. */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4563 c = vpeekc_any();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4564 if (c != NUL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4565 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4566 if (vim_is_ctrl_x_key(c) && c != Ctrl_X && c != Ctrl_R)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4567 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4568 c = safe_vgetc(); /* Eat the character */
610
cd3689efd90a updated for version 7.0173
vimboss
parents: 603
diff changeset
4569 compl_shows_dir = ins_compl_key2dir(c);
665
21ab9abf0f08 updated for version 7.0196
vimboss
parents: 661
diff changeset
4570 (void)ins_compl_next(FALSE, ins_compl_key2count(c),
21ab9abf0f08 updated for version 7.0196
vimboss
parents: 661
diff changeset
4571 c != K_UP && c != K_DOWN);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4572 }
909
073f98f45a44 updated for version 7.0-035
vimboss
parents: 908
diff changeset
4573 else
073f98f45a44 updated for version 7.0-035
vimboss
parents: 908
diff changeset
4574 {
073f98f45a44 updated for version 7.0-035
vimboss
parents: 908
diff changeset
4575 /* Need to get the character to have KeyTyped set. We'll put it
1526
f79bb0320025 updated for version 7.1-241
vimboss
parents: 1516
diff changeset
4576 * back with vungetc() below. But skip K_IGNORE. */
909
073f98f45a44 updated for version 7.0-035
vimboss
parents: 908
diff changeset
4577 c = safe_vgetc();
1526
f79bb0320025 updated for version 7.1-241
vimboss
parents: 1516
diff changeset
4578 if (c != K_IGNORE)
f79bb0320025 updated for version 7.1-241
vimboss
parents: 1516
diff changeset
4579 {
f79bb0320025 updated for version 7.1-241
vimboss
parents: 1516
diff changeset
4580 /* Don't interrupt completion when the character wasn't typed,
f79bb0320025 updated for version 7.1-241
vimboss
parents: 1516
diff changeset
4581 * e.g., when doing @q to replay keys. */
f79bb0320025 updated for version 7.1-241
vimboss
parents: 1516
diff changeset
4582 if (c != Ctrl_R && KeyTyped)
f79bb0320025 updated for version 7.1-241
vimboss
parents: 1516
diff changeset
4583 compl_interrupted = TRUE;
f79bb0320025 updated for version 7.1-241
vimboss
parents: 1516
diff changeset
4584
f79bb0320025 updated for version 7.1-241
vimboss
parents: 1516
diff changeset
4585 vungetc(c);
f79bb0320025 updated for version 7.1-241
vimboss
parents: 1516
diff changeset
4586 }
909
073f98f45a44 updated for version 7.0-035
vimboss
parents: 908
diff changeset
4587 }
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4588 }
716
8ae24f338cab updated for version 7.0217
vimboss
parents: 714
diff changeset
4589 if (compl_pending != 0 && !got_int)
909
073f98f45a44 updated for version 7.0-035
vimboss
parents: 908
diff changeset
4590 {
073f98f45a44 updated for version 7.0-035
vimboss
parents: 908
diff changeset
4591 int todo = compl_pending > 0 ? compl_pending : -compl_pending;
073f98f45a44 updated for version 7.0-035
vimboss
parents: 908
diff changeset
4592
073f98f45a44 updated for version 7.0-035
vimboss
parents: 908
diff changeset
4593 compl_pending = 0;
073f98f45a44 updated for version 7.0-035
vimboss
parents: 908
diff changeset
4594 (void)ins_compl_next(FALSE, todo, TRUE);
073f98f45a44 updated for version 7.0-035
vimboss
parents: 908
diff changeset
4595 }
610
cd3689efd90a updated for version 7.0173
vimboss
parents: 603
diff changeset
4596 }
cd3689efd90a updated for version 7.0173
vimboss
parents: 603
diff changeset
4597
cd3689efd90a updated for version 7.0173
vimboss
parents: 603
diff changeset
4598 /*
cd3689efd90a updated for version 7.0173
vimboss
parents: 603
diff changeset
4599 * Decide the direction of Insert mode complete from the key typed.
cd3689efd90a updated for version 7.0173
vimboss
parents: 603
diff changeset
4600 * Returns BACKWARD or FORWARD.
cd3689efd90a updated for version 7.0173
vimboss
parents: 603
diff changeset
4601 */
cd3689efd90a updated for version 7.0173
vimboss
parents: 603
diff changeset
4602 static int
cd3689efd90a updated for version 7.0173
vimboss
parents: 603
diff changeset
4603 ins_compl_key2dir(c)
cd3689efd90a updated for version 7.0173
vimboss
parents: 603
diff changeset
4604 int c;
cd3689efd90a updated for version 7.0173
vimboss
parents: 603
diff changeset
4605 {
665
21ab9abf0f08 updated for version 7.0196
vimboss
parents: 661
diff changeset
4606 if (c == Ctrl_P || c == Ctrl_L
21ab9abf0f08 updated for version 7.0196
vimboss
parents: 661
diff changeset
4607 || (pum_visible() && (c == K_PAGEUP || c == K_KPAGEUP
21ab9abf0f08 updated for version 7.0196
vimboss
parents: 661
diff changeset
4608 || c == K_S_UP || c == K_UP)))
610
cd3689efd90a updated for version 7.0173
vimboss
parents: 603
diff changeset
4609 return BACKWARD;
cd3689efd90a updated for version 7.0173
vimboss
parents: 603
diff changeset
4610 return FORWARD;
cd3689efd90a updated for version 7.0173
vimboss
parents: 603
diff changeset
4611 }
cd3689efd90a updated for version 7.0173
vimboss
parents: 603
diff changeset
4612
cd3689efd90a updated for version 7.0173
vimboss
parents: 603
diff changeset
4613 /*
644
e4fa26ce8769 updated for version 7.0187
vimboss
parents: 634
diff changeset
4614 * Return TRUE for keys that are used for completion only when the popup menu
e4fa26ce8769 updated for version 7.0187
vimboss
parents: 634
diff changeset
4615 * is visible.
e4fa26ce8769 updated for version 7.0187
vimboss
parents: 634
diff changeset
4616 */
e4fa26ce8769 updated for version 7.0187
vimboss
parents: 634
diff changeset
4617 static int
e4fa26ce8769 updated for version 7.0187
vimboss
parents: 634
diff changeset
4618 ins_compl_pum_key(c)
e4fa26ce8769 updated for version 7.0187
vimboss
parents: 634
diff changeset
4619 int c;
e4fa26ce8769 updated for version 7.0187
vimboss
parents: 634
diff changeset
4620 {
e4fa26ce8769 updated for version 7.0187
vimboss
parents: 634
diff changeset
4621 return pum_visible() && (c == K_PAGEUP || c == K_KPAGEUP || c == K_S_UP
665
21ab9abf0f08 updated for version 7.0196
vimboss
parents: 661
diff changeset
4622 || c == K_PAGEDOWN || c == K_KPAGEDOWN || c == K_S_DOWN
21ab9abf0f08 updated for version 7.0196
vimboss
parents: 661
diff changeset
4623 || c == K_UP || c == K_DOWN);
644
e4fa26ce8769 updated for version 7.0187
vimboss
parents: 634
diff changeset
4624 }
e4fa26ce8769 updated for version 7.0187
vimboss
parents: 634
diff changeset
4625
e4fa26ce8769 updated for version 7.0187
vimboss
parents: 634
diff changeset
4626 /*
610
cd3689efd90a updated for version 7.0173
vimboss
parents: 603
diff changeset
4627 * Decide the number of completions to move forward.
cd3689efd90a updated for version 7.0173
vimboss
parents: 603
diff changeset
4628 * Returns 1 for most keys, height of the popup menu for page-up/down keys.
cd3689efd90a updated for version 7.0173
vimboss
parents: 603
diff changeset
4629 */
cd3689efd90a updated for version 7.0173
vimboss
parents: 603
diff changeset
4630 static int
cd3689efd90a updated for version 7.0173
vimboss
parents: 603
diff changeset
4631 ins_compl_key2count(c)
cd3689efd90a updated for version 7.0173
vimboss
parents: 603
diff changeset
4632 int c;
cd3689efd90a updated for version 7.0173
vimboss
parents: 603
diff changeset
4633 {
cd3689efd90a updated for version 7.0173
vimboss
parents: 603
diff changeset
4634 int h;
cd3689efd90a updated for version 7.0173
vimboss
parents: 603
diff changeset
4635
665
21ab9abf0f08 updated for version 7.0196
vimboss
parents: 661
diff changeset
4636 if (ins_compl_pum_key(c) && c != K_UP && c != K_DOWN)
610
cd3689efd90a updated for version 7.0173
vimboss
parents: 603
diff changeset
4637 {
cd3689efd90a updated for version 7.0173
vimboss
parents: 603
diff changeset
4638 h = pum_get_height();
cd3689efd90a updated for version 7.0173
vimboss
parents: 603
diff changeset
4639 if (h > 3)
cd3689efd90a updated for version 7.0173
vimboss
parents: 603
diff changeset
4640 h -= 2; /* keep some context */
cd3689efd90a updated for version 7.0173
vimboss
parents: 603
diff changeset
4641 return h;
cd3689efd90a updated for version 7.0173
vimboss
parents: 603
diff changeset
4642 }
cd3689efd90a updated for version 7.0173
vimboss
parents: 603
diff changeset
4643 return 1;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4644 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4645
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4646 /*
681
9364d114ed8d updated for version 7.0204
vimboss
parents: 677
diff changeset
4647 * Return TRUE if completion with "c" should insert the match, FALSE if only
9364d114ed8d updated for version 7.0204
vimboss
parents: 677
diff changeset
4648 * to change the currently selected completion.
9364d114ed8d updated for version 7.0204
vimboss
parents: 677
diff changeset
4649 */
9364d114ed8d updated for version 7.0204
vimboss
parents: 677
diff changeset
4650 static int
9364d114ed8d updated for version 7.0204
vimboss
parents: 677
diff changeset
4651 ins_compl_use_match(c)
9364d114ed8d updated for version 7.0204
vimboss
parents: 677
diff changeset
4652 int c;
9364d114ed8d updated for version 7.0204
vimboss
parents: 677
diff changeset
4653 {
9364d114ed8d updated for version 7.0204
vimboss
parents: 677
diff changeset
4654 switch (c)
9364d114ed8d updated for version 7.0204
vimboss
parents: 677
diff changeset
4655 {
9364d114ed8d updated for version 7.0204
vimboss
parents: 677
diff changeset
4656 case K_UP:
9364d114ed8d updated for version 7.0204
vimboss
parents: 677
diff changeset
4657 case K_DOWN:
9364d114ed8d updated for version 7.0204
vimboss
parents: 677
diff changeset
4658 case K_PAGEDOWN:
9364d114ed8d updated for version 7.0204
vimboss
parents: 677
diff changeset
4659 case K_KPAGEDOWN:
9364d114ed8d updated for version 7.0204
vimboss
parents: 677
diff changeset
4660 case K_S_DOWN:
9364d114ed8d updated for version 7.0204
vimboss
parents: 677
diff changeset
4661 case K_PAGEUP:
9364d114ed8d updated for version 7.0204
vimboss
parents: 677
diff changeset
4662 case K_KPAGEUP:
9364d114ed8d updated for version 7.0204
vimboss
parents: 677
diff changeset
4663 case K_S_UP:
9364d114ed8d updated for version 7.0204
vimboss
parents: 677
diff changeset
4664 return FALSE;
9364d114ed8d updated for version 7.0204
vimboss
parents: 677
diff changeset
4665 }
9364d114ed8d updated for version 7.0204
vimboss
parents: 677
diff changeset
4666 return TRUE;
9364d114ed8d updated for version 7.0204
vimboss
parents: 677
diff changeset
4667 }
9364d114ed8d updated for version 7.0204
vimboss
parents: 677
diff changeset
4668
9364d114ed8d updated for version 7.0204
vimboss
parents: 677
diff changeset
4669 /*
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4670 * Do Insert mode completion.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4671 * Called when character "c" was typed, which has a meaning for completion.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4672 * Returns OK if completion was done, FAIL if something failed (out of mem).
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4673 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4674 static int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4675 ins_complete(c)
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4676 int c;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4677 {
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4678 char_u *line;
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4679 int startcol = 0; /* column where searched text starts */
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4680 colnr_T curs_col; /* cursor column */
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4681 int n;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4682
610
cd3689efd90a updated for version 7.0173
vimboss
parents: 603
diff changeset
4683 compl_direction = ins_compl_key2dir(c);
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4684 if (!compl_started)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4685 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4686 /* First time we hit ^N or ^P (in a row, I mean) */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4687
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4688 did_ai = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4689 #ifdef FEAT_SMARTINDENT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4690 did_si = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4691 can_si = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4692 can_si_back = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4693 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4694 if (stop_arrow() == FAIL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4695 return FAIL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4696
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4697 line = ml_get(curwin->w_cursor.lnum);
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4698 curs_col = curwin->w_cursor.col;
716
8ae24f338cab updated for version 7.0217
vimboss
parents: 714
diff changeset
4699 compl_pending = 0;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4700
1430
342cf2a9f5cc updated for version 7.1-145
vimboss
parents: 1389
diff changeset
4701 /* If this same ctrl_x_mode has been interrupted use the text from
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4702 * "compl_startpos" to the cursor as a pattern to add a new word
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4703 * instead of expand the one before the cursor, in word-wise if
1430
342cf2a9f5cc updated for version 7.1-145
vimboss
parents: 1389
diff changeset
4704 * "compl_startpos" is not in the same line as the cursor then fix it
342cf2a9f5cc updated for version 7.1-145
vimboss
parents: 1389
diff changeset
4705 * (the line has been split because it was longer than 'tw'). if SOL
342cf2a9f5cc updated for version 7.1-145
vimboss
parents: 1389
diff changeset
4706 * is set then skip the previous pattern, a word at the beginning of
342cf2a9f5cc updated for version 7.1-145
vimboss
parents: 1389
diff changeset
4707 * the line has been inserted, we'll look for that -- Acevedo. */
665
21ab9abf0f08 updated for version 7.0196
vimboss
parents: 661
diff changeset
4708 if ((compl_cont_status & CONT_INTRPT) == CONT_INTRPT
21ab9abf0f08 updated for version 7.0196
vimboss
parents: 661
diff changeset
4709 && compl_cont_mode == ctrl_x_mode)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4710 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4711 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4712 * it is a continued search
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4713 */
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4714 compl_cont_status &= ~CONT_INTRPT; /* remove INTRPT */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4715 if (ctrl_x_mode == 0 || ctrl_x_mode == CTRL_X_PATH_PATTERNS
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4716 || ctrl_x_mode == CTRL_X_PATH_DEFINES)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4717 {
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4718 if (compl_startpos.lnum != curwin->w_cursor.lnum)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4719 {
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4720 /* line (probably) wrapped, set compl_startpos to the
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4721 * first non_blank in the line, if it is not a wordchar
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4722 * include it to get a better pattern, but then we don't
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4723 * want the "\\<" prefix, check it bellow */
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4724 compl_col = (colnr_T)(skipwhite(line) - line);
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4725 compl_startpos.col = compl_col;
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4726 compl_startpos.lnum = curwin->w_cursor.lnum;
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4727 compl_cont_status &= ~CONT_SOL; /* clear SOL if present */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4728 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4729 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4730 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4731 /* S_IPOS was set when we inserted a word that was at the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4732 * beginning of the line, which means that we'll go to SOL
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4733 * mode but first we need to redefine compl_startpos */
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4734 if (compl_cont_status & CONT_S_IPOS)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4735 {
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4736 compl_cont_status |= CONT_SOL;
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4737 compl_startpos.col = (colnr_T)(skipwhite(
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4738 line + compl_length
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4739 + compl_startpos.col) - line);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4740 }
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4741 compl_col = compl_startpos.col;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4742 }
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4743 compl_length = curwin->w_cursor.col - (int)compl_col;
502
52e76e2b5b65 updated for version 7.0140
vimboss
parents: 499
diff changeset
4744 /* IObuff is used to add a "word from the next line" would we
1796
4589d1792c03 updated for version 7.2-094
vimboss
parents: 1782
diff changeset
4745 * have enough space? just being paranoid */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4746 #define MIN_SPACE 75
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4747 if (compl_length > (IOSIZE - MIN_SPACE))
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4748 {
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4749 compl_cont_status &= ~CONT_SOL;
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4750 compl_length = (IOSIZE - MIN_SPACE);
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4751 compl_col = curwin->w_cursor.col - compl_length;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4752 }
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4753 compl_cont_status |= CONT_ADDING | CONT_N_ADDS;
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4754 if (compl_length < 1)
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4755 compl_cont_status &= CONT_LOCAL;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4756 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4757 else if (ctrl_x_mode == CTRL_X_WHOLE_LINE)
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4758 compl_cont_status = CONT_ADDING | CONT_N_ADDS;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4759 else
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4760 compl_cont_status = 0;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4761 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4762 else
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4763 compl_cont_status &= CONT_LOCAL;
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4764
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4765 if (!(compl_cont_status & CONT_ADDING)) /* normal expansion */
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4766 {
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4767 compl_cont_mode = ctrl_x_mode;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4768 if (ctrl_x_mode != 0) /* Remove LOCAL if ctrl_x_mode != 0 */
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4769 compl_cont_status = 0;
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4770 compl_cont_status |= CONT_N_ADDS;
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4771 compl_startpos = curwin->w_cursor;
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4772 startcol = (int)curs_col;
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4773 compl_col = 0;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4774 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4775
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4776 /* Work out completion pattern and original text -- webb */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4777 if (ctrl_x_mode == 0 || (ctrl_x_mode & CTRL_X_WANT_IDENT))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4778 {
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4779 if ((compl_cont_status & CONT_SOL)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4780 || ctrl_x_mode == CTRL_X_PATH_DEFINES)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4781 {
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4782 if (!(compl_cont_status & CONT_ADDING))
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4783 {
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4784 while (--startcol >= 0 && vim_isIDc(line[startcol]))
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4785 ;
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4786 compl_col += ++startcol;
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4787 compl_length = curs_col - startcol;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4788 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4789 if (p_ic)
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4790 compl_pattern = str_foldcase(line + compl_col,
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4791 compl_length, NULL, 0);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4792 else
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4793 compl_pattern = vim_strnsave(line + compl_col,
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4794 compl_length);
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4795 if (compl_pattern == NULL)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4796 return FAIL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4797 }
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4798 else if (compl_cont_status & CONT_ADDING)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4799 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4800 char_u *prefix = (char_u *)"\\<";
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4801
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4802 /* we need 3 extra chars, 1 for the NUL and
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4803 * 2 >= strlen(prefix) -- Acevedo */
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4804 compl_pattern = alloc(quote_meta(NULL, line + compl_col,
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4805 compl_length) + 3);
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4806 if (compl_pattern == NULL)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4807 return FAIL;
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4808 if (!vim_iswordp(line + compl_col)
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4809 || (compl_col > 0
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4810 && (
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4811 #ifdef FEAT_MBYTE
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4812 vim_iswordp(mb_prevptr(line, line + compl_col))
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4813 #else
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4814 vim_iswordc(line[compl_col - 1])
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4815 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4816 )))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4817 prefix = (char_u *)"";
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4818 STRCPY((char *)compl_pattern, prefix);
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4819 (void)quote_meta(compl_pattern + STRLEN(prefix),
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4820 line + compl_col, compl_length);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4821 }
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4822 else if (--startcol < 0 ||
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4823 #ifdef FEAT_MBYTE
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4824 !vim_iswordp(mb_prevptr(line, line + startcol + 1))
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4825 #else
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4826 !vim_iswordc(line[startcol])
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4827 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4828 )
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4829 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4830 /* Match any word of at least two chars */
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4831 compl_pattern = vim_strsave((char_u *)"\\<\\k\\k");
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4832 if (compl_pattern == NULL)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4833 return FAIL;
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4834 compl_col += curs_col;
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4835 compl_length = 0;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4836 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4837 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4838 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4839 #ifdef FEAT_MBYTE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4840 /* Search the point of change class of multibyte character
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4841 * or not a word single byte character backward. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4842 if (has_mbyte)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4843 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4844 int base_class;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4845 int head_off;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4846
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4847 startcol -= (*mb_head_off)(line, line + startcol);
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4848 base_class = mb_get_class(line + startcol);
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4849 while (--startcol >= 0)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4850 {
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4851 head_off = (*mb_head_off)(line, line + startcol);
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4852 if (base_class != mb_get_class(line + startcol
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4853 - head_off))
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4854 break;
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4855 startcol -= head_off;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4856 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4857 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4858 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4859 #endif
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4860 while (--startcol >= 0 && vim_iswordc(line[startcol]))
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4861 ;
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4862 compl_col += ++startcol;
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4863 compl_length = (int)curs_col - startcol;
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4864 if (compl_length == 1)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4865 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4866 /* Only match word with at least two chars -- webb
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4867 * there's no need to call quote_meta,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4868 * alloc(7) is enough -- Acevedo
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4869 */
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4870 compl_pattern = alloc(7);
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4871 if (compl_pattern == NULL)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4872 return FAIL;
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4873 STRCPY((char *)compl_pattern, "\\<");
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4874 (void)quote_meta(compl_pattern + 2, line + compl_col, 1);
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4875 STRCAT((char *)compl_pattern, "\\k");
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4876 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4877 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4878 {
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4879 compl_pattern = alloc(quote_meta(NULL, line + compl_col,
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4880 compl_length) + 3);
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4881 if (compl_pattern == NULL)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4882 return FAIL;
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4883 STRCPY((char *)compl_pattern, "\\<");
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4884 (void)quote_meta(compl_pattern + 2, line + compl_col,
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4885 compl_length);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4886 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4887 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4888 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4889 else if (ctrl_x_mode == CTRL_X_WHOLE_LINE)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4890 {
835
8bebcabccc2c updated for version 7.0e01
vimboss
parents: 829
diff changeset
4891 compl_col = (colnr_T)(skipwhite(line) - line);
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4892 compl_length = (int)curs_col - (int)compl_col;
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4893 if (compl_length < 0) /* cursor in indent: empty pattern */
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4894 compl_length = 0;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4895 if (p_ic)
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4896 compl_pattern = str_foldcase(line + compl_col, compl_length,
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4897 NULL, 0);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4898 else
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4899 compl_pattern = vim_strnsave(line + compl_col, compl_length);
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4900 if (compl_pattern == NULL)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4901 return FAIL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4902 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4903 else if (ctrl_x_mode == CTRL_X_FILES)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4904 {
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4905 while (--startcol >= 0 && vim_isfilec(line[startcol]))
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4906 ;
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4907 compl_col += ++startcol;
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4908 compl_length = (int)curs_col - startcol;
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4909 compl_pattern = addstar(line + compl_col, compl_length,
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4910 EXPAND_FILES);
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4911 if (compl_pattern == NULL)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4912 return FAIL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4913 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4914 else if (ctrl_x_mode == CTRL_X_CMDLINE)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4915 {
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4916 compl_pattern = vim_strnsave(line, curs_col);
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4917 if (compl_pattern == NULL)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4918 return FAIL;
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4919 set_cmd_context(&compl_xp, compl_pattern,
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4920 (int)STRLEN(compl_pattern), curs_col);
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4921 if (compl_xp.xp_context == EXPAND_UNSUCCESSFUL
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4922 || compl_xp.xp_context == EXPAND_NOTHING)
935
c8cae82dee30 updated for version 7.0-061
vimboss
parents: 929
diff changeset
4923 /* No completion possible, use an empty pattern to get a
c8cae82dee30 updated for version 7.0-061
vimboss
parents: 929
diff changeset
4924 * "pattern not found" message. */
897
2e1e9b708941 updated for version 7.0-023
vimboss
parents: 887
diff changeset
4925 compl_col = curs_col;
2e1e9b708941 updated for version 7.0-023
vimboss
parents: 887
diff changeset
4926 else
935
c8cae82dee30 updated for version 7.0-061
vimboss
parents: 929
diff changeset
4927 compl_col = (int)(compl_xp.xp_pattern - compl_pattern);
c8cae82dee30 updated for version 7.0-061
vimboss
parents: 929
diff changeset
4928 compl_length = curs_col - compl_col;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4929 }
523
a7ae7e043e43 updated for version 7.0146
vimboss
parents: 502
diff changeset
4930 else if (ctrl_x_mode == CTRL_X_FUNCTION || ctrl_x_mode == CTRL_X_OMNI)
502
52e76e2b5b65 updated for version 7.0140
vimboss
parents: 499
diff changeset
4931 {
12
bdeee1504ac1 updated for version 7.0004
vimboss
parents: 11
diff changeset
4932 #ifdef FEAT_COMPL_FUNC
bdeee1504ac1 updated for version 7.0004
vimboss
parents: 11
diff changeset
4933 /*
502
52e76e2b5b65 updated for version 7.0140
vimboss
parents: 499
diff changeset
4934 * Call user defined function 'completefunc' with "a:findstart"
52e76e2b5b65 updated for version 7.0140
vimboss
parents: 499
diff changeset
4935 * set to 1 to obtain the length of text to use for completion.
12
bdeee1504ac1 updated for version 7.0004
vimboss
parents: 11
diff changeset
4936 */
502
52e76e2b5b65 updated for version 7.0140
vimboss
parents: 499
diff changeset
4937 char_u *args[2];
452
01af1008a8d8 updated for version 7.0120
vimboss
parents: 449
diff changeset
4938 int col;
502
52e76e2b5b65 updated for version 7.0140
vimboss
parents: 499
diff changeset
4939 char_u *funcname;
52e76e2b5b65 updated for version 7.0140
vimboss
parents: 499
diff changeset
4940 pos_T pos;
52e76e2b5b65 updated for version 7.0140
vimboss
parents: 499
diff changeset
4941
523
a7ae7e043e43 updated for version 7.0146
vimboss
parents: 502
diff changeset
4942 /* Call 'completefunc' or 'omnifunc' and get pattern length as a
502
52e76e2b5b65 updated for version 7.0140
vimboss
parents: 499
diff changeset
4943 * string */
52e76e2b5b65 updated for version 7.0140
vimboss
parents: 499
diff changeset
4944 funcname = ctrl_x_mode == CTRL_X_FUNCTION
52e76e2b5b65 updated for version 7.0140
vimboss
parents: 499
diff changeset
4945 ? curbuf->b_p_cfu : curbuf->b_p_ofu;
52e76e2b5b65 updated for version 7.0140
vimboss
parents: 499
diff changeset
4946 if (*funcname == NUL)
523
a7ae7e043e43 updated for version 7.0146
vimboss
parents: 502
diff changeset
4947 {
a7ae7e043e43 updated for version 7.0146
vimboss
parents: 502
diff changeset
4948 EMSG2(_(e_notset), ctrl_x_mode == CTRL_X_FUNCTION
a7ae7e043e43 updated for version 7.0146
vimboss
parents: 502
diff changeset
4949 ? "completefunc" : "omnifunc");
12
bdeee1504ac1 updated for version 7.0004
vimboss
parents: 11
diff changeset
4950 return FAIL;
523
a7ae7e043e43 updated for version 7.0146
vimboss
parents: 502
diff changeset
4951 }
452
01af1008a8d8 updated for version 7.0120
vimboss
parents: 449
diff changeset
4952
01af1008a8d8 updated for version 7.0120
vimboss
parents: 449
diff changeset
4953 args[0] = (char_u *)"1";
502
52e76e2b5b65 updated for version 7.0140
vimboss
parents: 499
diff changeset
4954 args[1] = NULL;
52e76e2b5b65 updated for version 7.0140
vimboss
parents: 499
diff changeset
4955 pos = curwin->w_cursor;
52e76e2b5b65 updated for version 7.0140
vimboss
parents: 499
diff changeset
4956 col = call_func_retnr(funcname, 2, args, FALSE);
52e76e2b5b65 updated for version 7.0140
vimboss
parents: 499
diff changeset
4957 curwin->w_cursor = pos; /* restore the cursor position */
52e76e2b5b65 updated for version 7.0140
vimboss
parents: 499
diff changeset
4958
452
01af1008a8d8 updated for version 7.0120
vimboss
parents: 449
diff changeset
4959 if (col < 0)
523
a7ae7e043e43 updated for version 7.0146
vimboss
parents: 502
diff changeset
4960 col = curs_col;
452
01af1008a8d8 updated for version 7.0120
vimboss
parents: 449
diff changeset
4961 compl_col = col;
01af1008a8d8 updated for version 7.0120
vimboss
parents: 449
diff changeset
4962 if ((colnr_T)compl_col > curs_col)
01af1008a8d8 updated for version 7.0120
vimboss
parents: 449
diff changeset
4963 compl_col = curs_col;
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4964
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4965 /* Setup variables for completion. Need to obtain "line" again,
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4966 * it may have become invalid. */
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4967 line = ml_get(curwin->w_cursor.lnum);
452
01af1008a8d8 updated for version 7.0120
vimboss
parents: 449
diff changeset
4968 compl_length = curs_col - compl_col;
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4969 compl_pattern = vim_strnsave(line + compl_col, compl_length);
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4970 if (compl_pattern == NULL)
502
52e76e2b5b65 updated for version 7.0140
vimboss
parents: 499
diff changeset
4971 #endif
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4972 return FAIL;
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4973 }
477
f8b75b8f1988 updated for version 7.0128
vimboss
parents: 474
diff changeset
4974 else if (ctrl_x_mode == CTRL_X_SPELL)
f8b75b8f1988 updated for version 7.0128
vimboss
parents: 474
diff changeset
4975 {
744
07f7b4a7755c updated for version 7.0222
vimboss
parents: 732
diff changeset
4976 #ifdef FEAT_SPELL
497
73f10d8124f4 updated for version 7.0136
vimboss
parents: 484
diff changeset
4977 if (spell_bad_len > 0)
73f10d8124f4 updated for version 7.0136
vimboss
parents: 484
diff changeset
4978 compl_col = curs_col - spell_bad_len;
73f10d8124f4 updated for version 7.0136
vimboss
parents: 484
diff changeset
4979 else
73f10d8124f4 updated for version 7.0136
vimboss
parents: 484
diff changeset
4980 compl_col = spell_word_start(startcol);
73f10d8124f4 updated for version 7.0136
vimboss
parents: 484
diff changeset
4981 if (compl_col >= (colnr_T)startcol)
897
2e1e9b708941 updated for version 7.0-023
vimboss
parents: 887
diff changeset
4982 {
2e1e9b708941 updated for version 7.0-023
vimboss
parents: 887
diff changeset
4983 compl_length = 0;
2e1e9b708941 updated for version 7.0-023
vimboss
parents: 887
diff changeset
4984 compl_col = curs_col;
2e1e9b708941 updated for version 7.0-023
vimboss
parents: 887
diff changeset
4985 }
2e1e9b708941 updated for version 7.0-023
vimboss
parents: 887
diff changeset
4986 else
2e1e9b708941 updated for version 7.0-023
vimboss
parents: 887
diff changeset
4987 {
2e1e9b708941 updated for version 7.0-023
vimboss
parents: 887
diff changeset
4988 spell_expand_check_cap(compl_col);
2e1e9b708941 updated for version 7.0-023
vimboss
parents: 887
diff changeset
4989 compl_length = (int)curs_col - compl_col;
2e1e9b708941 updated for version 7.0-023
vimboss
parents: 887
diff changeset
4990 }
818
1f929f3ca806 updated for version 7.0c03
vimboss
parents: 816
diff changeset
4991 /* Need to obtain "line" again, it may have become invalid. */
1f929f3ca806 updated for version 7.0c03
vimboss
parents: 816
diff changeset
4992 line = ml_get(curwin->w_cursor.lnum);
477
f8b75b8f1988 updated for version 7.0128
vimboss
parents: 474
diff changeset
4993 compl_pattern = vim_strnsave(line + compl_col, compl_length);
f8b75b8f1988 updated for version 7.0128
vimboss
parents: 474
diff changeset
4994 if (compl_pattern == NULL)
f8b75b8f1988 updated for version 7.0128
vimboss
parents: 474
diff changeset
4995 #endif
f8b75b8f1988 updated for version 7.0128
vimboss
parents: 474
diff changeset
4996 return FAIL;
f8b75b8f1988 updated for version 7.0128
vimboss
parents: 474
diff changeset
4997 }
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4998 else
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
4999 {
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
5000 EMSG2(_(e_intern2), "ins_complete()");
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
5001 return FAIL;
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
5002 }
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
5003
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
5004 if (compl_cont_status & CONT_ADDING)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5005 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5006 edit_submode_pre = (char_u *)_(" Adding");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5007 if (ctrl_x_mode == CTRL_X_WHOLE_LINE)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5008 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5009 /* Insert a new line, keep indentation but ignore 'comments' */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5010 #ifdef FEAT_COMMENTS
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5011 char_u *old = curbuf->b_p_com;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5012
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5013 curbuf->b_p_com = (char_u *)"";
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5014 #endif
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
5015 compl_startpos.lnum = curwin->w_cursor.lnum;
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
5016 compl_startpos.col = compl_col;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5017 ins_eol('\r');
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5018 #ifdef FEAT_COMMENTS
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5019 curbuf->b_p_com = old;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5020 #endif
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
5021 compl_length = 0;
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
5022 compl_col = curwin->w_cursor.col;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5023 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5024 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5025 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5026 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5027 edit_submode_pre = NULL;
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
5028 compl_startpos.col = compl_col;
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
5029 }
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
5030
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
5031 if (compl_cont_status & CONT_LOCAL)
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
5032 edit_submode = (char_u *)_(ctrl_x_msgs[CTRL_X_LOCAL_MSG]);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5033 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5034 edit_submode = (char_u *)_(CTRL_X_MSG(ctrl_x_mode));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5035
694
07d199fe02ed updated for version 7.0209
vimboss
parents: 692
diff changeset
5036 /* Always add completion for the original text. */
07d199fe02ed updated for version 7.0209
vimboss
parents: 692
diff changeset
5037 vim_free(compl_orig_text);
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
5038 compl_orig_text = vim_strnsave(line + compl_col, compl_length);
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
5039 if (compl_orig_text == NULL || ins_compl_add(compl_orig_text,
942
29bf49bad20d updated for version 7.0-068
vimboss
parents: 941
diff changeset
5040 -1, p_ic, NULL, NULL, 0, ORIGINAL_TEXT, FALSE) != OK)
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
5041 {
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
5042 vim_free(compl_pattern);
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
5043 compl_pattern = NULL;
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
5044 vim_free(compl_orig_text);
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
5045 compl_orig_text = NULL;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5046 return FAIL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5047 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5048
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5049 /* showmode might reset the internal line pointers, so it must
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5050 * be called before line = ml_get(), or when this address is no
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5051 * longer needed. -- Acevedo.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5052 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5053 edit_submode_extra = (char_u *)_("-- Searching...");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5054 edit_submode_highl = HLF_COUNT;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5055 showmode();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5056 edit_submode_extra = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5057 out_flush();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5058 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5059
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
5060 compl_shown_match = compl_curr_match;
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
5061 compl_shows_dir = compl_direction;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5062
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5063 /*
665
21ab9abf0f08 updated for version 7.0196
vimboss
parents: 661
diff changeset
5064 * Find next match (and following matches).
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5065 */
681
9364d114ed8d updated for version 7.0204
vimboss
parents: 677
diff changeset
5066 n = ins_compl_next(TRUE, ins_compl_key2count(c), ins_compl_use_match(c));
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
5067
540
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
5068 /* may undisplay the popup menu */
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
5069 ins_compl_upd_pum();
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
5070
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
5071 if (n > 1) /* all matches have been found */
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
5072 compl_matches = n;
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
5073 compl_curr_match = compl_shown_match;
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
5074 compl_direction = compl_shows_dir;
857
b933657f7c9d updated for version 7.0g01
vimboss
parents: 853
diff changeset
5075
b933657f7c9d updated for version 7.0g01
vimboss
parents: 853
diff changeset
5076 /* Eat the ESC that vgetc() returns after a CTRL-C to avoid leaving Insert
b933657f7c9d updated for version 7.0g01
vimboss
parents: 853
diff changeset
5077 * mode. */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5078 if (got_int && !global_busy)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5079 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5080 (void)vgetc();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5081 got_int = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5082 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5083
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
5084 /* we found no match if the list has only the "compl_orig_text"-entry */
464
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
5085 if (compl_first_match == compl_first_match->cp_next)
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
5086 {
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
5087 edit_submode_extra = (compl_cont_status & CONT_ADDING)
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
5088 && compl_length > 1
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5089 ? (char_u *)_(e_hitend) : (char_u *)_(e_patnotf);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5090 edit_submode_highl = HLF_E;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5091 /* remove N_ADDS flag, so next ^X<> won't try to go to ADDING mode,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5092 * because we couldn't expand anything at first place, but if we used
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5093 * ^P, ^N, ^X^I or ^X^D we might want to add-expand a single-char-word
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5094 * (such as M in M'exico) if not tried already. -- Acevedo */
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
5095 if ( compl_length > 1
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
5096 || (compl_cont_status & CONT_ADDING)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5097 || (ctrl_x_mode != 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5098 && ctrl_x_mode != CTRL_X_PATH_PATTERNS
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5099 && ctrl_x_mode != CTRL_X_PATH_DEFINES))
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
5100 compl_cont_status &= ~CONT_N_ADDS;
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
5101 }
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
5102
464
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
5103 if (compl_curr_match->cp_flags & CONT_S_IPOS)
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
5104 compl_cont_status |= CONT_S_IPOS;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5105 else
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
5106 compl_cont_status &= ~CONT_S_IPOS;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5107
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5108 if (edit_submode_extra == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5109 {
464
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
5110 if (compl_curr_match->cp_flags & ORIGINAL_TEXT)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5111 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5112 edit_submode_extra = (char_u *)_("Back at original");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5113 edit_submode_highl = HLF_W;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5114 }
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
5115 else if (compl_cont_status & CONT_S_IPOS)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5116 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5117 edit_submode_extra = (char_u *)_("Word from other line");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5118 edit_submode_highl = HLF_COUNT;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5119 }
464
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
5120 else if (compl_curr_match->cp_next == compl_curr_match->cp_prev)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5121 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5122 edit_submode_extra = (char_u *)_("The only match");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5123 edit_submode_highl = HLF_COUNT;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5124 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5125 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5126 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5127 /* Update completion sequence number when needed. */
464
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
5128 if (compl_curr_match->cp_number == -1)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5129 {
464
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
5130 int number = 0;
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
5131 compl_T *match;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5132
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
5133 if (compl_direction == FORWARD)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5134 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5135 /* search backwards for the first valid (!= -1) number.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5136 * This should normally succeed already at the first loop
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5137 * cycle, so it's fast! */
464
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
5138 for (match = compl_curr_match->cp_prev; match != NULL
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
5139 && match != compl_first_match;
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
5140 match = match->cp_prev)
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
5141 if (match->cp_number != -1)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5142 {
464
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
5143 number = match->cp_number;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5144 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5145 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5146 if (match != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5147 /* go up and assign all numbers which are not assigned
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5148 * yet */
540
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
5149 for (match = match->cp_next;
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
5150 match != NULL && match->cp_number == -1;
464
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
5151 match = match->cp_next)
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
5152 match->cp_number = ++number;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5153 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5154 else /* BACKWARD */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5155 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5156 /* search forwards (upwards) for the first valid (!= -1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5157 * number. This should normally succeed already at the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5158 * first loop cycle, so it's fast! */
464
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
5159 for (match = compl_curr_match->cp_next; match != NULL
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
5160 && match != compl_first_match;
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
5161 match = match->cp_next)
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
5162 if (match->cp_number != -1)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5163 {
464
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
5164 number = match->cp_number;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5165 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5166 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5167 if (match != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5168 /* go down and assign all numbers which are not
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5169 * assigned yet */
464
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
5170 for (match = match->cp_prev; match
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
5171 && match->cp_number == -1;
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
5172 match = match->cp_prev)
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
5173 match->cp_number = ++number;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5174 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5175 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5176
540
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
5177 /* The match should always have a sequence number now, this is
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
5178 * just a safety check. */
464
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
5179 if (compl_curr_match->cp_number != -1)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5180 {
1063
d763e7d7e938 updated for version 7.0-189
vimboss
parents: 1032
diff changeset
5181 /* Space for 10 text chars. + 2x10-digit no.s = 31.
d763e7d7e938 updated for version 7.0-189
vimboss
parents: 1032
diff changeset
5182 * Translations may need more than twice that. */
d763e7d7e938 updated for version 7.0-189
vimboss
parents: 1032
diff changeset
5183 static char_u match_ref[81];
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5184
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
5185 if (compl_matches > 0)
1063
d763e7d7e938 updated for version 7.0-189
vimboss
parents: 1032
diff changeset
5186 vim_snprintf((char *)match_ref, sizeof(match_ref),
d763e7d7e938 updated for version 7.0-189
vimboss
parents: 1032
diff changeset
5187 _("match %d of %d"),
464
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
5188 compl_curr_match->cp_number, compl_matches);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5189 else
1063
d763e7d7e938 updated for version 7.0-189
vimboss
parents: 1032
diff changeset
5190 vim_snprintf((char *)match_ref, sizeof(match_ref),
d763e7d7e938 updated for version 7.0-189
vimboss
parents: 1032
diff changeset
5191 _("match %d"),
d763e7d7e938 updated for version 7.0-189
vimboss
parents: 1032
diff changeset
5192 compl_curr_match->cp_number);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5193 edit_submode_extra = match_ref;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5194 edit_submode_highl = HLF_R;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5195 if (dollar_vcol)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5196 curs_columns(FALSE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5197 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5198 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5199 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5200
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5201 /* Show a message about what (completion) mode we're in. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5202 showmode();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5203 if (edit_submode_extra != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5204 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5205 if (!p_smd)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5206 msg_attr(edit_submode_extra,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5207 edit_submode_highl < HLF_COUNT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5208 ? hl_attr(edit_submode_highl) : 0);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5209 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5210 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5211 msg_clr_cmdline(); /* necessary for "noshowmode" */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5212
857
b933657f7c9d updated for version 7.0g01
vimboss
parents: 853
diff changeset
5213 /* Show the popup menu, unless we got interrupted. */
b933657f7c9d updated for version 7.0g01
vimboss
parents: 853
diff changeset
5214 if (!compl_interrupted)
b933657f7c9d updated for version 7.0g01
vimboss
parents: 853
diff changeset
5215 {
b933657f7c9d updated for version 7.0g01
vimboss
parents: 853
diff changeset
5216 /* RedrawingDisabled may be set when invoked through complete(). */
b933657f7c9d updated for version 7.0g01
vimboss
parents: 853
diff changeset
5217 n = RedrawingDisabled;
b933657f7c9d updated for version 7.0g01
vimboss
parents: 853
diff changeset
5218 RedrawingDisabled = 0;
b933657f7c9d updated for version 7.0g01
vimboss
parents: 853
diff changeset
5219 ins_compl_show_pum();
b933657f7c9d updated for version 7.0g01
vimboss
parents: 853
diff changeset
5220 setcursor();
b933657f7c9d updated for version 7.0g01
vimboss
parents: 853
diff changeset
5221 RedrawingDisabled = n;
b933657f7c9d updated for version 7.0g01
vimboss
parents: 853
diff changeset
5222 }
874
4bac29d27e2f updated for version 7.0
vimboss
parents: 867
diff changeset
5223 compl_was_interrupted = compl_interrupted;
857
b933657f7c9d updated for version 7.0g01
vimboss
parents: 853
diff changeset
5224 compl_interrupted = FALSE;
540
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
5225
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5226 return OK;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5227 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5228
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5229 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5230 * Looks in the first "len" chars. of "src" for search-metachars.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5231 * If dest is not NULL the chars. are copied there quoting (with
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5232 * a backslash) the metachars, and dest would be NUL terminated.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5233 * Returns the length (needed) of dest
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5234 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5235 static int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5236 quote_meta(dest, src, len)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5237 char_u *dest;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5238 char_u *src;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5239 int len;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5240 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5241 int m;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5242
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5243 for (m = len; --len >= 0; src++)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5244 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5245 switch (*src)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5246 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5247 case '.':
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5248 case '*':
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5249 case '[':
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5250 if (ctrl_x_mode == CTRL_X_DICTIONARY
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5251 || ctrl_x_mode == CTRL_X_THESAURUS)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5252 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5253 case '~':
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5254 if (!p_magic) /* quote these only if magic is set */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5255 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5256 case '\\':
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5257 if (ctrl_x_mode == CTRL_X_DICTIONARY
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5258 || ctrl_x_mode == CTRL_X_THESAURUS)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5259 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5260 case '^': /* currently it's not needed. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5261 case '$':
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5262 m++;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5263 if (dest != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5264 *dest++ = '\\';
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5265 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5266 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5267 if (dest != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5268 *dest++ = *src;
464
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
5269 # ifdef FEAT_MBYTE
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5270 /* Copy remaining bytes of a multibyte character. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5271 if (has_mbyte)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5272 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5273 int i, mb_len;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5274
474
a5fcf36ef512 updated for version 7.0127
vimboss
parents: 470
diff changeset
5275 mb_len = (*mb_ptr2len)(src) - 1;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5276 if (mb_len > 0 && len >= mb_len)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5277 for (i = 0; i < mb_len; ++i)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5278 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5279 --len;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5280 ++src;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5281 if (dest != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5282 *dest++ = *src;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5283 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5284 }
464
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
5285 # endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5286 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5287 if (dest != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5288 *dest = NUL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5289
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5290 return m;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5291 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5292 #endif /* FEAT_INS_EXPAND */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5293
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5294 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5295 * Next character is interpreted literally.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5296 * A one, two or three digit decimal number is interpreted as its byte value.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5297 * If one or two digits are entered, the next character is given to vungetc().
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5298 * For Unicode a character > 255 may be returned.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5299 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5300 int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5301 get_literal()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5302 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5303 int cc;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5304 int nc;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5305 int i;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5306 int hex = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5307 int octal = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5308 #ifdef FEAT_MBYTE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5309 int unicode = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5310 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5311
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5312 if (got_int)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5313 return Ctrl_C;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5314
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5315 #ifdef FEAT_GUI
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5316 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5317 * In GUI there is no point inserting the internal code for a special key.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5318 * It is more useful to insert the string "<KEY>" instead. This would
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5319 * probably be useful in a text window too, but it would not be
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5320 * vi-compatible (maybe there should be an option for it?) -- webb
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5321 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5322 if (gui.in_use)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5323 ++allow_keys;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5324 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5325 #ifdef USE_ON_FLY_SCROLL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5326 dont_scroll = TRUE; /* disallow scrolling here */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5327 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5328 ++no_mapping; /* don't map the next key hits */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5329 cc = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5330 i = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5331 for (;;)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5332 {
1389
bdcfe793d49f updated for version 7.1-104
vimboss
parents: 1353
diff changeset
5333 nc = plain_vgetc();
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5334 #ifdef FEAT_CMDL_INFO
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5335 if (!(State & CMDLINE)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5336 # ifdef FEAT_MBYTE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5337 && MB_BYTE2LEN_CHECK(nc) == 1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5338 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5339 )
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5340 add_to_showcmd(nc);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5341 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5342 if (nc == 'x' || nc == 'X')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5343 hex = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5344 else if (nc == 'o' || nc == 'O')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5345 octal = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5346 #ifdef FEAT_MBYTE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5347 else if (nc == 'u' || nc == 'U')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5348 unicode = nc;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5349 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5350 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5351 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5352 if (hex
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5353 #ifdef FEAT_MBYTE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5354 || unicode != 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5355 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5356 )
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5357 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5358 if (!vim_isxdigit(nc))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5359 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5360 cc = cc * 16 + hex2nr(nc);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5361 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5362 else if (octal)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5363 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5364 if (nc < '0' || nc > '7')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5365 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5366 cc = cc * 8 + nc - '0';
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5367 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5368 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5369 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5370 if (!VIM_ISDIGIT(nc))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5371 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5372 cc = cc * 10 + nc - '0';
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5373 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5374
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5375 ++i;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5376 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5377
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5378 if (cc > 255
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5379 #ifdef FEAT_MBYTE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5380 && unicode == 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5381 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5382 )
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5383 cc = 255; /* limit range to 0-255 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5384 nc = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5385
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5386 if (hex) /* hex: up to two chars */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5387 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5388 if (i >= 2)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5389 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5390 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5391 #ifdef FEAT_MBYTE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5392 else if (unicode) /* Unicode: up to four or eight chars */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5393 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5394 if ((unicode == 'u' && i >= 4) || (unicode == 'U' && i >= 8))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5395 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5396 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5397 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5398 else if (i >= 3) /* decimal or octal: up to three chars */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5399 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5400 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5401 if (i == 0) /* no number entered */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5402 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5403 if (nc == K_ZERO) /* NUL is stored as NL */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5404 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5405 cc = '\n';
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5406 nc = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5407 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5408 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5409 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5410 cc = nc;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5411 nc = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5412 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5413 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5414
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5415 if (cc == 0) /* NUL is stored as NL */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5416 cc = '\n';
221
7fd4b5df33be updated for version 7.0062
vimboss
parents: 180
diff changeset
5417 #ifdef FEAT_MBYTE
7fd4b5df33be updated for version 7.0062
vimboss
parents: 180
diff changeset
5418 if (enc_dbcs && (cc & 0xff) == 0)
7fd4b5df33be updated for version 7.0062
vimboss
parents: 180
diff changeset
5419 cc = '?'; /* don't accept an illegal DBCS char, the NUL in the
7fd4b5df33be updated for version 7.0062
vimboss
parents: 180
diff changeset
5420 second byte will cause trouble! */
7fd4b5df33be updated for version 7.0062
vimboss
parents: 180
diff changeset
5421 #endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5422
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5423 --no_mapping;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5424 #ifdef FEAT_GUI
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5425 if (gui.in_use)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5426 --allow_keys;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5427 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5428 if (nc)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5429 vungetc(nc);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5430 got_int = FALSE; /* CTRL-C typed after CTRL-V is not an interrupt */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5431 return cc;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5432 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5433
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5434 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5435 * Insert character, taking care of special keys and mod_mask
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5436 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5437 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5438 insert_special(c, allow_modmask, ctrlv)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5439 int c;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5440 int allow_modmask;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5441 int ctrlv; /* c was typed after CTRL-V */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5442 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5443 char_u *p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5444 int len;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5445
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5446 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5447 * Special function key, translate into "<Key>". Up to the last '>' is
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5448 * inserted with ins_str(), so as not to replace characters in replace
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5449 * mode.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5450 * Only use mod_mask for special keys, to avoid things like <S-Space>,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5451 * unless 'allow_modmask' is TRUE.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5452 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5453 #ifdef MACOS
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5454 /* Command-key never produces a normal key */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5455 if (mod_mask & MOD_MASK_CMD)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5456 allow_modmask = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5457 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5458 if (IS_SPECIAL(c) || (mod_mask && allow_modmask))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5459 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5460 p = get_special_key_name(c, mod_mask);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5461 len = (int)STRLEN(p);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5462 c = p[len - 1];
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5463 if (len > 2)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5464 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5465 if (stop_arrow() == FAIL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5466 return;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5467 p[len - 1] = NUL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5468 ins_str(p);
620
9e359e5759f6 updated for version 7.0177
vimboss
parents: 615
diff changeset
5469 AppendToRedobuffLit(p, -1);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5470 ctrlv = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5471 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5472 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5473 if (stop_arrow() == OK)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5474 insertchar(c, ctrlv ? INSCHAR_CTRLV : 0, -1);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5475 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5476
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5477 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5478 * Special characters in this context are those that need processing other
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5479 * than the simple insertion that can be performed here. This includes ESC
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5480 * which terminates the insert, and CR/NL which need special processing to
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5481 * open up a new line. This routine tries to optimize insertions performed by
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5482 * the "redo", "undo" or "put" commands, so it needs to know when it should
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5483 * stop and defer processing to the "normal" mechanism.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5484 * '0' and '^' are special, because they can be followed by CTRL-D.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5485 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5486 #ifdef EBCDIC
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5487 # define ISSPECIAL(c) ((c) < ' ' || (c) == '0' || (c) == '^')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5488 #else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5489 # define ISSPECIAL(c) ((c) < ' ' || (c) >= DEL || (c) == '0' || (c) == '^')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5490 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5491
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5492 #ifdef FEAT_MBYTE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5493 # define WHITECHAR(cc) (vim_iswhite(cc) && (!enc_utf8 || !utf_iscomposing(utf_ptr2char(ml_get_cursor() + 1))))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5494 #else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5495 # define WHITECHAR(cc) vim_iswhite(cc)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5496 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5497
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5498 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5499 insertchar(c, flags, second_indent)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5500 int c; /* character to insert or NUL */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5501 int flags; /* INSCHAR_FORMAT, etc. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5502 int second_indent; /* indent for second line if >= 0 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5503 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5504 int textwidth;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5505 #ifdef FEAT_COMMENTS
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5506 char_u *p;
667
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5507 #endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5508 int fo_ins_blank;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5509
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5510 textwidth = comp_textwidth(flags & INSCHAR_FORMAT);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5511 fo_ins_blank = has_format_option(FO_INS_BLANK);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5512
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5513 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5514 * Try to break the line in two or more pieces when:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5515 * - Always do this if we have been called to do formatting only.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5516 * - Always do this when 'formatoptions' has the 'a' flag and the line
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5517 * ends in white space.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5518 * - Otherwise:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5519 * - Don't do this if inserting a blank
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5520 * - Don't do this if an existing character is being replaced, unless
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5521 * we're in VREPLACE mode.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5522 * - Do this if the cursor is not on the line where insert started
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5523 * or - 'formatoptions' doesn't have 'l' or the line was not too long
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5524 * before the insert.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5525 * - 'formatoptions' doesn't have 'b' or a blank was inserted at or
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5526 * before 'textwidth'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5527 */
667
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5528 if (textwidth > 0
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5529 && ((flags & INSCHAR_FORMAT)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5530 || (!vim_iswhite(c)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5531 && !((State & REPLACE_FLAG)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5532 #ifdef FEAT_VREPLACE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5533 && !(State & VREPLACE_FLAG)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5534 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5535 && *ml_get_cursor() != NUL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5536 && (curwin->w_cursor.lnum != Insstart.lnum
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5537 || ((!has_format_option(FO_INS_LONG)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5538 || Insstart_textlen <= (colnr_T)textwidth)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5539 && (!fo_ins_blank
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5540 || Insstart_blank_vcol <= (colnr_T)textwidth
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5541 ))))))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5542 {
667
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5543 /* Format with 'formatexpr' when it's set. Use internal formatting
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5544 * when 'formatexpr' isn't set or it returns non-zero. */
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5545 #if defined(FEAT_EVAL)
1000
cb49fa8c7196 updated for version 7.0-126
vimboss
parents: 993
diff changeset
5546 int do_internal = TRUE;
cb49fa8c7196 updated for version 7.0-126
vimboss
parents: 993
diff changeset
5547
1563
ed7fefbef738 updated for version 7.1-276
vimboss
parents: 1526
diff changeset
5548 if (*curbuf->b_p_fex != NUL && (flags & INSCHAR_NO_FEX) == 0)
1000
cb49fa8c7196 updated for version 7.0-126
vimboss
parents: 993
diff changeset
5549 {
cb49fa8c7196 updated for version 7.0-126
vimboss
parents: 993
diff changeset
5550 do_internal = (fex_format(curwin->w_cursor.lnum, 1L, c) != 0);
cb49fa8c7196 updated for version 7.0-126
vimboss
parents: 993
diff changeset
5551 /* It may be required to save for undo again, e.g. when setline()
cb49fa8c7196 updated for version 7.0-126
vimboss
parents: 993
diff changeset
5552 * was called. */
cb49fa8c7196 updated for version 7.0-126
vimboss
parents: 993
diff changeset
5553 ins_need_undo = TRUE;
cb49fa8c7196 updated for version 7.0-126
vimboss
parents: 993
diff changeset
5554 }
cb49fa8c7196 updated for version 7.0-126
vimboss
parents: 993
diff changeset
5555 if (do_internal)
667
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5556 #endif
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5557 internal_format(textwidth, second_indent, flags, c == NUL);
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5558 }
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5559
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5560 if (c == NUL) /* only formatting was wanted */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5561 return;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5562
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5563 #ifdef FEAT_COMMENTS
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5564 /* Check whether this character should end a comment. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5565 if (did_ai && (int)c == end_comment_pending)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5566 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5567 char_u *line;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5568 char_u lead_end[COM_MAX_LEN]; /* end-comment string */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5569 int middle_len, end_len;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5570 int i;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5571
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5572 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5573 * Need to remove existing (middle) comment leader and insert end
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5574 * comment leader. First, check what comment leader we can find.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5575 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5576 i = get_leader_len(line = ml_get_curline(), &p, FALSE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5577 if (i > 0 && vim_strchr(p, COM_MIDDLE) != NULL) /* Just checking */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5578 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5579 /* Skip middle-comment string */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5580 while (*p && p[-1] != ':') /* find end of middle flags */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5581 ++p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5582 middle_len = copy_option_part(&p, lead_end, COM_MAX_LEN, ",");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5583 /* Don't count trailing white space for middle_len */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5584 while (middle_len > 0 && vim_iswhite(lead_end[middle_len - 1]))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5585 --middle_len;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5586
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5587 /* Find the end-comment string */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5588 while (*p && p[-1] != ':') /* find end of end flags */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5589 ++p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5590 end_len = copy_option_part(&p, lead_end, COM_MAX_LEN, ",");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5591
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5592 /* Skip white space before the cursor */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5593 i = curwin->w_cursor.col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5594 while (--i >= 0 && vim_iswhite(line[i]))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5595 ;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5596 i++;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5597
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5598 /* Skip to before the middle leader */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5599 i -= middle_len;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5600
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5601 /* Check some expected things before we go on */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5602 if (i >= 0 && lead_end[end_len - 1] == end_comment_pending)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5603 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5604 /* Backspace over all the stuff we want to replace */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5605 backspace_until_column(i);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5606
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5607 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5608 * Insert the end-comment string, except for the last
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5609 * character, which will get inserted as normal later.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5610 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5611 ins_bytes_len(lead_end, end_len - 1);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5612 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5613 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5614 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5615 end_comment_pending = NUL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5616 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5617
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5618 did_ai = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5619 #ifdef FEAT_SMARTINDENT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5620 did_si = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5621 can_si = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5622 can_si_back = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5623 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5624
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5625 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5626 * If there's any pending input, grab up to INPUT_BUFLEN at once.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5627 * This speeds up normal text input considerably.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5628 * Don't do this when 'cindent' or 'indentexpr' is set, because we might
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5629 * need to re-indent at a ':', or any other character (but not what
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5630 * 'paste' is set)..
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5631 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5632 #ifdef USE_ON_FLY_SCROLL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5633 dont_scroll = FALSE; /* allow scrolling here */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5634 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5635
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5636 if ( !ISSPECIAL(c)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5637 #ifdef FEAT_MBYTE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5638 && (!has_mbyte || (*mb_char2len)(c) == 1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5639 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5640 && vpeekc() != NUL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5641 && !(State & REPLACE_FLAG)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5642 #ifdef FEAT_CINDENT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5643 && !cindent_on()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5644 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5645 #ifdef FEAT_RIGHTLEFT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5646 && !p_ri
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5647 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5648 )
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5649 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5650 #define INPUT_BUFLEN 100
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5651 char_u buf[INPUT_BUFLEN + 1];
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5652 int i;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5653 colnr_T virtcol = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5654
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5655 buf[0] = c;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5656 i = 1;
667
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5657 if (textwidth > 0)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5658 virtcol = get_nolist_virtcol();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5659 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5660 * Stop the string when:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5661 * - no more chars available
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5662 * - finding a special character (command key)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5663 * - buffer is full
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5664 * - running into the 'textwidth' boundary
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5665 * - need to check for abbreviation: A non-word char after a word-char
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5666 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5667 while ( (c = vpeekc()) != NUL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5668 && !ISSPECIAL(c)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5669 #ifdef FEAT_MBYTE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5670 && (!has_mbyte || MB_BYTE2LEN_CHECK(c) == 1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5671 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5672 && i < INPUT_BUFLEN
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5673 && (textwidth == 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5674 || (virtcol += byte2cells(buf[i - 1])) < (colnr_T)textwidth)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5675 && !(!no_abbr && !vim_iswordc(c) && vim_iswordc(buf[i - 1])))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5676 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5677 #ifdef FEAT_RIGHTLEFT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5678 c = vgetc();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5679 if (p_hkmap && KeyTyped)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5680 c = hkmap(c); /* Hebrew mode mapping */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5681 # ifdef FEAT_FKMAP
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5682 if (p_fkmap && KeyTyped)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5683 c = fkmap(c); /* Farsi mode mapping */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5684 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5685 buf[i++] = c;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5686 #else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5687 buf[i++] = vgetc();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5688 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5689 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5690
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5691 #ifdef FEAT_DIGRAPHS
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5692 do_digraph(-1); /* clear digraphs */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5693 do_digraph(buf[i-1]); /* may be the start of a digraph */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5694 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5695 buf[i] = NUL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5696 ins_str(buf);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5697 if (flags & INSCHAR_CTRLV)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5698 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5699 redo_literal(*buf);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5700 i = 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5701 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5702 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5703 i = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5704 if (buf[i] != NUL)
620
9e359e5759f6 updated for version 7.0177
vimboss
parents: 615
diff changeset
5705 AppendToRedobuffLit(buf + i, -1);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5706 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5707 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5708 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5709 #ifdef FEAT_MBYTE
667
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5710 int cc;
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5711
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5712 if (has_mbyte && (cc = (*mb_char2len)(c)) > 1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5713 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5714 char_u buf[MB_MAXBYTES + 1];
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5715
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5716 (*mb_char2bytes)(c, buf);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5717 buf[cc] = NUL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5718 ins_char_bytes(buf, cc);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5719 AppendCharToRedobuff(c);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5720 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5721 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5722 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5723 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5724 ins_char(c);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5725 if (flags & INSCHAR_CTRLV)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5726 redo_literal(c);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5727 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5728 AppendCharToRedobuff(c);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5729 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5730 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5731 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5732
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5733 /*
667
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5734 * Format text at the current insert position.
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5735 */
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5736 static void
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5737 internal_format(textwidth, second_indent, flags, format_only)
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5738 int textwidth;
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5739 int second_indent;
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5740 int flags;
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5741 int format_only;
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5742 {
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5743 int cc;
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5744 int save_char = NUL;
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5745 int haveto_redraw = FALSE;
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5746 int fo_ins_blank = has_format_option(FO_INS_BLANK);
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5747 #ifdef FEAT_MBYTE
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5748 int fo_multibyte = has_format_option(FO_MBYTE_BREAK);
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5749 #endif
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5750 int fo_white_par = has_format_option(FO_WHITE_PAR);
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5751 int first_line = TRUE;
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5752 #ifdef FEAT_COMMENTS
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5753 colnr_T leader_len;
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5754 int no_leader = FALSE;
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5755 int do_comments = (flags & INSCHAR_DO_COM);
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5756 #endif
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5757
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5758 /*
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5759 * When 'ai' is off we don't want a space under the cursor to be
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5760 * deleted. Replace it with an 'x' temporarily.
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5761 */
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5762 if (!curbuf->b_p_ai)
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5763 {
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5764 cc = gchar_cursor();
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5765 if (vim_iswhite(cc))
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5766 {
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5767 save_char = cc;
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5768 pchar_cursor('x');
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5769 }
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5770 }
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5771
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5772 /*
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5773 * Repeat breaking lines, until the current line is not too long.
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5774 */
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5775 while (!got_int)
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5776 {
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5777 int startcol; /* Cursor column at entry */
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5778 int wantcol; /* column at textwidth border */
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5779 int foundcol; /* column for start of spaces */
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5780 int end_foundcol = 0; /* column for start of word */
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5781 colnr_T len;
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5782 colnr_T virtcol;
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5783 #ifdef FEAT_VREPLACE
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5784 int orig_col = 0;
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5785 char_u *saved_text = NULL;
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5786 #endif
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5787 colnr_T col;
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5788
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5789 virtcol = get_nolist_virtcol();
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5790 if (virtcol < (colnr_T)textwidth)
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5791 break;
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5792
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5793 #ifdef FEAT_COMMENTS
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5794 if (no_leader)
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5795 do_comments = FALSE;
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5796 else if (!(flags & INSCHAR_FORMAT)
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5797 && has_format_option(FO_WRAP_COMS))
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5798 do_comments = TRUE;
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5799
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5800 /* Don't break until after the comment leader */
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5801 if (do_comments)
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5802 leader_len = get_leader_len(ml_get_curline(), NULL, FALSE);
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5803 else
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5804 leader_len = 0;
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5805
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5806 /* If the line doesn't start with a comment leader, then don't
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5807 * start one in a following broken line. Avoids that a %word
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5808 * moved to the start of the next line causes all following lines
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5809 * to start with %. */
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5810 if (leader_len == 0)
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5811 no_leader = TRUE;
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5812 #endif
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5813 if (!(flags & INSCHAR_FORMAT)
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5814 #ifdef FEAT_COMMENTS
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5815 && leader_len == 0
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5816 #endif
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5817 && !has_format_option(FO_WRAP))
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5818
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5819 {
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5820 textwidth = 0;
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5821 break;
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5822 }
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5823 if ((startcol = curwin->w_cursor.col) == 0)
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5824 break;
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5825
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5826 /* find column of textwidth border */
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5827 coladvance((colnr_T)textwidth);
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5828 wantcol = curwin->w_cursor.col;
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5829
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5830 curwin->w_cursor.col = startcol - 1;
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5831 #ifdef FEAT_MBYTE
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5832 /* Correct cursor for multi-byte character. */
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5833 if (has_mbyte)
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5834 mb_adjust_cursor();
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5835 #endif
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5836 foundcol = 0;
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5837
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5838 /*
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5839 * Find position to break at.
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5840 * Stop at first entered white when 'formatoptions' has 'v'
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5841 */
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5842 while ((!fo_ins_blank && !has_format_option(FO_INS_VI))
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5843 || curwin->w_cursor.lnum != Insstart.lnum
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5844 || curwin->w_cursor.col >= Insstart.col)
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5845 {
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5846 cc = gchar_cursor();
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5847 if (WHITECHAR(cc))
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5848 {
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5849 /* remember position of blank just before text */
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5850 end_foundcol = curwin->w_cursor.col;
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5851
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5852 /* find start of sequence of blanks */
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5853 while (curwin->w_cursor.col > 0 && WHITECHAR(cc))
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5854 {
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5855 dec_cursor();
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5856 cc = gchar_cursor();
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5857 }
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5858 if (curwin->w_cursor.col == 0 && WHITECHAR(cc))
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5859 break; /* only spaces in front of text */
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5860 #ifdef FEAT_COMMENTS
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5861 /* Don't break until after the comment leader */
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5862 if (curwin->w_cursor.col < leader_len)
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5863 break;
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5864 #endif
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5865 if (has_format_option(FO_ONE_LETTER))
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5866 {
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5867 /* do not break after one-letter words */
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5868 if (curwin->w_cursor.col == 0)
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5869 break; /* one-letter word at begin */
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5870
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5871 col = curwin->w_cursor.col;
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5872 dec_cursor();
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5873 cc = gchar_cursor();
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5874
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5875 if (WHITECHAR(cc))
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5876 continue; /* one-letter, continue */
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5877 curwin->w_cursor.col = col;
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5878 }
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5879 #ifdef FEAT_MBYTE
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5880 if (has_mbyte)
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5881 foundcol = curwin->w_cursor.col
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5882 + (*mb_ptr2len)(ml_get_cursor());
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5883 else
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5884 #endif
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5885 foundcol = curwin->w_cursor.col + 1;
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5886 if (curwin->w_cursor.col < (colnr_T)wantcol)
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5887 break;
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5888 }
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5889 #ifdef FEAT_MBYTE
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5890 else if (cc >= 0x100 && fo_multibyte
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5891 && curwin->w_cursor.col <= (colnr_T)wantcol)
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5892 {
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5893 /* Break after or before a multi-byte character. */
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5894 foundcol = curwin->w_cursor.col;
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5895 if (curwin->w_cursor.col < (colnr_T)wantcol)
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5896 foundcol += (*mb_char2len)(cc);
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5897 end_foundcol = foundcol;
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5898 break;
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5899 }
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5900 #endif
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5901 if (curwin->w_cursor.col == 0)
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5902 break;
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5903 dec_cursor();
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5904 }
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5905
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5906 if (foundcol == 0) /* no spaces, cannot break line */
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5907 {
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5908 curwin->w_cursor.col = startcol;
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5909 break;
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5910 }
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5911
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5912 /* Going to break the line, remove any "$" now. */
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5913 undisplay_dollar();
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5914
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5915 /*
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5916 * Offset between cursor position and line break is used by replace
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5917 * stack functions. VREPLACE does not use this, and backspaces
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5918 * over the text instead.
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5919 */
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5920 #ifdef FEAT_VREPLACE
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5921 if (State & VREPLACE_FLAG)
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5922 orig_col = startcol; /* Will start backspacing from here */
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5923 else
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5924 #endif
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5925 replace_offset = startcol - end_foundcol - 1;
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5926
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5927 /*
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5928 * adjust startcol for spaces that will be deleted and
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5929 * characters that will remain on top line
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5930 */
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5931 curwin->w_cursor.col = foundcol;
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5932 while (cc = gchar_cursor(), WHITECHAR(cc))
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5933 inc_cursor();
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5934 startcol -= curwin->w_cursor.col;
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5935 if (startcol < 0)
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5936 startcol = 0;
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5937
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5938 #ifdef FEAT_VREPLACE
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5939 if (State & VREPLACE_FLAG)
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5940 {
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5941 /*
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5942 * In VREPLACE mode, we will backspace over the text to be
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5943 * wrapped, so save a copy now to put on the next line.
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5944 */
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5945 saved_text = vim_strsave(ml_get_cursor());
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5946 curwin->w_cursor.col = orig_col;
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5947 if (saved_text == NULL)
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5948 break; /* Can't do it, out of memory */
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5949 saved_text[startcol] = NUL;
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5950
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5951 /* Backspace over characters that will move to the next line */
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5952 if (!fo_white_par)
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5953 backspace_until_column(foundcol);
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5954 }
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5955 else
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5956 #endif
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5957 {
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5958 /* put cursor after pos. to break line */
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5959 if (!fo_white_par)
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5960 curwin->w_cursor.col = foundcol;
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5961 }
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5962
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5963 /*
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5964 * Split the line just before the margin.
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5965 * Only insert/delete lines, but don't really redraw the window.
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5966 */
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5967 open_line(FORWARD, OPENLINE_DELSPACES + OPENLINE_MARKFIX
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5968 + (fo_white_par ? OPENLINE_KEEPTRAIL : 0)
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5969 #ifdef FEAT_COMMENTS
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5970 + (do_comments ? OPENLINE_DO_COM : 0)
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5971 #endif
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5972 , old_indent);
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5973 old_indent = 0;
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5974
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5975 replace_offset = 0;
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5976 if (first_line)
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5977 {
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5978 if (second_indent < 0 && has_format_option(FO_Q_NUMBER))
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5979 second_indent = get_number_indent(curwin->w_cursor.lnum -1);
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5980 if (second_indent >= 0)
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5981 {
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5982 #ifdef FEAT_VREPLACE
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5983 if (State & VREPLACE_FLAG)
1516
ee9d2d24ea9b updated for version 7.1-231
vimboss
parents: 1514
diff changeset
5984 change_indent(INDENT_SET, second_indent, FALSE, NUL, TRUE);
667
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5985 else
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5986 #endif
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5987 (void)set_indent(second_indent, SIN_CHANGED);
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5988 }
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5989 first_line = FALSE;
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5990 }
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5991
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5992 #ifdef FEAT_VREPLACE
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5993 if (State & VREPLACE_FLAG)
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5994 {
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5995 /*
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5996 * In VREPLACE mode we have backspaced over the text to be
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5997 * moved, now we re-insert it into the new line.
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5998 */
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
5999 ins_bytes(saved_text);
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
6000 vim_free(saved_text);
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
6001 }
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
6002 else
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
6003 #endif
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
6004 {
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
6005 /*
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
6006 * Check if cursor is not past the NUL off the line, cindent
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
6007 * may have added or removed indent.
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
6008 */
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
6009 curwin->w_cursor.col += startcol;
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
6010 len = (colnr_T)STRLEN(ml_get_curline());
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
6011 if (curwin->w_cursor.col > len)
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
6012 curwin->w_cursor.col = len;
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
6013 }
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
6014
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
6015 haveto_redraw = TRUE;
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
6016 #ifdef FEAT_CINDENT
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
6017 can_cindent = TRUE;
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
6018 #endif
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
6019 /* moved the cursor, don't autoindent or cindent now */
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
6020 did_ai = FALSE;
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
6021 #ifdef FEAT_SMARTINDENT
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
6022 did_si = FALSE;
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
6023 can_si = FALSE;
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
6024 can_si_back = FALSE;
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
6025 #endif
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
6026 line_breakcheck();
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
6027 }
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
6028
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
6029 if (save_char != NUL) /* put back space after cursor */
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
6030 pchar_cursor(save_char);
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
6031
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
6032 if (!format_only && haveto_redraw)
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
6033 {
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
6034 update_topline();
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
6035 redraw_curbuf_later(VALID);
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
6036 }
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
6037 }
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
6038
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
6039 /*
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6040 * Called after inserting or deleting text: When 'formatoptions' includes the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6041 * 'a' flag format from the current line until the end of the paragraph.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6042 * Keep the cursor at the same position relative to the text.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6043 * The caller must have saved the cursor line for undo, following ones will be
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6044 * saved here.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6045 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6046 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6047 auto_format(trailblank, prev_line)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6048 int trailblank; /* when TRUE also format with trailing blank */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6049 int prev_line; /* may start in previous line */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6050 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6051 pos_T pos;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6052 colnr_T len;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6053 char_u *old;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6054 char_u *new, *pnew;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6055 int wasatend;
301
006e9c8a6a8a updated for version 7.0079
vimboss
parents: 298
diff changeset
6056 int cc;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6057
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6058 if (!has_format_option(FO_AUTO))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6059 return;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6060
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6061 pos = curwin->w_cursor;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6062 old = ml_get_curline();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6063
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6064 /* may remove added space */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6065 check_auto_format(FALSE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6066
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6067 /* Don't format in Insert mode when the cursor is on a trailing blank, the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6068 * user might insert normal text next. Also skip formatting when "1" is
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6069 * in 'formatoptions' and there is a single character before the cursor.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6070 * Otherwise the line would be broken and when typing another non-white
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6071 * next they are not joined back together. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6072 wasatend = (pos.col == STRLEN(old));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6073 if (*old != NUL && !trailblank && wasatend)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6074 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6075 dec_cursor();
301
006e9c8a6a8a updated for version 7.0079
vimboss
parents: 298
diff changeset
6076 cc = gchar_cursor();
006e9c8a6a8a updated for version 7.0079
vimboss
parents: 298
diff changeset
6077 if (!WHITECHAR(cc) && curwin->w_cursor.col > 0
006e9c8a6a8a updated for version 7.0079
vimboss
parents: 298
diff changeset
6078 && has_format_option(FO_ONE_LETTER))
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6079 dec_cursor();
301
006e9c8a6a8a updated for version 7.0079
vimboss
parents: 298
diff changeset
6080 cc = gchar_cursor();
006e9c8a6a8a updated for version 7.0079
vimboss
parents: 298
diff changeset
6081 if (WHITECHAR(cc))
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6082 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6083 curwin->w_cursor = pos;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6084 return;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6085 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6086 curwin->w_cursor = pos;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6087 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6088
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6089 #ifdef FEAT_COMMENTS
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6090 /* With the 'c' flag in 'formatoptions' and 't' missing: only format
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6091 * comments. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6092 if (has_format_option(FO_WRAP_COMS) && !has_format_option(FO_WRAP)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6093 && get_leader_len(old, NULL, FALSE) == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6094 return;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6095 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6096
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6097 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6098 * May start formatting in a previous line, so that after "x" a word is
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6099 * moved to the previous line if it fits there now. Only when this is not
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6100 * the start of a paragraph.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6101 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6102 if (prev_line && !paragraph_start(curwin->w_cursor.lnum))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6103 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6104 --curwin->w_cursor.lnum;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6105 if (u_save_cursor() == FAIL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6106 return;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6107 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6108
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6109 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6110 * Do the formatting and restore the cursor position. "saved_cursor" will
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6111 * be adjusted for the text formatting.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6112 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6113 saved_cursor = pos;
1563
ed7fefbef738 updated for version 7.1-276
vimboss
parents: 1526
diff changeset
6114 format_lines((linenr_T)-1, FALSE);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6115 curwin->w_cursor = saved_cursor;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6116 saved_cursor.lnum = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6117
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6118 if (curwin->w_cursor.lnum > curbuf->b_ml.ml_line_count)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6119 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6120 /* "cannot happen" */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6121 curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6122 coladvance((colnr_T)MAXCOL);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6123 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6124 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6125 check_cursor_col();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6126
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6127 /* Insert mode: If the cursor is now after the end of the line while it
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6128 * previously wasn't, the line was broken. Because of the rule above we
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6129 * need to add a space when 'w' is in 'formatoptions' to keep a paragraph
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6130 * formatted. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6131 if (!wasatend && has_format_option(FO_WHITE_PAR))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6132 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6133 new = ml_get_curline();
835
8bebcabccc2c updated for version 7.0e01
vimboss
parents: 829
diff changeset
6134 len = (colnr_T)STRLEN(new);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6135 if (curwin->w_cursor.col == len)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6136 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6137 pnew = vim_strnsave(new, len + 2);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6138 pnew[len] = ' ';
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6139 pnew[len + 1] = NUL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6140 ml_replace(curwin->w_cursor.lnum, pnew, FALSE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6141 /* remove the space later */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6142 did_add_space = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6143 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6144 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6145 /* may remove added space */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6146 check_auto_format(FALSE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6147 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6148
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6149 check_cursor();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6150 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6151
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6152 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6153 * When an extra space was added to continue a paragraph for auto-formatting,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6154 * delete it now. The space must be under the cursor, just after the insert
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6155 * position.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6156 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6157 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6158 check_auto_format(end_insert)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6159 int end_insert; /* TRUE when ending Insert mode */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6160 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6161 int c = ' ';
301
006e9c8a6a8a updated for version 7.0079
vimboss
parents: 298
diff changeset
6162 int cc;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6163
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6164 if (did_add_space)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6165 {
301
006e9c8a6a8a updated for version 7.0079
vimboss
parents: 298
diff changeset
6166 cc = gchar_cursor();
006e9c8a6a8a updated for version 7.0079
vimboss
parents: 298
diff changeset
6167 if (!WHITECHAR(cc))
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6168 /* Somehow the space was removed already. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6169 did_add_space = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6170 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6171 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6172 if (!end_insert)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6173 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6174 inc_cursor();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6175 c = gchar_cursor();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6176 dec_cursor();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6177 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6178 if (c != NUL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6179 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6180 /* The space is no longer at the end of the line, delete it. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6181 del_char(FALSE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6182 did_add_space = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6183 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6184 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6185 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6186 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6187
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6188 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6189 * Find out textwidth to be used for formatting:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6190 * if 'textwidth' option is set, use it
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6191 * else if 'wrapmargin' option is set, use W_WIDTH(curwin) - 'wrapmargin'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6192 * if invalid value, use 0.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6193 * Set default to window width (maximum 79) for "gq" operator.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6194 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6195 int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6196 comp_textwidth(ff)
867
a5677b7ce858 updated for version 7.0g04
vimboss
parents: 864
diff changeset
6197 int ff; /* force formatting (for "gq" command) */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6198 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6199 int textwidth;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6200
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6201 textwidth = curbuf->b_p_tw;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6202 if (textwidth == 0 && curbuf->b_p_wm)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6203 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6204 /* The width is the window width minus 'wrapmargin' minus all the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6205 * things that add to the margin. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6206 textwidth = W_WIDTH(curwin) - curbuf->b_p_wm;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6207 #ifdef FEAT_CMDWIN
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6208 if (cmdwin_type != 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6209 textwidth -= 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6210 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6211 #ifdef FEAT_FOLDING
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6212 textwidth -= curwin->w_p_fdc;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6213 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6214 #ifdef FEAT_SIGNS
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6215 if (curwin->w_buffer->b_signlist != NULL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6216 # ifdef FEAT_NETBEANS_INTG
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6217 || usingNetbeans
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6218 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6219 )
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6220 textwidth -= 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6221 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6222 if (curwin->w_p_nu)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6223 textwidth -= 8;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6224 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6225 if (textwidth < 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6226 textwidth = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6227 if (ff && textwidth == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6228 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6229 textwidth = W_WIDTH(curwin) - 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6230 if (textwidth > 79)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6231 textwidth = 79;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6232 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6233 return textwidth;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6234 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6235
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6236 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6237 * Put a character in the redo buffer, for when just after a CTRL-V.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6238 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6239 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6240 redo_literal(c)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6241 int c;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6242 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6243 char_u buf[10];
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6244
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6245 /* Only digits need special treatment. Translate them into a string of
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6246 * three digits. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6247 if (VIM_ISDIGIT(c))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6248 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6249 sprintf((char *)buf, "%03d", c);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6250 AppendToRedobuff(buf);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6251 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6252 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6253 AppendCharToRedobuff(c);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6254 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6255
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6256 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6257 * start_arrow() is called when an arrow key is used in insert mode.
484
f012c4ed8c38 updated for version 7.0132
vimboss
parents: 477
diff changeset
6258 * For undo/redo it resembles hitting the <ESC> key.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6259 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6260 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6261 start_arrow(end_insert_pos)
840
2c885fab04e3 updated for version 7.0e06
vimboss
parents: 836
diff changeset
6262 pos_T *end_insert_pos; /* can be NULL */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6263 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6264 if (!arrow_used) /* something has been inserted */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6265 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6266 AppendToRedobuff(ESC_STR);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6267 stop_insert(end_insert_pos, FALSE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6268 arrow_used = TRUE; /* this means we stopped the current insert */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6269 }
744
07f7b4a7755c updated for version 7.0222
vimboss
parents: 732
diff changeset
6270 #ifdef FEAT_SPELL
221
7fd4b5df33be updated for version 7.0062
vimboss
parents: 180
diff changeset
6271 check_spell_redraw();
7fd4b5df33be updated for version 7.0062
vimboss
parents: 180
diff changeset
6272 #endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6273 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6274
744
07f7b4a7755c updated for version 7.0222
vimboss
parents: 732
diff changeset
6275 #ifdef FEAT_SPELL
221
7fd4b5df33be updated for version 7.0062
vimboss
parents: 180
diff changeset
6276 /*
7fd4b5df33be updated for version 7.0062
vimboss
parents: 180
diff changeset
6277 * If we skipped highlighting word at cursor, do it now.
7fd4b5df33be updated for version 7.0062
vimboss
parents: 180
diff changeset
6278 * It may be skipped again, thus reset spell_redraw_lnum first.
7fd4b5df33be updated for version 7.0062
vimboss
parents: 180
diff changeset
6279 */
7fd4b5df33be updated for version 7.0062
vimboss
parents: 180
diff changeset
6280 static void
7fd4b5df33be updated for version 7.0062
vimboss
parents: 180
diff changeset
6281 check_spell_redraw()
7fd4b5df33be updated for version 7.0062
vimboss
parents: 180
diff changeset
6282 {
7fd4b5df33be updated for version 7.0062
vimboss
parents: 180
diff changeset
6283 if (spell_redraw_lnum != 0)
7fd4b5df33be updated for version 7.0062
vimboss
parents: 180
diff changeset
6284 {
7fd4b5df33be updated for version 7.0062
vimboss
parents: 180
diff changeset
6285 linenr_T lnum = spell_redraw_lnum;
7fd4b5df33be updated for version 7.0062
vimboss
parents: 180
diff changeset
6286
7fd4b5df33be updated for version 7.0062
vimboss
parents: 180
diff changeset
6287 spell_redraw_lnum = 0;
7fd4b5df33be updated for version 7.0062
vimboss
parents: 180
diff changeset
6288 redrawWinline(lnum, FALSE);
7fd4b5df33be updated for version 7.0062
vimboss
parents: 180
diff changeset
6289 }
7fd4b5df33be updated for version 7.0062
vimboss
parents: 180
diff changeset
6290 }
484
f012c4ed8c38 updated for version 7.0132
vimboss
parents: 477
diff changeset
6291
f012c4ed8c38 updated for version 7.0132
vimboss
parents: 477
diff changeset
6292 /*
f012c4ed8c38 updated for version 7.0132
vimboss
parents: 477
diff changeset
6293 * Called when starting CTRL_X_SPELL mode: Move backwards to a previous badly
f012c4ed8c38 updated for version 7.0132
vimboss
parents: 477
diff changeset
6294 * spelled word, if there is one.
f012c4ed8c38 updated for version 7.0132
vimboss
parents: 477
diff changeset
6295 */
f012c4ed8c38 updated for version 7.0132
vimboss
parents: 477
diff changeset
6296 static void
f012c4ed8c38 updated for version 7.0132
vimboss
parents: 477
diff changeset
6297 spell_back_to_badword()
f012c4ed8c38 updated for version 7.0132
vimboss
parents: 477
diff changeset
6298 {
f012c4ed8c38 updated for version 7.0132
vimboss
parents: 477
diff changeset
6299 pos_T tpos = curwin->w_cursor;
f012c4ed8c38 updated for version 7.0132
vimboss
parents: 477
diff changeset
6300
499
08012a1ff8d4 updated for version 7.0137
vimboss
parents: 497
diff changeset
6301 spell_bad_len = spell_move_to(curwin, BACKWARD, TRUE, TRUE, NULL);
484
f012c4ed8c38 updated for version 7.0132
vimboss
parents: 477
diff changeset
6302 if (curwin->w_cursor.col != tpos.col)
f012c4ed8c38 updated for version 7.0132
vimboss
parents: 477
diff changeset
6303 start_arrow(&tpos);
f012c4ed8c38 updated for version 7.0132
vimboss
parents: 477
diff changeset
6304 }
221
7fd4b5df33be updated for version 7.0062
vimboss
parents: 180
diff changeset
6305 #endif
7fd4b5df33be updated for version 7.0062
vimboss
parents: 180
diff changeset
6306
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6307 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6308 * stop_arrow() is called before a change is made in insert mode.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6309 * If an arrow key has been used, start a new insertion.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6310 * Returns FAIL if undo is impossible, shouldn't insert then.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6311 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6312 int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6313 stop_arrow()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6314 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6315 if (arrow_used)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6316 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6317 if (u_save_cursor() == OK)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6318 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6319 arrow_used = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6320 ins_need_undo = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6321 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6322 Insstart = curwin->w_cursor; /* new insertion starts here */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6323 Insstart_textlen = linetabsize(ml_get_curline());
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6324 ai_col = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6325 #ifdef FEAT_VREPLACE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6326 if (State & VREPLACE_FLAG)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6327 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6328 orig_line_count = curbuf->b_ml.ml_line_count;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6329 vr_lines_changed = 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6330 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6331 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6332 ResetRedobuff();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6333 AppendToRedobuff((char_u *)"1i"); /* pretend we start an insertion */
613
53114ef7778f updated for version 7.0174
vimboss
parents: 610
diff changeset
6334 new_insert_skip = 2;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6335 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6336 else if (ins_need_undo)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6337 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6338 if (u_save_cursor() == OK)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6339 ins_need_undo = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6340 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6341
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6342 #ifdef FEAT_FOLDING
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6343 /* Always open fold at the cursor line when inserting something. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6344 foldOpenCursor();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6345 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6346
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6347 return (arrow_used || ins_need_undo ? FAIL : OK);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6348 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6349
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6350 /*
840
2c885fab04e3 updated for version 7.0e06
vimboss
parents: 836
diff changeset
6351 * Do a few things to stop inserting.
2c885fab04e3 updated for version 7.0e06
vimboss
parents: 836
diff changeset
6352 * "end_insert_pos" is where insert ended. It is NULL when we already jumped
2c885fab04e3 updated for version 7.0e06
vimboss
parents: 836
diff changeset
6353 * to another window/buffer.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6354 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6355 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6356 stop_insert(end_insert_pos, esc)
840
2c885fab04e3 updated for version 7.0e06
vimboss
parents: 836
diff changeset
6357 pos_T *end_insert_pos;
603
e4c00ec07598 updated for version 7.0171
vimboss
parents: 574
diff changeset
6358 int esc; /* called by ins_esc() */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6359 {
603
e4c00ec07598 updated for version 7.0171
vimboss
parents: 574
diff changeset
6360 int cc;
e4c00ec07598 updated for version 7.0171
vimboss
parents: 574
diff changeset
6361 char_u *ptr;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6362
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6363 stop_redo_ins();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6364 replace_flush(); /* abandon replace stack */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6365
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6366 /*
603
e4c00ec07598 updated for version 7.0171
vimboss
parents: 574
diff changeset
6367 * Save the inserted text for later redo with ^@ and CTRL-A.
e4c00ec07598 updated for version 7.0171
vimboss
parents: 574
diff changeset
6368 * Don't do it when "restart_edit" was set and nothing was inserted,
e4c00ec07598 updated for version 7.0171
vimboss
parents: 574
diff changeset
6369 * otherwise CTRL-O w and then <Left> will clear "last_insert".
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6370 */
603
e4c00ec07598 updated for version 7.0171
vimboss
parents: 574
diff changeset
6371 ptr = get_inserted();
615
7fe13e0f5dce updated for version 7.0175
vimboss
parents: 613
diff changeset
6372 if (did_restart_edit == 0 || (ptr != NULL
7fe13e0f5dce updated for version 7.0175
vimboss
parents: 613
diff changeset
6373 && (int)STRLEN(ptr) > new_insert_skip))
603
e4c00ec07598 updated for version 7.0171
vimboss
parents: 574
diff changeset
6374 {
e4c00ec07598 updated for version 7.0171
vimboss
parents: 574
diff changeset
6375 vim_free(last_insert);
e4c00ec07598 updated for version 7.0171
vimboss
parents: 574
diff changeset
6376 last_insert = ptr;
e4c00ec07598 updated for version 7.0171
vimboss
parents: 574
diff changeset
6377 last_insert_skip = new_insert_skip;
e4c00ec07598 updated for version 7.0171
vimboss
parents: 574
diff changeset
6378 }
e4c00ec07598 updated for version 7.0171
vimboss
parents: 574
diff changeset
6379 else
e4c00ec07598 updated for version 7.0171
vimboss
parents: 574
diff changeset
6380 vim_free(ptr);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6381
840
2c885fab04e3 updated for version 7.0e06
vimboss
parents: 836
diff changeset
6382 if (!arrow_used && end_insert_pos != NULL)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6383 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6384 /* Auto-format now. It may seem strange to do this when stopping an
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6385 * insertion (or moving the cursor), but it's required when appending
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6386 * a line and having it end in a space. But only do it when something
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6387 * was actually inserted, otherwise undo won't work. */
10
4e2284e71352 updated for version 7.0002
vimboss
parents: 7
diff changeset
6388 if (!ins_need_undo && has_format_option(FO_AUTO))
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6389 {
10
4e2284e71352 updated for version 7.0002
vimboss
parents: 7
diff changeset
6390 pos_T tpos = curwin->w_cursor;
4e2284e71352 updated for version 7.0002
vimboss
parents: 7
diff changeset
6391
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6392 /* When the cursor is at the end of the line after a space the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6393 * formatting will move it to the following word. Avoid that by
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6394 * moving the cursor onto the space. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6395 cc = 'x';
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6396 if (curwin->w_cursor.col > 0 && gchar_cursor() == NUL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6397 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6398 dec_cursor();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6399 cc = gchar_cursor();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6400 if (!vim_iswhite(cc))
10
4e2284e71352 updated for version 7.0002
vimboss
parents: 7
diff changeset
6401 curwin->w_cursor = tpos;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6402 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6403
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6404 auto_format(TRUE, FALSE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6405
10
4e2284e71352 updated for version 7.0002
vimboss
parents: 7
diff changeset
6406 if (vim_iswhite(cc))
4e2284e71352 updated for version 7.0002
vimboss
parents: 7
diff changeset
6407 {
4e2284e71352 updated for version 7.0002
vimboss
parents: 7
diff changeset
6408 if (gchar_cursor() != NUL)
4e2284e71352 updated for version 7.0002
vimboss
parents: 7
diff changeset
6409 inc_cursor();
4e2284e71352 updated for version 7.0002
vimboss
parents: 7
diff changeset
6410 #ifdef FEAT_VIRTUALEDIT
4e2284e71352 updated for version 7.0002
vimboss
parents: 7
diff changeset
6411 /* If the cursor is still at the same character, also keep
4e2284e71352 updated for version 7.0002
vimboss
parents: 7
diff changeset
6412 * the "coladd". */
4e2284e71352 updated for version 7.0002
vimboss
parents: 7
diff changeset
6413 if (gchar_cursor() == NUL
4e2284e71352 updated for version 7.0002
vimboss
parents: 7
diff changeset
6414 && curwin->w_cursor.lnum == tpos.lnum
4e2284e71352 updated for version 7.0002
vimboss
parents: 7
diff changeset
6415 && curwin->w_cursor.col == tpos.col)
4e2284e71352 updated for version 7.0002
vimboss
parents: 7
diff changeset
6416 curwin->w_cursor.coladd = tpos.coladd;
4e2284e71352 updated for version 7.0002
vimboss
parents: 7
diff changeset
6417 #endif
4e2284e71352 updated for version 7.0002
vimboss
parents: 7
diff changeset
6418 }
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6419 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6420
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6421 /* If a space was inserted for auto-formatting, remove it now. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6422 check_auto_format(TRUE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6423
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6424 /* If we just did an auto-indent, remove the white space from the end
10
4e2284e71352 updated for version 7.0002
vimboss
parents: 7
diff changeset
6425 * of the line, and put the cursor back.
4e2284e71352 updated for version 7.0002
vimboss
parents: 7
diff changeset
6426 * Do this when ESC was used or moving the cursor up/down. */
4e2284e71352 updated for version 7.0002
vimboss
parents: 7
diff changeset
6427 if (did_ai && (esc || (vim_strchr(p_cpo, CPO_INDENT) == NULL
840
2c885fab04e3 updated for version 7.0e06
vimboss
parents: 836
diff changeset
6428 && curwin->w_cursor.lnum != end_insert_pos->lnum)))
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6429 {
10
4e2284e71352 updated for version 7.0002
vimboss
parents: 7
diff changeset
6430 pos_T tpos = curwin->w_cursor;
4e2284e71352 updated for version 7.0002
vimboss
parents: 7
diff changeset
6431
4e2284e71352 updated for version 7.0002
vimboss
parents: 7
diff changeset
6432 curwin->w_cursor = *end_insert_pos;
786
8f6a426bc1e0 updated for version 7.0229
vimboss
parents: 782
diff changeset
6433 for (;;)
8f6a426bc1e0 updated for version 7.0229
vimboss
parents: 782
diff changeset
6434 {
8f6a426bc1e0 updated for version 7.0229
vimboss
parents: 782
diff changeset
6435 if (gchar_cursor() == NUL && curwin->w_cursor.col > 0)
8f6a426bc1e0 updated for version 7.0229
vimboss
parents: 782
diff changeset
6436 --curwin->w_cursor.col;
8f6a426bc1e0 updated for version 7.0229
vimboss
parents: 782
diff changeset
6437 cc = gchar_cursor();
8f6a426bc1e0 updated for version 7.0229
vimboss
parents: 782
diff changeset
6438 if (!vim_iswhite(cc))
8f6a426bc1e0 updated for version 7.0229
vimboss
parents: 782
diff changeset
6439 break;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6440 (void)del_char(TRUE);
786
8f6a426bc1e0 updated for version 7.0229
vimboss
parents: 782
diff changeset
6441 }
10
4e2284e71352 updated for version 7.0002
vimboss
parents: 7
diff changeset
6442 if (curwin->w_cursor.lnum != tpos.lnum)
4e2284e71352 updated for version 7.0002
vimboss
parents: 7
diff changeset
6443 curwin->w_cursor = tpos;
4e2284e71352 updated for version 7.0002
vimboss
parents: 7
diff changeset
6444 else if (cc != NUL)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6445 ++curwin->w_cursor.col; /* put cursor back on the NUL */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6446
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6447 #ifdef FEAT_VISUAL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6448 /* <C-S-Right> may have started Visual mode, adjust the position for
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6449 * deleted characters. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6450 if (VIsual_active && VIsual.lnum == curwin->w_cursor.lnum)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6451 {
835
8bebcabccc2c updated for version 7.0e01
vimboss
parents: 829
diff changeset
6452 cc = (int)STRLEN(ml_get_curline());
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6453 if (VIsual.col > (colnr_T)cc)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6454 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6455 VIsual.col = cc;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6456 # ifdef FEAT_VIRTUALEDIT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6457 VIsual.coladd = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6458 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6459 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6460 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6461 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6462 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6463 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6464 did_ai = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6465 #ifdef FEAT_SMARTINDENT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6466 did_si = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6467 can_si = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6468 can_si_back = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6469 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6470
840
2c885fab04e3 updated for version 7.0e06
vimboss
parents: 836
diff changeset
6471 /* Set '[ and '] to the inserted text. When end_insert_pos is NULL we are
2c885fab04e3 updated for version 7.0e06
vimboss
parents: 836
diff changeset
6472 * now in a different buffer. */
2c885fab04e3 updated for version 7.0e06
vimboss
parents: 836
diff changeset
6473 if (end_insert_pos != NULL)
2c885fab04e3 updated for version 7.0e06
vimboss
parents: 836
diff changeset
6474 {
2c885fab04e3 updated for version 7.0e06
vimboss
parents: 836
diff changeset
6475 curbuf->b_op_start = Insstart;
2c885fab04e3 updated for version 7.0e06
vimboss
parents: 836
diff changeset
6476 curbuf->b_op_end = *end_insert_pos;
2c885fab04e3 updated for version 7.0e06
vimboss
parents: 836
diff changeset
6477 }
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6478 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6479
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6480 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6481 * Set the last inserted text to a single character.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6482 * Used for the replace command.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6483 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6484 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6485 set_last_insert(c)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6486 int c;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6487 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6488 char_u *s;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6489
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6490 vim_free(last_insert);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6491 #ifdef FEAT_MBYTE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6492 last_insert = alloc(MB_MAXBYTES * 3 + 5);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6493 #else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6494 last_insert = alloc(6);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6495 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6496 if (last_insert != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6497 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6498 s = last_insert;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6499 /* Use the CTRL-V only when entering a special char */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6500 if (c < ' ' || c == DEL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6501 *s++ = Ctrl_V;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6502 s = add_char2buf(c, s);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6503 *s++ = ESC;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6504 *s++ = NUL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6505 last_insert_skip = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6506 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6507 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6508
359
6c62b9b939bd updated for version 7.0093
vimboss
parents: 301
diff changeset
6509 #if defined(EXITFREE) || defined(PROTO)
6c62b9b939bd updated for version 7.0093
vimboss
parents: 301
diff changeset
6510 void
6c62b9b939bd updated for version 7.0093
vimboss
parents: 301
diff changeset
6511 free_last_insert()
6c62b9b939bd updated for version 7.0093
vimboss
parents: 301
diff changeset
6512 {
6c62b9b939bd updated for version 7.0093
vimboss
parents: 301
diff changeset
6513 vim_free(last_insert);
6c62b9b939bd updated for version 7.0093
vimboss
parents: 301
diff changeset
6514 last_insert = NULL;
1446
f0b3b9ac2147 updated for version 7.1-161
vimboss
parents: 1436
diff changeset
6515 # ifdef FEAT_INS_EXPAND
694
07d199fe02ed updated for version 7.0209
vimboss
parents: 692
diff changeset
6516 vim_free(compl_orig_text);
07d199fe02ed updated for version 7.0209
vimboss
parents: 692
diff changeset
6517 compl_orig_text = NULL;
1446
f0b3b9ac2147 updated for version 7.1-161
vimboss
parents: 1436
diff changeset
6518 # endif
359
6c62b9b939bd updated for version 7.0093
vimboss
parents: 301
diff changeset
6519 }
6c62b9b939bd updated for version 7.0093
vimboss
parents: 301
diff changeset
6520 #endif
6c62b9b939bd updated for version 7.0093
vimboss
parents: 301
diff changeset
6521
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6522 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6523 * Add character "c" to buffer "s". Escape the special meaning of K_SPECIAL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6524 * and CSI. Handle multi-byte characters.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6525 * Returns a pointer to after the added bytes.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6526 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6527 char_u *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6528 add_char2buf(c, s)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6529 int c;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6530 char_u *s;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6531 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6532 #ifdef FEAT_MBYTE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6533 char_u temp[MB_MAXBYTES];
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6534 int i;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6535 int len;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6536
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6537 len = (*mb_char2bytes)(c, temp);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6538 for (i = 0; i < len; ++i)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6539 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6540 c = temp[i];
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6541 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6542 /* Need to escape K_SPECIAL and CSI like in the typeahead buffer. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6543 if (c == K_SPECIAL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6544 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6545 *s++ = K_SPECIAL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6546 *s++ = KS_SPECIAL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6547 *s++ = KE_FILLER;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6548 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6549 #ifdef FEAT_GUI
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6550 else if (c == CSI)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6551 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6552 *s++ = CSI;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6553 *s++ = KS_EXTRA;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6554 *s++ = (int)KE_CSI;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6555 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6556 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6557 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6558 *s++ = c;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6559 #ifdef FEAT_MBYTE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6560 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6561 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6562 return s;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6563 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6564
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6565 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6566 * move cursor to start of line
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6567 * if flags & BL_WHITE move to first non-white
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6568 * if flags & BL_SOL move to first non-white if startofline is set,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6569 * otherwise keep "curswant" column
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6570 * if flags & BL_FIX don't leave the cursor on a NUL.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6571 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6572 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6573 beginline(flags)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6574 int flags;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6575 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6576 if ((flags & BL_SOL) && !p_sol)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6577 coladvance(curwin->w_curswant);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6578 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6579 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6580 curwin->w_cursor.col = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6581 #ifdef FEAT_VIRTUALEDIT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6582 curwin->w_cursor.coladd = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6583 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6584
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6585 if (flags & (BL_WHITE | BL_SOL))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6586 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6587 char_u *ptr;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6588
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6589 for (ptr = ml_get_curline(); vim_iswhite(*ptr)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6590 && !((flags & BL_FIX) && ptr[1] == NUL); ++ptr)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6591 ++curwin->w_cursor.col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6592 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6593 curwin->w_set_curswant = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6594 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6595 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6596
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6597 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6598 * oneright oneleft cursor_down cursor_up
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6599 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6600 * Move one char {right,left,down,up}.
773
8c9ef63b1ccc updated for version 7.0226
vimboss
parents: 767
diff changeset
6601 * Doesn't move onto the NUL past the end of the line, unless it is allowed.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6602 * Return OK when successful, FAIL when we hit a line of file boundary.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6603 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6604
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6605 int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6606 oneright()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6607 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6608 char_u *ptr;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6609 int l;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6610
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6611 #ifdef FEAT_VIRTUALEDIT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6612 if (virtual_active())
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6613 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6614 pos_T prevpos = curwin->w_cursor;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6615
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6616 /* Adjust for multi-wide char (excluding TAB) */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6617 ptr = ml_get_cursor();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6618 coladvance(getviscol() + ((*ptr != TAB && vim_isprintc(
773
8c9ef63b1ccc updated for version 7.0226
vimboss
parents: 767
diff changeset
6619 # ifdef FEAT_MBYTE
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6620 (*mb_ptr2char)(ptr)
773
8c9ef63b1ccc updated for version 7.0226
vimboss
parents: 767
diff changeset
6621 # else
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6622 *ptr
773
8c9ef63b1ccc updated for version 7.0226
vimboss
parents: 767
diff changeset
6623 # endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6624 ))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6625 ? ptr2cells(ptr) : 1));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6626 curwin->w_set_curswant = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6627 /* Return OK if the cursor moved, FAIL otherwise (at window edge). */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6628 return (prevpos.col != curwin->w_cursor.col
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6629 || prevpos.coladd != curwin->w_cursor.coladd) ? OK : FAIL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6630 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6631 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6632
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6633 ptr = ml_get_cursor();
773
8c9ef63b1ccc updated for version 7.0226
vimboss
parents: 767
diff changeset
6634 if (*ptr == NUL)
8c9ef63b1ccc updated for version 7.0226
vimboss
parents: 767
diff changeset
6635 return FAIL; /* already at the very end */
8c9ef63b1ccc updated for version 7.0226
vimboss
parents: 767
diff changeset
6636
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6637 #ifdef FEAT_MBYTE
773
8c9ef63b1ccc updated for version 7.0226
vimboss
parents: 767
diff changeset
6638 if (has_mbyte)
8c9ef63b1ccc updated for version 7.0226
vimboss
parents: 767
diff changeset
6639 l = (*mb_ptr2len)(ptr);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6640 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6641 #endif
773
8c9ef63b1ccc updated for version 7.0226
vimboss
parents: 767
diff changeset
6642 l = 1;
8c9ef63b1ccc updated for version 7.0226
vimboss
parents: 767
diff changeset
6643
8c9ef63b1ccc updated for version 7.0226
vimboss
parents: 767
diff changeset
6644 /* move "l" bytes right, but don't end up on the NUL, unless 'virtualedit'
8c9ef63b1ccc updated for version 7.0226
vimboss
parents: 767
diff changeset
6645 * contains "onemore". */
8c9ef63b1ccc updated for version 7.0226
vimboss
parents: 767
diff changeset
6646 if (ptr[l] == NUL
8c9ef63b1ccc updated for version 7.0226
vimboss
parents: 767
diff changeset
6647 #ifdef FEAT_VIRTUALEDIT
8c9ef63b1ccc updated for version 7.0226
vimboss
parents: 767
diff changeset
6648 && (ve_flags & VE_ONEMORE) == 0
8c9ef63b1ccc updated for version 7.0226
vimboss
parents: 767
diff changeset
6649 #endif
8c9ef63b1ccc updated for version 7.0226
vimboss
parents: 767
diff changeset
6650 )
8c9ef63b1ccc updated for version 7.0226
vimboss
parents: 767
diff changeset
6651 return FAIL;
8c9ef63b1ccc updated for version 7.0226
vimboss
parents: 767
diff changeset
6652 curwin->w_cursor.col += l;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6653
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6654 curwin->w_set_curswant = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6655 return OK;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6656 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6657
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6658 int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6659 oneleft()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6660 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6661 #ifdef FEAT_VIRTUALEDIT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6662 if (virtual_active())
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6663 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6664 int width;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6665 int v = getviscol();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6666
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6667 if (v == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6668 return FAIL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6669
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6670 # ifdef FEAT_LINEBREAK
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6671 /* We might get stuck on 'showbreak', skip over it. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6672 width = 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6673 for (;;)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6674 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6675 coladvance(v - width);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6676 /* getviscol() is slow, skip it when 'showbreak' is empty and
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6677 * there are no multi-byte characters */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6678 if ((*p_sbr == NUL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6679 # ifdef FEAT_MBYTE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6680 && !has_mbyte
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6681 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6682 ) || getviscol() < v)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6683 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6684 ++width;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6685 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6686 # else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6687 coladvance(v - 1);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6688 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6689
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6690 if (curwin->w_cursor.coladd == 1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6691 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6692 char_u *ptr;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6693
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6694 /* Adjust for multi-wide char (not a TAB) */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6695 ptr = ml_get_cursor();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6696 if (*ptr != TAB && vim_isprintc(
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6697 # ifdef FEAT_MBYTE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6698 (*mb_ptr2char)(ptr)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6699 # else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6700 *ptr
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6701 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6702 ) && ptr2cells(ptr) > 1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6703 curwin->w_cursor.coladd = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6704 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6705
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6706 curwin->w_set_curswant = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6707 return OK;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6708 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6709 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6710
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6711 if (curwin->w_cursor.col == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6712 return FAIL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6713
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6714 curwin->w_set_curswant = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6715 --curwin->w_cursor.col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6716
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6717 #ifdef FEAT_MBYTE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6718 /* if the character on the left of the current cursor is a multi-byte
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6719 * character, move to its first byte */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6720 if (has_mbyte)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6721 mb_adjust_cursor();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6722 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6723 return OK;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6724 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6725
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6726 int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6727 cursor_up(n, upd_topline)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6728 long n;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6729 int upd_topline; /* When TRUE: update topline */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6730 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6731 linenr_T lnum;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6732
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6733 if (n > 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6734 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6735 lnum = curwin->w_cursor.lnum;
161
6df0106fc595 updated for version 7.0049
vimboss
parents: 140
diff changeset
6736 /* This fails if the cursor is already in the first line or the count
6df0106fc595 updated for version 7.0049
vimboss
parents: 140
diff changeset
6737 * is larger than the line number and '-' is in 'cpoptions' */
6df0106fc595 updated for version 7.0049
vimboss
parents: 140
diff changeset
6738 if (lnum <= 1 || (n >= lnum && vim_strchr(p_cpo, CPO_MINUS) != NULL))
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6739 return FAIL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6740 if (n >= lnum)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6741 lnum = 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6742 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6743 #ifdef FEAT_FOLDING
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6744 if (hasAnyFolding(curwin))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6745 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6746 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6747 * Count each sequence of folded lines as one logical line.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6748 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6749 /* go to the the start of the current fold */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6750 (void)hasFolding(lnum, &lnum, NULL);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6751
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6752 while (n--)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6753 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6754 /* move up one line */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6755 --lnum;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6756 if (lnum <= 1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6757 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6758 /* If we entered a fold, move to the beginning, unless in
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6759 * Insert mode or when 'foldopen' contains "all": it will open
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6760 * in a moment. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6761 if (n > 0 || !((State & INSERT) || (fdo_flags & FDO_ALL)))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6762 (void)hasFolding(lnum, &lnum, NULL);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6763 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6764 if (lnum < 1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6765 lnum = 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6766 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6767 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6768 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6769 lnum -= n;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6770 curwin->w_cursor.lnum = lnum;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6771 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6772
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6773 /* try to advance to the column we want to be at */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6774 coladvance(curwin->w_curswant);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6775
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6776 if (upd_topline)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6777 update_topline(); /* make sure curwin->w_topline is valid */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6778
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6779 return OK;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6780 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6781
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6782 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6783 * Cursor down a number of logical lines.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6784 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6785 int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6786 cursor_down(n, upd_topline)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6787 long n;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6788 int upd_topline; /* When TRUE: update topline */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6789 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6790 linenr_T lnum;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6791
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6792 if (n > 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6793 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6794 lnum = curwin->w_cursor.lnum;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6795 #ifdef FEAT_FOLDING
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6796 /* Move to last line of fold, will fail if it's the end-of-file. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6797 (void)hasFolding(lnum, NULL, &lnum);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6798 #endif
161
6df0106fc595 updated for version 7.0049
vimboss
parents: 140
diff changeset
6799 /* This fails if the cursor is already in the last line or would move
6df0106fc595 updated for version 7.0049
vimboss
parents: 140
diff changeset
6800 * beyound the last line and '-' is in 'cpoptions' */
6df0106fc595 updated for version 7.0049
vimboss
parents: 140
diff changeset
6801 if (lnum >= curbuf->b_ml.ml_line_count
6df0106fc595 updated for version 7.0049
vimboss
parents: 140
diff changeset
6802 || (lnum + n > curbuf->b_ml.ml_line_count
6df0106fc595 updated for version 7.0049
vimboss
parents: 140
diff changeset
6803 && vim_strchr(p_cpo, CPO_MINUS) != NULL))
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6804 return FAIL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6805 if (lnum + n >= curbuf->b_ml.ml_line_count)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6806 lnum = curbuf->b_ml.ml_line_count;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6807 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6808 #ifdef FEAT_FOLDING
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6809 if (hasAnyFolding(curwin))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6810 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6811 linenr_T last;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6812
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6813 /* count each sequence of folded lines as one logical line */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6814 while (n--)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6815 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6816 if (hasFolding(lnum, NULL, &last))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6817 lnum = last + 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6818 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6819 ++lnum;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6820 if (lnum >= curbuf->b_ml.ml_line_count)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6821 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6822 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6823 if (lnum > curbuf->b_ml.ml_line_count)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6824 lnum = curbuf->b_ml.ml_line_count;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6825 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6826 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6827 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6828 lnum += n;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6829 curwin->w_cursor.lnum = lnum;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6830 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6831
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6832 /* try to advance to the column we want to be at */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6833 coladvance(curwin->w_curswant);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6834
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6835 if (upd_topline)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6836 update_topline(); /* make sure curwin->w_topline is valid */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6837
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6838 return OK;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6839 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6840
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6841 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6842 * Stuff the last inserted text in the read buffer.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6843 * Last_insert actually is a copy of the redo buffer, so we
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6844 * first have to remove the command.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6845 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6846 int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6847 stuff_inserted(c, count, no_esc)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6848 int c; /* Command character to be inserted */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6849 long count; /* Repeat this many times */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6850 int no_esc; /* Don't add an ESC at the end */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6851 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6852 char_u *esc_ptr;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6853 char_u *ptr;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6854 char_u *last_ptr;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6855 char_u last = NUL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6856
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6857 ptr = get_last_insert();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6858 if (ptr == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6859 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6860 EMSG(_(e_noinstext));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6861 return FAIL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6862 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6863
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6864 /* may want to stuff the command character, to start Insert mode */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6865 if (c != NUL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6866 stuffcharReadbuff(c);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6867 if ((esc_ptr = (char_u *)vim_strrchr(ptr, ESC)) != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6868 *esc_ptr = NUL; /* remove the ESC */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6869
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6870 /* when the last char is either "0" or "^" it will be quoted if no ESC
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6871 * comes after it OR if it will inserted more than once and "ptr"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6872 * starts with ^D. -- Acevedo
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6873 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6874 last_ptr = (esc_ptr ? esc_ptr : ptr + STRLEN(ptr)) - 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6875 if (last_ptr >= ptr && (*last_ptr == '0' || *last_ptr == '^')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6876 && (no_esc || (*ptr == Ctrl_D && count > 1)))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6877 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6878 last = *last_ptr;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6879 *last_ptr = NUL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6880 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6881
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6882 do
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6883 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6884 stuffReadbuff(ptr);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6885 /* a trailing "0" is inserted as "<C-V>048", "^" as "<C-V>^" */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6886 if (last)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6887 stuffReadbuff((char_u *)(last == '0'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6888 ? IF_EB("\026\060\064\070", CTRL_V_STR "xf0")
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6889 : IF_EB("\026^", CTRL_V_STR "^")));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6890 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6891 while (--count > 0);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6892
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6893 if (last)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6894 *last_ptr = last;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6895
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6896 if (esc_ptr != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6897 *esc_ptr = ESC; /* put the ESC back */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6898
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6899 /* may want to stuff a trailing ESC, to get out of Insert mode */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6900 if (!no_esc)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6901 stuffcharReadbuff(ESC);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6902
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6903 return OK;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6904 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6905
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6906 char_u *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6907 get_last_insert()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6908 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6909 if (last_insert == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6910 return NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6911 return last_insert + last_insert_skip;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6912 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6913
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6914 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6915 * Get last inserted string, and remove trailing <Esc>.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6916 * Returns pointer to allocated memory (must be freed) or NULL.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6917 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6918 char_u *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6919 get_last_insert_save()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6920 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6921 char_u *s;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6922 int len;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6923
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6924 if (last_insert == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6925 return NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6926 s = vim_strsave(last_insert + last_insert_skip);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6927 if (s != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6928 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6929 len = (int)STRLEN(s);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6930 if (len > 0 && s[len - 1] == ESC) /* remove trailing ESC */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6931 s[len - 1] = NUL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6932 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6933 return s;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6934 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6935
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6936 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6937 * Check the word in front of the cursor for an abbreviation.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6938 * Called when the non-id character "c" has been entered.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6939 * When an abbreviation is recognized it is removed from the text and
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6940 * the replacement string is inserted in typebuf.tb_buf[], followed by "c".
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6941 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6942 static int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6943 echeck_abbr(c)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6944 int c;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6945 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6946 /* Don't check for abbreviation in paste mode, when disabled and just
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6947 * after moving around with cursor keys. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6948 if (p_paste || no_abbr || arrow_used)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6949 return FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6950
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6951 return check_abbr(c, ml_get_curline(), curwin->w_cursor.col,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6952 curwin->w_cursor.lnum == Insstart.lnum ? Insstart.col : 0);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6953 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6954
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6955 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6956 * replace-stack functions
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6957 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6958 * When replacing characters, the replaced characters are remembered for each
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6959 * new character. This is used to re-insert the old text when backspacing.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6960 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6961 * There is a NUL headed list of characters for each character that is
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6962 * currently in the file after the insertion point. When BS is used, one NUL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6963 * headed list is put back for the deleted character.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6964 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6965 * For a newline, there are two NUL headed lists. One contains the characters
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6966 * that the NL replaced. The extra one stores the characters after the cursor
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6967 * that were deleted (always white space).
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6968 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6969 * Replace_offset is normally 0, in which case replace_push will add a new
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6970 * character at the end of the stack. If replace_offset is not 0, that many
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6971 * characters will be left on the stack above the newly inserted character.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6972 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6973
298
f9de3e679a04 updated for version 7.0078
vimboss
parents: 278
diff changeset
6974 static char_u *replace_stack = NULL;
f9de3e679a04 updated for version 7.0078
vimboss
parents: 278
diff changeset
6975 static long replace_stack_nr = 0; /* next entry in replace stack */
f9de3e679a04 updated for version 7.0078
vimboss
parents: 278
diff changeset
6976 static long replace_stack_len = 0; /* max. number of entries */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6977
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6978 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6979 replace_push(c)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6980 int c; /* character that is replaced (NUL is none) */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6981 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6982 char_u *p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6983
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6984 if (replace_stack_nr < replace_offset) /* nothing to do */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6985 return;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6986 if (replace_stack_len <= replace_stack_nr)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6987 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6988 replace_stack_len += 50;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6989 p = lalloc(sizeof(char_u) * replace_stack_len, TRUE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6990 if (p == NULL) /* out of memory */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6991 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6992 replace_stack_len -= 50;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6993 return;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6994 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6995 if (replace_stack != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6996 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6997 mch_memmove(p, replace_stack,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6998 (size_t)(replace_stack_nr * sizeof(char_u)));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6999 vim_free(replace_stack);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7000 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7001 replace_stack = p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7002 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7003 p = replace_stack + replace_stack_nr - replace_offset;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7004 if (replace_offset)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7005 mch_memmove(p + 1, p, (size_t)(replace_offset * sizeof(char_u)));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7006 *p = c;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7007 ++replace_stack_nr;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7008 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7009
1470
48b22e2eb1ed updated for version 7.1-185
vimboss
parents: 1460
diff changeset
7010 #if defined(FEAT_MBYTE) || defined(PROTO)
48b22e2eb1ed updated for version 7.1-185
vimboss
parents: 1460
diff changeset
7011 /*
48b22e2eb1ed updated for version 7.1-185
vimboss
parents: 1460
diff changeset
7012 * Push a character onto the replace stack. Handles a multi-byte character in
48b22e2eb1ed updated for version 7.1-185
vimboss
parents: 1460
diff changeset
7013 * reverse byte order, so that the first byte is popped off first.
48b22e2eb1ed updated for version 7.1-185
vimboss
parents: 1460
diff changeset
7014 * Return the number of bytes done (includes composing characters).
48b22e2eb1ed updated for version 7.1-185
vimboss
parents: 1460
diff changeset
7015 */
48b22e2eb1ed updated for version 7.1-185
vimboss
parents: 1460
diff changeset
7016 int
48b22e2eb1ed updated for version 7.1-185
vimboss
parents: 1460
diff changeset
7017 replace_push_mb(p)
48b22e2eb1ed updated for version 7.1-185
vimboss
parents: 1460
diff changeset
7018 char_u *p;
48b22e2eb1ed updated for version 7.1-185
vimboss
parents: 1460
diff changeset
7019 {
48b22e2eb1ed updated for version 7.1-185
vimboss
parents: 1460
diff changeset
7020 int l = (*mb_ptr2len)(p);
48b22e2eb1ed updated for version 7.1-185
vimboss
parents: 1460
diff changeset
7021 int j;
48b22e2eb1ed updated for version 7.1-185
vimboss
parents: 1460
diff changeset
7022
48b22e2eb1ed updated for version 7.1-185
vimboss
parents: 1460
diff changeset
7023 for (j = l - 1; j >= 0; --j)
48b22e2eb1ed updated for version 7.1-185
vimboss
parents: 1460
diff changeset
7024 replace_push(p[j]);
48b22e2eb1ed updated for version 7.1-185
vimboss
parents: 1460
diff changeset
7025 return l;
48b22e2eb1ed updated for version 7.1-185
vimboss
parents: 1460
diff changeset
7026 }
48b22e2eb1ed updated for version 7.1-185
vimboss
parents: 1460
diff changeset
7027 #endif
48b22e2eb1ed updated for version 7.1-185
vimboss
parents: 1460
diff changeset
7028
840
2c885fab04e3 updated for version 7.0e06
vimboss
parents: 836
diff changeset
7029 #if 0
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7030 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7031 * call replace_push(c) with replace_offset set to the first NUL.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7032 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7033 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7034 replace_push_off(c)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7035 int c;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7036 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7037 char_u *p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7038
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7039 p = replace_stack + replace_stack_nr;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7040 for (replace_offset = 1; replace_offset < replace_stack_nr;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7041 ++replace_offset)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7042 if (*--p == NUL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7043 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7044 replace_push(c);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7045 replace_offset = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7046 }
840
2c885fab04e3 updated for version 7.0e06
vimboss
parents: 836
diff changeset
7047 #endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7048
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7049 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7050 * Pop one item from the replace stack.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7051 * return -1 if stack empty
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7052 * return replaced character or NUL otherwise
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7053 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7054 static int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7055 replace_pop()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7056 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7057 if (replace_stack_nr == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7058 return -1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7059 return (int)replace_stack[--replace_stack_nr];
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7060 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7061
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7062 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7063 * Join the top two items on the replace stack. This removes to "off"'th NUL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7064 * encountered.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7065 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7066 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7067 replace_join(off)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7068 int off; /* offset for which NUL to remove */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7069 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7070 int i;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7071
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7072 for (i = replace_stack_nr; --i >= 0; )
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7073 if (replace_stack[i] == NUL && off-- <= 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7074 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7075 --replace_stack_nr;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7076 mch_memmove(replace_stack + i, replace_stack + i + 1,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7077 (size_t)(replace_stack_nr - i));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7078 return;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7079 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7080 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7081
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7082 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7083 * Pop bytes from the replace stack until a NUL is found, and insert them
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7084 * before the cursor. Can only be used in REPLACE or VREPLACE mode.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7085 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7086 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7087 replace_pop_ins()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7088 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7089 int cc;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7090 int oldState = State;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7091
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7092 State = NORMAL; /* don't want REPLACE here */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7093 while ((cc = replace_pop()) > 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7094 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7095 #ifdef FEAT_MBYTE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7096 mb_replace_pop_ins(cc);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7097 #else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7098 ins_char(cc);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7099 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7100 dec_cursor();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7101 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7102 State = oldState;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7103 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7104
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7105 #ifdef FEAT_MBYTE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7106 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7107 * Insert bytes popped from the replace stack. "cc" is the first byte. If it
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7108 * indicates a multi-byte char, pop the other bytes too.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7109 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7110 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7111 mb_replace_pop_ins(cc)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7112 int cc;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7113 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7114 int n;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7115 char_u buf[MB_MAXBYTES];
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7116 int i;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7117 int c;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7118
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7119 if (has_mbyte && (n = MB_BYTE2LEN(cc)) > 1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7120 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7121 buf[0] = cc;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7122 for (i = 1; i < n; ++i)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7123 buf[i] = replace_pop();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7124 ins_bytes_len(buf, n);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7125 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7126 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7127 ins_char(cc);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7128
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7129 if (enc_utf8)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7130 /* Handle composing chars. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7131 for (;;)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7132 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7133 c = replace_pop();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7134 if (c == -1) /* stack empty */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7135 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7136 if ((n = MB_BYTE2LEN(c)) == 1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7137 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7138 /* Not a multi-byte char, put it back. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7139 replace_push(c);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7140 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7141 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7142 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7143 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7144 buf[0] = c;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7145 for (i = 1; i < n; ++i)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7146 buf[i] = replace_pop();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7147 if (utf_iscomposing(utf_ptr2char(buf)))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7148 ins_bytes_len(buf, n);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7149 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7150 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7151 /* Not a composing char, put it back. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7152 for (i = n - 1; i >= 0; --i)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7153 replace_push(buf[i]);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7154 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7155 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7156 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7157 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7158 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7159 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7160
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7161 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7162 * make the replace stack empty
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7163 * (called when exiting replace mode)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7164 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7165 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7166 replace_flush()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7167 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7168 vim_free(replace_stack);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7169 replace_stack = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7170 replace_stack_len = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7171 replace_stack_nr = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7172 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7173
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7174 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7175 * Handle doing a BS for one character.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7176 * cc < 0: replace stack empty, just move cursor
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7177 * cc == 0: character was inserted, delete it
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7178 * cc > 0: character was replaced, put cc (first byte of original char) back
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7179 * and check for more characters to be put back
1782
12cecc379574 updated for version 7.2-080
vimboss
parents: 1698
diff changeset
7180 * When "limit_col" is >= 0, don't delete before this column. Matters when
12cecc379574 updated for version 7.2-080
vimboss
parents: 1698
diff changeset
7181 * using composing characters, use del_char_after_col() instead of del_char().
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7182 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7183 static void
1782
12cecc379574 updated for version 7.2-080
vimboss
parents: 1698
diff changeset
7184 replace_do_bs(limit_col)
12cecc379574 updated for version 7.2-080
vimboss
parents: 1698
diff changeset
7185 int limit_col;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7186 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7187 int cc;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7188 #ifdef FEAT_VREPLACE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7189 int orig_len = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7190 int ins_len;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7191 int orig_vcols = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7192 colnr_T start_vcol;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7193 char_u *p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7194 int i;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7195 int vcol;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7196 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7197
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7198 cc = replace_pop();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7199 if (cc > 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7200 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7201 #ifdef FEAT_VREPLACE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7202 if (State & VREPLACE_FLAG)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7203 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7204 /* Get the number of screen cells used by the character we are
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7205 * going to delete. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7206 getvcol(curwin, &curwin->w_cursor, NULL, &start_vcol, NULL);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7207 orig_vcols = chartabsize(ml_get_cursor(), start_vcol);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7208 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7209 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7210 #ifdef FEAT_MBYTE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7211 if (has_mbyte)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7212 {
1782
12cecc379574 updated for version 7.2-080
vimboss
parents: 1698
diff changeset
7213 (void)del_char_after_col(limit_col);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7214 # ifdef FEAT_VREPLACE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7215 if (State & VREPLACE_FLAG)
835
8bebcabccc2c updated for version 7.0e01
vimboss
parents: 829
diff changeset
7216 orig_len = (int)STRLEN(ml_get_cursor());
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7217 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7218 replace_push(cc);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7219 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7220 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7221 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7222 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7223 pchar_cursor(cc);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7224 #ifdef FEAT_VREPLACE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7225 if (State & VREPLACE_FLAG)
835
8bebcabccc2c updated for version 7.0e01
vimboss
parents: 829
diff changeset
7226 orig_len = (int)STRLEN(ml_get_cursor()) - 1;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7227 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7228 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7229 replace_pop_ins();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7230
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7231 #ifdef FEAT_VREPLACE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7232 if (State & VREPLACE_FLAG)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7233 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7234 /* Get the number of screen cells used by the inserted characters */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7235 p = ml_get_cursor();
835
8bebcabccc2c updated for version 7.0e01
vimboss
parents: 829
diff changeset
7236 ins_len = (int)STRLEN(p) - orig_len;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7237 vcol = start_vcol;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7238 for (i = 0; i < ins_len; ++i)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7239 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7240 vcol += chartabsize(p + i, vcol);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7241 #ifdef FEAT_MBYTE
474
a5fcf36ef512 updated for version 7.0127
vimboss
parents: 470
diff changeset
7242 i += (*mb_ptr2len)(p) - 1;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7243 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7244 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7245 vcol -= start_vcol;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7246
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7247 /* Delete spaces that were inserted after the cursor to keep the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7248 * text aligned. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7249 curwin->w_cursor.col += ins_len;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7250 while (vcol > orig_vcols && gchar_cursor() == ' ')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7251 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7252 del_char(FALSE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7253 ++orig_vcols;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7254 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7255 curwin->w_cursor.col -= ins_len;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7256 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7257 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7258
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7259 /* mark the buffer as changed and prepare for displaying */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7260 changed_bytes(curwin->w_cursor.lnum, curwin->w_cursor.col);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7261 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7262 else if (cc == 0)
1782
12cecc379574 updated for version 7.2-080
vimboss
parents: 1698
diff changeset
7263 (void)del_char_after_col(limit_col);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7264 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7265
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7266 #ifdef FEAT_CINDENT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7267 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7268 * Return TRUE if C-indenting is on.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7269 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7270 static int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7271 cindent_on()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7272 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7273 return (!p_paste && (curbuf->b_p_cin
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7274 # ifdef FEAT_EVAL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7275 || *curbuf->b_p_inde != NUL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7276 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7277 ));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7278 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7279 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7280
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7281 #if defined(FEAT_LISP) || defined(FEAT_CINDENT) || defined(PROTO)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7282 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7283 * Re-indent the current line, based on the current contents of it and the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7284 * surrounding lines. Fixing the cursor position seems really easy -- I'm very
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7285 * confused what all the part that handles Control-T is doing that I'm not.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7286 * "get_the_indent" should be get_c_indent, get_expr_indent or get_lisp_indent.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7287 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7288
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7289 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7290 fixthisline(get_the_indent)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7291 int (*get_the_indent) __ARGS((void));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7292 {
1516
ee9d2d24ea9b updated for version 7.1-231
vimboss
parents: 1514
diff changeset
7293 change_indent(INDENT_SET, get_the_indent(), FALSE, 0, TRUE);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7294 if (linewhite(curwin->w_cursor.lnum))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7295 did_ai = TRUE; /* delete the indent if the line stays empty */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7296 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7297
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7298 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7299 fix_indent()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7300 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7301 if (p_paste)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7302 return;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7303 # ifdef FEAT_LISP
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7304 if (curbuf->b_p_lisp && curbuf->b_p_ai)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7305 fixthisline(get_lisp_indent);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7306 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7307 # if defined(FEAT_LISP) && defined(FEAT_CINDENT)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7308 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7309 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7310 # ifdef FEAT_CINDENT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7311 if (cindent_on())
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7312 do_c_expr_indent();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7313 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7314 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7315
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7316 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7317
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7318 #ifdef FEAT_CINDENT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7319 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7320 * return TRUE if 'cinkeys' contains the key "keytyped",
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7321 * when == '*': Only if key is preceded with '*' (indent before insert)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7322 * when == '!': Only if key is prededed with '!' (don't insert)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7323 * when == ' ': Only if key is not preceded with '*'(indent afterwards)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7324 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7325 * "keytyped" can have a few special values:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7326 * KEY_OPEN_FORW
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7327 * KEY_OPEN_BACK
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7328 * KEY_COMPLETE just finished completion.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7329 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7330 * If line_is_empty is TRUE accept keys with '0' before them.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7331 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7332 int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7333 in_cinkeys(keytyped, when, line_is_empty)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7334 int keytyped;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7335 int when;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7336 int line_is_empty;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7337 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7338 char_u *look;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7339 int try_match;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7340 int try_match_word;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7341 char_u *p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7342 char_u *line;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7343 int icase;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7344 int i;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7345
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7346 #ifdef FEAT_EVAL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7347 if (*curbuf->b_p_inde != NUL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7348 look = curbuf->b_p_indk; /* 'indentexpr' set: use 'indentkeys' */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7349 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7350 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7351 look = curbuf->b_p_cink; /* 'indentexpr' empty: use 'cinkeys' */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7352 while (*look)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7353 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7354 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7355 * Find out if we want to try a match with this key, depending on
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7356 * 'when' and a '*' or '!' before the key.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7357 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7358 switch (when)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7359 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7360 case '*': try_match = (*look == '*'); break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7361 case '!': try_match = (*look == '!'); break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7362 default: try_match = (*look != '*'); break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7363 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7364 if (*look == '*' || *look == '!')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7365 ++look;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7366
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7367 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7368 * If there is a '0', only accept a match if the line is empty.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7369 * But may still match when typing last char of a word.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7370 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7371 if (*look == '0')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7372 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7373 try_match_word = try_match;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7374 if (!line_is_empty)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7375 try_match = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7376 ++look;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7377 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7378 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7379 try_match_word = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7380
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7381 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7382 * does it look like a control character?
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7383 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7384 if (*look == '^'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7385 #ifdef EBCDIC
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7386 && (Ctrl_chr(look[1]) != 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7387 #else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7388 && look[1] >= '?' && look[1] <= '_'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7389 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7390 )
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7391 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7392 if (try_match && keytyped == Ctrl_chr(look[1]))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7393 return TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7394 look += 2;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7395 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7396 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7397 * 'o' means "o" command, open forward.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7398 * 'O' means "O" command, open backward.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7399 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7400 else if (*look == 'o')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7401 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7402 if (try_match && keytyped == KEY_OPEN_FORW)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7403 return TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7404 ++look;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7405 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7406 else if (*look == 'O')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7407 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7408 if (try_match && keytyped == KEY_OPEN_BACK)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7409 return TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7410 ++look;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7411 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7412
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7413 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7414 * 'e' means to check for "else" at start of line and just before the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7415 * cursor.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7416 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7417 else if (*look == 'e')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7418 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7419 if (try_match && keytyped == 'e' && curwin->w_cursor.col >= 4)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7420 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7421 p = ml_get_curline();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7422 if (skipwhite(p) == p + curwin->w_cursor.col - 4 &&
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7423 STRNCMP(p + curwin->w_cursor.col - 4, "else", 4) == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7424 return TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7425 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7426 ++look;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7427 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7428
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7429 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7430 * ':' only causes an indent if it is at the end of a label or case
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7431 * statement, or when it was before typing the ':' (to fix
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7432 * class::method for C++).
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7433 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7434 else if (*look == ':')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7435 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7436 if (try_match && keytyped == ':')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7437 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7438 p = ml_get_curline();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7439 if (cin_iscase(p) || cin_isscopedecl(p) || cin_islabel(30))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7440 return TRUE;
1300
bacdeee78827 updated for version 7.1-014
vimboss
parents: 1219
diff changeset
7441 /* Need to get the line again after cin_islabel(). */
bacdeee78827 updated for version 7.1-014
vimboss
parents: 1219
diff changeset
7442 p = ml_get_curline();
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7443 if (curwin->w_cursor.col > 2
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7444 && p[curwin->w_cursor.col - 1] == ':'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7445 && p[curwin->w_cursor.col - 2] == ':')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7446 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7447 p[curwin->w_cursor.col - 1] = ' ';
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7448 i = (cin_iscase(p) || cin_isscopedecl(p)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7449 || cin_islabel(30));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7450 p = ml_get_curline();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7451 p[curwin->w_cursor.col - 1] = ':';
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7452 if (i)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7453 return TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7454 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7455 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7456 ++look;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7457 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7458
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7459
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7460 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7461 * Is it a key in <>, maybe?
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7462 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7463 else if (*look == '<')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7464 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7465 if (try_match)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7466 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7467 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7468 * make up some named keys <o>, <O>, <e>, <0>, <>>, <<>, <*>,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7469 * <:> and <!> so that people can re-indent on o, O, e, 0, <,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7470 * >, *, : and ! keys if they really really want to.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7471 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7472 if (vim_strchr((char_u *)"<>!*oOe0:", look[1]) != NULL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7473 && keytyped == look[1])
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7474 return TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7475
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7476 if (keytyped == get_special_key_code(look + 1))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7477 return TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7478 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7479 while (*look && *look != '>')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7480 look++;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7481 while (*look == '>')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7482 look++;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7483 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7484
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7485 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7486 * Is it a word: "=word"?
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7487 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7488 else if (*look == '=' && look[1] != ',' && look[1] != NUL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7489 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7490 ++look;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7491 if (*look == '~')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7492 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7493 icase = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7494 ++look;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7495 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7496 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7497 icase = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7498 p = vim_strchr(look, ',');
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7499 if (p == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7500 p = look + STRLEN(look);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7501 if ((try_match || try_match_word)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7502 && curwin->w_cursor.col >= (colnr_T)(p - look))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7503 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7504 int match = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7505
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7506 #ifdef FEAT_INS_EXPAND
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7507 if (keytyped == KEY_COMPLETE)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7508 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7509 char_u *s;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7510
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7511 /* Just completed a word, check if it starts with "look".
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7512 * search back for the start of a word. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7513 line = ml_get_curline();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7514 # ifdef FEAT_MBYTE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7515 if (has_mbyte)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7516 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7517 char_u *n;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7518
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7519 for (s = line + curwin->w_cursor.col; s > line; s = n)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7520 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7521 n = mb_prevptr(line, s);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7522 if (!vim_iswordp(n))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7523 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7524 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7525 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7526 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7527 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7528 for (s = line + curwin->w_cursor.col; s > line; --s)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7529 if (!vim_iswordc(s[-1]))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7530 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7531 if (s + (p - look) <= line + curwin->w_cursor.col
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7532 && (icase
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7533 ? MB_STRNICMP(s, look, p - look)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7534 : STRNCMP(s, look, p - look)) == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7535 match = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7536 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7537 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7538 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7539 /* TODO: multi-byte */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7540 if (keytyped == (int)p[-1] || (icase && keytyped < 256
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7541 && TOLOWER_LOC(keytyped) == TOLOWER_LOC((int)p[-1])))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7542 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7543 line = ml_get_cursor();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7544 if ((curwin->w_cursor.col == (colnr_T)(p - look)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7545 || !vim_iswordc(line[-(p - look) - 1]))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7546 && (icase
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7547 ? MB_STRNICMP(line - (p - look), look, p - look)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7548 : STRNCMP(line - (p - look), look, p - look))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7549 == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7550 match = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7551 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7552 if (match && try_match_word && !try_match)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7553 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7554 /* "0=word": Check if there are only blanks before the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7555 * word. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7556 line = ml_get_curline();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7557 if ((int)(skipwhite(line) - line) !=
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7558 (int)(curwin->w_cursor.col - (p - look)))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7559 match = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7560 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7561 if (match)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7562 return TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7563 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7564 look = p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7565 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7566
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7567 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7568 * ok, it's a boring generic character.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7569 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7570 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7571 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7572 if (try_match && *look == keytyped)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7573 return TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7574 ++look;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7575 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7576
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7577 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7578 * Skip over ", ".
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7579 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7580 look = skip_to_option_part(look);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7581 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7582 return FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7583 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7584 #endif /* FEAT_CINDENT */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7585
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7586 #if defined(FEAT_RIGHTLEFT) || defined(PROTO)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7587 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7588 * Map Hebrew keyboard when in hkmap mode.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7589 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7590 int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7591 hkmap(c)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7592 int c;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7593 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7594 if (p_hkmapp) /* phonetic mapping, by Ilya Dogolazky */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7595 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7596 enum {hALEF=0, BET, GIMEL, DALET, HEI, VAV, ZAIN, HET, TET, IUD,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7597 KAFsofit, hKAF, LAMED, MEMsofit, MEM, NUNsofit, NUN, SAMEH, AIN,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7598 PEIsofit, PEI, ZADIsofit, ZADI, KOF, RESH, hSHIN, TAV};
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7599 static char_u map[26] =
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7600 {(char_u)hALEF/*a*/, (char_u)BET /*b*/, (char_u)hKAF /*c*/,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7601 (char_u)DALET/*d*/, (char_u)-1 /*e*/, (char_u)PEIsofit/*f*/,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7602 (char_u)GIMEL/*g*/, (char_u)HEI /*h*/, (char_u)IUD /*i*/,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7603 (char_u)HET /*j*/, (char_u)KOF /*k*/, (char_u)LAMED /*l*/,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7604 (char_u)MEM /*m*/, (char_u)NUN /*n*/, (char_u)SAMEH /*o*/,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7605 (char_u)PEI /*p*/, (char_u)-1 /*q*/, (char_u)RESH /*r*/,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7606 (char_u)ZAIN /*s*/, (char_u)TAV /*t*/, (char_u)TET /*u*/,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7607 (char_u)VAV /*v*/, (char_u)hSHIN/*w*/, (char_u)-1 /*x*/,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7608 (char_u)AIN /*y*/, (char_u)ZADI /*z*/};
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7609
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7610 if (c == 'N' || c == 'M' || c == 'P' || c == 'C' || c == 'Z')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7611 return (int)(map[CharOrd(c)] - 1 + p_aleph);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7612 /* '-1'='sofit' */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7613 else if (c == 'x')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7614 return 'X';
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7615 else if (c == 'q')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7616 return '\''; /* {geresh}={'} */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7617 else if (c == 246)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7618 return ' '; /* \"o --> ' ' for a german keyboard */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7619 else if (c == 228)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7620 return ' '; /* \"a --> ' ' -- / -- */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7621 else if (c == 252)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7622 return ' '; /* \"u --> ' ' -- / -- */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7623 #ifdef EBCDIC
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7624 else if (islower(c))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7625 #else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7626 /* NOTE: islower() does not do the right thing for us on Linux so we
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7627 * do this the same was as 5.7 and previous, so it works correctly on
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7628 * all systems. Specifically, the e.g. Delete and Arrow keys are
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7629 * munged and won't work if e.g. searching for Hebrew text.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7630 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7631 else if (c >= 'a' && c <= 'z')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7632 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7633 return (int)(map[CharOrdLow(c)] + p_aleph);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7634 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7635 return c;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7636 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7637 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7638 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7639 switch (c)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7640 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7641 case '`': return ';';
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7642 case '/': return '.';
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7643 case '\'': return ',';
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7644 case 'q': return '/';
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7645 case 'w': return '\'';
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7646
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7647 /* Hebrew letters - set offset from 'a' */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7648 case ',': c = '{'; break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7649 case '.': c = 'v'; break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7650 case ';': c = 't'; break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7651 default: {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7652 static char str[] = "zqbcxlsjphmkwonu ydafe rig";
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7653
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7654 #ifdef EBCDIC
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7655 /* see note about islower() above */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7656 if (!islower(c))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7657 #else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7658 if (c < 'a' || c > 'z')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7659 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7660 return c;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7661 c = str[CharOrdLow(c)];
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7662 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7663 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7664 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7665
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7666 return (int)(CharOrdLow(c) + p_aleph);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7667 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7668 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7669 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7670
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7671 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7672 ins_reg()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7673 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7674 int need_redraw = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7675 int regname;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7676 int literally = 0;
844
d3bbb5dd3913 updated for version 7.0f02
vimboss
parents: 842
diff changeset
7677 #ifdef FEAT_VISUAL
d3bbb5dd3913 updated for version 7.0f02
vimboss
parents: 842
diff changeset
7678 int vis_active = VIsual_active;
d3bbb5dd3913 updated for version 7.0f02
vimboss
parents: 842
diff changeset
7679 #endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7680
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7681 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7682 * If we are going to wait for a character, show a '"'.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7683 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7684 pc_status = PC_STATUS_UNSET;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7685 if (redrawing() && !char_avail())
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7686 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7687 /* may need to redraw when no more chars available now */
661
e93a99ef31d0 updated for version 7.0195
vimboss
parents: 659
diff changeset
7688 ins_redraw(FALSE);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7689
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7690 edit_putchar('"', TRUE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7691 #ifdef FEAT_CMDL_INFO
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7692 add_to_showcmd_c(Ctrl_R);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7693 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7694 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7695
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7696 #ifdef USE_ON_FLY_SCROLL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7697 dont_scroll = TRUE; /* disallow scrolling here */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7698 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7699
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7700 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7701 * Don't map the register name. This also prevents the mode message to be
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7702 * deleted when ESC is hit.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7703 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7704 ++no_mapping;
1389
bdcfe793d49f updated for version 7.1-104
vimboss
parents: 1353
diff changeset
7705 regname = plain_vgetc();
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7706 LANGMAP_ADJUST(regname, TRUE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7707 if (regname == Ctrl_R || regname == Ctrl_O || regname == Ctrl_P)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7708 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7709 /* Get a third key for literal register insertion */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7710 literally = regname;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7711 #ifdef FEAT_CMDL_INFO
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7712 add_to_showcmd_c(literally);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7713 #endif
1389
bdcfe793d49f updated for version 7.1-104
vimboss
parents: 1353
diff changeset
7714 regname = plain_vgetc();
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7715 LANGMAP_ADJUST(regname, TRUE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7716 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7717 --no_mapping;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7718
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7719 #ifdef FEAT_EVAL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7720 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7721 * Don't call u_sync() while getting the expression,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7722 * evaluating it or giving an error message for it!
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7723 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7724 ++no_u_sync;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7725 if (regname == '=')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7726 {
133
bcb347a8f934 updated for version 7.0044
vimboss
parents: 75
diff changeset
7727 # ifdef USE_IM_CONTROL
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7728 int im_on = im_get_status();
133
bcb347a8f934 updated for version 7.0044
vimboss
parents: 75
diff changeset
7729 # endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7730 regname = get_expr_register();
133
bcb347a8f934 updated for version 7.0044
vimboss
parents: 75
diff changeset
7731 # ifdef USE_IM_CONTROL
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7732 /* Restore the Input Method. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7733 if (im_on)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7734 im_set_active(TRUE);
133
bcb347a8f934 updated for version 7.0044
vimboss
parents: 75
diff changeset
7735 # endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7736 }
140
8ecb0db93e9a updated for version 7.0045
vimboss
parents: 133
diff changeset
7737 if (regname == NUL || !valid_yank_reg(regname, FALSE))
8ecb0db93e9a updated for version 7.0045
vimboss
parents: 133
diff changeset
7738 {
8ecb0db93e9a updated for version 7.0045
vimboss
parents: 133
diff changeset
7739 vim_beep();
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7740 need_redraw = TRUE; /* remove the '"' */
140
8ecb0db93e9a updated for version 7.0045
vimboss
parents: 133
diff changeset
7741 }
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7742 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7743 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7744 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7745 if (literally == Ctrl_O || literally == Ctrl_P)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7746 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7747 /* Append the command to the redo buffer. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7748 AppendCharToRedobuff(Ctrl_R);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7749 AppendCharToRedobuff(literally);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7750 AppendCharToRedobuff(regname);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7751
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7752 do_put(regname, BACKWARD, 1L,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7753 (literally == Ctrl_P ? PUT_FIXINDENT : 0) | PUT_CURSEND);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7754 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7755 else if (insert_reg(regname, literally) == FAIL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7756 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7757 vim_beep();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7758 need_redraw = TRUE; /* remove the '"' */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7759 }
133
bcb347a8f934 updated for version 7.0044
vimboss
parents: 75
diff changeset
7760 else if (stop_insert_mode)
bcb347a8f934 updated for version 7.0044
vimboss
parents: 75
diff changeset
7761 /* When the '=' register was used and a function was invoked that
bcb347a8f934 updated for version 7.0044
vimboss
parents: 75
diff changeset
7762 * did ":stopinsert" then stuff_empty() returns FALSE but we won't
bcb347a8f934 updated for version 7.0044
vimboss
parents: 75
diff changeset
7763 * insert anything, need to remove the '"' */
bcb347a8f934 updated for version 7.0044
vimboss
parents: 75
diff changeset
7764 need_redraw = TRUE;
bcb347a8f934 updated for version 7.0044
vimboss
parents: 75
diff changeset
7765
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7766 #ifdef FEAT_EVAL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7767 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7768 --no_u_sync;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7769 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7770 #ifdef FEAT_CMDL_INFO
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7771 clear_showcmd();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7772 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7773
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7774 /* If the inserted register is empty, we need to remove the '"' */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7775 if (need_redraw || stuff_empty())
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7776 edit_unputchar();
844
d3bbb5dd3913 updated for version 7.0f02
vimboss
parents: 842
diff changeset
7777
d3bbb5dd3913 updated for version 7.0f02
vimboss
parents: 842
diff changeset
7778 #ifdef FEAT_VISUAL
d3bbb5dd3913 updated for version 7.0f02
vimboss
parents: 842
diff changeset
7779 /* Disallow starting Visual mode here, would get a weird mode. */
d3bbb5dd3913 updated for version 7.0f02
vimboss
parents: 842
diff changeset
7780 if (!vis_active && VIsual_active)
d3bbb5dd3913 updated for version 7.0f02
vimboss
parents: 842
diff changeset
7781 end_visual_mode();
d3bbb5dd3913 updated for version 7.0f02
vimboss
parents: 842
diff changeset
7782 #endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7783 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7784
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7785 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7786 * CTRL-G commands in Insert mode.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7787 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7788 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7789 ins_ctrl_g()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7790 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7791 int c;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7792
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7793 #ifdef FEAT_INS_EXPAND
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7794 /* Right after CTRL-X the cursor will be after the ruler. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7795 setcursor();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7796 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7797
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7798 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7799 * Don't map the second key. This also prevents the mode message to be
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7800 * deleted when ESC is hit.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7801 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7802 ++no_mapping;
1389
bdcfe793d49f updated for version 7.1-104
vimboss
parents: 1353
diff changeset
7803 c = plain_vgetc();
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7804 --no_mapping;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7805 switch (c)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7806 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7807 /* CTRL-G k and CTRL-G <Up>: cursor up to Insstart.col */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7808 case K_UP:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7809 case Ctrl_K:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7810 case 'k': ins_up(TRUE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7811 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7812
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7813 /* CTRL-G j and CTRL-G <Down>: cursor down to Insstart.col */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7814 case K_DOWN:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7815 case Ctrl_J:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7816 case 'j': ins_down(TRUE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7817 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7818
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7819 /* CTRL-G u: start new undoable edit */
825
6675076019ae updated for version 7.0d
vimboss
parents: 819
diff changeset
7820 case 'u': u_sync(TRUE);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7821 ins_need_undo = TRUE;
626
732c7ae5743e updated for version 7.0180
vimboss
parents: 625
diff changeset
7822
732c7ae5743e updated for version 7.0180
vimboss
parents: 625
diff changeset
7823 /* Need to reset Insstart, esp. because a BS that joins
1219
aea597af5b4e updated for version 7.1b
vimboss
parents: 1159
diff changeset
7824 * a line to the previous one must save for undo. */
626
732c7ae5743e updated for version 7.0180
vimboss
parents: 625
diff changeset
7825 Insstart = curwin->w_cursor;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7826 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7827
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7828 /* Unknown CTRL-G command, reserved for future expansion. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7829 default: vim_beep();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7830 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7831 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7832
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7833 /*
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
7834 * CTRL-^ in Insert mode.
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
7835 */
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
7836 static void
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
7837 ins_ctrl_hat()
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
7838 {
782
d20041a02ee5 updated for version 7.0228
vimboss
parents: 773
diff changeset
7839 if (map_to_exists_mode((char_u *)"", LANGMAP, FALSE))
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
7840 {
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
7841 /* ":lmap" mappings exists, Toggle use of ":lmap" mappings. */
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
7842 if (State & LANGMAP)
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
7843 {
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
7844 curbuf->b_p_iminsert = B_IMODE_NONE;
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
7845 State &= ~LANGMAP;
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
7846 }
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
7847 else
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
7848 {
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
7849 curbuf->b_p_iminsert = B_IMODE_LMAP;
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
7850 State |= LANGMAP;
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
7851 #ifdef USE_IM_CONTROL
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
7852 im_set_active(FALSE);
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
7853 #endif
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
7854 }
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
7855 }
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
7856 #ifdef USE_IM_CONTROL
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
7857 else
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
7858 {
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
7859 /* There are no ":lmap" mappings, toggle IM */
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
7860 if (im_get_status())
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
7861 {
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
7862 curbuf->b_p_iminsert = B_IMODE_NONE;
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
7863 im_set_active(FALSE);
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
7864 }
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
7865 else
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
7866 {
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
7867 curbuf->b_p_iminsert = B_IMODE_IM;
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
7868 State &= ~LANGMAP;
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
7869 im_set_active(TRUE);
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
7870 }
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
7871 }
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
7872 #endif
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
7873 set_iminsert_global();
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
7874 showmode();
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
7875 #ifdef FEAT_GUI
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
7876 /* may show different cursor shape or color */
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
7877 if (gui.in_use)
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
7878 gui_update_cursor(TRUE, FALSE);
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
7879 #endif
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
7880 #if defined(FEAT_WINDOWS) && defined(FEAT_KEYMAP)
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
7881 /* Show/unshow value of 'keymap' in status lines. */
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
7882 status_redraw_curbuf();
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
7883 #endif
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
7884 }
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
7885
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
7886 /*
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7887 * Handle ESC in insert mode.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7888 * Returns TRUE when leaving insert mode, FALSE when going to repeat the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7889 * insert.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7890 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7891 static int
477
f8b75b8f1988 updated for version 7.0128
vimboss
parents: 474
diff changeset
7892 ins_esc(count, cmdchar, nomove)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7893 long *count;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7894 int cmdchar;
477
f8b75b8f1988 updated for version 7.0128
vimboss
parents: 474
diff changeset
7895 int nomove; /* don't move cursor */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7896 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7897 int temp;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7898 static int disabled_redraw = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7899
744
07f7b4a7755c updated for version 7.0222
vimboss
parents: 732
diff changeset
7900 #ifdef FEAT_SPELL
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
7901 check_spell_redraw();
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
7902 #endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7903 #if defined(FEAT_HANGULIN)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7904 # if defined(ESC_CHG_TO_ENG_MODE)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7905 hangul_input_state_set(0);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7906 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7907 if (composing_hangul)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7908 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7909 push_raw_key(composing_hangul_buffer, 2);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7910 composing_hangul = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7911 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7912 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7913
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7914 temp = curwin->w_cursor.col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7915 if (disabled_redraw)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7916 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7917 --RedrawingDisabled;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7918 disabled_redraw = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7919 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7920 if (!arrow_used)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7921 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7922 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7923 * Don't append the ESC for "r<CR>" and "grx".
75
388f285bda1b updated for version 7.0031
vimboss
parents: 41
diff changeset
7924 * When 'insertmode' is set only CTRL-L stops Insert mode. Needed for
388f285bda1b updated for version 7.0031
vimboss
parents: 41
diff changeset
7925 * when "count" is non-zero.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7926 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7927 if (cmdchar != 'r' && cmdchar != 'v')
75
388f285bda1b updated for version 7.0031
vimboss
parents: 41
diff changeset
7928 AppendToRedobuff(p_im ? (char_u *)"\014" : ESC_STR);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7929
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7930 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7931 * Repeating insert may take a long time. Check for
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7932 * interrupt now and then.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7933 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7934 if (*count > 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7935 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7936 line_breakcheck();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7937 if (got_int)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7938 *count = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7939 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7940
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7941 if (--*count > 0) /* repeat what was typed */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7942 {
164
8b0ee9d57d7f updated for version 7.0050
vimboss
parents: 161
diff changeset
7943 /* Vi repeats the insert without replacing characters. */
8b0ee9d57d7f updated for version 7.0050
vimboss
parents: 161
diff changeset
7944 if (vim_strchr(p_cpo, CPO_REPLCNT) != NULL)
8b0ee9d57d7f updated for version 7.0050
vimboss
parents: 161
diff changeset
7945 State &= ~REPLACE_FLAG;
8b0ee9d57d7f updated for version 7.0050
vimboss
parents: 161
diff changeset
7946
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7947 (void)start_redo_ins();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7948 if (cmdchar == 'r' || cmdchar == 'v')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7949 stuffReadbuff(ESC_STR); /* no ESC in redo buffer */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7950 ++RedrawingDisabled;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7951 disabled_redraw = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7952 return FALSE; /* repeat the insert */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7953 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7954 stop_insert(&curwin->w_cursor, TRUE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7955 undisplay_dollar();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7956 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7957
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7958 /* When an autoindent was removed, curswant stays after the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7959 * indent */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7960 if (restart_edit == NUL && (colnr_T)temp == curwin->w_cursor.col)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7961 curwin->w_set_curswant = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7962
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7963 /* Remember the last Insert position in the '^ mark. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7964 if (!cmdmod.keepjumps)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7965 curbuf->b_last_insert = curwin->w_cursor;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7966
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7967 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7968 * The cursor should end up on the last inserted character.
477
f8b75b8f1988 updated for version 7.0128
vimboss
parents: 474
diff changeset
7969 * Don't do it for CTRL-O, unless past the end of the line.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7970 */
477
f8b75b8f1988 updated for version 7.0128
vimboss
parents: 474
diff changeset
7971 if (!nomove
f8b75b8f1988 updated for version 7.0128
vimboss
parents: 474
diff changeset
7972 && (curwin->w_cursor.col != 0
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7973 #ifdef FEAT_VIRTUALEDIT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7974 || curwin->w_cursor.coladd > 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7975 #endif
477
f8b75b8f1988 updated for version 7.0128
vimboss
parents: 474
diff changeset
7976 )
f8b75b8f1988 updated for version 7.0128
vimboss
parents: 474
diff changeset
7977 && (restart_edit == NUL
f8b75b8f1988 updated for version 7.0128
vimboss
parents: 474
diff changeset
7978 || (gchar_cursor() == NUL
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7979 #ifdef FEAT_VISUAL
477
f8b75b8f1988 updated for version 7.0128
vimboss
parents: 474
diff changeset
7980 && !VIsual_active
f8b75b8f1988 updated for version 7.0128
vimboss
parents: 474
diff changeset
7981 #endif
f8b75b8f1988 updated for version 7.0128
vimboss
parents: 474
diff changeset
7982 ))
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7983 #ifdef FEAT_RIGHTLEFT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7984 && !revins_on
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7985 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7986 )
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7987 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7988 #ifdef FEAT_VIRTUALEDIT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7989 if (curwin->w_cursor.coladd > 0 || ve_flags == VE_ALL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7990 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7991 oneleft();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7992 if (restart_edit != NUL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7993 ++curwin->w_cursor.coladd;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7994 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7995 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7996 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7997 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7998 --curwin->w_cursor.col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7999 #ifdef FEAT_MBYTE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8000 /* Correct cursor for multi-byte character. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8001 if (has_mbyte)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8002 mb_adjust_cursor();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8003 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8004 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8005 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8006
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8007 #ifdef USE_IM_CONTROL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8008 /* Disable IM to allow typing English directly for Normal mode commands.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8009 * When ":lmap" is enabled don't change 'iminsert' (IM can be enabled as
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8010 * well). */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8011 if (!(State & LANGMAP))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8012 im_save_status(&curbuf->b_p_iminsert);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8013 im_set_active(FALSE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8014 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8015
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8016 State = NORMAL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8017 /* need to position cursor again (e.g. when on a TAB ) */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8018 changed_cline_bef_curs();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8019
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8020 #ifdef FEAT_MOUSE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8021 setmouse();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8022 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8023 #ifdef CURSOR_SHAPE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8024 ui_cursor_shape(); /* may show different cursor shape */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8025 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8026
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8027 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8028 * When recording or for CTRL-O, need to display the new mode.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8029 * Otherwise remove the mode message.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8030 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8031 if (Recording || restart_edit != NUL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8032 showmode();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8033 else if (p_smd)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8034 MSG("");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8035
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8036 return TRUE; /* exit Insert mode */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8037 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8038
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8039 #ifdef FEAT_RIGHTLEFT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8040 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8041 * Toggle language: hkmap and revins_on.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8042 * Move to end of reverse inserted text.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8043 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8044 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8045 ins_ctrl_()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8046 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8047 if (revins_on && revins_chars && revins_scol >= 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8048 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8049 while (gchar_cursor() != NUL && revins_chars--)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8050 ++curwin->w_cursor.col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8051 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8052 p_ri = !p_ri;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8053 revins_on = (State == INSERT && p_ri);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8054 if (revins_on)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8055 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8056 revins_scol = curwin->w_cursor.col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8057 revins_legal++;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8058 revins_chars = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8059 undisplay_dollar();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8060 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8061 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8062 revins_scol = -1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8063 #ifdef FEAT_FKMAP
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8064 if (p_altkeymap)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8065 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8066 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8067 * to be consistent also for redo command, using '.'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8068 * set arrow_used to true and stop it - causing to redo
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8069 * characters entered in one mode (normal/reverse insert).
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8070 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8071 arrow_used = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8072 (void)stop_arrow();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8073 p_fkmap = curwin->w_p_rl ^ p_ri;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8074 if (p_fkmap && p_ri)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8075 State = INSERT;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8076 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8077 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8078 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8079 p_hkmap = curwin->w_p_rl ^ p_ri; /* be consistent! */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8080 showmode();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8081 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8082 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8083
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8084 #ifdef FEAT_VISUAL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8085 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8086 * If 'keymodel' contains "startsel", may start selection.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8087 * Returns TRUE when a CTRL-O and other keys stuffed.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8088 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8089 static int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8090 ins_start_select(c)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8091 int c;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8092 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8093 if (km_startsel)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8094 switch (c)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8095 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8096 case K_KHOME:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8097 case K_KEND:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8098 case K_PAGEUP:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8099 case K_KPAGEUP:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8100 case K_PAGEDOWN:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8101 case K_KPAGEDOWN:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8102 # ifdef MACOS
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8103 case K_LEFT:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8104 case K_RIGHT:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8105 case K_UP:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8106 case K_DOWN:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8107 case K_END:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8108 case K_HOME:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8109 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8110 if (!(mod_mask & MOD_MASK_SHIFT))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8111 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8112 /* FALLTHROUGH */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8113 case K_S_LEFT:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8114 case K_S_RIGHT:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8115 case K_S_UP:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8116 case K_S_DOWN:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8117 case K_S_END:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8118 case K_S_HOME:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8119 /* Start selection right away, the cursor can move with
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8120 * CTRL-O when beyond the end of the line. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8121 start_selection();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8122
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8123 /* Execute the key in (insert) Select mode. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8124 stuffcharReadbuff(Ctrl_O);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8125 if (mod_mask)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8126 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8127 char_u buf[4];
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8128
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8129 buf[0] = K_SPECIAL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8130 buf[1] = KS_MODIFIER;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8131 buf[2] = mod_mask;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8132 buf[3] = NUL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8133 stuffReadbuff(buf);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8134 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8135 stuffcharReadbuff(c);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8136 return TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8137 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8138 return FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8139 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8140 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8141
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8142 /*
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
8143 * <Insert> key in Insert mode: toggle insert/remplace mode.
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
8144 */
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
8145 static void
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
8146 ins_insert(replaceState)
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
8147 int replaceState;
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
8148 {
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
8149 #ifdef FEAT_FKMAP
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
8150 if (p_fkmap && p_ri)
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
8151 {
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
8152 beep_flush();
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
8153 EMSG(farsi_text_3); /* encoded in Farsi */
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
8154 return;
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
8155 }
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
8156 #endif
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
8157
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
8158 #ifdef FEAT_AUTOCMD
532
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 523
diff changeset
8159 # ifdef FEAT_EVAL
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
8160 set_vim_var_string(VV_INSERTMODE,
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
8161 (char_u *)((State & REPLACE_FLAG) ? "i" :
667
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
8162 # ifdef FEAT_VREPLACE
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
8163 replaceState == VREPLACE ? "v" :
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
8164 # endif
9090f866cd57 updated for version 7.0197
vimboss
parents: 665
diff changeset
8165 "r"), 1);
532
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 523
diff changeset
8166 # endif
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
8167 apply_autocmds(EVENT_INSERTCHANGE, NULL, NULL, FALSE, curbuf);
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
8168 #endif
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
8169 if (State & REPLACE_FLAG)
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
8170 State = INSERT | (State & LANGMAP);
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
8171 else
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
8172 State = replaceState | (State & LANGMAP);
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
8173 AppendCharToRedobuff(K_INS);
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
8174 showmode();
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
8175 #ifdef CURSOR_SHAPE
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
8176 ui_cursor_shape(); /* may show different cursor shape */
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
8177 #endif
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
8178 }
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
8179
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
8180 /*
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
8181 * Pressed CTRL-O in Insert mode.
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
8182 */
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
8183 static void
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
8184 ins_ctrl_o()
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
8185 {
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
8186 #ifdef FEAT_VREPLACE
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
8187 if (State & VREPLACE_FLAG)
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
8188 restart_edit = 'V';
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
8189 else
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
8190 #endif
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
8191 if (State & REPLACE_FLAG)
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
8192 restart_edit = 'R';
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
8193 else
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
8194 restart_edit = 'I';
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
8195 #ifdef FEAT_VIRTUALEDIT
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
8196 if (virtual_active())
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
8197 ins_at_eol = FALSE; /* cursor always keeps its column */
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
8198 else
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
8199 #endif
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
8200 ins_at_eol = (gchar_cursor() == NUL);
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
8201 }
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
8202
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
8203 /*
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8204 * If the cursor is on an indent, ^T/^D insert/delete one
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8205 * shiftwidth. Otherwise ^T/^D behave like a "<<" or ">>".
1796
4589d1792c03 updated for version 7.2-094
vimboss
parents: 1782
diff changeset
8206 * Always round the indent to 'shiftwidth', this is compatible
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8207 * with vi. But vi only supports ^T and ^D after an
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8208 * autoindent, we support it everywhere.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8209 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8210 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8211 ins_shift(c, lastc)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8212 int c;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8213 int lastc;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8214 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8215 if (stop_arrow() == FAIL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8216 return;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8217 AppendCharToRedobuff(c);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8218
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8219 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8220 * 0^D and ^^D: remove all indent.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8221 */
1330
9fb5bb1ea79b updated for version 7.1-044
vimboss
parents: 1300
diff changeset
8222 if (c == Ctrl_D && (lastc == '0' || lastc == '^')
9fb5bb1ea79b updated for version 7.1-044
vimboss
parents: 1300
diff changeset
8223 && curwin->w_cursor.col > 0)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8224 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8225 --curwin->w_cursor.col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8226 (void)del_char(FALSE); /* delete the '^' or '0' */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8227 /* In Replace mode, restore the characters that '^' or '0' replaced. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8228 if (State & REPLACE_FLAG)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8229 replace_pop_ins();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8230 if (lastc == '^')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8231 old_indent = get_indent(); /* remember curr. indent */
1516
ee9d2d24ea9b updated for version 7.1-231
vimboss
parents: 1514
diff changeset
8232 change_indent(INDENT_SET, 0, TRUE, 0, TRUE);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8233 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8234 else
1516
ee9d2d24ea9b updated for version 7.1-231
vimboss
parents: 1514
diff changeset
8235 change_indent(c == Ctrl_D ? INDENT_DEC : INDENT_INC, 0, TRUE, 0, TRUE);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8236
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8237 if (did_ai && *skipwhite(ml_get_curline()) != NUL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8238 did_ai = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8239 #ifdef FEAT_SMARTINDENT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8240 did_si = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8241 can_si = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8242 can_si_back = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8243 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8244 #ifdef FEAT_CINDENT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8245 can_cindent = FALSE; /* no cindenting after ^D or ^T */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8246 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8247 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8248
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8249 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8250 ins_del()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8251 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8252 int temp;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8253
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8254 if (stop_arrow() == FAIL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8255 return;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8256 if (gchar_cursor() == NUL) /* delete newline */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8257 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8258 temp = curwin->w_cursor.col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8259 if (!can_bs(BS_EOL) /* only if "eol" included */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8260 || u_save((linenr_T)(curwin->w_cursor.lnum - 1),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8261 (linenr_T)(curwin->w_cursor.lnum + 2)) == FAIL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8262 || do_join(FALSE) == FAIL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8263 vim_beep();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8264 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8265 curwin->w_cursor.col = temp;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8266 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8267 else if (del_char(FALSE) == FAIL) /* delete char under cursor */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8268 vim_beep();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8269 did_ai = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8270 #ifdef FEAT_SMARTINDENT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8271 did_si = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8272 can_si = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8273 can_si_back = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8274 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8275 AppendCharToRedobuff(K_DEL);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8276 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8277
1460
b0dabd584b8f updated for version 7.1-175
vimboss
parents: 1446
diff changeset
8278 static void ins_bs_one __ARGS((colnr_T *vcolp));
b0dabd584b8f updated for version 7.1-175
vimboss
parents: 1446
diff changeset
8279
b0dabd584b8f updated for version 7.1-175
vimboss
parents: 1446
diff changeset
8280 /*
b0dabd584b8f updated for version 7.1-175
vimboss
parents: 1446
diff changeset
8281 * Delete one character for ins_bs().
b0dabd584b8f updated for version 7.1-175
vimboss
parents: 1446
diff changeset
8282 */
b0dabd584b8f updated for version 7.1-175
vimboss
parents: 1446
diff changeset
8283 static void
b0dabd584b8f updated for version 7.1-175
vimboss
parents: 1446
diff changeset
8284 ins_bs_one(vcolp)
b0dabd584b8f updated for version 7.1-175
vimboss
parents: 1446
diff changeset
8285 colnr_T *vcolp;
b0dabd584b8f updated for version 7.1-175
vimboss
parents: 1446
diff changeset
8286 {
b0dabd584b8f updated for version 7.1-175
vimboss
parents: 1446
diff changeset
8287 dec_cursor();
b0dabd584b8f updated for version 7.1-175
vimboss
parents: 1446
diff changeset
8288 getvcol(curwin, &curwin->w_cursor, vcolp, NULL, NULL);
b0dabd584b8f updated for version 7.1-175
vimboss
parents: 1446
diff changeset
8289 if (State & REPLACE_FLAG)
b0dabd584b8f updated for version 7.1-175
vimboss
parents: 1446
diff changeset
8290 {
b0dabd584b8f updated for version 7.1-175
vimboss
parents: 1446
diff changeset
8291 /* Don't delete characters before the insert point when in
b0dabd584b8f updated for version 7.1-175
vimboss
parents: 1446
diff changeset
8292 * Replace mode */
b0dabd584b8f updated for version 7.1-175
vimboss
parents: 1446
diff changeset
8293 if (curwin->w_cursor.lnum != Insstart.lnum
b0dabd584b8f updated for version 7.1-175
vimboss
parents: 1446
diff changeset
8294 || curwin->w_cursor.col >= Insstart.col)
1782
12cecc379574 updated for version 7.2-080
vimboss
parents: 1698
diff changeset
8295 replace_do_bs(-1);
1460
b0dabd584b8f updated for version 7.1-175
vimboss
parents: 1446
diff changeset
8296 }
b0dabd584b8f updated for version 7.1-175
vimboss
parents: 1446
diff changeset
8297 else
b0dabd584b8f updated for version 7.1-175
vimboss
parents: 1446
diff changeset
8298 (void)del_char(FALSE);
b0dabd584b8f updated for version 7.1-175
vimboss
parents: 1446
diff changeset
8299 }
b0dabd584b8f updated for version 7.1-175
vimboss
parents: 1446
diff changeset
8300
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8301 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8302 * Handle Backspace, delete-word and delete-line in Insert mode.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8303 * Return TRUE when backspace was actually used.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8304 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8305 static int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8306 ins_bs(c, mode, inserted_space_p)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8307 int c;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8308 int mode;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8309 int *inserted_space_p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8310 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8311 linenr_T lnum;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8312 int cc;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8313 int temp = 0; /* init for GCC */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8314 colnr_T mincol;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8315 int did_backspace = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8316 int in_indent;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8317 int oldState;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8318 #ifdef FEAT_MBYTE
714
0f9f4761ad9c updated for version 7.0216
vimboss
parents: 712
diff changeset
8319 int cpc[MAX_MCO]; /* composing characters */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8320 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8321
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8322 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8323 * can't delete anything in an empty file
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8324 * can't backup past first character in buffer
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8325 * can't backup past starting point unless 'backspace' > 1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8326 * can backup to a previous line if 'backspace' == 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8327 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8328 if ( bufempty()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8329 || (
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8330 #ifdef FEAT_RIGHTLEFT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8331 !revins_on &&
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8332 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8333 ((curwin->w_cursor.lnum == 1 && curwin->w_cursor.col == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8334 || (!can_bs(BS_START)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8335 && (arrow_used
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8336 || (curwin->w_cursor.lnum == Insstart.lnum
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8337 && curwin->w_cursor.col <= Insstart.col)))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8338 || (!can_bs(BS_INDENT) && !arrow_used && ai_col > 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8339 && curwin->w_cursor.col <= ai_col)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8340 || (!can_bs(BS_EOL) && curwin->w_cursor.col == 0))))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8341 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8342 vim_beep();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8343 return FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8344 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8345
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8346 if (stop_arrow() == FAIL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8347 return FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8348 in_indent = inindent(0);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8349 #ifdef FEAT_CINDENT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8350 if (in_indent)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8351 can_cindent = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8352 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8353 #ifdef FEAT_COMMENTS
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8354 end_comment_pending = NUL; /* After BS, don't auto-end comment */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8355 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8356 #ifdef FEAT_RIGHTLEFT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8357 if (revins_on) /* put cursor after last inserted char */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8358 inc_cursor();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8359 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8360
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8361 #ifdef FEAT_VIRTUALEDIT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8362 /* Virtualedit:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8363 * BACKSPACE_CHAR eats a virtual space
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8364 * BACKSPACE_WORD eats all coladd
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8365 * BACKSPACE_LINE eats all coladd and keeps going
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8366 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8367 if (curwin->w_cursor.coladd > 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8368 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8369 if (mode == BACKSPACE_CHAR)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8370 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8371 --curwin->w_cursor.coladd;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8372 return TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8373 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8374 if (mode == BACKSPACE_WORD)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8375 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8376 curwin->w_cursor.coladd = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8377 return TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8378 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8379 curwin->w_cursor.coladd = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8380 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8381 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8382
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8383 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8384 * delete newline!
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8385 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8386 if (curwin->w_cursor.col == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8387 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8388 lnum = Insstart.lnum;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8389 if (curwin->w_cursor.lnum == Insstart.lnum
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8390 #ifdef FEAT_RIGHTLEFT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8391 || revins_on
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8392 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8393 )
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8394 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8395 if (u_save((linenr_T)(curwin->w_cursor.lnum - 2),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8396 (linenr_T)(curwin->w_cursor.lnum + 1)) == FAIL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8397 return FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8398 --Insstart.lnum;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8399 Insstart.col = MAXCOL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8400 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8401 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8402 * In replace mode:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8403 * cc < 0: NL was inserted, delete it
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8404 * cc >= 0: NL was replaced, put original characters back
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8405 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8406 cc = -1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8407 if (State & REPLACE_FLAG)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8408 cc = replace_pop(); /* returns -1 if NL was inserted */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8409 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8410 * In replace mode, in the line we started replacing, we only move the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8411 * cursor.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8412 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8413 if ((State & REPLACE_FLAG) && curwin->w_cursor.lnum <= lnum)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8414 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8415 dec_cursor();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8416 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8417 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8418 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8419 #ifdef FEAT_VREPLACE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8420 if (!(State & VREPLACE_FLAG)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8421 || curwin->w_cursor.lnum > orig_line_count)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8422 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8423 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8424 temp = gchar_cursor(); /* remember current char */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8425 --curwin->w_cursor.lnum;
278
a7e59720a155 updated for version 7.0074
vimboss
parents: 274
diff changeset
8426
a7e59720a155 updated for version 7.0074
vimboss
parents: 274
diff changeset
8427 /* When "aw" is in 'formatoptions' we must delete the space at
a7e59720a155 updated for version 7.0074
vimboss
parents: 274
diff changeset
8428 * the end of the line, otherwise the line will be broken
a7e59720a155 updated for version 7.0074
vimboss
parents: 274
diff changeset
8429 * again when auto-formatting. */
a7e59720a155 updated for version 7.0074
vimboss
parents: 274
diff changeset
8430 if (has_format_option(FO_AUTO)
a7e59720a155 updated for version 7.0074
vimboss
parents: 274
diff changeset
8431 && has_format_option(FO_WHITE_PAR))
a7e59720a155 updated for version 7.0074
vimboss
parents: 274
diff changeset
8432 {
a7e59720a155 updated for version 7.0074
vimboss
parents: 274
diff changeset
8433 char_u *ptr = ml_get_buf(curbuf, curwin->w_cursor.lnum,
a7e59720a155 updated for version 7.0074
vimboss
parents: 274
diff changeset
8434 TRUE);
a7e59720a155 updated for version 7.0074
vimboss
parents: 274
diff changeset
8435 int len;
a7e59720a155 updated for version 7.0074
vimboss
parents: 274
diff changeset
8436
835
8bebcabccc2c updated for version 7.0e01
vimboss
parents: 829
diff changeset
8437 len = (int)STRLEN(ptr);
278
a7e59720a155 updated for version 7.0074
vimboss
parents: 274
diff changeset
8438 if (len > 0 && ptr[len - 1] == ' ')
a7e59720a155 updated for version 7.0074
vimboss
parents: 274
diff changeset
8439 ptr[len - 1] = NUL;
a7e59720a155 updated for version 7.0074
vimboss
parents: 274
diff changeset
8440 }
a7e59720a155 updated for version 7.0074
vimboss
parents: 274
diff changeset
8441
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8442 (void)do_join(FALSE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8443 if (temp == NUL && gchar_cursor() != NUL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8444 inc_cursor();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8445 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8446 #ifdef FEAT_VREPLACE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8447 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8448 dec_cursor();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8449 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8450
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8451 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8452 * In REPLACE mode we have to put back the text that was replaced
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8453 * by the NL. On the replace stack is first a NUL-terminated
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8454 * sequence of characters that were deleted and then the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8455 * characters that NL replaced.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8456 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8457 if (State & REPLACE_FLAG)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8458 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8459 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8460 * Do the next ins_char() in NORMAL state, to
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8461 * prevent ins_char() from replacing characters and
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8462 * avoiding showmatch().
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8463 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8464 oldState = State;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8465 State = NORMAL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8466 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8467 * restore characters (blanks) deleted after cursor
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8468 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8469 while (cc > 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8470 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8471 temp = curwin->w_cursor.col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8472 #ifdef FEAT_MBYTE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8473 mb_replace_pop_ins(cc);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8474 #else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8475 ins_char(cc);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8476 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8477 curwin->w_cursor.col = temp;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8478 cc = replace_pop();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8479 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8480 /* restore the characters that NL replaced */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8481 replace_pop_ins();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8482 State = oldState;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8483 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8484 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8485 did_ai = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8486 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8487 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8488 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8489 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8490 * Delete character(s) before the cursor.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8491 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8492 #ifdef FEAT_RIGHTLEFT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8493 if (revins_on) /* put cursor on last inserted char */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8494 dec_cursor();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8495 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8496 mincol = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8497 /* keep indent */
1085
f299f0bf32d7 updated for version 7.0-211
vimboss
parents: 1074
diff changeset
8498 if (mode == BACKSPACE_LINE
f299f0bf32d7 updated for version 7.0-211
vimboss
parents: 1074
diff changeset
8499 && (curbuf->b_p_ai
f299f0bf32d7 updated for version 7.0-211
vimboss
parents: 1074
diff changeset
8500 #ifdef FEAT_CINDENT
f299f0bf32d7 updated for version 7.0-211
vimboss
parents: 1074
diff changeset
8501 || cindent_on()
f299f0bf32d7 updated for version 7.0-211
vimboss
parents: 1074
diff changeset
8502 #endif
f299f0bf32d7 updated for version 7.0-211
vimboss
parents: 1074
diff changeset
8503 )
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8504 #ifdef FEAT_RIGHTLEFT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8505 && !revins_on
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8506 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8507 )
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8508 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8509 temp = curwin->w_cursor.col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8510 beginline(BL_WHITE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8511 if (curwin->w_cursor.col < (colnr_T)temp)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8512 mincol = curwin->w_cursor.col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8513 curwin->w_cursor.col = temp;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8514 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8515
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8516 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8517 * Handle deleting one 'shiftwidth' or 'softtabstop'.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8518 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8519 if ( mode == BACKSPACE_CHAR
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8520 && ((p_sta && in_indent)
648
9032e4668296 updated for version 7.0189
vimboss
parents: 644
diff changeset
8521 || (curbuf->b_p_sts != 0
1497
f14f7aab5187 updated for version 7.1-212
vimboss
parents: 1496
diff changeset
8522 && curwin->w_cursor.col > 0
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8523 && (*(ml_get_cursor() - 1) == TAB
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8524 || (*(ml_get_cursor() - 1) == ' '
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8525 && (!*inserted_space_p
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8526 || arrow_used))))))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8527 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8528 int ts;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8529 colnr_T vcol;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8530 colnr_T want_vcol;
1460
b0dabd584b8f updated for version 7.1-175
vimboss
parents: 1446
diff changeset
8531 colnr_T start_vcol;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8532
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8533 *inserted_space_p = FALSE;
648
9032e4668296 updated for version 7.0189
vimboss
parents: 644
diff changeset
8534 if (p_sta && in_indent)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8535 ts = curbuf->b_p_sw;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8536 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8537 ts = curbuf->b_p_sts;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8538 /* Compute the virtual column where we want to be. Since
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8539 * 'showbreak' may get in the way, need to get the last column of
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8540 * the previous character. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8541 getvcol(curwin, &curwin->w_cursor, &vcol, NULL, NULL);
1460
b0dabd584b8f updated for version 7.1-175
vimboss
parents: 1446
diff changeset
8542 start_vcol = vcol;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8543 dec_cursor();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8544 getvcol(curwin, &curwin->w_cursor, NULL, NULL, &want_vcol);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8545 inc_cursor();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8546 want_vcol = (want_vcol / ts) * ts;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8547
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8548 /* delete characters until we are at or before want_vcol */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8549 while (vcol > want_vcol
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8550 && (cc = *(ml_get_cursor() - 1), vim_iswhite(cc)))
1460
b0dabd584b8f updated for version 7.1-175
vimboss
parents: 1446
diff changeset
8551 ins_bs_one(&vcol);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8552
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8553 /* insert extra spaces until we are at want_vcol */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8554 while (vcol < want_vcol)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8555 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8556 /* Remember the first char we inserted */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8557 if (curwin->w_cursor.lnum == Insstart.lnum
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8558 && curwin->w_cursor.col < Insstart.col)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8559 Insstart.col = curwin->w_cursor.col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8560
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8561 #ifdef FEAT_VREPLACE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8562 if (State & VREPLACE_FLAG)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8563 ins_char(' ');
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8564 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8565 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8566 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8567 ins_str((char_u *)" ");
1460
b0dabd584b8f updated for version 7.1-175
vimboss
parents: 1446
diff changeset
8568 if ((State & REPLACE_FLAG))
b0dabd584b8f updated for version 7.1-175
vimboss
parents: 1446
diff changeset
8569 replace_push(NUL);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8570 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8571 getvcol(curwin, &curwin->w_cursor, &vcol, NULL, NULL);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8572 }
1460
b0dabd584b8f updated for version 7.1-175
vimboss
parents: 1446
diff changeset
8573
b0dabd584b8f updated for version 7.1-175
vimboss
parents: 1446
diff changeset
8574 /* If we are now back where we started delete one character. Can
b0dabd584b8f updated for version 7.1-175
vimboss
parents: 1446
diff changeset
8575 * happen when using 'sts' and 'linebreak'. */
b0dabd584b8f updated for version 7.1-175
vimboss
parents: 1446
diff changeset
8576 if (vcol >= start_vcol)
b0dabd584b8f updated for version 7.1-175
vimboss
parents: 1446
diff changeset
8577 ins_bs_one(&vcol);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8578 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8579
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8580 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8581 * Delete upto starting point, start of line or previous word.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8582 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8583 else do
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8584 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8585 #ifdef FEAT_RIGHTLEFT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8586 if (!revins_on) /* put cursor on char to be deleted */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8587 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8588 dec_cursor();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8589
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8590 /* start of word? */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8591 if (mode == BACKSPACE_WORD && !vim_isspace(gchar_cursor()))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8592 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8593 mode = BACKSPACE_WORD_NOT_SPACE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8594 temp = vim_iswordc(gchar_cursor());
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8595 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8596 /* end of word? */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8597 else if (mode == BACKSPACE_WORD_NOT_SPACE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8598 && (vim_isspace(cc = gchar_cursor())
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8599 || vim_iswordc(cc) != temp))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8600 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8601 #ifdef FEAT_RIGHTLEFT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8602 if (!revins_on)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8603 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8604 inc_cursor();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8605 #ifdef FEAT_RIGHTLEFT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8606 else if (State & REPLACE_FLAG)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8607 dec_cursor();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8608 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8609 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8610 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8611 if (State & REPLACE_FLAG)
1782
12cecc379574 updated for version 7.2-080
vimboss
parents: 1698
diff changeset
8612 replace_do_bs(-1);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8613 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8614 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8615 #ifdef FEAT_MBYTE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8616 if (enc_utf8 && p_deco)
714
0f9f4761ad9c updated for version 7.0216
vimboss
parents: 712
diff changeset
8617 (void)utfc_ptr2char(ml_get_cursor(), cpc);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8618 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8619 (void)del_char(FALSE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8620 #ifdef FEAT_MBYTE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8621 /*
714
0f9f4761ad9c updated for version 7.0216
vimboss
parents: 712
diff changeset
8622 * If there are combining characters and 'delcombine' is set
0f9f4761ad9c updated for version 7.0216
vimboss
parents: 712
diff changeset
8623 * move the cursor back. Don't back up before the base
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8624 * character.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8625 */
714
0f9f4761ad9c updated for version 7.0216
vimboss
parents: 712
diff changeset
8626 if (enc_utf8 && p_deco && cpc[0] != NUL)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8627 inc_cursor();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8628 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8629 #ifdef FEAT_RIGHTLEFT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8630 if (revins_chars)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8631 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8632 revins_chars--;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8633 revins_legal++;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8634 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8635 if (revins_on && gchar_cursor() == NUL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8636 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8637 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8638 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8639 /* Just a single backspace?: */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8640 if (mode == BACKSPACE_CHAR)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8641 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8642 } while (
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8643 #ifdef FEAT_RIGHTLEFT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8644 revins_on ||
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8645 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8646 (curwin->w_cursor.col > mincol
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8647 && (curwin->w_cursor.lnum != Insstart.lnum
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8648 || curwin->w_cursor.col != Insstart.col)));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8649 did_backspace = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8650 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8651 #ifdef FEAT_SMARTINDENT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8652 did_si = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8653 can_si = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8654 can_si_back = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8655 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8656 if (curwin->w_cursor.col <= 1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8657 did_ai = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8658 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8659 * It's a little strange to put backspaces into the redo
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8660 * buffer, but it makes auto-indent a lot easier to deal
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8661 * with.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8662 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8663 AppendCharToRedobuff(c);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8664
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8665 /* If deleted before the insertion point, adjust it */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8666 if (curwin->w_cursor.lnum == Insstart.lnum
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8667 && curwin->w_cursor.col < Insstart.col)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8668 Insstart.col = curwin->w_cursor.col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8669
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8670 /* vi behaviour: the cursor moves backward but the character that
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8671 * was there remains visible
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8672 * Vim behaviour: the cursor moves backward and the character that
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8673 * was there is erased from the screen.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8674 * We can emulate the vi behaviour by pretending there is a dollar
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8675 * displayed even when there isn't.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8676 * --pkv Sun Jan 19 01:56:40 EST 2003 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8677 if (vim_strchr(p_cpo, CPO_BACKSPACE) != NULL && dollar_vcol == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8678 dollar_vcol = curwin->w_virtcol;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8679
1514
8a22a90c964a updated for version 7.1-229
vimboss
parents: 1506
diff changeset
8680 #ifdef FEAT_FOLDING
8a22a90c964a updated for version 7.1-229
vimboss
parents: 1506
diff changeset
8681 /* When deleting a char the cursor line must never be in a closed fold.
8a22a90c964a updated for version 7.1-229
vimboss
parents: 1506
diff changeset
8682 * E.g., when 'foldmethod' is indent and deleting the first non-white
8a22a90c964a updated for version 7.1-229
vimboss
parents: 1506
diff changeset
8683 * char before a Tab. */
8a22a90c964a updated for version 7.1-229
vimboss
parents: 1506
diff changeset
8684 if (did_backspace)
8a22a90c964a updated for version 7.1-229
vimboss
parents: 1506
diff changeset
8685 foldOpenCursor();
8a22a90c964a updated for version 7.1-229
vimboss
parents: 1506
diff changeset
8686 #endif
8a22a90c964a updated for version 7.1-229
vimboss
parents: 1506
diff changeset
8687
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8688 return did_backspace;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8689 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8690
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8691 #ifdef FEAT_MOUSE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8692 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8693 ins_mouse(c)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8694 int c;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8695 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8696 pos_T tpos;
840
2c885fab04e3 updated for version 7.0e06
vimboss
parents: 836
diff changeset
8697 win_T *old_curwin = curwin;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8698
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8699 # ifdef FEAT_GUI
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8700 /* When GUI is active, also move/paste when 'mouse' is empty */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8701 if (!gui.in_use)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8702 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8703 if (!mouse_has(MOUSE_INSERT))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8704 return;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8705
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8706 undisplay_dollar();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8707 tpos = curwin->w_cursor;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8708 if (do_mouse(NULL, c, BACKWARD, 1L, 0))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8709 {
840
2c885fab04e3 updated for version 7.0e06
vimboss
parents: 836
diff changeset
8710 #ifdef FEAT_WINDOWS
2c885fab04e3 updated for version 7.0e06
vimboss
parents: 836
diff changeset
8711 win_T *new_curwin = curwin;
2c885fab04e3 updated for version 7.0e06
vimboss
parents: 836
diff changeset
8712
2c885fab04e3 updated for version 7.0e06
vimboss
parents: 836
diff changeset
8713 if (curwin != old_curwin && win_valid(old_curwin))
2c885fab04e3 updated for version 7.0e06
vimboss
parents: 836
diff changeset
8714 {
2c885fab04e3 updated for version 7.0e06
vimboss
parents: 836
diff changeset
8715 /* Mouse took us to another window. We need to go back to the
2c885fab04e3 updated for version 7.0e06
vimboss
parents: 836
diff changeset
8716 * previous one to stop insert there properly. */
2c885fab04e3 updated for version 7.0e06
vimboss
parents: 836
diff changeset
8717 curwin = old_curwin;
2c885fab04e3 updated for version 7.0e06
vimboss
parents: 836
diff changeset
8718 curbuf = curwin->w_buffer;
2c885fab04e3 updated for version 7.0e06
vimboss
parents: 836
diff changeset
8719 }
2c885fab04e3 updated for version 7.0e06
vimboss
parents: 836
diff changeset
8720 #endif
2c885fab04e3 updated for version 7.0e06
vimboss
parents: 836
diff changeset
8721 start_arrow(curwin == old_curwin ? &tpos : NULL);
2c885fab04e3 updated for version 7.0e06
vimboss
parents: 836
diff changeset
8722 #ifdef FEAT_WINDOWS
2c885fab04e3 updated for version 7.0e06
vimboss
parents: 836
diff changeset
8723 if (curwin != new_curwin && win_valid(new_curwin))
2c885fab04e3 updated for version 7.0e06
vimboss
parents: 836
diff changeset
8724 {
2c885fab04e3 updated for version 7.0e06
vimboss
parents: 836
diff changeset
8725 curwin = new_curwin;
2c885fab04e3 updated for version 7.0e06
vimboss
parents: 836
diff changeset
8726 curbuf = curwin->w_buffer;
2c885fab04e3 updated for version 7.0e06
vimboss
parents: 836
diff changeset
8727 }
2c885fab04e3 updated for version 7.0e06
vimboss
parents: 836
diff changeset
8728 #endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8729 # ifdef FEAT_CINDENT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8730 can_cindent = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8731 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8732 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8733
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8734 #ifdef FEAT_WINDOWS
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8735 /* redraw status lines (in case another window became active) */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8736 redraw_statuslines();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8737 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8738 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8739
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8740 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8741 ins_mousescroll(up)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8742 int up;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8743 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8744 pos_T tpos;
1434
40aa7ae37901 updated for version 7.1-149
vimboss
parents: 1430
diff changeset
8745 # if defined(FEAT_WINDOWS)
40aa7ae37901 updated for version 7.1-149
vimboss
parents: 1430
diff changeset
8746 win_T *old_curwin = curwin;
40aa7ae37901 updated for version 7.1-149
vimboss
parents: 1430
diff changeset
8747 # endif
40aa7ae37901 updated for version 7.1-149
vimboss
parents: 1430
diff changeset
8748 # ifdef FEAT_INS_EXPAND
40aa7ae37901 updated for version 7.1-149
vimboss
parents: 1430
diff changeset
8749 int did_scroll = FALSE;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8750 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8751
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8752 tpos = curwin->w_cursor;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8753
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8754 # if defined(FEAT_GUI) && defined(FEAT_WINDOWS)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8755 /* Currently the mouse coordinates are only known in the GUI. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8756 if (gui.in_use && mouse_row >= 0 && mouse_col >= 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8757 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8758 int row, col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8759
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8760 row = mouse_row;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8761 col = mouse_col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8762
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8763 /* find the window at the pointer coordinates */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8764 curwin = mouse_find_win(&row, &col);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8765 curbuf = curwin->w_buffer;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8766 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8767 if (curwin == old_curwin)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8768 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8769 undisplay_dollar();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8770
1434
40aa7ae37901 updated for version 7.1-149
vimboss
parents: 1430
diff changeset
8771 # ifdef FEAT_INS_EXPAND
40aa7ae37901 updated for version 7.1-149
vimboss
parents: 1430
diff changeset
8772 /* Don't scroll the window in which completion is being done. */
40aa7ae37901 updated for version 7.1-149
vimboss
parents: 1430
diff changeset
8773 if (!pum_visible()
40aa7ae37901 updated for version 7.1-149
vimboss
parents: 1430
diff changeset
8774 # if defined(FEAT_WINDOWS)
40aa7ae37901 updated for version 7.1-149
vimboss
parents: 1430
diff changeset
8775 || curwin != old_curwin
40aa7ae37901 updated for version 7.1-149
vimboss
parents: 1430
diff changeset
8776 # endif
40aa7ae37901 updated for version 7.1-149
vimboss
parents: 1430
diff changeset
8777 )
40aa7ae37901 updated for version 7.1-149
vimboss
parents: 1430
diff changeset
8778 # endif
40aa7ae37901 updated for version 7.1-149
vimboss
parents: 1430
diff changeset
8779 {
40aa7ae37901 updated for version 7.1-149
vimboss
parents: 1430
diff changeset
8780 if (mod_mask & (MOD_MASK_SHIFT | MOD_MASK_CTRL))
40aa7ae37901 updated for version 7.1-149
vimboss
parents: 1430
diff changeset
8781 scroll_redraw(up, (long)(curwin->w_botline - curwin->w_topline));
40aa7ae37901 updated for version 7.1-149
vimboss
parents: 1430
diff changeset
8782 else
40aa7ae37901 updated for version 7.1-149
vimboss
parents: 1430
diff changeset
8783 scroll_redraw(up, 3L);
40aa7ae37901 updated for version 7.1-149
vimboss
parents: 1430
diff changeset
8784 # ifdef FEAT_INS_EXPAND
40aa7ae37901 updated for version 7.1-149
vimboss
parents: 1430
diff changeset
8785 did_scroll = TRUE;
40aa7ae37901 updated for version 7.1-149
vimboss
parents: 1430
diff changeset
8786 # endif
40aa7ae37901 updated for version 7.1-149
vimboss
parents: 1430
diff changeset
8787 }
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8788
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8789 # if defined(FEAT_GUI) && defined(FEAT_WINDOWS)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8790 curwin->w_redr_status = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8791
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8792 curwin = old_curwin;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8793 curbuf = curwin->w_buffer;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8794 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8795
1434
40aa7ae37901 updated for version 7.1-149
vimboss
parents: 1430
diff changeset
8796 # ifdef FEAT_INS_EXPAND
40aa7ae37901 updated for version 7.1-149
vimboss
parents: 1430
diff changeset
8797 /* The popup menu may overlay the window, need to redraw it.
40aa7ae37901 updated for version 7.1-149
vimboss
parents: 1430
diff changeset
8798 * TODO: Would be more efficient to only redraw the windows that are
40aa7ae37901 updated for version 7.1-149
vimboss
parents: 1430
diff changeset
8799 * overlapped by the popup menu. */
40aa7ae37901 updated for version 7.1-149
vimboss
parents: 1430
diff changeset
8800 if (pum_visible() && did_scroll)
40aa7ae37901 updated for version 7.1-149
vimboss
parents: 1430
diff changeset
8801 {
40aa7ae37901 updated for version 7.1-149
vimboss
parents: 1430
diff changeset
8802 redraw_all_later(NOT_VALID);
40aa7ae37901 updated for version 7.1-149
vimboss
parents: 1430
diff changeset
8803 ins_compl_show_pum();
40aa7ae37901 updated for version 7.1-149
vimboss
parents: 1430
diff changeset
8804 }
40aa7ae37901 updated for version 7.1-149
vimboss
parents: 1430
diff changeset
8805 # endif
40aa7ae37901 updated for version 7.1-149
vimboss
parents: 1430
diff changeset
8806
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8807 if (!equalpos(curwin->w_cursor, tpos))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8808 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8809 start_arrow(&tpos);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8810 # ifdef FEAT_CINDENT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8811 can_cindent = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8812 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8813 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8814 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8815 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8816
692
a28f83d37113 updated for version 7.0208
vimboss
parents: 683
diff changeset
8817 #if defined(FEAT_GUI_TABLINE) || defined(PROTO)
724
a35dce0cabc5 updated for version 7.0220
vimboss
parents: 716
diff changeset
8818 static void
692
a28f83d37113 updated for version 7.0208
vimboss
parents: 683
diff changeset
8819 ins_tabline(c)
a28f83d37113 updated for version 7.0208
vimboss
parents: 683
diff changeset
8820 int c;
a28f83d37113 updated for version 7.0208
vimboss
parents: 683
diff changeset
8821 {
a28f83d37113 updated for version 7.0208
vimboss
parents: 683
diff changeset
8822 /* We will be leaving the current window, unless closing another tab. */
a28f83d37113 updated for version 7.0208
vimboss
parents: 683
diff changeset
8823 if (c != K_TABMENU || current_tabmenu != TABLINE_MENU_CLOSE
a28f83d37113 updated for version 7.0208
vimboss
parents: 683
diff changeset
8824 || (current_tab != 0 && current_tab != tabpage_index(curtab)))
a28f83d37113 updated for version 7.0208
vimboss
parents: 683
diff changeset
8825 {
a28f83d37113 updated for version 7.0208
vimboss
parents: 683
diff changeset
8826 undisplay_dollar();
a28f83d37113 updated for version 7.0208
vimboss
parents: 683
diff changeset
8827 start_arrow(&curwin->w_cursor);
a28f83d37113 updated for version 7.0208
vimboss
parents: 683
diff changeset
8828 # ifdef FEAT_CINDENT
a28f83d37113 updated for version 7.0208
vimboss
parents: 683
diff changeset
8829 can_cindent = TRUE;
a28f83d37113 updated for version 7.0208
vimboss
parents: 683
diff changeset
8830 # endif
a28f83d37113 updated for version 7.0208
vimboss
parents: 683
diff changeset
8831 }
a28f83d37113 updated for version 7.0208
vimboss
parents: 683
diff changeset
8832
a28f83d37113 updated for version 7.0208
vimboss
parents: 683
diff changeset
8833 if (c == K_TABLINE)
a28f83d37113 updated for version 7.0208
vimboss
parents: 683
diff changeset
8834 goto_tabpage(current_tab);
a28f83d37113 updated for version 7.0208
vimboss
parents: 683
diff changeset
8835 else
846
db44f7b81373 updated for version 7.0f03
vimboss
parents: 844
diff changeset
8836 {
692
a28f83d37113 updated for version 7.0208
vimboss
parents: 683
diff changeset
8837 handle_tabmenu();
846
db44f7b81373 updated for version 7.0f03
vimboss
parents: 844
diff changeset
8838 redraw_statuslines(); /* will redraw the tabline when needed */
db44f7b81373 updated for version 7.0f03
vimboss
parents: 844
diff changeset
8839 }
692
a28f83d37113 updated for version 7.0208
vimboss
parents: 683
diff changeset
8840 }
a28f83d37113 updated for version 7.0208
vimboss
parents: 683
diff changeset
8841 #endif
a28f83d37113 updated for version 7.0208
vimboss
parents: 683
diff changeset
8842
a28f83d37113 updated for version 7.0208
vimboss
parents: 683
diff changeset
8843 #if defined(FEAT_GUI) || defined(PROTO)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8844 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8845 ins_scroll()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8846 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8847 pos_T tpos;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8848
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8849 undisplay_dollar();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8850 tpos = curwin->w_cursor;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8851 if (gui_do_scroll())
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8852 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8853 start_arrow(&tpos);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8854 # ifdef FEAT_CINDENT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8855 can_cindent = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8856 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8857 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8858 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8859
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8860 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8861 ins_horscroll()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8862 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8863 pos_T tpos;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8864
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8865 undisplay_dollar();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8866 tpos = curwin->w_cursor;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8867 if (gui_do_horiz_scroll())
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8868 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8869 start_arrow(&tpos);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8870 # ifdef FEAT_CINDENT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8871 can_cindent = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8872 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8873 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8874 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8875 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8876
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8877 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8878 ins_left()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8879 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8880 pos_T tpos;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8881
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8882 #ifdef FEAT_FOLDING
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8883 if ((fdo_flags & FDO_HOR) && KeyTyped)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8884 foldOpenCursor();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8885 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8886 undisplay_dollar();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8887 tpos = curwin->w_cursor;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8888 if (oneleft() == OK)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8889 {
941
d95676480093 updated for version 7.0-067
vimboss
parents: 938
diff changeset
8890 #if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
d95676480093 updated for version 7.0-067
vimboss
parents: 938
diff changeset
8891 /* Only call start_arrow() when not busy with preediting, it will
d95676480093 updated for version 7.0-067
vimboss
parents: 938
diff changeset
8892 * break undo. K_LEFT is inserted in im_correct_cursor(). */
d95676480093 updated for version 7.0-067
vimboss
parents: 938
diff changeset
8893 if (!im_is_preediting())
d95676480093 updated for version 7.0-067
vimboss
parents: 938
diff changeset
8894 #endif
d95676480093 updated for version 7.0-067
vimboss
parents: 938
diff changeset
8895 start_arrow(&tpos);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8896 #ifdef FEAT_RIGHTLEFT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8897 /* If exit reversed string, position is fixed */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8898 if (revins_scol != -1 && (int)curwin->w_cursor.col >= revins_scol)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8899 revins_legal++;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8900 revins_chars++;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8901 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8902 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8903
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8904 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8905 * if 'whichwrap' set for cursor in insert mode may go to
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8906 * previous line
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8907 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8908 else if (vim_strchr(p_ww, '[') != NULL && curwin->w_cursor.lnum > 1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8909 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8910 start_arrow(&tpos);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8911 --(curwin->w_cursor.lnum);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8912 coladvance((colnr_T)MAXCOL);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8913 curwin->w_set_curswant = TRUE; /* so we stay at the end */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8914 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8915 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8916 vim_beep();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8917 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8918
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8919 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8920 ins_home(c)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8921 int c;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8922 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8923 pos_T tpos;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8924
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8925 #ifdef FEAT_FOLDING
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8926 if ((fdo_flags & FDO_HOR) && KeyTyped)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8927 foldOpenCursor();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8928 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8929 undisplay_dollar();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8930 tpos = curwin->w_cursor;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8931 if (c == K_C_HOME)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8932 curwin->w_cursor.lnum = 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8933 curwin->w_cursor.col = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8934 #ifdef FEAT_VIRTUALEDIT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8935 curwin->w_cursor.coladd = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8936 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8937 curwin->w_curswant = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8938 start_arrow(&tpos);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8939 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8940
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8941 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8942 ins_end(c)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8943 int c;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8944 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8945 pos_T tpos;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8946
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8947 #ifdef FEAT_FOLDING
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8948 if ((fdo_flags & FDO_HOR) && KeyTyped)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8949 foldOpenCursor();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8950 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8951 undisplay_dollar();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8952 tpos = curwin->w_cursor;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8953 if (c == K_C_END)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8954 curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8955 coladvance((colnr_T)MAXCOL);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8956 curwin->w_curswant = MAXCOL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8957
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8958 start_arrow(&tpos);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8959 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8960
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8961 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8962 ins_s_left()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8963 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8964 #ifdef FEAT_FOLDING
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8965 if ((fdo_flags & FDO_HOR) && KeyTyped)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8966 foldOpenCursor();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8967 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8968 undisplay_dollar();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8969 if (curwin->w_cursor.lnum > 1 || curwin->w_cursor.col > 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8970 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8971 start_arrow(&curwin->w_cursor);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8972 (void)bck_word(1L, FALSE, FALSE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8973 curwin->w_set_curswant = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8974 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8975 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8976 vim_beep();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8977 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8978
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8979 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8980 ins_right()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8981 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8982 #ifdef FEAT_FOLDING
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8983 if ((fdo_flags & FDO_HOR) && KeyTyped)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8984 foldOpenCursor();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8985 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8986 undisplay_dollar();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8987 if (gchar_cursor() != NUL || virtual_active()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8988 )
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8989 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8990 start_arrow(&curwin->w_cursor);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8991 curwin->w_set_curswant = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8992 #ifdef FEAT_VIRTUALEDIT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8993 if (virtual_active())
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8994 oneright();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8995 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8996 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8997 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8998 #ifdef FEAT_MBYTE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8999 if (has_mbyte)
474
a5fcf36ef512 updated for version 7.0127
vimboss
parents: 470
diff changeset
9000 curwin->w_cursor.col += (*mb_ptr2len)(ml_get_cursor());
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9001 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9002 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9003 ++curwin->w_cursor.col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9004 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9005
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9006 #ifdef FEAT_RIGHTLEFT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9007 revins_legal++;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9008 if (revins_chars)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9009 revins_chars--;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9010 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9011 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9012 /* if 'whichwrap' set for cursor in insert mode, may move the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9013 * cursor to the next line */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9014 else if (vim_strchr(p_ww, ']') != NULL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9015 && curwin->w_cursor.lnum < curbuf->b_ml.ml_line_count)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9016 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9017 start_arrow(&curwin->w_cursor);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9018 curwin->w_set_curswant = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9019 ++curwin->w_cursor.lnum;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9020 curwin->w_cursor.col = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9021 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9022 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9023 vim_beep();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9024 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9025
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9026 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9027 ins_s_right()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9028 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9029 #ifdef FEAT_FOLDING
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9030 if ((fdo_flags & FDO_HOR) && KeyTyped)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9031 foldOpenCursor();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9032 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9033 undisplay_dollar();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9034 if (curwin->w_cursor.lnum < curbuf->b_ml.ml_line_count
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9035 || gchar_cursor() != NUL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9036 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9037 start_arrow(&curwin->w_cursor);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9038 (void)fwd_word(1L, FALSE, 0);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9039 curwin->w_set_curswant = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9040 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9041 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9042 vim_beep();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9043 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9044
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9045 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9046 ins_up(startcol)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9047 int startcol; /* when TRUE move to Insstart.col */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9048 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9049 pos_T tpos;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9050 linenr_T old_topline = curwin->w_topline;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9051 #ifdef FEAT_DIFF
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9052 int old_topfill = curwin->w_topfill;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9053 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9054
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9055 undisplay_dollar();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9056 tpos = curwin->w_cursor;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9057 if (cursor_up(1L, TRUE) == OK)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9058 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9059 if (startcol)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9060 coladvance(getvcol_nolist(&Insstart));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9061 if (old_topline != curwin->w_topline
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9062 #ifdef FEAT_DIFF
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9063 || old_topfill != curwin->w_topfill
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9064 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9065 )
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9066 redraw_later(VALID);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9067 start_arrow(&tpos);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9068 #ifdef FEAT_CINDENT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9069 can_cindent = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9070 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9071 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9072 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9073 vim_beep();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9074 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9075
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9076 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9077 ins_pageup()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9078 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9079 pos_T tpos;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9080
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9081 undisplay_dollar();
828
01583c79d5f4 updated for version 7.0d03
vimboss
parents: 826
diff changeset
9082
01583c79d5f4 updated for version 7.0d03
vimboss
parents: 826
diff changeset
9083 #ifdef FEAT_WINDOWS
01583c79d5f4 updated for version 7.0d03
vimboss
parents: 826
diff changeset
9084 if (mod_mask & MOD_MASK_CTRL)
01583c79d5f4 updated for version 7.0d03
vimboss
parents: 826
diff changeset
9085 {
01583c79d5f4 updated for version 7.0d03
vimboss
parents: 826
diff changeset
9086 /* <C-PageUp>: tab page back */
1013
61e5d40135d0 updated for version 7.0-139
vimboss
parents: 1007
diff changeset
9087 if (first_tabpage->tp_next != NULL)
61e5d40135d0 updated for version 7.0-139
vimboss
parents: 1007
diff changeset
9088 {
61e5d40135d0 updated for version 7.0-139
vimboss
parents: 1007
diff changeset
9089 start_arrow(&curwin->w_cursor);
61e5d40135d0 updated for version 7.0-139
vimboss
parents: 1007
diff changeset
9090 goto_tabpage(-1);
61e5d40135d0 updated for version 7.0-139
vimboss
parents: 1007
diff changeset
9091 }
828
01583c79d5f4 updated for version 7.0d03
vimboss
parents: 826
diff changeset
9092 return;
01583c79d5f4 updated for version 7.0d03
vimboss
parents: 826
diff changeset
9093 }
01583c79d5f4 updated for version 7.0d03
vimboss
parents: 826
diff changeset
9094 #endif
01583c79d5f4 updated for version 7.0d03
vimboss
parents: 826
diff changeset
9095
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9096 tpos = curwin->w_cursor;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9097 if (onepage(BACKWARD, 1L) == OK)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9098 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9099 start_arrow(&tpos);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9100 #ifdef FEAT_CINDENT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9101 can_cindent = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9102 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9103 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9104 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9105 vim_beep();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9106 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9107
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9108 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9109 ins_down(startcol)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9110 int startcol; /* when TRUE move to Insstart.col */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9111 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9112 pos_T tpos;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9113 linenr_T old_topline = curwin->w_topline;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9114 #ifdef FEAT_DIFF
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9115 int old_topfill = curwin->w_topfill;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9116 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9117
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9118 undisplay_dollar();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9119 tpos = curwin->w_cursor;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9120 if (cursor_down(1L, TRUE) == OK)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9121 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9122 if (startcol)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9123 coladvance(getvcol_nolist(&Insstart));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9124 if (old_topline != curwin->w_topline
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9125 #ifdef FEAT_DIFF
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9126 || old_topfill != curwin->w_topfill
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9127 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9128 )
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9129 redraw_later(VALID);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9130 start_arrow(&tpos);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9131 #ifdef FEAT_CINDENT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9132 can_cindent = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9133 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9134 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9135 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9136 vim_beep();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9137 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9138
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9139 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9140 ins_pagedown()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9141 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9142 pos_T tpos;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9143
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9144 undisplay_dollar();
828
01583c79d5f4 updated for version 7.0d03
vimboss
parents: 826
diff changeset
9145
01583c79d5f4 updated for version 7.0d03
vimboss
parents: 826
diff changeset
9146 #ifdef FEAT_WINDOWS
01583c79d5f4 updated for version 7.0d03
vimboss
parents: 826
diff changeset
9147 if (mod_mask & MOD_MASK_CTRL)
01583c79d5f4 updated for version 7.0d03
vimboss
parents: 826
diff changeset
9148 {
01583c79d5f4 updated for version 7.0d03
vimboss
parents: 826
diff changeset
9149 /* <C-PageDown>: tab page forward */
1013
61e5d40135d0 updated for version 7.0-139
vimboss
parents: 1007
diff changeset
9150 if (first_tabpage->tp_next != NULL)
61e5d40135d0 updated for version 7.0-139
vimboss
parents: 1007
diff changeset
9151 {
61e5d40135d0 updated for version 7.0-139
vimboss
parents: 1007
diff changeset
9152 start_arrow(&curwin->w_cursor);
61e5d40135d0 updated for version 7.0-139
vimboss
parents: 1007
diff changeset
9153 goto_tabpage(0);
61e5d40135d0 updated for version 7.0-139
vimboss
parents: 1007
diff changeset
9154 }
828
01583c79d5f4 updated for version 7.0d03
vimboss
parents: 826
diff changeset
9155 return;
01583c79d5f4 updated for version 7.0d03
vimboss
parents: 826
diff changeset
9156 }
01583c79d5f4 updated for version 7.0d03
vimboss
parents: 826
diff changeset
9157 #endif
01583c79d5f4 updated for version 7.0d03
vimboss
parents: 826
diff changeset
9158
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9159 tpos = curwin->w_cursor;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9160 if (onepage(FORWARD, 1L) == OK)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9161 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9162 start_arrow(&tpos);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9163 #ifdef FEAT_CINDENT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9164 can_cindent = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9165 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9166 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9167 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9168 vim_beep();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9169 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9170
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9171 #ifdef FEAT_DND
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9172 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9173 ins_drop()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9174 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9175 do_put('~', BACKWARD, 1L, PUT_CURSEND);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9176 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9177 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9178
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9179 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9180 * Handle TAB in Insert or Replace mode.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9181 * Return TRUE when the TAB needs to be inserted like a normal character.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9182 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9183 static int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9184 ins_tab()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9185 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9186 int ind;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9187 int i;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9188 int temp;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9189
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9190 if (Insstart_blank_vcol == MAXCOL && curwin->w_cursor.lnum == Insstart.lnum)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9191 Insstart_blank_vcol = get_nolist_virtcol();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9192 if (echeck_abbr(TAB + ABBR_OFF))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9193 return FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9194
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9195 ind = inindent(0);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9196 #ifdef FEAT_CINDENT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9197 if (ind)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9198 can_cindent = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9199 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9200
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9201 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9202 * When nothing special, insert TAB like a normal character
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9203 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9204 if (!curbuf->b_p_et
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9205 && !(p_sta && ind && curbuf->b_p_ts != curbuf->b_p_sw)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9206 && curbuf->b_p_sts == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9207 return TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9208
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9209 if (stop_arrow() == FAIL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9210 return TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9211
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9212 did_ai = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9213 #ifdef FEAT_SMARTINDENT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9214 did_si = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9215 can_si = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9216 can_si_back = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9217 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9218 AppendToRedobuff((char_u *)"\t");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9219
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9220 if (p_sta && ind) /* insert tab in indent, use 'shiftwidth' */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9221 temp = (int)curbuf->b_p_sw;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9222 else if (curbuf->b_p_sts > 0) /* use 'softtabstop' when set */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9223 temp = (int)curbuf->b_p_sts;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9224 else /* otherwise use 'tabstop' */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9225 temp = (int)curbuf->b_p_ts;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9226 temp -= get_nolist_virtcol() % temp;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9227
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9228 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9229 * Insert the first space with ins_char(). It will delete one char in
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9230 * replace mode. Insert the rest with ins_str(); it will not delete any
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9231 * chars. For VREPLACE mode, we use ins_char() for all characters.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9232 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9233 ins_char(' ');
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9234 while (--temp > 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9235 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9236 #ifdef FEAT_VREPLACE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9237 if (State & VREPLACE_FLAG)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9238 ins_char(' ');
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9239 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9240 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9241 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9242 ins_str((char_u *)" ");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9243 if (State & REPLACE_FLAG) /* no char replaced */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9244 replace_push(NUL);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9245 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9246 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9247
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9248 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9249 * When 'expandtab' not set: Replace spaces by TABs where possible.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9250 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9251 if (!curbuf->b_p_et && (curbuf->b_p_sts || (p_sta && ind)))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9252 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9253 char_u *ptr;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9254 #ifdef FEAT_VREPLACE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9255 char_u *saved_line = NULL; /* init for GCC */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9256 pos_T pos;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9257 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9258 pos_T fpos;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9259 pos_T *cursor;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9260 colnr_T want_vcol, vcol;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9261 int change_col = -1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9262 int save_list = curwin->w_p_list;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9263
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9264 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9265 * Get the current line. For VREPLACE mode, don't make real changes
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9266 * yet, just work on a copy of the line.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9267 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9268 #ifdef FEAT_VREPLACE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9269 if (State & VREPLACE_FLAG)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9270 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9271 pos = curwin->w_cursor;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9272 cursor = &pos;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9273 saved_line = vim_strsave(ml_get_curline());
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9274 if (saved_line == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9275 return FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9276 ptr = saved_line + pos.col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9277 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9278 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9279 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9280 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9281 ptr = ml_get_cursor();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9282 cursor = &curwin->w_cursor;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9283 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9284
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9285 /* When 'L' is not in 'cpoptions' a tab always takes up 'ts' spaces. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9286 if (vim_strchr(p_cpo, CPO_LISTWM) == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9287 curwin->w_p_list = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9288
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9289 /* Find first white before the cursor */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9290 fpos = curwin->w_cursor;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9291 while (fpos.col > 0 && vim_iswhite(ptr[-1]))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9292 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9293 --fpos.col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9294 --ptr;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9295 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9296
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9297 /* In Replace mode, don't change characters before the insert point. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9298 if ((State & REPLACE_FLAG)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9299 && fpos.lnum == Insstart.lnum
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9300 && fpos.col < Insstart.col)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9301 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9302 ptr += Insstart.col - fpos.col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9303 fpos.col = Insstart.col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9304 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9305
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9306 /* compute virtual column numbers of first white and cursor */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9307 getvcol(curwin, &fpos, &vcol, NULL, NULL);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9308 getvcol(curwin, cursor, &want_vcol, NULL, NULL);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9309
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9310 /* Use as many TABs as possible. Beware of 'showbreak' and
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9311 * 'linebreak' adding extra virtual columns. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9312 while (vim_iswhite(*ptr))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9313 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9314 i = lbr_chartabsize((char_u *)"\t", vcol);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9315 if (vcol + i > want_vcol)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9316 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9317 if (*ptr != TAB)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9318 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9319 *ptr = TAB;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9320 if (change_col < 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9321 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9322 change_col = fpos.col; /* Column of first change */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9323 /* May have to adjust Insstart */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9324 if (fpos.lnum == Insstart.lnum && fpos.col < Insstart.col)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9325 Insstart.col = fpos.col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9326 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9327 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9328 ++fpos.col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9329 ++ptr;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9330 vcol += i;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9331 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9332
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9333 if (change_col >= 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9334 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9335 int repl_off = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9336
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9337 /* Skip over the spaces we need. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9338 while (vcol < want_vcol && *ptr == ' ')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9339 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9340 vcol += lbr_chartabsize(ptr, vcol);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9341 ++ptr;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9342 ++repl_off;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9343 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9344 if (vcol > want_vcol)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9345 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9346 /* Must have a char with 'showbreak' just before it. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9347 --ptr;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9348 --repl_off;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9349 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9350 fpos.col += repl_off;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9351
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9352 /* Delete following spaces. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9353 i = cursor->col - fpos.col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9354 if (i > 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9355 {
1622
149d8b46404c updated for version 7.2a
vimboss
parents: 1563
diff changeset
9356 STRMOVE(ptr, ptr + i);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9357 /* correct replace stack. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9358 if ((State & REPLACE_FLAG)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9359 #ifdef FEAT_VREPLACE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9360 && !(State & VREPLACE_FLAG)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9361 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9362 )
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9363 for (temp = i; --temp >= 0; )
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9364 replace_join(repl_off);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9365 }
33
f6033dcbaf31 updated for version 7.0020
vimboss
parents: 20
diff changeset
9366 #ifdef FEAT_NETBEANS_INTG
f6033dcbaf31 updated for version 7.0020
vimboss
parents: 20
diff changeset
9367 if (usingNetbeans)
f6033dcbaf31 updated for version 7.0020
vimboss
parents: 20
diff changeset
9368 {
f6033dcbaf31 updated for version 7.0020
vimboss
parents: 20
diff changeset
9369 netbeans_removed(curbuf, fpos.lnum, cursor->col,
f6033dcbaf31 updated for version 7.0020
vimboss
parents: 20
diff changeset
9370 (long)(i + 1));
f6033dcbaf31 updated for version 7.0020
vimboss
parents: 20
diff changeset
9371 netbeans_inserted(curbuf, fpos.lnum, cursor->col,
f6033dcbaf31 updated for version 7.0020
vimboss
parents: 20
diff changeset
9372 (char_u *)"\t", 1);
f6033dcbaf31 updated for version 7.0020
vimboss
parents: 20
diff changeset
9373 }
f6033dcbaf31 updated for version 7.0020
vimboss
parents: 20
diff changeset
9374 #endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9375 cursor->col -= i;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9376
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9377 #ifdef FEAT_VREPLACE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9378 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9379 * In VREPLACE mode, we haven't changed anything yet. Do it now by
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9380 * backspacing over the changed spacing and then inserting the new
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9381 * spacing.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9382 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9383 if (State & VREPLACE_FLAG)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9384 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9385 /* Backspace from real cursor to change_col */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9386 backspace_until_column(change_col);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9387
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9388 /* Insert each char in saved_line from changed_col to
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9389 * ptr-cursor */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9390 ins_bytes_len(saved_line + change_col,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9391 cursor->col - change_col);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9392 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9393 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9394 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9395
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9396 #ifdef FEAT_VREPLACE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9397 if (State & VREPLACE_FLAG)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9398 vim_free(saved_line);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9399 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9400 curwin->w_p_list = save_list;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9401 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9402
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9403 return FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9404 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9405
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9406 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9407 * Handle CR or NL in insert mode.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9408 * Return TRUE when out of memory or can't undo.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9409 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9410 static int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9411 ins_eol(c)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9412 int c;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9413 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9414 int i;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9415
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9416 if (echeck_abbr(c + ABBR_OFF))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9417 return FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9418 if (stop_arrow() == FAIL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9419 return TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9420 undisplay_dollar();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9421
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9422 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9423 * Strange Vi behaviour: In Replace mode, typing a NL will not delete the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9424 * character under the cursor. Only push a NUL on the replace stack,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9425 * nothing to put back when the NL is deleted.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9426 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9427 if ((State & REPLACE_FLAG)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9428 #ifdef FEAT_VREPLACE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9429 && !(State & VREPLACE_FLAG)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9430 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9431 )
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9432 replace_push(NUL);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9433
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9434 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9435 * In VREPLACE mode, a NL replaces the rest of the line, and starts
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9436 * replacing the next line, so we push all of the characters left on the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9437 * line onto the replace stack. This is not done here though, it is done
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9438 * in open_line().
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9439 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9440
844
d3bbb5dd3913 updated for version 7.0f02
vimboss
parents: 842
diff changeset
9441 #ifdef FEAT_VIRTUALEDIT
d3bbb5dd3913 updated for version 7.0f02
vimboss
parents: 842
diff changeset
9442 /* Put cursor on NUL if on the last char and coladd is 1 (happens after
d3bbb5dd3913 updated for version 7.0f02
vimboss
parents: 842
diff changeset
9443 * CTRL-O). */
d3bbb5dd3913 updated for version 7.0f02
vimboss
parents: 842
diff changeset
9444 if (virtual_active() && curwin->w_cursor.coladd > 0)
d3bbb5dd3913 updated for version 7.0f02
vimboss
parents: 842
diff changeset
9445 coladvance(getviscol());
d3bbb5dd3913 updated for version 7.0f02
vimboss
parents: 842
diff changeset
9446 #endif
d3bbb5dd3913 updated for version 7.0f02
vimboss
parents: 842
diff changeset
9447
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9448 #ifdef FEAT_RIGHTLEFT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9449 # ifdef FEAT_FKMAP
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9450 if (p_altkeymap && p_fkmap)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9451 fkmap(NL);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9452 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9453 /* NL in reverse insert will always start in the end of
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9454 * current line. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9455 if (revins_on)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9456 curwin->w_cursor.col += (colnr_T)STRLEN(ml_get_cursor());
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9457 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9458
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9459 AppendToRedobuff(NL_STR);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9460 i = open_line(FORWARD,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9461 #ifdef FEAT_COMMENTS
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9462 has_format_option(FO_RET_COMS) ? OPENLINE_DO_COM :
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9463 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9464 0, old_indent);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9465 old_indent = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9466 #ifdef FEAT_CINDENT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9467 can_cindent = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9468 #endif
1032
e6aed39f1264 updated for version 7.0-158
vimboss
parents: 1013
diff changeset
9469 #ifdef FEAT_FOLDING
e6aed39f1264 updated for version 7.0-158
vimboss
parents: 1013
diff changeset
9470 /* When inserting a line the cursor line must never be in a closed fold. */
e6aed39f1264 updated for version 7.0-158
vimboss
parents: 1013
diff changeset
9471 foldOpenCursor();
e6aed39f1264 updated for version 7.0-158
vimboss
parents: 1013
diff changeset
9472 #endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9473
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9474 return (!i);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9475 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9476
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9477 #ifdef FEAT_DIGRAPHS
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9478 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9479 * Handle digraph in insert mode.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9480 * Returns character still to be inserted, or NUL when nothing remaining to be
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9481 * done.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9482 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9483 static int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9484 ins_digraph()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9485 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9486 int c;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9487 int cc;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9488
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9489 pc_status = PC_STATUS_UNSET;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9490 if (redrawing() && !char_avail())
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9491 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9492 /* may need to redraw when no more chars available now */
661
e93a99ef31d0 updated for version 7.0195
vimboss
parents: 659
diff changeset
9493 ins_redraw(FALSE);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9494
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9495 edit_putchar('?', TRUE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9496 #ifdef FEAT_CMDL_INFO
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9497 add_to_showcmd_c(Ctrl_K);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9498 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9499 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9500
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9501 #ifdef USE_ON_FLY_SCROLL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9502 dont_scroll = TRUE; /* disallow scrolling here */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9503 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9504
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9505 /* don't map the digraph chars. This also prevents the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9506 * mode message to be deleted when ESC is hit */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9507 ++no_mapping;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9508 ++allow_keys;
1389
bdcfe793d49f updated for version 7.1-104
vimboss
parents: 1353
diff changeset
9509 c = plain_vgetc();
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9510 --no_mapping;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9511 --allow_keys;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9512 if (IS_SPECIAL(c) || mod_mask) /* special key */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9513 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9514 #ifdef FEAT_CMDL_INFO
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9515 clear_showcmd();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9516 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9517 insert_special(c, TRUE, FALSE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9518 return NUL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9519 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9520 if (c != ESC)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9521 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9522 if (redrawing() && !char_avail())
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9523 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9524 /* may need to redraw when no more chars available now */
661
e93a99ef31d0 updated for version 7.0195
vimboss
parents: 659
diff changeset
9525 ins_redraw(FALSE);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9526
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9527 if (char2cells(c) == 1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9528 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9529 /* first remove the '?', otherwise it's restored when typing
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9530 * an ESC next */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9531 edit_unputchar();
661
e93a99ef31d0 updated for version 7.0195
vimboss
parents: 659
diff changeset
9532 ins_redraw(FALSE);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9533 edit_putchar(c, TRUE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9534 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9535 #ifdef FEAT_CMDL_INFO
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9536 add_to_showcmd_c(c);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9537 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9538 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9539 ++no_mapping;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9540 ++allow_keys;
1389
bdcfe793d49f updated for version 7.1-104
vimboss
parents: 1353
diff changeset
9541 cc = plain_vgetc();
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9542 --no_mapping;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9543 --allow_keys;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9544 if (cc != ESC)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9545 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9546 AppendToRedobuff((char_u *)CTRL_V_STR);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9547 c = getdigraph(c, cc, TRUE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9548 #ifdef FEAT_CMDL_INFO
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9549 clear_showcmd();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9550 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9551 return c;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9552 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9553 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9554 edit_unputchar();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9555 #ifdef FEAT_CMDL_INFO
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9556 clear_showcmd();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9557 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9558 return NUL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9559 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9560 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9561
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9562 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9563 * Handle CTRL-E and CTRL-Y in Insert mode: copy char from other line.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9564 * Returns the char to be inserted, or NUL if none found.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9565 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9566 static int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9567 ins_copychar(lnum)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9568 linenr_T lnum;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9569 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9570 int c;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9571 int temp;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9572 char_u *ptr, *prev_ptr;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9573
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9574 if (lnum < 1 || lnum > curbuf->b_ml.ml_line_count)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9575 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9576 vim_beep();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9577 return NUL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9578 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9579
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9580 /* try to advance to the cursor column */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9581 temp = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9582 ptr = ml_get(lnum);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9583 prev_ptr = ptr;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9584 validate_virtcol();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9585 while ((colnr_T)temp < curwin->w_virtcol && *ptr != NUL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9586 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9587 prev_ptr = ptr;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9588 temp += lbr_chartabsize_adv(&ptr, (colnr_T)temp);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9589 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9590 if ((colnr_T)temp > curwin->w_virtcol)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9591 ptr = prev_ptr;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9592
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9593 #ifdef FEAT_MBYTE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9594 c = (*mb_ptr2char)(ptr);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9595 #else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9596 c = *ptr;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9597 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9598 if (c == NUL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9599 vim_beep();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9600 return c;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9601 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9602
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
9603 /*
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
9604 * CTRL-Y or CTRL-E typed in Insert mode.
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
9605 */
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
9606 static int
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
9607 ins_ctrl_ey(tc)
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
9608 int tc;
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
9609 {
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
9610 int c = tc;
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
9611
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
9612 #ifdef FEAT_INS_EXPAND
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
9613 if (ctrl_x_mode == CTRL_X_SCROLL)
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
9614 {
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
9615 if (c == Ctrl_Y)
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
9616 scrolldown_clamp();
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
9617 else
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
9618 scrollup_clamp();
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
9619 redraw_later(VALID);
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
9620 }
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
9621 else
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
9622 #endif
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
9623 {
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
9624 c = ins_copychar(curwin->w_cursor.lnum + (c == Ctrl_Y ? -1 : 1));
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
9625 if (c != NUL)
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
9626 {
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
9627 long tw_save;
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
9628
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
9629 /* The character must be taken literally, insert like it
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
9630 * was typed after a CTRL-V, and pretend 'textwidth'
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
9631 * wasn't set. Digits, 'o' and 'x' are special after a
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
9632 * CTRL-V, don't use it for these. */
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
9633 if (c < 256 && !isalnum(c))
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
9634 AppendToRedobuff((char_u *)CTRL_V_STR); /* CTRL-V */
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
9635 tw_save = curbuf->b_p_tw;
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
9636 curbuf->b_p_tw = -1;
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
9637 insert_special(c, TRUE, FALSE);
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
9638 curbuf->b_p_tw = tw_save;
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
9639 #ifdef FEAT_RIGHTLEFT
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
9640 revins_chars++;
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
9641 revins_legal++;
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
9642 #endif
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
9643 c = Ctrl_V; /* pretend CTRL-V is last character */
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
9644 auto_format(FALSE, TRUE);
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
9645 }
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
9646 }
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
9647 return c;
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
9648 }
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
9649
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9650 #ifdef FEAT_SMARTINDENT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9651 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9652 * Try to do some very smart auto-indenting.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9653 * Used when inserting a "normal" character.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9654 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9655 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9656 ins_try_si(c)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9657 int c;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9658 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9659 pos_T *pos, old_pos;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9660 char_u *ptr;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9661 int i;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9662 int temp;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9663
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9664 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9665 * do some very smart indenting when entering '{' or '}'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9666 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9667 if (((did_si || can_si_back) && c == '{') || (can_si && c == '}'))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9668 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9669 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9670 * for '}' set indent equal to indent of line containing matching '{'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9671 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9672 if (c == '}' && (pos = findmatch(NULL, '{')) != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9673 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9674 old_pos = curwin->w_cursor;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9675 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9676 * If the matching '{' has a ')' immediately before it (ignoring
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9677 * white-space), then line up with the start of the line
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9678 * containing the matching '(' if there is one. This handles the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9679 * case where an "if (..\n..) {" statement continues over multiple
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9680 * lines -- webb
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9681 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9682 ptr = ml_get(pos->lnum);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9683 i = pos->col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9684 if (i > 0) /* skip blanks before '{' */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9685 while (--i > 0 && vim_iswhite(ptr[i]))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9686 ;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9687 curwin->w_cursor.lnum = pos->lnum;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9688 curwin->w_cursor.col = i;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9689 if (ptr[i] == ')' && (pos = findmatch(NULL, '(')) != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9690 curwin->w_cursor = *pos;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9691 i = get_indent();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9692 curwin->w_cursor = old_pos;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9693 #ifdef FEAT_VREPLACE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9694 if (State & VREPLACE_FLAG)
1516
ee9d2d24ea9b updated for version 7.1-231
vimboss
parents: 1514
diff changeset
9695 change_indent(INDENT_SET, i, FALSE, NUL, TRUE);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9696 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9697 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9698 (void)set_indent(i, SIN_CHANGED);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9699 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9700 else if (curwin->w_cursor.col > 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9701 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9702 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9703 * when inserting '{' after "O" reduce indent, but not
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9704 * more than indent of previous line
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9705 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9706 temp = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9707 if (c == '{' && can_si_back && curwin->w_cursor.lnum > 1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9708 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9709 old_pos = curwin->w_cursor;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9710 i = get_indent();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9711 while (curwin->w_cursor.lnum > 1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9712 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9713 ptr = skipwhite(ml_get(--(curwin->w_cursor.lnum)));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9714
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9715 /* ignore empty lines and lines starting with '#'. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9716 if (*ptr != '#' && *ptr != NUL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9717 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9718 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9719 if (get_indent() >= i)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9720 temp = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9721 curwin->w_cursor = old_pos;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9722 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9723 if (temp)
1516
ee9d2d24ea9b updated for version 7.1-231
vimboss
parents: 1514
diff changeset
9724 shift_line(TRUE, FALSE, 1, TRUE);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9725 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9726 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9727
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9728 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9729 * set indent of '#' always to 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9730 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9731 if (curwin->w_cursor.col > 0 && can_si && c == '#')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9732 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9733 /* remember current indent for next line */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9734 old_indent = get_indent();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9735 (void)set_indent(0, SIN_CHANGED);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9736 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9737
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9738 /* Adjust ai_col, the char at this position can be deleted. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9739 if (ai_col > curwin->w_cursor.col)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9740 ai_col = curwin->w_cursor.col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9741 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9742 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9743
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9744 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9745 * Get the value that w_virtcol would have when 'list' is off.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9746 * Unless 'cpo' contains the 'L' flag.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9747 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9748 static colnr_T
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9749 get_nolist_virtcol()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9750 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9751 if (curwin->w_p_list && vim_strchr(p_cpo, CPO_LISTWM) == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9752 return getvcol_nolist(&curwin->w_cursor);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9753 validate_virtcol();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9754 return curwin->w_virtcol;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9755 }