annotate src/edit.c @ 572:2244be18d9e9 v7.0162

updated for version 7.0162
author vimboss
date Fri, 02 Dec 2005 00:50:49 +0000
parents f43150a669dc
children 25a70b1cd2da
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. */
477
f8b75b8f1988 updated for version 7.0128
vimboss
parents: 474
diff changeset
43 N_(" ^X mode (^]^D^E^F^I^K^L^N^O^P^S^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)"),
477
f8b75b8f1988 updated for version 7.0128
vimboss
parents: 474
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 */
464
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
65 typedef struct Completion compl_T;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
66 struct Completion
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 */
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
71 char_u *cp_fname; /* file containing the match */
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
72 int cp_flags; /* ORIGINAL_TEXT, CONT_S_IPOS or FREE_FNAME */
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
73 int cp_number; /* sequence number */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
74 };
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
75
464
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
76 #define ORIGINAL_TEXT (1) /* the original text when the expansion begun */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
77 #define FREE_FNAME (2)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
78
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
79 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
80 * All the current matches are stored in a list.
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
81 * "compl_first_match" points to the start of the list.
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
82 * "compl_curr_match" points to the currently selected entry.
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
83 * "compl_shown_match" is different from compl_curr_match during
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
84 * ins_compl_get_exp().
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
85 */
464
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
86 static compl_T *compl_first_match = NULL;
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
87 static compl_T *compl_curr_match = NULL;
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
88 static compl_T *compl_shown_match = NULL;
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
89
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
90 /* When the first completion is done "compl_started" is set. When it's
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
91 * FALSE the word to be completed must be located. */
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
92 static int compl_started = FALSE;
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
93
464
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
94 static int compl_matches = 0;
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
95 static char_u *compl_pattern = NULL;
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
96 static int compl_direction = FORWARD;
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
97 static int compl_shows_dir = FORWARD;
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
98 static int compl_pending = FALSE;
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
99 static pos_T compl_startpos;
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
100 static colnr_T compl_col = 0; /* column where the text starts
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
101 * that is being completed */
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
102 static int save_sm = -1;
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
103 static char_u *compl_orig_text = NULL; /* text as it was before
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
104 * completion started */
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
105 static int compl_cont_mode = 0;
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
106 static expand_T compl_xp;
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
107
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
108 static void ins_ctrl_x __ARGS((void));
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
109 static int has_compl_option __ARGS((int dict_opt));
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
110 static void ins_compl_add_matches __ARGS((int num_matches, char_u **matches, int dir));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
111 static int ins_compl_make_cyclic __ARGS((void));
540
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
112 static void ins_compl_upd_pum __ARGS((void));
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
113 static void ins_compl_del_pum __ARGS((void));
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
114 static int pum_wanted __ARGS((void));
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
115 static void ins_compl_show_pum __ARGS((void));
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
116 static void ins_compl_dictionaries __ARGS((char_u *dict, char_u *pat, int dir, int flags, int thesaurus));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
117 static void ins_compl_free __ARGS((void));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
118 static void ins_compl_clear __ARGS((void));
540
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
119 static int ins_compl_prep __ARGS((int c));
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
120 static buf_T *ins_compl_next_buf __ARGS((buf_T *buf, int flag));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
121 static int ins_compl_get_exp __ARGS((pos_T *ini, int dir));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
122 static void ins_compl_delete __ARGS((void));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
123 static void ins_compl_insert __ARGS((void));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
124 static int ins_compl_next __ARGS((int allow_get_expansion));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
125 static int ins_complete __ARGS((int c));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
126 static int quote_meta __ARGS((char_u *dest, char_u *str, int len));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
127 #endif /* FEAT_INS_EXPAND */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
128
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
129 #define BACKSPACE_CHAR 1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
130 #define BACKSPACE_WORD 2
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
131 #define BACKSPACE_WORD_NOT_SPACE 3
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
132 #define BACKSPACE_LINE 4
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
133
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
134 static void ins_redraw __ARGS((void));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
135 static void ins_ctrl_v __ARGS((void));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
136 static void undisplay_dollar __ARGS((void));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
137 static void insert_special __ARGS((int, int, int));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
138 static void check_auto_format __ARGS((int));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
139 static void redo_literal __ARGS((int c));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
140 static void start_arrow __ARGS((pos_T *end_insert_pos));
221
7fd4b5df33be updated for version 7.0062
vimboss
parents: 180
diff changeset
141 #ifdef FEAT_SYN_HL
7fd4b5df33be updated for version 7.0062
vimboss
parents: 180
diff changeset
142 static void check_spell_redraw __ARGS((void));
484
f012c4ed8c38 updated for version 7.0132
vimboss
parents: 477
diff changeset
143 static void spell_back_to_badword __ARGS((void));
497
73f10d8124f4 updated for version 7.0136
vimboss
parents: 484
diff changeset
144 static int spell_bad_len = 0; /* length of located bad word */
221
7fd4b5df33be updated for version 7.0062
vimboss
parents: 180
diff changeset
145 #endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
146 static void stop_insert __ARGS((pos_T *end_insert_pos, int esc));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
147 static int echeck_abbr __ARGS((int));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
148 static void replace_push_off __ARGS((int c));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
149 static int replace_pop __ARGS((void));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
150 static void replace_join __ARGS((int off));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
151 static void replace_pop_ins __ARGS((void));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
152 #ifdef FEAT_MBYTE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
153 static void mb_replace_pop_ins __ARGS((int cc));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
154 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
155 static void replace_flush __ARGS((void));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
156 static void replace_do_bs __ARGS((void));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
157 #ifdef FEAT_CINDENT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
158 static int cindent_on __ARGS((void));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
159 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
160 static void ins_reg __ARGS((void));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
161 static void ins_ctrl_g __ARGS((void));
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
162 static void ins_ctrl_hat __ARGS((void));
477
f8b75b8f1988 updated for version 7.0128
vimboss
parents: 474
diff changeset
163 static int ins_esc __ARGS((long *count, int cmdchar, int nomove));
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
164 #ifdef FEAT_RIGHTLEFT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
165 static void ins_ctrl_ __ARGS((void));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
166 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
167 #ifdef FEAT_VISUAL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
168 static int ins_start_select __ARGS((int c));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
169 #endif
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
170 static void ins_insert __ARGS((int replaceState));
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
171 static void ins_ctrl_o __ARGS((void));
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
172 static void ins_shift __ARGS((int c, int lastc));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
173 static void ins_del __ARGS((void));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
174 static int ins_bs __ARGS((int c, int mode, int *inserted_space_p));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
175 #ifdef FEAT_MOUSE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
176 static void ins_mouse __ARGS((int c));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
177 static void ins_mousescroll __ARGS((int up));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
178 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
179 static void ins_left __ARGS((void));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
180 static void ins_home __ARGS((int c));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
181 static void ins_end __ARGS((int c));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
182 static void ins_s_left __ARGS((void));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
183 static void ins_right __ARGS((void));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
184 static void ins_s_right __ARGS((void));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
185 static void ins_up __ARGS((int startcol));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
186 static void ins_pageup __ARGS((void));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
187 static void ins_down __ARGS((int startcol));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
188 static void ins_pagedown __ARGS((void));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
189 #ifdef FEAT_DND
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
190 static void ins_drop __ARGS((void));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
191 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
192 static int ins_tab __ARGS((void));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
193 static int ins_eol __ARGS((int c));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
194 #ifdef FEAT_DIGRAPHS
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
195 static int ins_digraph __ARGS((void));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
196 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
197 static int ins_copychar __ARGS((linenr_T lnum));
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
198 static int ins_ctrl_ey __ARGS((int tc));
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
199 #ifdef FEAT_SMARTINDENT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
200 static void ins_try_si __ARGS((int c));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
201 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
202 static colnr_T get_nolist_virtcol __ARGS((void));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
203
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
204 static colnr_T Insstart_textlen; /* length of line when insert started */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
205 static colnr_T Insstart_blank_vcol; /* vcol for first inserted blank */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
206
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
207 static char_u *last_insert = NULL; /* the text of the previous insert,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
208 K_SPECIAL and CSI are escaped */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
209 static int last_insert_skip; /* nr of chars in front of previous insert */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
210 static int new_insert_skip; /* nr of chars in front of current insert */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
211
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
212 #ifdef FEAT_CINDENT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
213 static int can_cindent; /* may do cindenting on this line */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
214 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
215
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
216 static int old_indent = 0; /* for ^^D command in insert mode */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
217
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
218 #ifdef FEAT_RIGHTLEFT
298
f9de3e679a04 updated for version 7.0078
vimboss
parents: 278
diff changeset
219 static int revins_on; /* reverse insert mode on */
f9de3e679a04 updated for version 7.0078
vimboss
parents: 278
diff changeset
220 static int revins_chars; /* how much to skip after edit */
f9de3e679a04 updated for version 7.0078
vimboss
parents: 278
diff changeset
221 static int revins_legal; /* was the last char 'legal'? */
f9de3e679a04 updated for version 7.0078
vimboss
parents: 278
diff changeset
222 static int revins_scol; /* start column of revins session */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
223 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
224
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
225 #if defined(FEAT_MBYTE) && defined(MACOS_CLASSIC)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
226 static short previous_script = smRoman;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
227 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
228
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
229 static int ins_need_undo; /* call u_save() before inserting a
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
230 char. Set when edit() is called.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
231 after that arrow_used is used. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
232
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
233 static int did_add_space = FALSE; /* auto_format() added an extra space
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
234 under the cursor */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
235
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
236 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
237 * edit(): Start inserting text.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
238 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
239 * "cmdchar" can be:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
240 * 'i' normal insert command
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
241 * 'a' normal append command
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
242 * 'R' replace command
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
243 * 'r' "r<CR>" command: insert one <CR>. Note: count can be > 1, for redo,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
244 * but still only one <CR> is inserted. The <Esc> is not used for redo.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
245 * 'g' "gI" command.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
246 * 'V' "gR" command for Virtual Replace mode.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
247 * 'v' "gr" command for single character Virtual Replace mode.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
248 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
249 * This function is not called recursively. For CTRL-O commands, it returns
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
250 * and lets the caller handle the Normal-mode command.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
251 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
252 * Return TRUE if a CTRL-O command caused the return (insert mode pending).
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
253 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
254 int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
255 edit(cmdchar, startln, count)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
256 int cmdchar;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
257 int startln; /* if set, insert at start of line */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
258 long count;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
259 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
260 int c = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
261 char_u *ptr;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
262 int lastc;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
263 colnr_T mincol;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
264 static linenr_T o_lnum = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
265 int i;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
266 int did_backspace = TRUE; /* previous char was backspace */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
267 #ifdef FEAT_CINDENT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
268 int line_is_white = FALSE; /* line is empty before insert */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
269 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
270 linenr_T old_topline = 0; /* topline before insertion */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
271 #ifdef FEAT_DIFF
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
272 int old_topfill = -1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
273 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
274 int inserted_space = FALSE; /* just inserted a space */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
275 int replaceState = REPLACE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
276 int did_restart_edit = restart_edit;
477
f8b75b8f1988 updated for version 7.0128
vimboss
parents: 474
diff changeset
277 int nomove = FALSE; /* don't move cursor on return */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
278
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
279 /* sleep before redrawing, needed for "CTRL-O :" that results in an
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
280 * error message */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
281 check_for_delay(TRUE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
282
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
283 #ifdef HAVE_SANDBOX
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
284 /* Don't allow inserting in the sandbox. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
285 if (sandbox != 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
286 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
287 EMSG(_(e_sandbox));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
288 return FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
289 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
290 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
291
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
292 #ifdef FEAT_INS_EXPAND
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
293 ins_compl_clear(); /* clear stuff for CTRL-X mode */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
294 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
295
11
4424b47a0797 updated for version 7.0003
vimboss
parents: 10
diff changeset
296 #ifdef FEAT_AUTOCMD
4424b47a0797 updated for version 7.0003
vimboss
parents: 10
diff changeset
297 /*
4424b47a0797 updated for version 7.0003
vimboss
parents: 10
diff changeset
298 * Trigger InsertEnter autocommands. Do not do this for "r<CR>" or "grx".
4424b47a0797 updated for version 7.0003
vimboss
parents: 10
diff changeset
299 */
4424b47a0797 updated for version 7.0003
vimboss
parents: 10
diff changeset
300 if (cmdchar != 'r' && cmdchar != 'v')
4424b47a0797 updated for version 7.0003
vimboss
parents: 10
diff changeset
301 {
532
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 523
diff changeset
302 # ifdef FEAT_EVAL
11
4424b47a0797 updated for version 7.0003
vimboss
parents: 10
diff changeset
303 if (cmdchar == 'R')
4424b47a0797 updated for version 7.0003
vimboss
parents: 10
diff changeset
304 ptr = (char_u *)"r";
4424b47a0797 updated for version 7.0003
vimboss
parents: 10
diff changeset
305 else if (cmdchar == 'V')
4424b47a0797 updated for version 7.0003
vimboss
parents: 10
diff changeset
306 ptr = (char_u *)"v";
4424b47a0797 updated for version 7.0003
vimboss
parents: 10
diff changeset
307 else
4424b47a0797 updated for version 7.0003
vimboss
parents: 10
diff changeset
308 ptr = (char_u *)"i";
4424b47a0797 updated for version 7.0003
vimboss
parents: 10
diff changeset
309 set_vim_var_string(VV_INSERTMODE, ptr, 1);
532
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 523
diff changeset
310 # endif
11
4424b47a0797 updated for version 7.0003
vimboss
parents: 10
diff changeset
311 apply_autocmds(EVENT_INSERTENTER, NULL, NULL, FALSE, curbuf);
4424b47a0797 updated for version 7.0003
vimboss
parents: 10
diff changeset
312 }
4424b47a0797 updated for version 7.0003
vimboss
parents: 10
diff changeset
313 #endif
4424b47a0797 updated for version 7.0003
vimboss
parents: 10
diff changeset
314
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
315 #ifdef FEAT_MOUSE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
316 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
317 * When doing a paste with the middle mouse button, Insstart is set to
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
318 * where the paste started.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
319 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
320 if (where_paste_started.lnum != 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
321 Insstart = where_paste_started;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
322 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
323 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
324 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
325 Insstart = curwin->w_cursor;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
326 if (startln)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
327 Insstart.col = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
328 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
329 Insstart_textlen = linetabsize(ml_get_curline());
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
330 Insstart_blank_vcol = MAXCOL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
331 if (!did_ai)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
332 ai_col = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
333
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
334 if (cmdchar != NUL && restart_edit == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
335 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
336 ResetRedobuff();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
337 AppendNumberToRedobuff(count);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
338 #ifdef FEAT_VREPLACE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
339 if (cmdchar == 'V' || cmdchar == 'v')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
340 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
341 /* "gR" or "gr" command */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
342 AppendCharToRedobuff('g');
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
343 AppendCharToRedobuff((cmdchar == 'v') ? 'r' : 'R');
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
344 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
345 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
346 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
347 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
348 AppendCharToRedobuff(cmdchar);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
349 if (cmdchar == 'g') /* "gI" command */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
350 AppendCharToRedobuff('I');
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
351 else if (cmdchar == 'r') /* "r<CR>" command */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
352 count = 1; /* insert only one <CR> */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
353 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
354 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
355
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
356 if (cmdchar == 'R')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
357 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
358 #ifdef FEAT_FKMAP
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
359 if (p_fkmap && p_ri)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
360 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
361 beep_flush();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
362 EMSG(farsi_text_3); /* encoded in Farsi */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
363 State = INSERT;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
364 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
365 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
366 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
367 State = REPLACE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
368 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
369 #ifdef FEAT_VREPLACE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
370 else if (cmdchar == 'V' || cmdchar == 'v')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
371 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
372 State = VREPLACE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
373 replaceState = VREPLACE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
374 orig_line_count = curbuf->b_ml.ml_line_count;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
375 vr_lines_changed = 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
376 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
377 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
378 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
379 State = INSERT;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
380
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
381 stop_insert_mode = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
382
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
383 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
384 * Need to recompute the cursor position, it might move when the cursor is
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
385 * on a TAB or special character.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
386 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
387 curs_columns(TRUE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
388
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
389 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
390 * Enable langmap or IME, indicated by 'iminsert'.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
391 * Note that IME may enabled/disabled without us noticing here, thus the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
392 * 'iminsert' value may not reflect what is actually used. It is updated
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
393 * when hitting <Esc>.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
394 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
395 if (curbuf->b_p_iminsert == B_IMODE_LMAP)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
396 State |= LANGMAP;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
397 #ifdef USE_IM_CONTROL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
398 im_set_active(curbuf->b_p_iminsert == B_IMODE_IM);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
399 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
400
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
401 #if defined(FEAT_MBYTE) && defined(MACOS_CLASSIC)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
402 KeyScript(previous_script);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
403 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
404
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
405 #ifdef FEAT_MOUSE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
406 setmouse();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
407 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
408 #ifdef FEAT_CMDL_INFO
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
409 clear_showcmd();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
410 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
411 #ifdef FEAT_RIGHTLEFT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
412 /* there is no reverse replace mode */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
413 revins_on = (State == INSERT && p_ri);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
414 if (revins_on)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
415 undisplay_dollar();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
416 revins_chars = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
417 revins_legal = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
418 revins_scol = -1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
419 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
420
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
421 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
422 * Handle restarting Insert mode.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
423 * Don't do this for "CTRL-O ." (repeat an insert): we get here with
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
424 * restart_edit non-zero, and something in the stuff buffer.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
425 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
426 if (restart_edit != 0 && stuff_empty())
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
427 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
428 #ifdef FEAT_MOUSE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
429 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
430 * After a paste we consider text typed to be part of the insert for
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
431 * the pasted text. You can backspace over the pasted text too.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
432 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
433 if (where_paste_started.lnum)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
434 arrow_used = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
435 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
436 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
437 arrow_used = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
438 restart_edit = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
439
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
440 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
441 * 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
442 * 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
443 * correct in very rare cases).
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
444 * Also do this if curswant is greater than the current virtual
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
445 * column. Eg after "^O$" or "^O80|".
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
446 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
447 validate_virtcol();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
448 update_curswant();
230
9281a51ca7a2 updated for version 7.0064
vimboss
parents: 221
diff changeset
449 if (((ins_at_eol && curwin->w_cursor.lnum == o_lnum)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
450 || curwin->w_curswant > curwin->w_virtcol)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
451 && *(ptr = ml_get_curline() + curwin->w_cursor.col) != NUL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
452 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
453 if (ptr[1] == NUL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
454 ++curwin->w_cursor.col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
455 #ifdef FEAT_MBYTE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
456 else if (has_mbyte)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
457 {
474
a5fcf36ef512 updated for version 7.0127
vimboss
parents: 470
diff changeset
458 i = (*mb_ptr2len)(ptr);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
459 if (ptr[i] == NUL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
460 curwin->w_cursor.col += i;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
461 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
462 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
463 }
230
9281a51ca7a2 updated for version 7.0064
vimboss
parents: 221
diff changeset
464 ins_at_eol = FALSE;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
465 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
466 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
467 arrow_used = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
468
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
469 /* we are in insert mode now, don't need to start it anymore */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
470 need_start_insertmode = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
471
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
472 /* Need to save the line for undo before inserting the first char. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
473 ins_need_undo = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
474
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
475 #ifdef FEAT_MOUSE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
476 where_paste_started.lnum = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
477 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
478 #ifdef FEAT_CINDENT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
479 can_cindent = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
480 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
481 #ifdef FEAT_FOLDING
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
482 /* The cursor line is not in a closed fold, unless 'insertmode' is set or
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
483 * restarting. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
484 if (!p_im && did_restart_edit == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
485 foldOpenCursor();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
486 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
487
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
488 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
489 * If 'showmode' is set, show the current (insert/replace/..) mode.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
490 * A warning message for changing a readonly file is given here, before
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
491 * actually changing anything. It's put after the mode, if any.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
492 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
493 i = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
494 if (p_smd)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
495 i = showmode();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
496
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
497 if (!p_im && did_restart_edit == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
498 change_warning(i + 1);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
499
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
500 #ifdef CURSOR_SHAPE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
501 ui_cursor_shape(); /* may show different cursor shape */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
502 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
503 #ifdef FEAT_DIGRAPHS
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
504 do_digraph(-1); /* clear digraphs */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
505 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
506
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
507 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
508 * Get the current length of the redo buffer, those characters have to be
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
509 * skipped if we want to get to the inserted characters.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
510 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
511 ptr = get_inserted();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
512 if (ptr == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
513 new_insert_skip = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
514 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
515 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
516 new_insert_skip = (int)STRLEN(ptr);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
517 vim_free(ptr);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
518 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
519
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
520 old_indent = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
521
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
522 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
523 * Main loop in Insert mode: repeat until Insert mode is left.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
524 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
525 for (;;)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
526 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
527 #ifdef FEAT_RIGHTLEFT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
528 if (!revins_legal)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
529 revins_scol = -1; /* reset on illegal motions */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
530 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
531 revins_legal = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
532 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
533 if (arrow_used) /* don't repeat insert when arrow key used */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
534 count = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
535
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
536 if (stop_insert_mode)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
537 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
538 /* ":stopinsert" used or 'insertmode' reset */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
539 count = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
540 goto doESCkey;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
541 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
542
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
543 /* set curwin->w_curswant for next K_DOWN or K_UP */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
544 if (!arrow_used)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
545 curwin->w_set_curswant = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
546
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
547 /* If there is no typeahead may check for timestamps (e.g., for when a
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
548 * menu invoked a shell command). */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
549 if (stuff_empty())
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
550 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
551 did_check_timestamps = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
552 if (need_check_timestamps)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
553 check_timestamps(FALSE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
554 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
555
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
556 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
557 * When emsg() was called msg_scroll will have been set.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
558 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
559 msg_scroll = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
560
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
561 #ifdef FEAT_GUI
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
562 /* When 'mousefocus' is set a mouse movement may have taken us to
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
563 * another window. "need_mouse_correct" may then be set because of an
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
564 * autocommand. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
565 if (need_mouse_correct)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
566 gui_mouse_correct();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
567 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
568
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
569 #ifdef FEAT_FOLDING
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
570 /* Open fold at the cursor line, according to 'foldopen'. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
571 if (fdo_flags & FDO_INSERT)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
572 foldOpenCursor();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
573 /* Close folds where the cursor isn't, according to 'foldclose' */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
574 if (!char_avail())
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
575 foldCheckClose();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
576 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
577
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
578 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
579 * If we inserted a character at the last position of the last line in
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
580 * the window, scroll the window one line up. This avoids an extra
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
581 * redraw.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
582 * This is detected when the cursor column is smaller after inserting
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
583 * something.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
584 * Don't do this when the topline changed already, it has
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
585 * already been adjusted (by insertchar() calling open_line())).
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
586 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
587 if (curbuf->b_mod_set
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
588 && curwin->w_p_wrap
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
589 && !did_backspace
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
590 && curwin->w_topline == old_topline
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
591 #ifdef FEAT_DIFF
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
592 && curwin->w_topfill == old_topfill
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
593 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
594 )
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
595 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
596 mincol = curwin->w_wcol;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
597 validate_cursor_col();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
598
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
599 if ((int)curwin->w_wcol < (int)mincol - curbuf->b_p_ts
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
600 && curwin->w_wrow == W_WINROW(curwin)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
601 + curwin->w_height - 1 - p_so
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
602 && (curwin->w_cursor.lnum != curwin->w_topline
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
603 #ifdef FEAT_DIFF
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
604 || curwin->w_topfill > 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
605 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
606 ))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
607 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
608 #ifdef FEAT_DIFF
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
609 if (curwin->w_topfill > 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
610 --curwin->w_topfill;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
611 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
612 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
613 #ifdef FEAT_FOLDING
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
614 if (hasFolding(curwin->w_topline, NULL, &old_topline))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
615 set_topline(curwin, old_topline + 1);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
616 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
617 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
618 set_topline(curwin, curwin->w_topline + 1);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
619 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
620 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
621
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
622 /* May need to adjust w_topline to show the cursor. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
623 update_topline();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
624
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
625 did_backspace = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
626
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
627 validate_cursor(); /* may set must_redraw */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
628
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
629 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
630 * Redraw the display when no characters are waiting.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
631 * Also shows mode, ruler and positions cursor.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
632 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
633 ins_redraw();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
634
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
635 #ifdef FEAT_SCROLLBIND
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
636 if (curwin->w_p_scb)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
637 do_check_scrollbind(TRUE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
638 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
639
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
640 update_curswant();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
641 old_topline = curwin->w_topline;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
642 #ifdef FEAT_DIFF
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
643 old_topfill = curwin->w_topfill;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
644 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
645
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
646 #ifdef USE_ON_FLY_SCROLL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
647 dont_scroll = FALSE; /* allow scrolling here */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
648 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
649
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
650 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
651 * Get a character for Insert mode.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
652 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
653 lastc = c; /* remember previous char for CTRL-D */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
654 c = safe_vgetc();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
655
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
656 #ifdef FEAT_RIGHTLEFT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
657 if (p_hkmap && KeyTyped)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
658 c = hkmap(c); /* Hebrew mode mapping */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
659 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
660 #ifdef FEAT_FKMAP
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
661 if (p_fkmap && KeyTyped)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
662 c = fkmap(c); /* Farsi mode mapping */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
663 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
664
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
665 #ifdef FEAT_INS_EXPAND
540
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
666 /* When the popup menu is visible cursor keys change the selection. */
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
667 if (c == K_UP && pum_visible())
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
668 c = Ctrl_P;
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
669 if (c == K_DOWN && pum_visible())
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
670 c = Ctrl_N;
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
671
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
672 /* Prepare for or stop CTRL-X mode. This doesn't do completion, but
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
673 * it does fix up the text when finishing completion. */
464
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
674 if (c != K_IGNORE)
540
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
675 {
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
676 if (ins_compl_prep(c))
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
677 continue;
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
678 }
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
679 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
680
477
f8b75b8f1988 updated for version 7.0128
vimboss
parents: 474
diff changeset
681 /* CTRL-\ CTRL-N goes to Normal mode,
f8b75b8f1988 updated for version 7.0128
vimboss
parents: 474
diff changeset
682 * CTRL-\ CTRL-G goes to mode selected with 'insertmode',
f8b75b8f1988 updated for version 7.0128
vimboss
parents: 474
diff changeset
683 * CTRL-\ CTRL-O is like CTRL-O but without moving the cursor. */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
684 if (c == Ctrl_BSL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
685 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
686 /* may need to redraw when no more chars available now */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
687 ins_redraw();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
688 ++no_mapping;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
689 ++allow_keys;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
690 c = safe_vgetc();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
691 --no_mapping;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
692 --allow_keys;
477
f8b75b8f1988 updated for version 7.0128
vimboss
parents: 474
diff changeset
693 if (c != Ctrl_N && c != Ctrl_G && c != Ctrl_O)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
694 {
477
f8b75b8f1988 updated for version 7.0128
vimboss
parents: 474
diff changeset
695 /* it's something else */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
696 vungetc(c);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
697 c = Ctrl_BSL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
698 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
699 else if (c == Ctrl_G && p_im)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
700 continue;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
701 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
702 {
477
f8b75b8f1988 updated for version 7.0128
vimboss
parents: 474
diff changeset
703 if (c == Ctrl_O)
f8b75b8f1988 updated for version 7.0128
vimboss
parents: 474
diff changeset
704 {
f8b75b8f1988 updated for version 7.0128
vimboss
parents: 474
diff changeset
705 ins_ctrl_o();
f8b75b8f1988 updated for version 7.0128
vimboss
parents: 474
diff changeset
706 ins_at_eol = FALSE; /* cursor keeps its column */
f8b75b8f1988 updated for version 7.0128
vimboss
parents: 474
diff changeset
707 nomove = TRUE;
f8b75b8f1988 updated for version 7.0128
vimboss
parents: 474
diff changeset
708 }
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
709 count = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
710 goto doESCkey;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
711 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
712 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
713
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
714 #ifdef FEAT_DIGRAPHS
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
715 c = do_digraph(c);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
716 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
717
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
718 #ifdef FEAT_INS_EXPAND
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
719 if ((c == Ctrl_V || c == Ctrl_Q) && ctrl_x_mode == CTRL_X_CMDLINE)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
720 goto docomplete;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
721 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
722 if (c == Ctrl_V || c == Ctrl_Q)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
723 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
724 ins_ctrl_v();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
725 c = Ctrl_V; /* pretend CTRL-V is last typed character */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
726 continue;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
727 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
728
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
729 #ifdef FEAT_CINDENT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
730 if (cindent_on()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
731 # ifdef FEAT_INS_EXPAND
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
732 && ctrl_x_mode == 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
733 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
734 )
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
735 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
736 /* A key name preceded by a bang means this key is not to be
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
737 * inserted. Skip ahead to the re-indenting below.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
738 * A key name preceded by a star means that indenting has to be
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
739 * done before inserting the key. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
740 line_is_white = inindent(0);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
741 if (in_cinkeys(c, '!', line_is_white))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
742 goto force_cindent;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
743 if (can_cindent && in_cinkeys(c, '*', line_is_white)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
744 && stop_arrow() == OK)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
745 do_c_expr_indent();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
746 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
747 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
748
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
749 #ifdef FEAT_RIGHTLEFT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
750 if (curwin->w_p_rl)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
751 switch (c)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
752 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
753 case K_LEFT: c = K_RIGHT; break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
754 case K_S_LEFT: c = K_S_RIGHT; break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
755 case K_C_LEFT: c = K_C_RIGHT; break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
756 case K_RIGHT: c = K_LEFT; break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
757 case K_S_RIGHT: c = K_S_LEFT; break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
758 case K_C_RIGHT: c = K_C_LEFT; break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
759 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
760 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
761
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
762 #ifdef FEAT_VISUAL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
763 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
764 * If 'keymodel' contains "startsel", may start selection. If it
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
765 * does, a CTRL-O and c will be stuffed, we need to get these
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
766 * characters.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
767 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
768 if (ins_start_select(c))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
769 continue;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
770 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
771
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
772 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
773 * The big switch to handle a character in insert mode.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
774 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
775 switch (c)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
776 {
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
777 case ESC: /* End input mode */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
778 if (echeck_abbr(ESC + ABBR_OFF))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
779 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
780 /*FALLTHROUGH*/
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
781
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
782 case Ctrl_C: /* End input mode */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
783 #ifdef FEAT_CMDWIN
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
784 if (c == Ctrl_C && cmdwin_type != 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
785 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
786 /* Close the cmdline window. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
787 cmdwin_result = K_IGNORE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
788 got_int = FALSE; /* don't stop executing autocommands et al. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
789 goto doESCkey;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
790 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
791 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
792
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
793 #ifdef UNIX
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
794 do_intr:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
795 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
796 /* when 'insertmode' set, and not halfway a mapping, don't leave
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
797 * Insert mode */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
798 if (goto_im())
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
799 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
800 if (got_int)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
801 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
802 (void)vgetc(); /* flush all buffers */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
803 got_int = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
804 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
805 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
806 vim_beep();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
807 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
808 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
809 doESCkey:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
810 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
811 * This is the ONLY return from edit()!
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
812 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
813 /* Always update o_lnum, so that a "CTRL-O ." that adds a line
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
814 * still puts the cursor back after the inserted text. */
230
9281a51ca7a2 updated for version 7.0064
vimboss
parents: 221
diff changeset
815 if (ins_at_eol && gchar_cursor() == NUL)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
816 o_lnum = curwin->w_cursor.lnum;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
817
477
f8b75b8f1988 updated for version 7.0128
vimboss
parents: 474
diff changeset
818 if (ins_esc(&count, cmdchar, nomove))
11
4424b47a0797 updated for version 7.0003
vimboss
parents: 10
diff changeset
819 {
4424b47a0797 updated for version 7.0003
vimboss
parents: 10
diff changeset
820 #ifdef FEAT_AUTOCMD
4424b47a0797 updated for version 7.0003
vimboss
parents: 10
diff changeset
821 if (cmdchar != 'r' && cmdchar != 'v')
4424b47a0797 updated for version 7.0003
vimboss
parents: 10
diff changeset
822 apply_autocmds(EVENT_INSERTLEAVE, NULL, NULL,
4424b47a0797 updated for version 7.0003
vimboss
parents: 10
diff changeset
823 FALSE, curbuf);
4424b47a0797 updated for version 7.0003
vimboss
parents: 10
diff changeset
824 #endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
825 return (c == Ctrl_O);
11
4424b47a0797 updated for version 7.0003
vimboss
parents: 10
diff changeset
826 }
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
827 continue;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
828
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
829 case Ctrl_Z: /* suspend when 'insertmode' set */
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
830 if (!p_im)
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
831 goto normalchar; /* insert CTRL-Z as normal char */
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
832 stuffReadbuff((char_u *)":st\r");
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
833 c = Ctrl_O;
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
834 /*FALLTHROUGH*/
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
835
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
836 case Ctrl_O: /* execute one command */
502
52e76e2b5b65 updated for version 7.0140
vimboss
parents: 499
diff changeset
837 #ifdef FEAT_COMPL_FUNC
523
a7ae7e043e43 updated for version 7.0146
vimboss
parents: 502
diff changeset
838 if (ctrl_x_mode == CTRL_X_OMNI)
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
839 goto docomplete;
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
840 #endif
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
841 if (echeck_abbr(Ctrl_O + ABBR_OFF))
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
842 break;
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
843 ins_ctrl_o();
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
844 count = 0;
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
845 goto doESCkey;
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
846
464
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
847 case K_INS: /* toggle insert/replace mode */
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
848 case K_KINS:
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
849 ins_insert(replaceState);
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
850 break;
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
851
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
852 case K_SELECT: /* end of Select mode mapping - ignore */
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
853 break;
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
854
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
855 #ifdef FEAT_SNIFF
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
856 case K_SNIFF: /* Sniff command received */
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
857 stuffcharReadbuff(K_SNIFF);
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
858 goto doESCkey;
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
859 #endif
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
860
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
861 case K_HELP: /* Help key works like <ESC> <Help> */
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
862 case K_F1:
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
863 case K_XF1:
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
864 stuffcharReadbuff(K_HELP);
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
865 if (p_im)
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
866 need_start_insertmode = TRUE;
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
867 goto doESCkey;
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
868
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
869 #ifdef FEAT_NETBEANS_INTG
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
870 case K_F21: /* NetBeans command */
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
871 ++no_mapping; /* don't map the next key hits */
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
872 i = safe_vgetc();
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
873 --no_mapping;
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
874 netbeans_keycommand(i);
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
875 break;
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
876 #endif
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
877
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
878 case K_ZERO: /* Insert the previously inserted text. */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
879 case NUL:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
880 case Ctrl_A:
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
881 /* For ^@ the trailing ESC will end the insert, unless there is an
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
882 * error. */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
883 if (stuff_inserted(NUL, 1L, (c == Ctrl_A)) == FAIL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
884 && c != Ctrl_A && !p_im)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
885 goto doESCkey; /* quit insert mode */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
886 inserted_space = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
887 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
888
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
889 case Ctrl_R: /* insert the contents of a register */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
890 ins_reg();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
891 auto_format(FALSE, TRUE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
892 inserted_space = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
893 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
894
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
895 case Ctrl_G: /* commands starting with CTRL-G */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
896 ins_ctrl_g();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
897 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
898
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
899 case Ctrl_HAT: /* switch input mode and/or langmap */
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
900 ins_ctrl_hat();
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
901 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
902
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
903 #ifdef FEAT_RIGHTLEFT
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
904 case Ctrl__: /* switch between languages */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
905 if (!p_ari)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
906 goto normalchar;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
907 ins_ctrl_();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
908 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
909 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
910
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
911 case Ctrl_D: /* Make indent one shiftwidth smaller. */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
912 #if defined(FEAT_INS_EXPAND) && defined(FEAT_FIND_ID)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
913 if (ctrl_x_mode == CTRL_X_PATH_DEFINES)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
914 goto docomplete;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
915 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
916 /* FALLTHROUGH */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
917
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
918 case Ctrl_T: /* Make indent one shiftwidth greater. */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
919 # ifdef FEAT_INS_EXPAND
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
920 if (c == Ctrl_T && ctrl_x_mode == CTRL_X_THESAURUS)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
921 {
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
922 if (has_compl_option(FALSE))
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
923 goto docomplete;
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
924 break;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
925 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
926 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
927 ins_shift(c, lastc);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
928 auto_format(FALSE, TRUE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
929 inserted_space = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
930 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
931
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
932 case K_DEL: /* delete character under the cursor */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
933 case K_KDEL:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
934 ins_del();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
935 auto_format(FALSE, TRUE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
936 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
937
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
938 case K_BS: /* delete character before the cursor */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
939 case Ctrl_H:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
940 did_backspace = ins_bs(c, BACKSPACE_CHAR, &inserted_space);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
941 auto_format(FALSE, TRUE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
942 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
943
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
944 case Ctrl_W: /* delete word before the cursor */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
945 did_backspace = ins_bs(c, BACKSPACE_WORD, &inserted_space);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
946 auto_format(FALSE, TRUE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
947 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
948
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
949 case Ctrl_U: /* delete all inserted text in current line */
12
bdeee1504ac1 updated for version 7.0004
vimboss
parents: 11
diff changeset
950 # ifdef FEAT_COMPL_FUNC
bdeee1504ac1 updated for version 7.0004
vimboss
parents: 11
diff changeset
951 /* CTRL-X CTRL-U completes with 'completefunc'. */
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
952 if (ctrl_x_mode == CTRL_X_FUNCTION)
12
bdeee1504ac1 updated for version 7.0004
vimboss
parents: 11
diff changeset
953 goto docomplete;
bdeee1504ac1 updated for version 7.0004
vimboss
parents: 11
diff changeset
954 # endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
955 did_backspace = ins_bs(c, BACKSPACE_LINE, &inserted_space);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
956 auto_format(FALSE, TRUE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
957 inserted_space = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
958 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
959
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
960 #ifdef FEAT_MOUSE
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
961 case K_LEFTMOUSE: /* mouse keys */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
962 case K_LEFTMOUSE_NM:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
963 case K_LEFTDRAG:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
964 case K_LEFTRELEASE:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
965 case K_LEFTRELEASE_NM:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
966 case K_MIDDLEMOUSE:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
967 case K_MIDDLEDRAG:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
968 case K_MIDDLERELEASE:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
969 case K_RIGHTMOUSE:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
970 case K_RIGHTDRAG:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
971 case K_RIGHTRELEASE:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
972 case K_X1MOUSE:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
973 case K_X1DRAG:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
974 case K_X1RELEASE:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
975 case K_X2MOUSE:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
976 case K_X2DRAG:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
977 case K_X2RELEASE:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
978 ins_mouse(c);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
979 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
980
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
981 case K_MOUSEDOWN: /* Default action for scroll wheel up: scroll up */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
982 ins_mousescroll(FALSE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
983 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
984
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
985 case K_MOUSEUP: /* Default action for scroll wheel down: scroll down */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
986 ins_mousescroll(TRUE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
987 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
988 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
989
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
990 case K_IGNORE: /* Something mapped to nothing */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
991 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
992
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
993 #ifdef FEAT_GUI
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
994 case K_VER_SCROLLBAR:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
995 ins_scroll();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
996 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
997
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
998 case K_HOR_SCROLLBAR:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
999 ins_horscroll();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1000 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1001 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1002
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
1003 case K_HOME: /* <Home> */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1004 case K_KHOME:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1005 case K_S_HOME:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1006 case K_C_HOME:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1007 ins_home(c);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1008 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1009
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
1010 case K_END: /* <End> */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1011 case K_KEND:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1012 case K_S_END:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1013 case K_C_END:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1014 ins_end(c);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1015 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1016
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
1017 case K_LEFT: /* <Left> */
180
7e70fc748752 updated for version 7.0056
vimboss
parents: 164
diff changeset
1018 if (mod_mask & (MOD_MASK_SHIFT|MOD_MASK_CTRL))
7e70fc748752 updated for version 7.0056
vimboss
parents: 164
diff changeset
1019 ins_s_left();
7e70fc748752 updated for version 7.0056
vimboss
parents: 164
diff changeset
1020 else
7e70fc748752 updated for version 7.0056
vimboss
parents: 164
diff changeset
1021 ins_left();
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1022 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1023
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
1024 case K_S_LEFT: /* <S-Left> */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1025 case K_C_LEFT:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1026 ins_s_left();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1027 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1028
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
1029 case K_RIGHT: /* <Right> */
180
7e70fc748752 updated for version 7.0056
vimboss
parents: 164
diff changeset
1030 if (mod_mask & (MOD_MASK_SHIFT|MOD_MASK_CTRL))
7e70fc748752 updated for version 7.0056
vimboss
parents: 164
diff changeset
1031 ins_s_right();
7e70fc748752 updated for version 7.0056
vimboss
parents: 164
diff changeset
1032 else
7e70fc748752 updated for version 7.0056
vimboss
parents: 164
diff changeset
1033 ins_right();
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1034 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1035
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
1036 case K_S_RIGHT: /* <S-Right> */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1037 case K_C_RIGHT:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1038 ins_s_right();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1039 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1040
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
1041 case K_UP: /* <Up> */
180
7e70fc748752 updated for version 7.0056
vimboss
parents: 164
diff changeset
1042 if (mod_mask & MOD_MASK_SHIFT)
7e70fc748752 updated for version 7.0056
vimboss
parents: 164
diff changeset
1043 ins_pageup();
7e70fc748752 updated for version 7.0056
vimboss
parents: 164
diff changeset
1044 else
7e70fc748752 updated for version 7.0056
vimboss
parents: 164
diff changeset
1045 ins_up(FALSE);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1046 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1047
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
1048 case K_S_UP: /* <S-Up> */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1049 case K_PAGEUP:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1050 case K_KPAGEUP:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1051 ins_pageup();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1052 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1053
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
1054 case K_DOWN: /* <Down> */
180
7e70fc748752 updated for version 7.0056
vimboss
parents: 164
diff changeset
1055 if (mod_mask & MOD_MASK_SHIFT)
7e70fc748752 updated for version 7.0056
vimboss
parents: 164
diff changeset
1056 ins_pagedown();
7e70fc748752 updated for version 7.0056
vimboss
parents: 164
diff changeset
1057 else
7e70fc748752 updated for version 7.0056
vimboss
parents: 164
diff changeset
1058 ins_down(FALSE);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1059 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1060
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
1061 case K_S_DOWN: /* <S-Down> */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1062 case K_PAGEDOWN:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1063 case K_KPAGEDOWN:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1064 ins_pagedown();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1065 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1066
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1067 #ifdef FEAT_DND
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
1068 case K_DROP: /* drag-n-drop event */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1069 ins_drop();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1070 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1071 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1072
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
1073 case K_S_TAB: /* When not mapped, use like a normal TAB */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1074 c = TAB;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1075 /* FALLTHROUGH */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1076
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
1077 case TAB: /* TAB or Complete patterns along path */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1078 #if defined(FEAT_INS_EXPAND) && defined(FEAT_FIND_ID)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1079 if (ctrl_x_mode == CTRL_X_PATH_PATTERNS)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1080 goto docomplete;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1081 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1082 inserted_space = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1083 if (ins_tab())
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1084 goto normalchar; /* insert TAB as a normal char */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1085 auto_format(FALSE, TRUE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1086 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1087
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
1088 case K_KENTER: /* <Enter> */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1089 c = CAR;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1090 /* FALLTHROUGH */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1091 case CAR:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1092 case NL:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1093 #if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1094 /* In a quickfix window a <CR> jumps to the error under the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1095 * cursor. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1096 if (bt_quickfix(curbuf) && c == CAR)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1097 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1098 do_cmdline_cmd((char_u *)".cc");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1099 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1100 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1101 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1102 #ifdef FEAT_CMDWIN
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1103 if (cmdwin_type != 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1104 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1105 /* Execute the command in the cmdline window. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1106 cmdwin_result = CAR;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1107 goto doESCkey;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1108 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1109 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1110 if (ins_eol(c) && !p_im)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1111 goto doESCkey; /* out of memory */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1112 auto_format(FALSE, FALSE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1113 inserted_space = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1114 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1115
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1116 #if defined(FEAT_DIGRAPHS) || defined (FEAT_INS_EXPAND)
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
1117 case Ctrl_K: /* digraph or keyword completion */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1118 # ifdef FEAT_INS_EXPAND
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1119 if (ctrl_x_mode == CTRL_X_DICTIONARY)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1120 {
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
1121 if (has_compl_option(TRUE))
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
1122 goto docomplete;
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
1123 break;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1124 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1125 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1126 # ifdef FEAT_DIGRAPHS
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1127 c = ins_digraph();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1128 if (c == NUL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1129 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1130 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1131 goto normalchar;
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
1132 #endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1133
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1134 #ifdef FEAT_INS_EXPAND
464
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
1135 case Ctrl_X: /* Enter CTRL-X mode */
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
1136 ins_ctrl_x();
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
1137 break;
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
1138
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
1139 case Ctrl_RSB: /* Tag name completion after ^X */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1140 if (ctrl_x_mode != CTRL_X_TAGS)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1141 goto normalchar;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1142 goto docomplete;
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 Ctrl_F: /* File name completion after ^X */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1145 if (ctrl_x_mode != CTRL_X_FILES)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1146 goto normalchar;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1147 goto docomplete;
477
f8b75b8f1988 updated for version 7.0128
vimboss
parents: 474
diff changeset
1148
f8b75b8f1988 updated for version 7.0128
vimboss
parents: 474
diff changeset
1149 case 's': /* Spelling completion after ^X */
f8b75b8f1988 updated for version 7.0128
vimboss
parents: 474
diff changeset
1150 case Ctrl_S:
f8b75b8f1988 updated for version 7.0128
vimboss
parents: 474
diff changeset
1151 if (ctrl_x_mode != CTRL_X_SPELL)
f8b75b8f1988 updated for version 7.0128
vimboss
parents: 474
diff changeset
1152 goto normalchar;
f8b75b8f1988 updated for version 7.0128
vimboss
parents: 474
diff changeset
1153 goto docomplete;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1154 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1155
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
1156 case Ctrl_L: /* Whole line completion after ^X */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1157 #ifdef FEAT_INS_EXPAND
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1158 if (ctrl_x_mode != CTRL_X_WHOLE_LINE)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1159 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1160 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1161 /* CTRL-L with 'insertmode' set: Leave Insert mode */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1162 if (p_im)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1163 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1164 if (echeck_abbr(Ctrl_L + ABBR_OFF))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1165 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1166 goto doESCkey;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1167 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1168 goto normalchar;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1169 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1170 #ifdef FEAT_INS_EXPAND
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1171 /* FALLTHROUGH */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1172
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
1173 case Ctrl_P: /* Do previous/next pattern completion */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1174 case Ctrl_N:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1175 /* if 'complete' is empty then plain ^P is no longer special,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1176 * but it is under other ^X modes */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1177 if (*curbuf->b_p_cpt == NUL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1178 && ctrl_x_mode != 0
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
1179 && !(compl_cont_status & CONT_LOCAL))
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1180 goto normalchar;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1181
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1182 docomplete:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1183 if (ins_complete(c) == FAIL)
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
1184 compl_cont_status = 0;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1185 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1186 #endif /* FEAT_INS_EXPAND */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1187
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
1188 case Ctrl_Y: /* copy from previous line or scroll down */
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
1189 case Ctrl_E: /* copy from next line or scroll up */
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
1190 c = ins_ctrl_ey(c);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1191 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1192
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1193 default:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1194 #ifdef UNIX
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1195 if (c == intr_char) /* special interrupt char */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1196 goto do_intr;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1197 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1198
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1199 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1200 * Insert a nomal character.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1201 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1202 normalchar:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1203 #ifdef FEAT_SMARTINDENT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1204 /* Try to perform smart-indenting. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1205 ins_try_si(c);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1206 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1207
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1208 if (c == ' ')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1209 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1210 inserted_space = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1211 #ifdef FEAT_CINDENT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1212 if (inindent(0))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1213 can_cindent = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1214 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1215 if (Insstart_blank_vcol == MAXCOL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1216 && curwin->w_cursor.lnum == Insstart.lnum)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1217 Insstart_blank_vcol = get_nolist_virtcol();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1218 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1219
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1220 if (vim_iswordc(c) || !echeck_abbr(
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1221 #ifdef FEAT_MBYTE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1222 /* Add ABBR_OFF for characters above 0x100, this is
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1223 * what check_abbr() expects. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1224 (has_mbyte && c >= 0x100) ? (c + ABBR_OFF) :
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1225 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1226 c))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1227 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1228 insert_special(c, FALSE, FALSE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1229 #ifdef FEAT_RIGHTLEFT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1230 revins_legal++;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1231 revins_chars++;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1232 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1233 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1234
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1235 auto_format(FALSE, TRUE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1236
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1237 #ifdef FEAT_FOLDING
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1238 /* When inserting a character the cursor line must never be in a
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1239 * closed fold. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1240 foldOpenCursor();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1241 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1242 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1243 } /* end of switch (c) */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1244
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1245 /* If the cursor was moved we didn't just insert a space */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1246 if (arrow_used)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1247 inserted_space = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1248
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1249 #ifdef FEAT_CINDENT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1250 if (can_cindent && cindent_on()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1251 # ifdef FEAT_INS_EXPAND
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1252 && ctrl_x_mode == 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1253 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1254 )
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1255 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1256 force_cindent:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1257 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1258 * Indent now if a key was typed that is in 'cinkeys'.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1259 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1260 if (in_cinkeys(c, ' ', line_is_white))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1261 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1262 if (stop_arrow() == OK)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1263 /* re-indent the current line */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1264 do_c_expr_indent();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1265 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1266 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1267 #endif /* FEAT_CINDENT */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1268
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1269 } /* for (;;) */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1270 /* NOTREACHED */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1271 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1272
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1273 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1274 * Redraw for Insert mode.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1275 * This is postponed until getting the next character to make '$' in the 'cpo'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1276 * option work correctly.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1277 * Only redraw when there are no characters available. This speeds up
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1278 * inserting sequences of characters (e.g., for CTRL-R).
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1279 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1280 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1281 ins_redraw()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1282 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1283 if (!char_avail())
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1284 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1285 if (must_redraw)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1286 update_screen(0);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1287 else if (clear_cmdline || redraw_cmdline)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1288 showmode(); /* clear cmdline and show mode */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1289 showruler(FALSE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1290 setcursor();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1291 emsg_on_display = FALSE; /* may remove error message now */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1292 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1293 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1294
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1295 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1296 * Handle a CTRL-V or CTRL-Q typed in Insert mode.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1297 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1298 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1299 ins_ctrl_v()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1300 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1301 int c;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1302
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1303 /* may need to redraw when no more chars available now */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1304 ins_redraw();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1305
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1306 if (redrawing() && !char_avail())
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1307 edit_putchar('^', TRUE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1308 AppendToRedobuff((char_u *)CTRL_V_STR); /* CTRL-V */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1309
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1310 #ifdef FEAT_CMDL_INFO
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1311 add_to_showcmd_c(Ctrl_V);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1312 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1313
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1314 c = get_literal();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1315 #ifdef FEAT_CMDL_INFO
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1316 clear_showcmd();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1317 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1318 insert_special(c, FALSE, TRUE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1319 #ifdef FEAT_RIGHTLEFT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1320 revins_chars++;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1321 revins_legal++;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1322 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1323 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1324
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1325 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1326 * Put a character directly onto the screen. It's not stored in a buffer.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1327 * Used while handling CTRL-K, CTRL-V, etc. in Insert mode.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1328 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1329 static int pc_status;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1330 #define PC_STATUS_UNSET 0 /* pc_bytes was not set */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1331 #define PC_STATUS_RIGHT 1 /* right halve of double-wide char */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1332 #define PC_STATUS_LEFT 2 /* left halve of double-wide char */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1333 #define PC_STATUS_SET 3 /* pc_bytes was filled */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1334 #ifdef FEAT_MBYTE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1335 static char_u pc_bytes[MB_MAXBYTES + 1]; /* saved bytes */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1336 #else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1337 static char_u pc_bytes[2]; /* saved bytes */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1338 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1339 static int pc_attr;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1340 static int pc_row;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1341 static int pc_col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1342
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1343 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1344 edit_putchar(c, highlight)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1345 int c;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1346 int highlight;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1347 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1348 int attr;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1349
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1350 if (ScreenLines != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1351 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1352 update_topline(); /* just in case w_topline isn't valid */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1353 validate_cursor();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1354 if (highlight)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1355 attr = hl_attr(HLF_8);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1356 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1357 attr = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1358 pc_row = W_WINROW(curwin) + curwin->w_wrow;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1359 pc_col = W_WINCOL(curwin);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1360 #if defined(FEAT_RIGHTLEFT) || defined(FEAT_MBYTE)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1361 pc_status = PC_STATUS_UNSET;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1362 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1363 #ifdef FEAT_RIGHTLEFT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1364 if (curwin->w_p_rl)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1365 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1366 pc_col += W_WIDTH(curwin) - 1 - curwin->w_wcol;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1367 # ifdef FEAT_MBYTE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1368 if (has_mbyte)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1369 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1370 int fix_col = mb_fix_col(pc_col, pc_row);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1371
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1372 if (fix_col != pc_col)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1373 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1374 screen_putchar(' ', pc_row, fix_col, attr);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1375 --curwin->w_wcol;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1376 pc_status = PC_STATUS_RIGHT;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1377 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1378 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1379 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1380 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1381 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1382 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1383 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1384 pc_col += curwin->w_wcol;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1385 #ifdef FEAT_MBYTE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1386 if (mb_lefthalve(pc_row, pc_col))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1387 pc_status = PC_STATUS_LEFT;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1388 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1389 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1390
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1391 /* save the character to be able to put it back */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1392 #if defined(FEAT_RIGHTLEFT) || defined(FEAT_MBYTE)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1393 if (pc_status == PC_STATUS_UNSET)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1394 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1395 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1396 screen_getbytes(pc_row, pc_col, pc_bytes, &pc_attr);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1397 pc_status = PC_STATUS_SET;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1398 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1399 screen_putchar(c, pc_row, pc_col, attr);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1400 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1401 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1402
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1403 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1404 * Undo the previous edit_putchar().
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1405 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1406 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1407 edit_unputchar()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1408 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1409 if (pc_status != PC_STATUS_UNSET && pc_row >= msg_scrolled)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1410 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1411 #if defined(FEAT_MBYTE)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1412 if (pc_status == PC_STATUS_RIGHT)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1413 ++curwin->w_wcol;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1414 if (pc_status == PC_STATUS_RIGHT || pc_status == PC_STATUS_LEFT)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1415 redrawWinline(curwin->w_cursor.lnum, FALSE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1416 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1417 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1418 screen_puts(pc_bytes, pc_row - msg_scrolled, pc_col, pc_attr);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1419 }
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 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1423 * 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
1424 * Only works when cursor is in the line that changes.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1425 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1426 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1427 display_dollar(col)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1428 colnr_T col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1429 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1430 colnr_T save_col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1431
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1432 if (!redrawing())
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1433 return;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1434
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1435 cursor_off();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1436 save_col = curwin->w_cursor.col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1437 curwin->w_cursor.col = col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1438 #ifdef FEAT_MBYTE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1439 if (has_mbyte)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1440 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1441 char_u *p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1442
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1443 /* If on the last byte of a multi-byte move to the first byte. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1444 p = ml_get_curline();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1445 curwin->w_cursor.col -= (*mb_head_off)(p, p + col);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1446 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1447 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1448 curs_columns(FALSE); /* recompute w_wrow and w_wcol */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1449 if (curwin->w_wcol < W_WIDTH(curwin))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1450 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1451 edit_putchar('$', FALSE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1452 dollar_vcol = curwin->w_virtcol;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1453 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1454 curwin->w_cursor.col = save_col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1455 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1456
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1457 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1458 * Call this function before moving the cursor from the normal insert position
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1459 * in insert mode.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1460 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1461 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1462 undisplay_dollar()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1463 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1464 if (dollar_vcol)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1465 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1466 dollar_vcol = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1467 redrawWinline(curwin->w_cursor.lnum, FALSE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1468 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1469 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1470
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1471 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1472 * 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
1473 * Keep the cursor on the same character.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1474 * type == INDENT_INC increase indent (for CTRL-T or <Tab>)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1475 * type == INDENT_DEC decrease indent (for CTRL-D)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1476 * type == INDENT_SET set indent to "amount"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1477 * if round is TRUE, round the indent to 'shiftwidth' (only with _INC and _Dec).
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1478 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1479 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1480 change_indent(type, amount, round, replaced)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1481 int type;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1482 int amount;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1483 int round;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1484 int replaced; /* replaced character, put on replace stack */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1485 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1486 int vcol;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1487 int last_vcol;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1488 int insstart_less; /* reduction for Insstart.col */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1489 int new_cursor_col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1490 int i;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1491 char_u *ptr;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1492 int save_p_list;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1493 int start_col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1494 colnr_T vc;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1495 #ifdef FEAT_VREPLACE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1496 colnr_T orig_col = 0; /* init for GCC */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1497 char_u *new_line, *orig_line = NULL; /* init for GCC */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1498
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1499 /* VREPLACE mode needs to know what the line was like before changing */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1500 if (State & VREPLACE_FLAG)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1501 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1502 orig_line = vim_strsave(ml_get_curline()); /* Deal with NULL below */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1503 orig_col = curwin->w_cursor.col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1504 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1505 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1506
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1507 /* for the following tricks we don't want list mode */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1508 save_p_list = curwin->w_p_list;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1509 curwin->w_p_list = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1510 vc = getvcol_nolist(&curwin->w_cursor);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1511 vcol = vc;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1512
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1513 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1514 * For Replace mode we need to fix the replace stack later, which is only
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1515 * possible when the cursor is in the indent. Remember the number of
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1516 * characters before the cursor if it's possible.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1517 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1518 start_col = curwin->w_cursor.col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1519
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1520 /* determine offset from first non-blank */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1521 new_cursor_col = curwin->w_cursor.col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1522 beginline(BL_WHITE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1523 new_cursor_col -= curwin->w_cursor.col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1524
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1525 insstart_less = curwin->w_cursor.col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1526
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1527 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1528 * If the cursor is in the indent, compute how many screen columns the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1529 * cursor is to the left of the first non-blank.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1530 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1531 if (new_cursor_col < 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1532 vcol = get_indent() - vcol;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1533
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1534 if (new_cursor_col > 0) /* can't fix replace stack */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1535 start_col = -1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1536
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1537 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1538 * Set the new indent. The cursor will be put on the first non-blank.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1539 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1540 if (type == INDENT_SET)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1541 (void)set_indent(amount, SIN_CHANGED);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1542 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1543 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1544 #ifdef FEAT_VREPLACE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1545 int save_State = State;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1546
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1547 /* Avoid being called recursively. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1548 if (State & VREPLACE_FLAG)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1549 State = INSERT;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1550 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1551 shift_line(type == INDENT_DEC, round, 1);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1552 #ifdef FEAT_VREPLACE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1553 State = save_State;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1554 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1555 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1556 insstart_less -= curwin->w_cursor.col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1557
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1558 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1559 * Try to put cursor on same character.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1560 * If the cursor is at or after the first non-blank in the line,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1561 * compute the cursor column relative to the column of the first
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1562 * non-blank character.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1563 * 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
1564 * If the cursor is before the first non-blank, position it relative
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1565 * to the first non-blank, counted in screen columns.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1566 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1567 if (new_cursor_col >= 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1568 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1569 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1570 * When changing the indent while the cursor is touching it, reset
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1571 * Insstart_col to 0.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1572 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1573 if (new_cursor_col == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1574 insstart_less = MAXCOL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1575 new_cursor_col += curwin->w_cursor.col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1576 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1577 else if (!(State & INSERT))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1578 new_cursor_col = curwin->w_cursor.col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1579 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1580 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1581 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1582 * Compute the screen column where the cursor should be.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1583 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1584 vcol = get_indent() - vcol;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1585 curwin->w_virtcol = (vcol < 0) ? 0 : vcol;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1586
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1587 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1588 * Advance the cursor until we reach the right screen column.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1589 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1590 vcol = last_vcol = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1591 new_cursor_col = -1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1592 ptr = ml_get_curline();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1593 while (vcol <= (int)curwin->w_virtcol)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1594 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1595 last_vcol = vcol;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1596 #ifdef FEAT_MBYTE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1597 if (has_mbyte && new_cursor_col >= 0)
474
a5fcf36ef512 updated for version 7.0127
vimboss
parents: 470
diff changeset
1598 new_cursor_col += (*mb_ptr2len)(ptr + new_cursor_col);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1599 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1600 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1601 ++new_cursor_col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1602 vcol += lbr_chartabsize(ptr + new_cursor_col, (colnr_T)vcol);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1603 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1604 vcol = last_vcol;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1605
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1606 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1607 * May need to insert spaces to be able to position the cursor on
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1608 * the right screen column.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1609 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1610 if (vcol != (int)curwin->w_virtcol)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1611 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1612 curwin->w_cursor.col = new_cursor_col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1613 i = (int)curwin->w_virtcol - vcol;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1614 ptr = alloc(i + 1);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1615 if (ptr != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1616 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1617 new_cursor_col += i;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1618 ptr[i] = NUL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1619 while (--i >= 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1620 ptr[i] = ' ';
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1621 ins_str(ptr);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1622 vim_free(ptr);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1623 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1624 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1625
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1626 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1627 * When changing the indent while the cursor is in it, reset
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1628 * Insstart_col to 0.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1629 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1630 insstart_less = MAXCOL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1631 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1632
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1633 curwin->w_p_list = save_p_list;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1634
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1635 if (new_cursor_col <= 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1636 curwin->w_cursor.col = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1637 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1638 curwin->w_cursor.col = new_cursor_col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1639 curwin->w_set_curswant = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1640 changed_cline_bef_curs();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1641
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1642 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1643 * May have to adjust the start of the insert.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1644 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1645 if (State & INSERT)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1646 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1647 if (curwin->w_cursor.lnum == Insstart.lnum && Insstart.col != 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1648 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1649 if ((int)Insstart.col <= insstart_less)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1650 Insstart.col = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1651 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1652 Insstart.col -= insstart_less;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1653 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1654 if ((int)ai_col <= insstart_less)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1655 ai_col = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1656 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1657 ai_col -= insstart_less;
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 * For REPLACE mode, may have to fix the replace stack, if it's possible.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1662 * If the number of characters before the cursor decreased, need to pop a
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1663 * few characters from the replace stack.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1664 * If the number of characters before the cursor increased, need to push a
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1665 * few NULs onto the replace stack.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1666 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1667 if (REPLACE_NORMAL(State) && start_col >= 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1668 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1669 while (start_col > (int)curwin->w_cursor.col)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1670 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1671 replace_join(0); /* remove a NUL from the replace stack */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1672 --start_col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1673 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1674 while (start_col < (int)curwin->w_cursor.col || replaced)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1675 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1676 replace_push(NUL);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1677 if (replaced)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1678 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1679 replace_push(replaced);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1680 replaced = NUL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1681 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1682 ++start_col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1683 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1684 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1685
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 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1688 * For VREPLACE mode, we also have to fix the replace stack. In this case
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1689 * it is always possible because we backspace over the whole line and then
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1690 * put it back again the way we wanted it.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1691 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1692 if (State & VREPLACE_FLAG)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1693 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1694 /* If orig_line didn't allocate, just return. At least we did the job,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1695 * even if you can't backspace. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1696 if (orig_line == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1697 return;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1698
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1699 /* Save new line */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1700 new_line = vim_strsave(ml_get_curline());
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1701 if (new_line == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1702 return;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1703
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1704 /* We only put back the new line up to the cursor */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1705 new_line[curwin->w_cursor.col] = NUL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1706
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1707 /* Put back original line */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1708 ml_replace(curwin->w_cursor.lnum, orig_line, FALSE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1709 curwin->w_cursor.col = orig_col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1710
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1711 /* Backspace from cursor to start of line */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1712 backspace_until_column(0);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1713
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1714 /* Insert new stuff into line again */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1715 ins_bytes(new_line);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1716
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1717 vim_free(new_line);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1718 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1719 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1720 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1721
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1722 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1723 * 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
1724 * insert mode. It handles fixing the replace stack for REPLACE and VREPLACE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1725 * modes.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1726 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1727 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1728 truncate_spaces(line)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1729 char_u *line;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1730 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1731 int i;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1732
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1733 /* find start of trailing white space */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1734 for (i = (int)STRLEN(line) - 1; i >= 0 && vim_iswhite(line[i]); i--)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1735 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1736 if (State & REPLACE_FLAG)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1737 replace_join(0); /* remove a NUL from the replace stack */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1738 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1739 line[i + 1] = NUL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1740 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1741
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1742 #if defined(FEAT_VREPLACE) || defined(FEAT_INS_EXPAND) \
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1743 || defined(FEAT_COMMENTS) || defined(PROTO)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1744 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1745 * Backspace the cursor until the given column. Handles REPLACE and VREPLACE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1746 * modes correctly. May also be used when not in insert mode at all.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1747 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1748 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1749 backspace_until_column(col)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1750 int col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1751 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1752 while ((int)curwin->w_cursor.col > col)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1753 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1754 curwin->w_cursor.col--;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1755 if (State & REPLACE_FLAG)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1756 replace_do_bs();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1757 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1758 (void)del_char(FALSE);
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 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1762
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1763 #if defined(FEAT_INS_EXPAND) || defined(PROTO)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1764 /*
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
1765 * CTRL-X pressed in Insert mode.
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
1766 */
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
1767 static void
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
1768 ins_ctrl_x()
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
1769 {
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
1770 /* 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
1771 * CTRL-V works like CTRL-N */
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
1772 if (ctrl_x_mode != CTRL_X_CMDLINE)
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
1773 {
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
1774 /* if the next ^X<> won't ADD nothing, then reset
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
1775 * compl_cont_status */
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
1776 if (compl_cont_status & CONT_N_ADDS)
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
1777 compl_cont_status = (compl_cont_status | CONT_INTRPT);
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
1778 else
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
1779 compl_cont_status = 0;
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
1780 /* We're not sure which CTRL-X mode it will be yet */
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
1781 ctrl_x_mode = CTRL_X_NOT_DEFINED_YET;
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
1782 edit_submode = (char_u *)_(CTRL_X_MSG(ctrl_x_mode));
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
1783 edit_submode_pre = NULL;
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
1784 showmode();
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
1785 }
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
1786 }
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
1787
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
1788 /*
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
1789 * Return TRUE if the 'dict' or 'tsr' option can be used.
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
1790 */
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
1791 static int
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
1792 has_compl_option(dict_opt)
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
1793 int dict_opt;
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
1794 {
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
1795 if (dict_opt ? (*curbuf->b_p_dict == NUL && *p_dict == NUL)
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
1796 : (*curbuf->b_p_tsr == NUL && *p_tsr == NUL))
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
1797 {
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
1798 ctrl_x_mode = 0;
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
1799 edit_submode = NULL;
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
1800 msg_attr(dict_opt ? (char_u *)_("'dictionary' option is empty")
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
1801 : (char_u *)_("'thesaurus' option is empty"),
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
1802 hl_attr(HLF_E));
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
1803 if (emsg_silent == 0)
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
1804 {
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
1805 vim_beep();
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
1806 setcursor();
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
1807 out_flush();
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
1808 ui_delay(2000L, FALSE);
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
1809 }
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
1810 return FALSE;
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
1811 }
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
1812 return TRUE;
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
1813 }
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
1814
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
1815 /*
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1816 * 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
1817 * This depends on the current mode.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1818 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1819 int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1820 vim_is_ctrl_x_key(c)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1821 int c;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1822 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1823 /* Always allow ^R - let it's results then be checked */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1824 if (c == Ctrl_R)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1825 return TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1826
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1827 switch (ctrl_x_mode)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1828 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1829 case 0: /* Not in any CTRL-X mode */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1830 return (c == Ctrl_N || c == Ctrl_P || c == Ctrl_X);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1831 case CTRL_X_NOT_DEFINED_YET:
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
1832 return ( c == Ctrl_X || c == Ctrl_Y || c == Ctrl_E
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1833 || c == Ctrl_L || c == Ctrl_F || c == Ctrl_RSB
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1834 || c == Ctrl_I || c == Ctrl_D || c == Ctrl_P
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1835 || c == Ctrl_N || c == Ctrl_T || c == Ctrl_V
477
f8b75b8f1988 updated for version 7.0128
vimboss
parents: 474
diff changeset
1836 || c == Ctrl_Q || c == Ctrl_U || c == Ctrl_O
f8b75b8f1988 updated for version 7.0128
vimboss
parents: 474
diff changeset
1837 || c == Ctrl_S || c == 's');
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1838 case CTRL_X_SCROLL:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1839 return (c == Ctrl_Y || c == Ctrl_E);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1840 case CTRL_X_WHOLE_LINE:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1841 return (c == Ctrl_L || c == Ctrl_P || c == Ctrl_N);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1842 case CTRL_X_FILES:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1843 return (c == Ctrl_F || c == Ctrl_P || c == Ctrl_N);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1844 case CTRL_X_DICTIONARY:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1845 return (c == Ctrl_K || c == Ctrl_P || c == Ctrl_N);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1846 case CTRL_X_THESAURUS:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1847 return (c == Ctrl_T || c == Ctrl_P || c == Ctrl_N);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1848 case CTRL_X_TAGS:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1849 return (c == Ctrl_RSB || c == Ctrl_P || c == Ctrl_N);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1850 #ifdef FEAT_FIND_ID
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1851 case CTRL_X_PATH_PATTERNS:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1852 return (c == Ctrl_P || c == Ctrl_N);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1853 case CTRL_X_PATH_DEFINES:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1854 return (c == Ctrl_D || c == Ctrl_P || c == Ctrl_N);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1855 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1856 case CTRL_X_CMDLINE:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1857 return (c == Ctrl_V || c == Ctrl_Q || c == Ctrl_P || c == Ctrl_N
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1858 || c == Ctrl_X);
12
bdeee1504ac1 updated for version 7.0004
vimboss
parents: 11
diff changeset
1859 #ifdef FEAT_COMPL_FUNC
bdeee1504ac1 updated for version 7.0004
vimboss
parents: 11
diff changeset
1860 case CTRL_X_FUNCTION:
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
1861 return (c == Ctrl_U || c == Ctrl_P || c == Ctrl_N);
523
a7ae7e043e43 updated for version 7.0146
vimboss
parents: 502
diff changeset
1862 case CTRL_X_OMNI:
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
1863 return (c == Ctrl_O || c == Ctrl_P || c == Ctrl_N);
502
52e76e2b5b65 updated for version 7.0140
vimboss
parents: 499
diff changeset
1864 #endif
477
f8b75b8f1988 updated for version 7.0128
vimboss
parents: 474
diff changeset
1865 case CTRL_X_SPELL:
f8b75b8f1988 updated for version 7.0128
vimboss
parents: 474
diff changeset
1866 return (c == Ctrl_S || c == Ctrl_P || c == Ctrl_N);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1867 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1868 EMSG(_(e_internal));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1869 return FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1870 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1871
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1872 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1873 * This is like ins_compl_add(), but if ic and inf are set, then the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1874 * case of the originally typed text is used, and the case of the completed
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1875 * text is infered, ie this tries to work out what case you probably wanted
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1876 * the rest of the word to be in -- webb
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
1877 * TODO: make this work for multi-byte characters.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1878 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1879 int
464
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
1880 ins_compl_add_infercase(str, len, fname, dir, flags)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1881 char_u *str;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1882 int len;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1883 char_u *fname;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1884 int dir;
464
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
1885 int flags;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1886 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1887 int has_lower = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1888 int was_letter = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1889 int idx;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1890
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1891 if (p_ic && curbuf->b_p_inf && len < IOSIZE)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1892 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1893 /* Infer case of completed part -- webb */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1894 /* Use IObuff, str would change text in buffer! */
419
f713fc55bf7b updated for version 7.0109
vimboss
parents: 408
diff changeset
1895 vim_strncpy(IObuff, str, len);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1896
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1897 /* Rule 1: Were any chars converted to lower? */
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
1898 for (idx = 0; idx < compl_length; ++idx)
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
1899 {
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
1900 if (islower(compl_orig_text[idx]))
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1901 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1902 has_lower = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1903 if (isupper(IObuff[idx]))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1904 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1905 /* Rule 1 is satisfied */
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
1906 for (idx = compl_length; idx < len; ++idx)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1907 IObuff[idx] = TOLOWER_LOC(IObuff[idx]);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1908 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1909 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1910 }
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 * Rule 2: No lower case, 2nd consecutive letter converted to
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1915 * upper case.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1916 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1917 if (!has_lower)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1918 {
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
1919 for (idx = 0; idx < compl_length; ++idx)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1920 {
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
1921 if (was_letter && isupper(compl_orig_text[idx])
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1922 && islower(IObuff[idx]))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1923 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1924 /* Rule 2 is satisfied */
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
1925 for (idx = compl_length; idx < len; ++idx)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1926 IObuff[idx] = TOUPPER_LOC(IObuff[idx]);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1927 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1928 }
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
1929 was_letter = isalpha(compl_orig_text[idx]);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1930 }
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 /* Copy the original case of the part we typed */
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
1934 STRNCPY(IObuff, compl_orig_text, compl_length);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1935
464
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
1936 return ins_compl_add(IObuff, len, fname, dir, flags);
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
1937 }
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
1938 return ins_compl_add(str, len, fname, dir, flags);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1939 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1940
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1941 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1942 * Add a match to the list of matches.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1943 * If the given string is already in the list of completions, then return
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1944 * FAIL, otherwise add it to the list and return OK. If there is an error,
464
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
1945 * maybe because alloc() returns NULL, then RET_ERROR is returned -- webb.
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
1946 *
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
1947 * New:
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
1948 * If the given string is already in the list of completions, then return
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
1949 * NOTDONE, otherwise add it to the list and return OK. If there is an error,
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
1950 * maybe because alloc() returns NULL, then FAIL is returned -- webb.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1951 */
464
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
1952 int
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
1953 ins_compl_add(str, len, fname, dir, flags)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1954 char_u *str;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1955 int len;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1956 char_u *fname;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1957 int dir;
464
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
1958 int flags;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1959 {
464
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
1960 compl_T *match;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1961
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1962 ui_breakcheck();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1963 if (got_int)
464
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
1964 return FAIL;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1965 if (len < 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1966 len = (int)STRLEN(str);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1967
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1968 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1969 * If the same match is already present, don't add it.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1970 */
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
1971 if (compl_first_match != NULL)
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
1972 {
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
1973 match = compl_first_match;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1974 do
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1975 {
464
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
1976 if ( !(match->cp_flags & ORIGINAL_TEXT)
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
1977 && STRNCMP(match->cp_str, str, (size_t)len) == 0
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
1978 && match->cp_str[len] == NUL)
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
1979 return NOTDONE;
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
1980 match = match->cp_next;
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
1981 } while (match != NULL && match != compl_first_match);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1982 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1983
540
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
1984 /* Remove any popup menu before changing the list of matches. */
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
1985 ins_compl_del_pum();
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
1986
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1987 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1988 * Allocate a new match structure.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1989 * Copy the values to the new match structure.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1990 */
464
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
1991 match = (compl_T *)alloc((unsigned)sizeof(compl_T));
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1992 if (match == NULL)
464
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
1993 return FAIL;
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
1994 match->cp_number = -1;
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
1995 if (flags & ORIGINAL_TEXT)
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
1996 {
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
1997 match->cp_number = 0;
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
1998 match->cp_str = compl_orig_text;
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
1999 }
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
2000 else if ((match->cp_str = vim_strnsave(str, len)) == NULL)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2001 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2002 vim_free(match);
464
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
2003 return FAIL;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2004 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2005 /* match-fname is:
464
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
2006 * - compl_curr_match->cp_fname if it is a string equal to fname.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2007 * - a copy of fname, FREE_FNAME is set to free later THE allocated mem.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2008 * - NULL otherwise. --Acevedo */
464
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
2009 if (fname && compl_curr_match && compl_curr_match->cp_fname
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
2010 && STRCMP(fname, compl_curr_match->cp_fname) == 0)
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
2011 match->cp_fname = compl_curr_match->cp_fname;
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
2012 else if (fname && (match->cp_fname = vim_strsave(fname)) != NULL)
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
2013 flags |= FREE_FNAME;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2014 else
464
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
2015 match->cp_fname = NULL;
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
2016 match->cp_flags = flags;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2017
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2018 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2019 * Link the new match structure in the list of matches.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2020 */
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
2021 if (compl_first_match == NULL)
464
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
2022 match->cp_next = match->cp_prev = NULL;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2023 else if (dir == FORWARD)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2024 {
464
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
2025 match->cp_next = compl_curr_match->cp_next;
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
2026 match->cp_prev = compl_curr_match;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2027 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2028 else /* BACKWARD */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2029 {
464
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
2030 match->cp_next = compl_curr_match;
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
2031 match->cp_prev = compl_curr_match->cp_prev;
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
2032 }
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
2033 if (match->cp_next)
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
2034 match->cp_next->cp_prev = match;
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
2035 if (match->cp_prev)
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
2036 match->cp_prev->cp_next = match;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2037 else /* if there's nothing before, it is the first match */
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
2038 compl_first_match = match;
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
2039 compl_curr_match = match;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2040
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2041 return OK;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2042 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2043
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2044 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2045 * Add an array of matches to the list of matches.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2046 * Frees matches[].
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2047 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2048 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2049 ins_compl_add_matches(num_matches, matches, dir)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2050 int num_matches;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2051 char_u **matches;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2052 int dir;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2053 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2054 int i;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2055 int add_r = OK;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2056 int ldir = dir;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2057
464
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
2058 for (i = 0; i < num_matches && add_r != FAIL; i++)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2059 if ((add_r = ins_compl_add(matches[i], -1, NULL, ldir, 0)) == OK)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2060 /* if dir was BACKWARD then honor it just once */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2061 ldir = FORWARD;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2062 FreeWild(num_matches, matches);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2063 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2064
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2065 /* Make the completion list cyclic.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2066 * Return the number of matches (excluding the original).
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2067 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2068 static int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2069 ins_compl_make_cyclic()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2070 {
464
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
2071 compl_T *match;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2072 int count = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2073
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
2074 if (compl_first_match != NULL)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2075 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2076 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2077 * Find the end of the list.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2078 */
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
2079 match = compl_first_match;
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
2080 /* 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
2081 while (match->cp_next != NULL && match->cp_next != compl_first_match)
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
2082 {
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
2083 match = match->cp_next;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2084 ++count;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2085 }
464
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
2086 match->cp_next = compl_first_match;
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
2087 compl_first_match->cp_prev = match;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2088 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2089 return count;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2090 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2091
540
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2092 static char_u **compl_match_array = NULL;
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2093 static int compl_match_arraysize;
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2094
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2095 /*
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2096 * Update the screen and when there is any scrolling remove the popup menu.
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2097 */
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2098 static void
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2099 ins_compl_upd_pum()
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2100 {
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2101 int h;
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2102
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2103 if (compl_match_array != NULL)
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2104 {
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2105 h = curwin->w_cline_height;
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2106 update_screen(0);
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2107 if (h != curwin->w_cline_height)
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2108 ins_compl_del_pum();
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2109 }
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2110 }
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2111
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2112 /*
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2113 * Remove any popup menu.
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2114 */
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2115 static void
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2116 ins_compl_del_pum()
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2117 {
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2118 if (compl_match_array != NULL)
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2119 {
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2120 pum_undisplay();
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2121 vim_free(compl_match_array);
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2122 compl_match_array = NULL;
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2123 }
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2124 }
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2125
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2126 /*
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2127 * Return TRUE if the popup menu should be displayed.
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2128 */
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2129 static int
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2130 pum_wanted()
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2131 {
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2132 compl_T *compl;
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2133 int i;
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2134
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2135 /* 'completeopt' must contain "menu" */
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2136 if (*p_cot == NUL)
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2137 return FALSE;
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2138
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2139 /* The display looks bad on a B&W display. */
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2140 if (t_colors < 8
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2141 #ifdef FEAT_GUI
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2142 && !gui.in_use
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2143 #endif
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2144 )
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2145 return FALSE;
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2146
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2147 /* 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
2148 * one (ignoring the original text). */
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2149 compl = compl_first_match;
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2150 i = 0;
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2151 do
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2152 {
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2153 if (compl == NULL
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2154 || ((compl->cp_flags & ORIGINAL_TEXT) == 0 && ++i == 2))
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2155 break;
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2156 compl = compl->cp_next;
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2157 } while (compl != compl_first_match);
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2158
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2159 return (i >= 2);
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2160 }
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2161
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2162 /*
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2163 * Show the popup menu for the list of matches.
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2164 */
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2165 static void
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2166 ins_compl_show_pum()
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2167 {
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2168 compl_T *compl;
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2169 int i;
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2170 int cur = -1;
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2171 colnr_T col;
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2172
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2173 if (!pum_wanted())
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2174 return;
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2175
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2176 /* Update the screen before drawing the popup menu over it. */
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2177 update_screen(0);
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2178
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2179 if (compl_match_array == NULL)
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2180 {
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2181 /* Need to build the popup menu list. */
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2182 compl_match_arraysize = 0;
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2183 compl = compl_first_match;
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2184 do
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2185 {
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2186 if ((compl->cp_flags & ORIGINAL_TEXT) == 0)
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2187 ++compl_match_arraysize;
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2188 compl = compl->cp_next;
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2189 } while (compl != NULL && compl != compl_first_match);
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2190 compl_match_array = (char_u **)alloc((unsigned)(sizeof(char_u **)
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2191 * compl_match_arraysize));
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2192 if (compl_match_array != NULL)
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2193 {
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2194 i = 0;
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2195 compl = compl_first_match;
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2196 do
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2197 {
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2198 if ((compl->cp_flags & ORIGINAL_TEXT) == 0)
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2199 {
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2200 if (compl == compl_shown_match)
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2201 cur = i;
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2202 compl_match_array[i++] = compl->cp_str;
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2203 }
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2204 compl = compl->cp_next;
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2205 } while (compl != NULL && compl != compl_first_match);
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2206 }
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2207 }
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2208 else
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2209 {
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2210 /* popup menu already exists, only need to find the current item.*/
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2211 i = 0;
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2212 compl = compl_first_match;
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2213 do
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2214 {
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2215 if ((compl->cp_flags & ORIGINAL_TEXT) == 0)
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2216 {
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2217 if (compl == compl_shown_match)
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2218 {
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2219 cur = i;
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2220 break;
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2221 }
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2222 ++i;
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2223 }
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2224 compl = compl->cp_next;
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2225 } while (compl != NULL && compl != compl_first_match);
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2226 }
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2227
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2228 if (compl_match_array != NULL)
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2229 {
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2230 /* Compute the screen column of the start of the completed text.
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2231 * Use the cursor to get all wrapping and other settings right. */
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2232 col = curwin->w_cursor.col;
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2233 curwin->w_cursor.col = compl_col;
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2234 validate_cursor_col();
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2235 pum_display(compl_match_array, compl_match_arraysize, cur,
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2236 curwin->w_cline_row + W_WINROW(curwin),
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2237 curwin->w_cline_height,
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2238 curwin->w_wcol + W_WINCOL(curwin));
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2239 curwin->w_cursor.col = col;
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2240 }
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2241 }
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2242
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2243 #define DICT_FIRST (1) /* use just first element in "dict" */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2244 #define DICT_EXACT (2) /* "dict" is the exact name of a file */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2245 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2246 * Add any identifiers that match the given pattern to the list of
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2247 * completions.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2248 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2249 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2250 ins_compl_dictionaries(dict, pat, dir, flags, thesaurus)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2251 char_u *dict;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2252 char_u *pat;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2253 int dir;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2254 int flags;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2255 int thesaurus;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2256 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2257 char_u *ptr;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2258 char_u *buf;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2259 FILE *fp;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2260 regmatch_T regmatch;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2261 int add_r;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2262 char_u **files;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2263 int count;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2264 int i;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2265 int save_p_scs;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2266
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2267 buf = alloc(LSIZE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2268 /* If 'infercase' is set, don't use 'smartcase' here */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2269 save_p_scs = p_scs;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2270 if (curbuf->b_p_inf)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2271 p_scs = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2272 regmatch.regprog = vim_regcomp(pat, p_magic ? RE_MAGIC : 0);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2273 /* ignore case depends on 'ignorecase', 'smartcase' and "pat" */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2274 regmatch.rm_ic = ignorecase(pat);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2275 while (buf != NULL && regmatch.regprog != NULL && *dict != NUL
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
2276 && !got_int && !compl_interrupted)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2277 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2278 /* copy one dictionary file name into buf */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2279 if (flags == DICT_EXACT)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2280 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2281 count = 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2282 files = &dict;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2283 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2284 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2285 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2286 /* Expand wildcards in the dictionary name, but do not allow
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2287 * backticks (for security, the 'dict' option may have been set in
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2288 * a modeline). */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2289 copy_option_part(&dict, buf, LSIZE, ",");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2290 if (vim_strchr(buf, '`') != NULL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2291 || expand_wildcards(1, &buf, &count, &files,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2292 EW_FILE|EW_SILENT) != OK)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2293 count = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2294 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2295
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
2296 for (i = 0; i < count && !got_int && !compl_interrupted; i++)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2297 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2298 fp = mch_fopen((char *)files[i], "r"); /* open dictionary file */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2299 if (flags != DICT_EXACT)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2300 {
274
8fa8d7964cf1 updated for version 7.0073
vimboss
parents: 237
diff changeset
2301 vim_snprintf((char *)IObuff, IOSIZE,
8fa8d7964cf1 updated for version 7.0073
vimboss
parents: 237
diff changeset
2302 _("Scanning dictionary: %s"), (char *)files[i]);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2303 msg_trunc_attr(IObuff, TRUE, hl_attr(HLF_R));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2304 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2305
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2306 if (fp != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2307 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2308 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2309 * Read dictionary file line by line.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2310 * Check each line for a match.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2311 */
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
2312 while (!got_int && !compl_interrupted
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
2313 && !vim_fgets(buf, LSIZE, fp))
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2314 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2315 ptr = buf;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2316 while (vim_regexec(&regmatch, buf, (colnr_T)(ptr - buf)))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2317 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2318 ptr = regmatch.startp[0];
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2319 ptr = find_word_end(ptr);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2320 add_r = ins_compl_add_infercase(regmatch.startp[0],
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2321 (int)(ptr - regmatch.startp[0]),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2322 files[i], dir, 0);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2323 if (thesaurus)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2324 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2325 char_u *wstart;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2326
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2327 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2328 * Add the other matches on the line
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2329 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2330 while (!got_int)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2331 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2332 /* Find start of the next word. Skip white
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2333 * space and punctuation. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2334 ptr = find_word_start(ptr);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2335 if (*ptr == NUL || *ptr == NL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2336 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2337 wstart = ptr;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2338
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2339 /* Find end of the word and add it. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2340 #ifdef FEAT_MBYTE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2341 if (has_mbyte)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2342 /* Japanese words may have characters in
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2343 * different classes, only separate words
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2344 * with single-byte non-word characters. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2345 while (*ptr != NUL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2346 {
474
a5fcf36ef512 updated for version 7.0127
vimboss
parents: 470
diff changeset
2347 int l = (*mb_ptr2len)(ptr);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2348
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2349 if (l < 2 && !vim_iswordc(*ptr))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2350 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2351 ptr += l;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2352 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2353 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2354 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2355 ptr = find_word_end(ptr);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2356 add_r = ins_compl_add_infercase(wstart,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2357 (int)(ptr - wstart), files[i], dir, 0);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2358 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2359 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2360 if (add_r == OK)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2361 /* if dir was BACKWARD then honor it just once */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2362 dir = FORWARD;
464
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
2363 else if (add_r == FAIL)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2364 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2365 /* avoid expensive call to vim_regexec() when at end
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2366 * of line */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2367 if (*ptr == '\n' || got_int)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2368 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2369 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2370 line_breakcheck();
464
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
2371 ins_compl_check_keys(50);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2372 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2373 fclose(fp);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2374 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2375 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2376 if (flags != DICT_EXACT)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2377 FreeWild(count, files);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2378 if (flags)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2379 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2380 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2381 p_scs = save_p_scs;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2382 vim_free(regmatch.regprog);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2383 vim_free(buf);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2384 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2385
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2386 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2387 * Find the start of the next word.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2388 * 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
2389 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2390 char_u *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2391 find_word_start(ptr)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2392 char_u *ptr;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2393 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2394 #ifdef FEAT_MBYTE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2395 if (has_mbyte)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2396 while (*ptr != NUL && *ptr != '\n' && mb_get_class(ptr) <= 1)
474
a5fcf36ef512 updated for version 7.0127
vimboss
parents: 470
diff changeset
2397 ptr += (*mb_ptr2len)(ptr);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2398 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2399 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2400 while (*ptr != NUL && *ptr != '\n' && !vim_iswordc(*ptr))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2401 ++ptr;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2402 return ptr;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2403 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2404
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2405 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2406 * Find the end of the word. Assumes it starts inside a word.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2407 * Returns a pointer to just after the word.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2408 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2409 char_u *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2410 find_word_end(ptr)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2411 char_u *ptr;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2412 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2413 #ifdef FEAT_MBYTE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2414 int start_class;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2415
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2416 if (has_mbyte)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2417 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2418 start_class = mb_get_class(ptr);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2419 if (start_class > 1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2420 while (*ptr != NUL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2421 {
474
a5fcf36ef512 updated for version 7.0127
vimboss
parents: 470
diff changeset
2422 ptr += (*mb_ptr2len)(ptr);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2423 if (mb_get_class(ptr) != start_class)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2424 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2425 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2426 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2427 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2428 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2429 while (vim_iswordc(*ptr))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2430 ++ptr;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2431 return ptr;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2432 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2433
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2434 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2435 * Free the list of completions
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2436 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2437 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2438 ins_compl_free()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2439 {
464
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
2440 compl_T *match;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2441
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
2442 vim_free(compl_pattern);
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
2443 compl_pattern = NULL;
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
2444
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
2445 if (compl_first_match == NULL)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2446 return;
540
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2447
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2448 ins_compl_del_pum();
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2449 pum_clear();
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2450
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
2451 compl_curr_match = compl_first_match;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2452 do
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2453 {
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
2454 match = compl_curr_match;
464
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
2455 compl_curr_match = compl_curr_match->cp_next;
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
2456 vim_free(match->cp_str);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2457 /* several entries may use the same fname, free it just once. */
464
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
2458 if (match->cp_flags & FREE_FNAME)
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
2459 vim_free(match->cp_fname);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2460 vim_free(match);
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
2461 } while (compl_curr_match != NULL && compl_curr_match != compl_first_match);
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
2462 compl_first_match = compl_curr_match = NULL;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2463 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2464
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2465 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2466 ins_compl_clear()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2467 {
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
2468 compl_cont_status = 0;
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
2469 compl_started = FALSE;
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
2470 compl_matches = 0;
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
2471 vim_free(compl_pattern);
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
2472 compl_pattern = NULL;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2473 save_sm = -1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2474 edit_submode_extra = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2475 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2476
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2477 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2478 * Prepare for Insert mode completion, or stop it.
464
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
2479 * Called just after typing a character in Insert mode.
540
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2480 * Returns TRUE when the character is not to be inserted;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2481 */
540
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2482 static int
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2483 ins_compl_prep(c)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2484 int c;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2485 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2486 char_u *ptr;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2487 int temp;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2488 int want_cindent;
540
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2489 int retval = FALSE;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2490
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2491 /* Forget any previous 'special' messages if this is actually
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2492 * 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
2493 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2494 if (c != Ctrl_R && vim_is_ctrl_x_key(c))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2495 edit_submode_extra = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2496
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2497 /* Ignore end of Select mode mapping */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2498 if (c == K_SELECT)
540
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2499 return retval;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2500
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2501 if (ctrl_x_mode == CTRL_X_NOT_DEFINED_YET)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2502 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2503 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2504 * 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
2505 * it will be yet. Now we decide.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2506 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2507 switch (c)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2508 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2509 case Ctrl_E:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2510 case Ctrl_Y:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2511 ctrl_x_mode = CTRL_X_SCROLL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2512 if (!(State & REPLACE_FLAG))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2513 edit_submode = (char_u *)_(" (insert) Scroll (^E/^Y)");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2514 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2515 edit_submode = (char_u *)_(" (replace) Scroll (^E/^Y)");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2516 edit_submode_pre = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2517 showmode();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2518 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2519 case Ctrl_L:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2520 ctrl_x_mode = CTRL_X_WHOLE_LINE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2521 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2522 case Ctrl_F:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2523 ctrl_x_mode = CTRL_X_FILES;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2524 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2525 case Ctrl_K:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2526 ctrl_x_mode = CTRL_X_DICTIONARY;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2527 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2528 case Ctrl_R:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2529 /* Simply allow ^R to happen without affecting ^X mode */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2530 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2531 case Ctrl_T:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2532 ctrl_x_mode = CTRL_X_THESAURUS;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2533 break;
12
bdeee1504ac1 updated for version 7.0004
vimboss
parents: 11
diff changeset
2534 #ifdef FEAT_COMPL_FUNC
bdeee1504ac1 updated for version 7.0004
vimboss
parents: 11
diff changeset
2535 case Ctrl_U:
bdeee1504ac1 updated for version 7.0004
vimboss
parents: 11
diff changeset
2536 ctrl_x_mode = CTRL_X_FUNCTION;
bdeee1504ac1 updated for version 7.0004
vimboss
parents: 11
diff changeset
2537 break;
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
2538 case Ctrl_O:
523
a7ae7e043e43 updated for version 7.0146
vimboss
parents: 502
diff changeset
2539 ctrl_x_mode = CTRL_X_OMNI;
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
2540 break;
502
52e76e2b5b65 updated for version 7.0140
vimboss
parents: 499
diff changeset
2541 #endif
477
f8b75b8f1988 updated for version 7.0128
vimboss
parents: 474
diff changeset
2542 case 's':
f8b75b8f1988 updated for version 7.0128
vimboss
parents: 474
diff changeset
2543 case Ctrl_S:
f8b75b8f1988 updated for version 7.0128
vimboss
parents: 474
diff changeset
2544 ctrl_x_mode = CTRL_X_SPELL;
484
f012c4ed8c38 updated for version 7.0132
vimboss
parents: 477
diff changeset
2545 #ifdef FEAT_SYN_HL
f012c4ed8c38 updated for version 7.0132
vimboss
parents: 477
diff changeset
2546 spell_back_to_badword();
f012c4ed8c38 updated for version 7.0132
vimboss
parents: 477
diff changeset
2547 #endif
477
f8b75b8f1988 updated for version 7.0128
vimboss
parents: 474
diff changeset
2548 break;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2549 case Ctrl_RSB:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2550 ctrl_x_mode = CTRL_X_TAGS;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2551 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2552 #ifdef FEAT_FIND_ID
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2553 case Ctrl_I:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2554 case K_S_TAB:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2555 ctrl_x_mode = CTRL_X_PATH_PATTERNS;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2556 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2557 case Ctrl_D:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2558 ctrl_x_mode = CTRL_X_PATH_DEFINES;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2559 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2560 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2561 case Ctrl_V:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2562 case Ctrl_Q:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2563 ctrl_x_mode = CTRL_X_CMDLINE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2564 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2565 case Ctrl_P:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2566 case Ctrl_N:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2567 /* ^X^P means LOCAL expansion if nothing interrupted (eg we
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2568 * just started ^X mode, or there were enough ^X's to cancel
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2569 * 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
2570 * do normal expansion when interrupting a different mode (say
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2571 * ^X^F^X^P or ^P^X^X^P, see below)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2572 * nothing changes if interrupting mode 0, (eg, the flag
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2573 * doesn't change when going to ADDING mode -- Acevedo */
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
2574 if (!(compl_cont_status & CONT_INTRPT))
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
2575 compl_cont_status |= CONT_LOCAL;
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
2576 else if (compl_cont_mode != 0)
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
2577 compl_cont_status &= ~CONT_LOCAL;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2578 /* FALLTHROUGH */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2579 default:
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
2580 /* 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
2581 * compl_cont_status = 0 (eg, as if we had just started ^X
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
2582 * mode).
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
2583 * For mode 0, we set "compl_cont_mode" to an impossible
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
2584 * value, in both cases ^X^X can be used to restart the same
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
2585 * mode (avoiding ADDING mode).
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
2586 * Undocumented feature: In a mode != 0 ^X^P and ^X^X^P start
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
2587 * 'complete' and local ^P expansions respectively.
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
2588 * 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
2589 * mode -- Acevedo */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2590 if (c == Ctrl_X)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2591 {
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
2592 if (compl_cont_mode != 0)
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
2593 compl_cont_status = 0;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2594 else
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
2595 compl_cont_mode = CTRL_X_NOT_DEFINED_YET;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2596 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2597 ctrl_x_mode = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2598 edit_submode = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2599 showmode();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2600 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2601 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2602 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2603 else if (ctrl_x_mode != 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2604 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2605 /* We're already in CTRL-X mode, do we stay in it? */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2606 if (!vim_is_ctrl_x_key(c))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2607 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2608 if (ctrl_x_mode == CTRL_X_SCROLL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2609 ctrl_x_mode = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2610 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2611 ctrl_x_mode = CTRL_X_FINISHED;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2612 edit_submode = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2613 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2614 showmode();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2615 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2616
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
2617 if (compl_started || ctrl_x_mode == CTRL_X_FINISHED)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2618 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2619 /* Show error message from attempted keyword completion (probably
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2620 * 'Pattern not found') until another key is hit, then go back to
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
2621 * showing what mode we are in. */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2622 showmode();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2623 if ((ctrl_x_mode == 0 && c != Ctrl_N && c != Ctrl_P && c != Ctrl_R)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2624 || ctrl_x_mode == CTRL_X_FINISHED)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2625 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2626 /* Get here when we have finished typing a sequence of ^N and
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2627 * ^P or other completion characters in CTRL-X mode. Free up
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
2628 * memory that was used, and make sure we can redo the insert. */
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
2629 if (compl_curr_match != NULL)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2630 {
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
2631 char_u *p;
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
2632
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2633 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2634 * If any of the original typed text has been changed,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2635 * eg when ignorecase is set, we must add back-spaces to
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2636 * the redo buffer. We add as few as necessary to delete
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2637 * just the part of the original text that has changed.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2638 */
464
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
2639 ptr = compl_curr_match->cp_str;
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
2640 p = compl_orig_text;
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
2641 while (*p && *p == *ptr)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2642 {
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
2643 ++p;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2644 ++ptr;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2645 }
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
2646 for (temp = 0; p[temp]; ++temp)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2647 AppendCharToRedobuff(K_BS);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2648 AppendToRedobuffLit(ptr);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2649 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2650
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2651 #ifdef FEAT_CINDENT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2652 want_cindent = (can_cindent && cindent_on());
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2653 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2654 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2655 * When completing whole lines: fix indent for 'cindent'.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2656 * Otherwise, break line if it's too long.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2657 */
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
2658 if (compl_cont_mode == CTRL_X_WHOLE_LINE)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2659 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2660 #ifdef FEAT_CINDENT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2661 /* re-indent the current line */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2662 if (want_cindent)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2663 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2664 do_c_expr_indent();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2665 want_cindent = FALSE; /* don't do it again */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2666 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2667 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2668 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2669 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2670 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2671 /* put the cursor on the last char, for 'tw' formatting */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2672 curwin->w_cursor.col--;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2673 if (stop_arrow() == OK)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2674 insertchar(NUL, 0, -1);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2675 curwin->w_cursor.col++;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2676 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2677
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2678 auto_format(FALSE, TRUE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2679
540
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2680 /* if the popup menu is displayed hitting Enter means accepting
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2681 * the selection without inserting anything. */
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2682 if ((c == CAR || c == K_KENTER || c == NL) && pum_visible())
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2683 retval = TRUE;
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2684
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2685 ins_compl_free();
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
2686 compl_started = FALSE;
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
2687 compl_matches = 0;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2688 msg_clr_cmdline(); /* necessary for "noshowmode" */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2689 ctrl_x_mode = 0;
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
2690 if (save_sm >= 0)
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
2691 p_sm = save_sm;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2692 if (edit_submode != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2693 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2694 edit_submode = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2695 showmode();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2696 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2697
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2698 #ifdef FEAT_CINDENT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2699 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2700 * Indent now if a key was typed that is in 'cinkeys'.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2701 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2702 if (want_cindent && in_cinkeys(KEY_COMPLETE, ' ', inindent(0)))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2703 do_c_expr_indent();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2704 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2705 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2706 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2707
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2708 /* reset continue_* if we left expansion-mode, if we stay they'll be
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2709 * (re)set properly in ins_complete() */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2710 if (!vim_is_ctrl_x_key(c))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2711 {
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
2712 compl_cont_status = 0;
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
2713 compl_cont_mode = 0;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2714 }
540
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2715
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
2716 return retval;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2717 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2718
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2719 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2720 * Loops through the list of windows, loaded-buffers or non-loaded-buffers
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2721 * (depending on flag) starting from buf and looking for a non-scanned
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2722 * buffer (other than curbuf). curbuf is special, if it is called with
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2723 * 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
2724 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2725 * Returns the buffer to scan, if any, otherwise returns curbuf -- Acevedo
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2726 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2727 static buf_T *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2728 ins_compl_next_buf(buf, flag)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2729 buf_T *buf;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2730 int flag;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2731 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2732 #ifdef FEAT_WINDOWS
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2733 static win_T *wp;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2734 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2735
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2736 if (flag == 'w') /* just windows */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2737 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2738 #ifdef FEAT_WINDOWS
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2739 if (buf == curbuf) /* first call for this flag/expansion */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2740 wp = curwin;
383
8c229eb52e34 updated for version 7.0099
vimboss
parents: 359
diff changeset
2741 while ((wp = (wp->w_next != NULL ? wp->w_next : firstwin)) != curwin
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2742 && wp->w_buffer->b_scanned)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2743 ;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2744 buf = wp->w_buffer;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2745 #else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2746 buf = curbuf;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2747 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2748 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2749 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2750 /* 'b' (just loaded buffers), 'u' (just non-loaded buffers) or 'U'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2751 * (unlisted buffers)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2752 * When completing whole lines skip unloaded buffers. */
383
8c229eb52e34 updated for version 7.0099
vimboss
parents: 359
diff changeset
2753 while ((buf = (buf->b_next != NULL ? buf->b_next : firstbuf)) != curbuf
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2754 && ((flag == 'U'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2755 ? buf->b_p_bl
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2756 : (!buf->b_p_bl
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2757 || (buf->b_ml.ml_mfp == NULL) != (flag == 'u')))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2758 || buf->b_scanned
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2759 || (buf->b_ml.ml_mfp == NULL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2760 && ctrl_x_mode == CTRL_X_WHOLE_LINE)))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2761 ;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2762 return buf;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2763 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2764
12
bdeee1504ac1 updated for version 7.0004
vimboss
parents: 11
diff changeset
2765 #ifdef FEAT_COMPL_FUNC
502
52e76e2b5b65 updated for version 7.0140
vimboss
parents: 499
diff changeset
2766 static int expand_by_function __ARGS((int type, char_u *base, char_u ***matches));
12
bdeee1504ac1 updated for version 7.0004
vimboss
parents: 11
diff changeset
2767
bdeee1504ac1 updated for version 7.0004
vimboss
parents: 11
diff changeset
2768 /*
523
a7ae7e043e43 updated for version 7.0146
vimboss
parents: 502
diff changeset
2769 * Execute user defined complete function 'completefunc' or 'omnifunc', and
502
52e76e2b5b65 updated for version 7.0140
vimboss
parents: 499
diff changeset
2770 * get matches in "matches".
452
01af1008a8d8 updated for version 7.0120
vimboss
parents: 449
diff changeset
2771 * Return value is number of matches.
12
bdeee1504ac1 updated for version 7.0004
vimboss
parents: 11
diff changeset
2772 */
bdeee1504ac1 updated for version 7.0004
vimboss
parents: 11
diff changeset
2773 static int
502
52e76e2b5b65 updated for version 7.0140
vimboss
parents: 499
diff changeset
2774 expand_by_function(type, base, matches)
523
a7ae7e043e43 updated for version 7.0146
vimboss
parents: 502
diff changeset
2775 int type; /* CTRL_X_OMNI or CTRL_X_FUNCTION */
12
bdeee1504ac1 updated for version 7.0004
vimboss
parents: 11
diff changeset
2776 char_u *base;
bdeee1504ac1 updated for version 7.0004
vimboss
parents: 11
diff changeset
2777 char_u ***matches;
bdeee1504ac1 updated for version 7.0004
vimboss
parents: 11
diff changeset
2778 {
452
01af1008a8d8 updated for version 7.0120
vimboss
parents: 449
diff changeset
2779 list_T *matchlist;
502
52e76e2b5b65 updated for version 7.0140
vimboss
parents: 499
diff changeset
2780 char_u *args[2];
452
01af1008a8d8 updated for version 7.0120
vimboss
parents: 449
diff changeset
2781 listitem_T *li;
01af1008a8d8 updated for version 7.0120
vimboss
parents: 449
diff changeset
2782 garray_T ga;
01af1008a8d8 updated for version 7.0120
vimboss
parents: 449
diff changeset
2783 char_u *p;
502
52e76e2b5b65 updated for version 7.0140
vimboss
parents: 499
diff changeset
2784 char_u *funcname;
52e76e2b5b65 updated for version 7.0140
vimboss
parents: 499
diff changeset
2785 pos_T pos;
52e76e2b5b65 updated for version 7.0140
vimboss
parents: 499
diff changeset
2786
52e76e2b5b65 updated for version 7.0140
vimboss
parents: 499
diff changeset
2787 funcname = (type == CTRL_X_FUNCTION) ? curbuf->b_p_cfu : curbuf->b_p_ofu;
52e76e2b5b65 updated for version 7.0140
vimboss
parents: 499
diff changeset
2788 if (*funcname == NUL)
452
01af1008a8d8 updated for version 7.0120
vimboss
parents: 449
diff changeset
2789 return 0;
01af1008a8d8 updated for version 7.0120
vimboss
parents: 449
diff changeset
2790
01af1008a8d8 updated for version 7.0120
vimboss
parents: 449
diff changeset
2791 /* Call 'completefunc' to obtain the list of matches. */
01af1008a8d8 updated for version 7.0120
vimboss
parents: 449
diff changeset
2792 args[0] = (char_u *)"0";
502
52e76e2b5b65 updated for version 7.0140
vimboss
parents: 499
diff changeset
2793 args[1] = base;
52e76e2b5b65 updated for version 7.0140
vimboss
parents: 499
diff changeset
2794
52e76e2b5b65 updated for version 7.0140
vimboss
parents: 499
diff changeset
2795 pos = curwin->w_cursor;
52e76e2b5b65 updated for version 7.0140
vimboss
parents: 499
diff changeset
2796 matchlist = call_func_retlist(funcname, 2, args, FALSE);
52e76e2b5b65 updated for version 7.0140
vimboss
parents: 499
diff changeset
2797 curwin->w_cursor = pos; /* restore the cursor position */
452
01af1008a8d8 updated for version 7.0120
vimboss
parents: 449
diff changeset
2798 if (matchlist == NULL)
01af1008a8d8 updated for version 7.0120
vimboss
parents: 449
diff changeset
2799 return 0;
01af1008a8d8 updated for version 7.0120
vimboss
parents: 449
diff changeset
2800
01af1008a8d8 updated for version 7.0120
vimboss
parents: 449
diff changeset
2801 /* Go through the List with matches and put them in an array. */
01af1008a8d8 updated for version 7.0120
vimboss
parents: 449
diff changeset
2802 ga_init2(&ga, (int)sizeof(char_u *), 8);
01af1008a8d8 updated for version 7.0120
vimboss
parents: 449
diff changeset
2803 for (li = matchlist->lv_first; li != NULL; li = li->li_next)
01af1008a8d8 updated for version 7.0120
vimboss
parents: 449
diff changeset
2804 {
01af1008a8d8 updated for version 7.0120
vimboss
parents: 449
diff changeset
2805 p = get_tv_string_chk(&li->li_tv);
01af1008a8d8 updated for version 7.0120
vimboss
parents: 449
diff changeset
2806 if (p != NULL && *p != NUL)
01af1008a8d8 updated for version 7.0120
vimboss
parents: 449
diff changeset
2807 {
01af1008a8d8 updated for version 7.0120
vimboss
parents: 449
diff changeset
2808 if (ga_grow(&ga, 1) == FAIL)
01af1008a8d8 updated for version 7.0120
vimboss
parents: 449
diff changeset
2809 break;
01af1008a8d8 updated for version 7.0120
vimboss
parents: 449
diff changeset
2810 ((char_u **)ga.ga_data)[ga.ga_len] = vim_strsave(p);
01af1008a8d8 updated for version 7.0120
vimboss
parents: 449
diff changeset
2811 ++ga.ga_len;
01af1008a8d8 updated for version 7.0120
vimboss
parents: 449
diff changeset
2812 }
01af1008a8d8 updated for version 7.0120
vimboss
parents: 449
diff changeset
2813 }
01af1008a8d8 updated for version 7.0120
vimboss
parents: 449
diff changeset
2814
01af1008a8d8 updated for version 7.0120
vimboss
parents: 449
diff changeset
2815 list_unref(matchlist);
01af1008a8d8 updated for version 7.0120
vimboss
parents: 449
diff changeset
2816 *matches = (char_u **)ga.ga_data;
01af1008a8d8 updated for version 7.0120
vimboss
parents: 449
diff changeset
2817 return ga.ga_len;
12
bdeee1504ac1 updated for version 7.0004
vimboss
parents: 11
diff changeset
2818 }
bdeee1504ac1 updated for version 7.0004
vimboss
parents: 11
diff changeset
2819 #endif /* FEAT_COMPL_FUNC */
bdeee1504ac1 updated for version 7.0004
vimboss
parents: 11
diff changeset
2820
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
2821 /*
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
2822 * Get the next expansion(s), using "compl_pattern".
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
2823 * The search starts at position "ini" in curbuf and in the direction dir.
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
2824 * When "compl_started" is FALSE start at that position, otherwise
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
2825 * continue where we stopped searching before.
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
2826 * This may return before finding all the matches.
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
2827 * Return the total number of matches or -1 if still unknown -- Acevedo
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2828 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2829 static int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2830 ins_compl_get_exp(ini, dir)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2831 pos_T *ini;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2832 int dir;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2833 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2834 static pos_T first_match_pos;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2835 static pos_T last_match_pos;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2836 static char_u *e_cpt = (char_u *)""; /* curr. entry in 'complete' */
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
2837 static int found_all = FALSE; /* Found all matches of a
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
2838 certain type. */
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
2839 static buf_T *ins_buf = NULL; /* buffer being scanned */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2840
464
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
2841 pos_T *pos;
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
2842 char_u **matches;
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
2843 int save_p_scs;
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
2844 int save_p_ws;
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
2845 int save_p_ic;
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
2846 int i;
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
2847 int num_matches;
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
2848 int len;
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
2849 int found_new_match;
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
2850 int type = ctrl_x_mode;
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
2851 char_u *ptr;
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
2852 char_u *dict = NULL;
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
2853 int dict_f = 0;
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
2854 compl_T *old_match;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2855
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
2856 if (!compl_started)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2857 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2858 for (ins_buf = firstbuf; ins_buf != NULL; ins_buf = ins_buf->b_next)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2859 ins_buf->b_scanned = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2860 found_all = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2861 ins_buf = curbuf;
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
2862 e_cpt = (compl_cont_status & CONT_LOCAL)
12
bdeee1504ac1 updated for version 7.0004
vimboss
parents: 11
diff changeset
2863 ? (char_u *)"." : curbuf->b_p_cpt;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2864 last_match_pos = first_match_pos = *ini;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2865 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2866
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
2867 old_match = compl_curr_match; /* remember the last current match */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2868 pos = (dir == FORWARD) ? &last_match_pos : &first_match_pos;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2869 /* For ^N/^P loop over all the flags/windows/buffers in 'complete' */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2870 for (;;)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2871 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2872 found_new_match = FAIL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2873
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
2874 /* 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
2875 * 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
2876 * entries from 'complete' that look in loaded buffers. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2877 if ((ctrl_x_mode == 0 || ctrl_x_mode == CTRL_X_WHOLE_LINE)
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
2878 && (!compl_started || found_all))
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2879 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2880 found_all = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2881 while (*e_cpt == ',' || *e_cpt == ' ')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2882 e_cpt++;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2883 if (*e_cpt == '.' && !curbuf->b_scanned)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2884 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2885 ins_buf = curbuf;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2886 first_match_pos = *ini;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2887 /* So that ^N can match word immediately after cursor */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2888 if (ctrl_x_mode == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2889 dec(&first_match_pos);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2890 last_match_pos = first_match_pos;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2891 type = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2892 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2893 else if (vim_strchr((char_u *)"buwU", *e_cpt) != NULL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2894 && (ins_buf = ins_compl_next_buf(ins_buf, *e_cpt)) != curbuf)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2895 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2896 /* Scan a buffer, but not the current one. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2897 if (ins_buf->b_ml.ml_mfp != NULL) /* loaded buffer */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2898 {
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
2899 compl_started = TRUE;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2900 first_match_pos.col = last_match_pos.col = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2901 first_match_pos.lnum = ins_buf->b_ml.ml_line_count + 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2902 last_match_pos.lnum = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2903 type = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2904 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2905 else /* unloaded buffer, scan like dictionary */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2906 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2907 found_all = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2908 if (ins_buf->b_fname == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2909 continue;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2910 type = CTRL_X_DICTIONARY;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2911 dict = ins_buf->b_fname;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2912 dict_f = DICT_EXACT;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2913 }
274
8fa8d7964cf1 updated for version 7.0073
vimboss
parents: 237
diff changeset
2914 vim_snprintf((char *)IObuff, IOSIZE, _("Scanning: %s"),
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2915 ins_buf->b_fname == NULL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2916 ? buf_spname(ins_buf)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2917 : ins_buf->b_sfname == NULL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2918 ? (char *)ins_buf->b_fname
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2919 : (char *)ins_buf->b_sfname);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2920 msg_trunc_attr(IObuff, TRUE, hl_attr(HLF_R));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2921 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2922 else if (*e_cpt == NUL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2923 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2924 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2925 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2926 if (ctrl_x_mode == CTRL_X_WHOLE_LINE)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2927 type = -1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2928 else if (*e_cpt == 'k' || *e_cpt == 's')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2929 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2930 if (*e_cpt == 'k')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2931 type = CTRL_X_DICTIONARY;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2932 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2933 type = CTRL_X_THESAURUS;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2934 if (*++e_cpt != ',' && *e_cpt != NUL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2935 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2936 dict = e_cpt;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2937 dict_f = DICT_FIRST;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2938 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2939 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2940 #ifdef FEAT_FIND_ID
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2941 else if (*e_cpt == 'i')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2942 type = CTRL_X_PATH_PATTERNS;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2943 else if (*e_cpt == 'd')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2944 type = CTRL_X_PATH_DEFINES;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2945 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2946 else if (*e_cpt == ']' || *e_cpt == 't')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2947 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2948 type = CTRL_X_TAGS;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2949 sprintf((char*)IObuff, _("Scanning tags."));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2950 msg_trunc_attr(IObuff, TRUE, hl_attr(HLF_R));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2951 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2952 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2953 type = -1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2954
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2955 /* in any case e_cpt is advanced to the next entry */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2956 (void)copy_option_part(&e_cpt, IObuff, IOSIZE, ",");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2957
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2958 found_all = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2959 if (type == -1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2960 continue;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2961 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2962 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2963
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2964 switch (type)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2965 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2966 case -1:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2967 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2968 #ifdef FEAT_FIND_ID
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2969 case CTRL_X_PATH_PATTERNS:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2970 case CTRL_X_PATH_DEFINES:
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
2971 find_pattern_in_path(compl_pattern, dir,
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
2972 (int)STRLEN(compl_pattern), FALSE, FALSE,
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2973 (type == CTRL_X_PATH_DEFINES
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
2974 && !(compl_cont_status & CONT_SOL))
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2975 ? FIND_DEFINE : FIND_ANY, 1L, ACTION_EXPAND,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2976 (linenr_T)1, (linenr_T)MAXLNUM);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2977 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2978 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2979
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2980 case CTRL_X_DICTIONARY:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2981 case CTRL_X_THESAURUS:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2982 ins_compl_dictionaries(
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2983 dict ? dict
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2984 : (type == CTRL_X_THESAURUS
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2985 ? (*curbuf->b_p_tsr == NUL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2986 ? p_tsr
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2987 : curbuf->b_p_tsr)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2988 : (*curbuf->b_p_dict == NUL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2989 ? p_dict
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2990 : curbuf->b_p_dict)),
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
2991 compl_pattern, dir,
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2992 dict ? dict_f : 0, type == CTRL_X_THESAURUS);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2993 dict = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2994 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2995
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2996 case CTRL_X_TAGS:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2997 /* set p_ic according to p_ic, p_scs and pat for find_tags(). */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2998 save_p_ic = p_ic;
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
2999 p_ic = ignorecase(compl_pattern);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3000
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3001 /* Find up to TAG_MANY matches. Avoids that an enourmous number
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3002 * of matches is found when compl_pattern is empty */
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3003 if (find_tags(compl_pattern, &num_matches, &matches,
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3004 TAG_REGEXP | TAG_NAMES | TAG_NOIC |
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3005 TAG_INS_COMP | (ctrl_x_mode ? TAG_VERBOSE : 0),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3006 TAG_MANY, curbuf->b_ffname) == OK && num_matches > 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3007 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3008 ins_compl_add_matches(num_matches, matches, dir);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3009 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3010 p_ic = save_p_ic;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3011 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3012
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3013 case CTRL_X_FILES:
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3014 if (expand_wildcards(1, &compl_pattern, &num_matches, &matches,
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3015 EW_FILE|EW_DIR|EW_ADDSLASH|EW_SILENT) == OK)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3016 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3017
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3018 /* May change home directory back to "~". */
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3019 tilde_replace(compl_pattern, num_matches, matches);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3020 ins_compl_add_matches(num_matches, matches, dir);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3021 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3022 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3023
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3024 case CTRL_X_CMDLINE:
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3025 if (expand_cmdline(&compl_xp, compl_pattern,
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3026 (int)STRLEN(compl_pattern),
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3027 &num_matches, &matches) == EXPAND_OK)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3028 ins_compl_add_matches(num_matches, matches, dir);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3029 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3030
12
bdeee1504ac1 updated for version 7.0004
vimboss
parents: 11
diff changeset
3031 #ifdef FEAT_COMPL_FUNC
bdeee1504ac1 updated for version 7.0004
vimboss
parents: 11
diff changeset
3032 case CTRL_X_FUNCTION:
523
a7ae7e043e43 updated for version 7.0146
vimboss
parents: 502
diff changeset
3033 case CTRL_X_OMNI:
548
f43150a669dc updated for version 7.0155
vimboss
parents: 540
diff changeset
3034 num_matches = expand_by_function(type, compl_pattern, &matches);
12
bdeee1504ac1 updated for version 7.0004
vimboss
parents: 11
diff changeset
3035 if (num_matches > 0)
bdeee1504ac1 updated for version 7.0004
vimboss
parents: 11
diff changeset
3036 ins_compl_add_matches(num_matches, matches, dir);
bdeee1504ac1 updated for version 7.0004
vimboss
parents: 11
diff changeset
3037 break;
bdeee1504ac1 updated for version 7.0004
vimboss
parents: 11
diff changeset
3038 #endif
bdeee1504ac1 updated for version 7.0004
vimboss
parents: 11
diff changeset
3039
477
f8b75b8f1988 updated for version 7.0128
vimboss
parents: 474
diff changeset
3040 case CTRL_X_SPELL:
f8b75b8f1988 updated for version 7.0128
vimboss
parents: 474
diff changeset
3041 #ifdef FEAT_SYN_HL
f8b75b8f1988 updated for version 7.0128
vimboss
parents: 474
diff changeset
3042 num_matches = expand_spelling(first_match_pos.lnum,
f8b75b8f1988 updated for version 7.0128
vimboss
parents: 474
diff changeset
3043 first_match_pos.col, compl_pattern, &matches);
f8b75b8f1988 updated for version 7.0128
vimboss
parents: 474
diff changeset
3044 if (num_matches > 0)
f8b75b8f1988 updated for version 7.0128
vimboss
parents: 474
diff changeset
3045 ins_compl_add_matches(num_matches, matches, dir);
f8b75b8f1988 updated for version 7.0128
vimboss
parents: 474
diff changeset
3046 #endif
f8b75b8f1988 updated for version 7.0128
vimboss
parents: 474
diff changeset
3047 break;
f8b75b8f1988 updated for version 7.0128
vimboss
parents: 474
diff changeset
3048
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3049 default: /* normal ^P/^N and ^X^L */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3050 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3051 * If 'infercase' is set, don't use 'smartcase' here
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3052 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3053 save_p_scs = p_scs;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3054 if (ins_buf->b_p_inf)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3055 p_scs = FALSE;
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3056
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3057 /* buffers other than curbuf are scanned from the beginning or the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3058 * end but never from the middle, thus setting nowrapscan in this
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3059 * buffers is a good idea, on the other hand, we always set
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3060 * wrapscan for curbuf to avoid missing matches -- Acevedo,Webb */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3061 save_p_ws = p_ws;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3062 if (ins_buf != curbuf)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3063 p_ws = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3064 else if (*e_cpt == '.')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3065 p_ws = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3066 for (;;)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3067 {
464
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
3068 int flags = 0;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3069
540
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
3070 /* ctrl_x_mode == CTRL_X_WHOLE_LINE || word-wise search that
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
3071 * has added a word that was at the beginning of the line */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3072 if ( ctrl_x_mode == CTRL_X_WHOLE_LINE
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3073 || (compl_cont_status & CONT_SOL))
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3074 found_new_match = search_for_exact_line(ins_buf, pos,
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3075 dir, compl_pattern);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3076 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3077 found_new_match = searchit(NULL, ins_buf, pos, dir,
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3078 compl_pattern, 1L, SEARCH_KEEP + SEARCH_NFMSG,
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3079 RE_LAST);
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3080 if (!compl_started)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3081 {
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3082 /* set compl_started even on fail */
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3083 compl_started = TRUE;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3084 first_match_pos = *pos;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3085 last_match_pos = *pos;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3086 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3087 else if (first_match_pos.lnum == last_match_pos.lnum
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3088 && first_match_pos.col == last_match_pos.col)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3089 found_new_match = FAIL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3090 if (found_new_match == FAIL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3091 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3092 if (ins_buf == curbuf)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3093 found_all = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3094 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3095 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3096
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3097 /* when ADDING, the text before the cursor matches, skip it */
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3098 if ( (compl_cont_status & CONT_ADDING) && ins_buf == curbuf
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3099 && ini->lnum == pos->lnum
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3100 && ini->col == pos->col)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3101 continue;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3102 ptr = ml_get_buf(ins_buf, pos->lnum, FALSE) + pos->col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3103 if (ctrl_x_mode == CTRL_X_WHOLE_LINE)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3104 {
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3105 if (compl_cont_status & CONT_ADDING)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3106 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3107 if (pos->lnum >= ins_buf->b_ml.ml_line_count)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3108 continue;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3109 ptr = ml_get_buf(ins_buf, pos->lnum + 1, FALSE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3110 if (!p_paste)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3111 ptr = skipwhite(ptr);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3112 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3113 len = (int)STRLEN(ptr);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3114 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3115 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3116 {
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3117 char_u *tmp_ptr = ptr;
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3118
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3119 if (compl_cont_status & CONT_ADDING)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3120 {
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3121 tmp_ptr += compl_length;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3122 /* Skip if already inside a word. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3123 if (vim_iswordp(tmp_ptr))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3124 continue;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3125 /* Find start of next word. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3126 tmp_ptr = find_word_start(tmp_ptr);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3127 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3128 /* Find end of this word. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3129 tmp_ptr = find_word_end(tmp_ptr);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3130 len = (int)(tmp_ptr - ptr);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3131
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3132 if ((compl_cont_status & CONT_ADDING)
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3133 && len == compl_length)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3134 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3135 if (pos->lnum < ins_buf->b_ml.ml_line_count)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3136 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3137 /* Try next line, if any. the new word will be
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3138 * "join" as if the normal command "J" was used.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3139 * IOSIZE is always greater than
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3140 * compl_length, so the next STRNCPY always
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3141 * works -- Acevedo */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3142 STRNCPY(IObuff, ptr, len);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3143 ptr = ml_get_buf(ins_buf, pos->lnum + 1, FALSE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3144 tmp_ptr = ptr = skipwhite(ptr);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3145 /* Find start of next word. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3146 tmp_ptr = find_word_start(tmp_ptr);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3147 /* Find end of next word. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3148 tmp_ptr = find_word_end(tmp_ptr);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3149 if (tmp_ptr > ptr)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3150 {
419
f713fc55bf7b updated for version 7.0109
vimboss
parents: 408
diff changeset
3151 if (*ptr != ')' && IObuff[len - 1] != TAB)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3152 {
419
f713fc55bf7b updated for version 7.0109
vimboss
parents: 408
diff changeset
3153 if (IObuff[len - 1] != ' ')
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3154 IObuff[len++] = ' ';
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3155 /* IObuf =~ "\k.* ", thus len >= 2 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3156 if (p_js
419
f713fc55bf7b updated for version 7.0109
vimboss
parents: 408
diff changeset
3157 && (IObuff[len - 2] == '.'
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3158 || (vim_strchr(p_cpo, CPO_JOINSP)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3159 == NULL
419
f713fc55bf7b updated for version 7.0109
vimboss
parents: 408
diff changeset
3160 && (IObuff[len - 2] == '?'
f713fc55bf7b updated for version 7.0109
vimboss
parents: 408
diff changeset
3161 || IObuff[len - 2] == '!'))))
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3162 IObuff[len++] = ' ';
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3163 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3164 /* copy as much as posible of the new word */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3165 if (tmp_ptr - ptr >= IOSIZE - len)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3166 tmp_ptr = ptr + IOSIZE - len - 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3167 STRNCPY(IObuff + len, ptr, tmp_ptr - ptr);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3168 len += (int)(tmp_ptr - ptr);
464
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
3169 flags |= CONT_S_IPOS;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3170 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3171 IObuff[len] = NUL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3172 ptr = IObuff;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3173 }
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3174 if (len == compl_length)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3175 continue;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3176 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3177 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3178 if (ins_compl_add_infercase(ptr, len,
540
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
3179 ins_buf == curbuf ? NULL : ins_buf->b_sfname,
464
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
3180 dir, flags) != NOTDONE)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3181 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3182 found_new_match = OK;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3183 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3184 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3185 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3186 p_scs = save_p_scs;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3187 p_ws = save_p_ws;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3188 }
540
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
3189
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3190 /* check if compl_curr_match has changed, (e.g. other type of
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3191 * expansion added somenthing) */
540
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
3192 if (type != 0 && compl_curr_match != old_match)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3193 found_new_match = OK;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3194
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3195 /* break the loop for specialized modes (use 'complete' just for the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3196 * generic ctrl_x_mode == 0) or when we've found a new match */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3197 if ((ctrl_x_mode != 0 && ctrl_x_mode != CTRL_X_WHOLE_LINE)
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3198 || found_new_match != FAIL)
540
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
3199 {
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
3200 if (got_int)
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
3201 break;
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
3202 if (pum_wanted() && type != -1)
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
3203 /* Fill the popup menu as soon as possible. */
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
3204 ins_compl_check_keys(0);
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
3205 if ((ctrl_x_mode != 0 && ctrl_x_mode != CTRL_X_WHOLE_LINE)
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
3206 || compl_interrupted)
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
3207 break;
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
3208 compl_started = TRUE;
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
3209 }
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
3210 else
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
3211 {
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
3212 /* Mark a buffer scanned when it has been scanned completely */
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
3213 if (type == 0 || type == CTRL_X_PATH_PATTERNS)
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
3214 ins_buf->b_scanned = TRUE;
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
3215
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
3216 compl_started = FALSE;
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
3217 }
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3218 }
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3219 compl_started = TRUE;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3220
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3221 if ((ctrl_x_mode == 0 || ctrl_x_mode == CTRL_X_WHOLE_LINE)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3222 && *e_cpt == NUL) /* Got to end of 'complete' */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3223 found_new_match = FAIL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3224
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3225 i = -1; /* total of matches, unknown */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3226 if (found_new_match == FAIL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3227 || (ctrl_x_mode != 0 && ctrl_x_mode != CTRL_X_WHOLE_LINE))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3228 i = ins_compl_make_cyclic();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3229
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3230 /* If several matches were added (FORWARD) or the search failed and has
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3231 * 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
3232 * or previous entry (if any) -- Acevedo */
464
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
3233 compl_curr_match = dir == FORWARD ? old_match->cp_next : old_match->cp_prev;
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3234 if (compl_curr_match == NULL)
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3235 compl_curr_match = old_match;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3236 return i;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3237 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3238
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3239 /* Delete the old text being completed. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3240 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3241 ins_compl_delete()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3242 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3243 int i;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3244
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3245 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3246 * In insert mode: Delete the typed part.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3247 * In replace mode: Put the old characters back, if any.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3248 */
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3249 i = compl_col + (compl_cont_status & CONT_ADDING ? compl_length : 0);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3250 backspace_until_column(i);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3251 changed_cline_bef_curs();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3252 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3253
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3254 /* Insert the new text being completed. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3255 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3256 ins_compl_insert()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3257 {
464
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
3258 ins_bytes(compl_shown_match->cp_str + curwin->w_cursor.col - compl_col);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3259 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3260
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3261 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3262 * Fill in the next completion in the current direction.
464
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
3263 * 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
3264 * 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
3265 * 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
3266 * we are still in the middle of finding completions, to allow browsing
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
3267 * through the ones found so far.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3268 * Return the total number of matches, or -1 if still unknown -- webb.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3269 *
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3270 * 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
3271 * compl_shown_match here.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3272 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3273 * Note that this function may be called recursively once only. First with
464
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
3274 * "allow_get_expansion" TRUE, which calls ins_compl_get_exp(), which in turn
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
3275 * calls this function with "allow_get_expansion" FALSE.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3276 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3277 static int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3278 ins_compl_next(allow_get_expansion)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3279 int allow_get_expansion;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3280 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3281 int num_matches = -1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3282 int i;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3283
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3284 if (allow_get_expansion)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3285 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3286 /* Delete old text to be replaced */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3287 ins_compl_delete();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3288 }
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3289 compl_pending = FALSE;
464
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
3290 if (compl_shows_dir == FORWARD && compl_shown_match->cp_next != NULL)
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
3291 compl_shown_match = compl_shown_match->cp_next;
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
3292 else if (compl_shows_dir == BACKWARD && compl_shown_match->cp_prev != NULL)
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
3293 compl_shown_match = compl_shown_match->cp_prev;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3294 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3295 {
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3296 compl_pending = TRUE;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3297 if (allow_get_expansion)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3298 {
540
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
3299 num_matches = ins_compl_get_exp(&compl_startpos, compl_direction);
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3300 if (compl_pending)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3301 {
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3302 if (compl_direction == compl_shows_dir)
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3303 compl_shown_match = compl_curr_match;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3304 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3305 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3306 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3307 return -1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3308 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3309
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3310 /* Insert the text of the new completion */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3311 ins_compl_insert();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3312
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3313 if (!allow_get_expansion)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3314 {
540
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
3315 /* may undisplay the popup menu first */
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
3316 ins_compl_upd_pum();
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
3317
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3318 /* Display the current match. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3319 update_screen(0);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3320
540
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
3321 /* display the updated popup menu */
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
3322 ins_compl_show_pum();
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
3323
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3324 /* Delete old text to be replaced, since we're still searching and
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3325 * don't want to match ourselves! */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3326 ins_compl_delete();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3327 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3328
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3329 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3330 * Show the file name for the match (if any)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3331 * Truncate the file name to avoid a wait for return.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3332 */
464
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
3333 if (compl_shown_match->cp_fname != NULL)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3334 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3335 STRCPY(IObuff, "match in file ");
464
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
3336 i = (vim_strsize(compl_shown_match->cp_fname) + 16) - sc_col;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3337 if (i <= 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3338 i = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3339 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3340 STRCAT(IObuff, "<");
464
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
3341 STRCAT(IObuff, compl_shown_match->cp_fname + i);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3342 msg(IObuff);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3343 redraw_cmdline = FALSE; /* don't overwrite! */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3344 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3345
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3346 return num_matches;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3347 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3348
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3349 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3350 * Call this while finding completions, to check whether the user has hit a key
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3351 * that should change the currently displayed completion, or exit completion
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3352 * mode. Also, when compl_pending is TRUE, show a completion as soon as
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3353 * possible. -- webb
464
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
3354 * "frequency" specifies out of how many calls we actually check.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3355 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3356 void
464
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
3357 ins_compl_check_keys(frequency)
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
3358 int frequency;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3359 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3360 static int count = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3361
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3362 int c;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3363
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3364 /* Don't check when reading keys from a script. That would break the test
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3365 * scripts */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3366 if (using_script())
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3367 return;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3368
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3369 /* Only do this at regular intervals */
464
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
3370 if (++count < frequency)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3371 return;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3372 count = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3373
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3374 ++no_mapping;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3375 c = vpeekc_any();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3376 --no_mapping;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3377 if (c != NUL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3378 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3379 if (vim_is_ctrl_x_key(c) && c != Ctrl_X && c != Ctrl_R)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3380 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3381 c = safe_vgetc(); /* Eat the character */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3382 if (c == Ctrl_P || c == Ctrl_L)
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3383 compl_shows_dir = BACKWARD;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3384 else
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3385 compl_shows_dir = FORWARD;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3386 (void)ins_compl_next(FALSE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3387 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3388 else if (c != Ctrl_R)
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3389 compl_interrupted = TRUE;
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3390 }
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3391 if (compl_pending && !got_int)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3392 (void)ins_compl_next(FALSE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3393 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3394
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3395 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3396 * Do Insert mode completion.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3397 * Called when character "c" was typed, which has a meaning for completion.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3398 * Returns OK if completion was done, FAIL if something failed (out of mem).
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3399 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3400 static int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3401 ins_complete(c)
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3402 int c;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3403 {
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3404 char_u *line;
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3405 int startcol = 0; /* column where searched text starts */
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3406 colnr_T curs_col; /* cursor column */
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3407 int n;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3408
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3409 if (c == Ctrl_P || c == Ctrl_L)
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3410 compl_direction = BACKWARD;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3411 else
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3412 compl_direction = FORWARD;
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3413 if (!compl_started)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3414 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3415 /* First time we hit ^N or ^P (in a row, I mean) */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3416
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3417 /* Turn off 'sm' so we don't show matches with ^X^L */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3418 save_sm = p_sm;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3419 p_sm = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3420
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3421 did_ai = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3422 #ifdef FEAT_SMARTINDENT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3423 did_si = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3424 can_si = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3425 can_si_back = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3426 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3427 if (stop_arrow() == FAIL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3428 return FAIL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3429
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3430 line = ml_get(curwin->w_cursor.lnum);
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3431 curs_col = curwin->w_cursor.col;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3432
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3433 /* 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
3434 * "compl_startpos" to the cursor as a pattern to add a new word
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3435 * instead of expand the one before the cursor, in word-wise if
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3436 * "compl_startpos"
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3437 * is not in the same line as the cursor then fix it (the line has
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3438 * been split because it was longer than 'tw'). if SOL is set then
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3439 * skip the previous pattern, a word at the beginning of the line has
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3440 * been inserted, we'll look for that -- Acevedo. */
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3441 if ((compl_cont_status & CONT_INTRPT) && compl_cont_mode == ctrl_x_mode)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3442 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3443 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3444 * it is a continued search
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3445 */
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3446 compl_cont_status &= ~CONT_INTRPT; /* remove INTRPT */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3447 if (ctrl_x_mode == 0 || ctrl_x_mode == CTRL_X_PATH_PATTERNS
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3448 || ctrl_x_mode == CTRL_X_PATH_DEFINES)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3449 {
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3450 if (compl_startpos.lnum != curwin->w_cursor.lnum)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3451 {
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3452 /* line (probably) wrapped, set compl_startpos to the
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3453 * first non_blank in the line, if it is not a wordchar
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3454 * include it to get a better pattern, but then we don't
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3455 * want the "\\<" prefix, check it bellow */
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3456 compl_col = (colnr_T)(skipwhite(line) - line);
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3457 compl_startpos.col = compl_col;
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3458 compl_startpos.lnum = curwin->w_cursor.lnum;
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3459 compl_cont_status &= ~CONT_SOL; /* clear SOL if present */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3460 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3461 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3462 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3463 /* S_IPOS was set when we inserted a word that was at the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3464 * beginning of the line, which means that we'll go to SOL
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3465 * mode but first we need to redefine compl_startpos */
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3466 if (compl_cont_status & CONT_S_IPOS)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3467 {
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3468 compl_cont_status |= CONT_SOL;
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3469 compl_startpos.col = (colnr_T)(skipwhite(
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3470 line + compl_length
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3471 + compl_startpos.col) - line);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3472 }
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3473 compl_col = compl_startpos.col;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3474 }
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3475 compl_length = curwin->w_cursor.col - (int)compl_col;
502
52e76e2b5b65 updated for version 7.0140
vimboss
parents: 499
diff changeset
3476 /* IObuff is used to add a "word from the next line" would we
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3477 * have enough space? just being paranoic */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3478 #define MIN_SPACE 75
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3479 if (compl_length > (IOSIZE - MIN_SPACE))
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3480 {
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3481 compl_cont_status &= ~CONT_SOL;
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3482 compl_length = (IOSIZE - MIN_SPACE);
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3483 compl_col = curwin->w_cursor.col - compl_length;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3484 }
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3485 compl_cont_status |= CONT_ADDING | CONT_N_ADDS;
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3486 if (compl_length < 1)
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3487 compl_cont_status &= CONT_LOCAL;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3488 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3489 else if (ctrl_x_mode == CTRL_X_WHOLE_LINE)
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3490 compl_cont_status = CONT_ADDING | CONT_N_ADDS;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3491 else
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3492 compl_cont_status = 0;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3493 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3494 else
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3495 compl_cont_status &= CONT_LOCAL;
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3496
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3497 if (!(compl_cont_status & CONT_ADDING)) /* normal expansion */
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3498 {
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3499 compl_cont_mode = ctrl_x_mode;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3500 if (ctrl_x_mode != 0) /* Remove LOCAL if ctrl_x_mode != 0 */
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3501 compl_cont_status = 0;
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3502 compl_cont_status |= CONT_N_ADDS;
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3503 compl_startpos = curwin->w_cursor;
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3504 startcol = (int)curs_col;
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3505 compl_col = 0;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3506 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3507
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3508 /* Work out completion pattern and original text -- webb */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3509 if (ctrl_x_mode == 0 || (ctrl_x_mode & CTRL_X_WANT_IDENT))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3510 {
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3511 if ((compl_cont_status & CONT_SOL)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3512 || ctrl_x_mode == CTRL_X_PATH_DEFINES)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3513 {
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3514 if (!(compl_cont_status & CONT_ADDING))
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3515 {
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3516 while (--startcol >= 0 && vim_isIDc(line[startcol]))
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3517 ;
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3518 compl_col += ++startcol;
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3519 compl_length = curs_col - startcol;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3520 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3521 if (p_ic)
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3522 compl_pattern = str_foldcase(line + compl_col,
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3523 compl_length, NULL, 0);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3524 else
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3525 compl_pattern = vim_strnsave(line + compl_col,
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3526 compl_length);
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3527 if (compl_pattern == NULL)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3528 return FAIL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3529 }
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3530 else if (compl_cont_status & CONT_ADDING)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3531 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3532 char_u *prefix = (char_u *)"\\<";
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3533
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3534 /* we need 3 extra chars, 1 for the NUL and
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3535 * 2 >= strlen(prefix) -- Acevedo */
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3536 compl_pattern = alloc(quote_meta(NULL, line + compl_col,
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3537 compl_length) + 3);
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3538 if (compl_pattern == NULL)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3539 return FAIL;
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3540 if (!vim_iswordp(line + compl_col)
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3541 || (compl_col > 0
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3542 && (
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3543 #ifdef FEAT_MBYTE
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3544 vim_iswordp(mb_prevptr(line, line + compl_col))
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3545 #else
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3546 vim_iswordc(line[compl_col - 1])
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3547 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3548 )))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3549 prefix = (char_u *)"";
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3550 STRCPY((char *)compl_pattern, prefix);
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3551 (void)quote_meta(compl_pattern + STRLEN(prefix),
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3552 line + compl_col, compl_length);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3553 }
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3554 else if (--startcol < 0 ||
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3555 #ifdef FEAT_MBYTE
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3556 !vim_iswordp(mb_prevptr(line, line + startcol + 1))
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3557 #else
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3558 !vim_iswordc(line[startcol])
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3559 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3560 )
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3561 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3562 /* Match any word of at least two chars */
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3563 compl_pattern = vim_strsave((char_u *)"\\<\\k\\k");
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3564 if (compl_pattern == NULL)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3565 return FAIL;
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3566 compl_col += curs_col;
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3567 compl_length = 0;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3568 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3569 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3570 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3571 #ifdef FEAT_MBYTE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3572 /* Search the point of change class of multibyte character
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3573 * or not a word single byte character backward. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3574 if (has_mbyte)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3575 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3576 int base_class;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3577 int head_off;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3578
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3579 startcol -= (*mb_head_off)(line, line + startcol);
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3580 base_class = mb_get_class(line + startcol);
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3581 while (--startcol >= 0)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3582 {
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3583 head_off = (*mb_head_off)(line, line + startcol);
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3584 if (base_class != mb_get_class(line + startcol
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3585 - head_off))
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3586 break;
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3587 startcol -= head_off;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3588 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3589 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3590 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3591 #endif
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3592 while (--startcol >= 0 && vim_iswordc(line[startcol]))
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3593 ;
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3594 compl_col += ++startcol;
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3595 compl_length = (int)curs_col - startcol;
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3596 if (compl_length == 1)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3597 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3598 /* Only match word with at least two chars -- webb
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3599 * there's no need to call quote_meta,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3600 * alloc(7) is enough -- Acevedo
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3601 */
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3602 compl_pattern = alloc(7);
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3603 if (compl_pattern == NULL)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3604 return FAIL;
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3605 STRCPY((char *)compl_pattern, "\\<");
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3606 (void)quote_meta(compl_pattern + 2, line + compl_col, 1);
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3607 STRCAT((char *)compl_pattern, "\\k");
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3608 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3609 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3610 {
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3611 compl_pattern = alloc(quote_meta(NULL, line + compl_col,
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3612 compl_length) + 3);
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3613 if (compl_pattern == NULL)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3614 return FAIL;
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3615 STRCPY((char *)compl_pattern, "\\<");
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3616 (void)quote_meta(compl_pattern + 2, line + compl_col,
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3617 compl_length);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3618 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3619 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3620 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3621 else if (ctrl_x_mode == CTRL_X_WHOLE_LINE)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3622 {
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3623 compl_col = skipwhite(line) - line;
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3624 compl_length = (int)curs_col - (int)compl_col;
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3625 if (compl_length < 0) /* cursor in indent: empty pattern */
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3626 compl_length = 0;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3627 if (p_ic)
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3628 compl_pattern = str_foldcase(line + compl_col, compl_length,
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3629 NULL, 0);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3630 else
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3631 compl_pattern = vim_strnsave(line + compl_col, compl_length);
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3632 if (compl_pattern == NULL)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3633 return FAIL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3634 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3635 else if (ctrl_x_mode == CTRL_X_FILES)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3636 {
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3637 while (--startcol >= 0 && vim_isfilec(line[startcol]))
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3638 ;
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3639 compl_col += ++startcol;
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3640 compl_length = (int)curs_col - startcol;
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3641 compl_pattern = addstar(line + compl_col, compl_length,
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3642 EXPAND_FILES);
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3643 if (compl_pattern == NULL)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3644 return FAIL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3645 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3646 else if (ctrl_x_mode == CTRL_X_CMDLINE)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3647 {
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3648 compl_pattern = vim_strnsave(line, curs_col);
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3649 if (compl_pattern == NULL)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3650 return FAIL;
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3651 set_cmd_context(&compl_xp, compl_pattern,
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3652 (int)STRLEN(compl_pattern), curs_col);
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3653 if (compl_xp.xp_context == EXPAND_UNSUCCESSFUL
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3654 || compl_xp.xp_context == EXPAND_NOTHING)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3655 return FAIL;
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3656 startcol = (int)(compl_xp.xp_pattern - compl_pattern);
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3657 compl_col = startcol;
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3658 compl_length = curs_col - startcol;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3659 }
523
a7ae7e043e43 updated for version 7.0146
vimboss
parents: 502
diff changeset
3660 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
3661 {
12
bdeee1504ac1 updated for version 7.0004
vimboss
parents: 11
diff changeset
3662 #ifdef FEAT_COMPL_FUNC
bdeee1504ac1 updated for version 7.0004
vimboss
parents: 11
diff changeset
3663 /*
502
52e76e2b5b65 updated for version 7.0140
vimboss
parents: 499
diff changeset
3664 * Call user defined function 'completefunc' with "a:findstart"
52e76e2b5b65 updated for version 7.0140
vimboss
parents: 499
diff changeset
3665 * 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
3666 */
502
52e76e2b5b65 updated for version 7.0140
vimboss
parents: 499
diff changeset
3667 char_u *args[2];
452
01af1008a8d8 updated for version 7.0120
vimboss
parents: 449
diff changeset
3668 int col;
502
52e76e2b5b65 updated for version 7.0140
vimboss
parents: 499
diff changeset
3669 char_u *funcname;
52e76e2b5b65 updated for version 7.0140
vimboss
parents: 499
diff changeset
3670 pos_T pos;
52e76e2b5b65 updated for version 7.0140
vimboss
parents: 499
diff changeset
3671
523
a7ae7e043e43 updated for version 7.0146
vimboss
parents: 502
diff changeset
3672 /* Call 'completefunc' or 'omnifunc' and get pattern length as a
502
52e76e2b5b65 updated for version 7.0140
vimboss
parents: 499
diff changeset
3673 * string */
52e76e2b5b65 updated for version 7.0140
vimboss
parents: 499
diff changeset
3674 funcname = ctrl_x_mode == CTRL_X_FUNCTION
52e76e2b5b65 updated for version 7.0140
vimboss
parents: 499
diff changeset
3675 ? curbuf->b_p_cfu : curbuf->b_p_ofu;
52e76e2b5b65 updated for version 7.0140
vimboss
parents: 499
diff changeset
3676 if (*funcname == NUL)
523
a7ae7e043e43 updated for version 7.0146
vimboss
parents: 502
diff changeset
3677 {
a7ae7e043e43 updated for version 7.0146
vimboss
parents: 502
diff changeset
3678 EMSG2(_(e_notset), ctrl_x_mode == CTRL_X_FUNCTION
a7ae7e043e43 updated for version 7.0146
vimboss
parents: 502
diff changeset
3679 ? "completefunc" : "omnifunc");
12
bdeee1504ac1 updated for version 7.0004
vimboss
parents: 11
diff changeset
3680 return FAIL;
523
a7ae7e043e43 updated for version 7.0146
vimboss
parents: 502
diff changeset
3681 }
452
01af1008a8d8 updated for version 7.0120
vimboss
parents: 449
diff changeset
3682
01af1008a8d8 updated for version 7.0120
vimboss
parents: 449
diff changeset
3683 args[0] = (char_u *)"1";
502
52e76e2b5b65 updated for version 7.0140
vimboss
parents: 499
diff changeset
3684 args[1] = NULL;
52e76e2b5b65 updated for version 7.0140
vimboss
parents: 499
diff changeset
3685 pos = curwin->w_cursor;
52e76e2b5b65 updated for version 7.0140
vimboss
parents: 499
diff changeset
3686 col = call_func_retnr(funcname, 2, args, FALSE);
52e76e2b5b65 updated for version 7.0140
vimboss
parents: 499
diff changeset
3687 curwin->w_cursor = pos; /* restore the cursor position */
52e76e2b5b65 updated for version 7.0140
vimboss
parents: 499
diff changeset
3688
452
01af1008a8d8 updated for version 7.0120
vimboss
parents: 449
diff changeset
3689 if (col < 0)
523
a7ae7e043e43 updated for version 7.0146
vimboss
parents: 502
diff changeset
3690 col = curs_col;
452
01af1008a8d8 updated for version 7.0120
vimboss
parents: 449
diff changeset
3691 compl_col = col;
01af1008a8d8 updated for version 7.0120
vimboss
parents: 449
diff changeset
3692 if ((colnr_T)compl_col > curs_col)
01af1008a8d8 updated for version 7.0120
vimboss
parents: 449
diff changeset
3693 compl_col = curs_col;
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3694
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3695 /* Setup variables for completion. Need to obtain "line" again,
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3696 * it may have become invalid. */
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3697 line = ml_get(curwin->w_cursor.lnum);
452
01af1008a8d8 updated for version 7.0120
vimboss
parents: 449
diff changeset
3698 compl_length = curs_col - compl_col;
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3699 compl_pattern = vim_strnsave(line + compl_col, compl_length);
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3700 if (compl_pattern == NULL)
502
52e76e2b5b65 updated for version 7.0140
vimboss
parents: 499
diff changeset
3701 #endif
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3702 return FAIL;
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3703 }
477
f8b75b8f1988 updated for version 7.0128
vimboss
parents: 474
diff changeset
3704 else if (ctrl_x_mode == CTRL_X_SPELL)
f8b75b8f1988 updated for version 7.0128
vimboss
parents: 474
diff changeset
3705 {
f8b75b8f1988 updated for version 7.0128
vimboss
parents: 474
diff changeset
3706 #ifdef FEAT_SYN_HL
497
73f10d8124f4 updated for version 7.0136
vimboss
parents: 484
diff changeset
3707 if (spell_bad_len > 0)
73f10d8124f4 updated for version 7.0136
vimboss
parents: 484
diff changeset
3708 compl_col = curs_col - spell_bad_len;
73f10d8124f4 updated for version 7.0136
vimboss
parents: 484
diff changeset
3709 else
73f10d8124f4 updated for version 7.0136
vimboss
parents: 484
diff changeset
3710 compl_col = spell_word_start(startcol);
73f10d8124f4 updated for version 7.0136
vimboss
parents: 484
diff changeset
3711 if (compl_col >= (colnr_T)startcol)
477
f8b75b8f1988 updated for version 7.0128
vimboss
parents: 474
diff changeset
3712 return FAIL;
537
e321639cfa3e updated for version 7.0152
vimboss
parents: 532
diff changeset
3713 spell_expand_check_cap(compl_col);
477
f8b75b8f1988 updated for version 7.0128
vimboss
parents: 474
diff changeset
3714 compl_length = (int)curs_col - compl_col;
f8b75b8f1988 updated for version 7.0128
vimboss
parents: 474
diff changeset
3715 compl_pattern = vim_strnsave(line + compl_col, compl_length);
f8b75b8f1988 updated for version 7.0128
vimboss
parents: 474
diff changeset
3716 if (compl_pattern == NULL)
f8b75b8f1988 updated for version 7.0128
vimboss
parents: 474
diff changeset
3717 #endif
f8b75b8f1988 updated for version 7.0128
vimboss
parents: 474
diff changeset
3718 return FAIL;
f8b75b8f1988 updated for version 7.0128
vimboss
parents: 474
diff changeset
3719 }
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3720 else
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3721 {
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3722 EMSG2(_(e_intern2), "ins_complete()");
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3723 return FAIL;
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3724 }
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3725
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3726 if (compl_cont_status & CONT_ADDING)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3727 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3728 edit_submode_pre = (char_u *)_(" Adding");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3729 if (ctrl_x_mode == CTRL_X_WHOLE_LINE)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3730 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3731 /* Insert a new line, keep indentation but ignore 'comments' */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3732 #ifdef FEAT_COMMENTS
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3733 char_u *old = curbuf->b_p_com;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3734
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3735 curbuf->b_p_com = (char_u *)"";
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3736 #endif
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3737 compl_startpos.lnum = curwin->w_cursor.lnum;
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3738 compl_startpos.col = compl_col;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3739 ins_eol('\r');
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3740 #ifdef FEAT_COMMENTS
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3741 curbuf->b_p_com = old;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3742 #endif
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3743 compl_length = 0;
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3744 compl_col = curwin->w_cursor.col;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3745 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3746 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3747 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3748 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3749 edit_submode_pre = NULL;
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3750 compl_startpos.col = compl_col;
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3751 }
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3752
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3753 if (compl_cont_status & CONT_LOCAL)
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3754 edit_submode = (char_u *)_(ctrl_x_msgs[CTRL_X_LOCAL_MSG]);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3755 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3756 edit_submode = (char_u *)_(CTRL_X_MSG(ctrl_x_mode));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3757
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3758 /* Always add completion for the original text. Note that
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3759 * "compl_orig_text" itself (not a copy) is added, it will be freed
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3760 * when the list of matches is freed. */
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3761 compl_orig_text = vim_strnsave(line + compl_col, compl_length);
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3762 if (compl_orig_text == NULL || ins_compl_add(compl_orig_text,
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3763 -1, NULL, 0, ORIGINAL_TEXT) != OK)
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3764 {
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3765 vim_free(compl_pattern);
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3766 compl_pattern = NULL;
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3767 vim_free(compl_orig_text);
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3768 compl_orig_text = NULL;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3769 return FAIL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3770 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3771
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3772 /* showmode might reset the internal line pointers, so it must
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3773 * be called before line = ml_get(), or when this address is no
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3774 * longer needed. -- Acevedo.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3775 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3776 edit_submode_extra = (char_u *)_("-- Searching...");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3777 edit_submode_highl = HLF_COUNT;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3778 showmode();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3779 edit_submode_extra = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3780 out_flush();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3781 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3782
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3783 compl_shown_match = compl_curr_match;
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3784 compl_shows_dir = compl_direction;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3785
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3786 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3787 * Find next match.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3788 */
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3789 n = ins_compl_next(TRUE);
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3790
540
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
3791 /* may undisplay the popup menu */
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
3792 ins_compl_upd_pum();
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
3793
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3794 if (n > 1) /* all matches have been found */
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3795 compl_matches = n;
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3796 compl_curr_match = compl_shown_match;
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3797 compl_direction = compl_shows_dir;
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3798 compl_interrupted = FALSE;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3799
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3800 /* eat the ESC to avoid leaving insert mode */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3801 if (got_int && !global_busy)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3802 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3803 (void)vgetc();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3804 got_int = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3805 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3806
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3807 /* 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
3808 if (compl_first_match == compl_first_match->cp_next)
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3809 {
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3810 edit_submode_extra = (compl_cont_status & CONT_ADDING)
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3811 && compl_length > 1
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3812 ? (char_u *)_(e_hitend) : (char_u *)_(e_patnotf);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3813 edit_submode_highl = HLF_E;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3814 /* 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
3815 * because we couldn't expand anything at first place, but if we used
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3816 * ^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
3817 * (such as M in M'exico) if not tried already. -- Acevedo */
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3818 if ( compl_length > 1
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3819 || (compl_cont_status & CONT_ADDING)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3820 || (ctrl_x_mode != 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3821 && ctrl_x_mode != CTRL_X_PATH_PATTERNS
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3822 && ctrl_x_mode != CTRL_X_PATH_DEFINES))
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3823 compl_cont_status &= ~CONT_N_ADDS;
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3824 }
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3825
464
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
3826 if (compl_curr_match->cp_flags & CONT_S_IPOS)
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3827 compl_cont_status |= CONT_S_IPOS;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3828 else
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3829 compl_cont_status &= ~CONT_S_IPOS;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3830
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3831 if (edit_submode_extra == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3832 {
464
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
3833 if (compl_curr_match->cp_flags & ORIGINAL_TEXT)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3834 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3835 edit_submode_extra = (char_u *)_("Back at original");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3836 edit_submode_highl = HLF_W;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3837 }
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3838 else if (compl_cont_status & CONT_S_IPOS)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3839 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3840 edit_submode_extra = (char_u *)_("Word from other line");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3841 edit_submode_highl = HLF_COUNT;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3842 }
464
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
3843 else if (compl_curr_match->cp_next == compl_curr_match->cp_prev)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3844 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3845 edit_submode_extra = (char_u *)_("The only match");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3846 edit_submode_highl = HLF_COUNT;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3847 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3848 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3849 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3850 /* Update completion sequence number when needed. */
464
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
3851 if (compl_curr_match->cp_number == -1)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3852 {
464
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
3853 int number = 0;
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
3854 compl_T *match;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3855
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3856 if (compl_direction == FORWARD)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3857 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3858 /* search backwards for the first valid (!= -1) number.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3859 * This should normally succeed already at the first loop
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3860 * cycle, so it's fast! */
464
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
3861 for (match = compl_curr_match->cp_prev; match != NULL
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
3862 && match != compl_first_match;
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
3863 match = match->cp_prev)
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
3864 if (match->cp_number != -1)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3865 {
464
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
3866 number = match->cp_number;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3867 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3868 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3869 if (match != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3870 /* go up and assign all numbers which are not assigned
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3871 * yet */
540
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
3872 for (match = match->cp_next;
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
3873 match != NULL && match->cp_number == -1;
464
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
3874 match = match->cp_next)
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
3875 match->cp_number = ++number;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3876 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3877 else /* BACKWARD */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3878 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3879 /* search forwards (upwards) for the first valid (!= -1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3880 * number. This should normally succeed already at the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3881 * first loop cycle, so it's fast! */
464
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
3882 for (match = compl_curr_match->cp_next; match != NULL
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
3883 && match != compl_first_match;
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
3884 match = match->cp_next)
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
3885 if (match->cp_number != -1)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3886 {
464
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
3887 number = match->cp_number;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3888 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3889 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3890 if (match != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3891 /* go down and assign all numbers which are not
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3892 * assigned yet */
464
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
3893 for (match = match->cp_prev; match
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
3894 && match->cp_number == -1;
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
3895 match = match->cp_prev)
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
3896 match->cp_number = ++number;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3897 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3898 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3899
540
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
3900 /* The match should always have a sequence number now, this is
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
3901 * just a safety check. */
464
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
3902 if (compl_curr_match->cp_number != -1)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3903 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3904 /* Space for 10 text chars. + 2x10-digit no.s */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3905 static char_u match_ref[31];
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3906
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3907 if (compl_matches > 0)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3908 sprintf((char *)IObuff, _("match %d of %d"),
464
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
3909 compl_curr_match->cp_number, compl_matches);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3910 else
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
3911 sprintf((char *)IObuff, _("match %d"),
464
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
3912 compl_curr_match->cp_number);
419
f713fc55bf7b updated for version 7.0109
vimboss
parents: 408
diff changeset
3913 vim_strncpy(match_ref, IObuff, 30);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3914 edit_submode_extra = match_ref;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3915 edit_submode_highl = HLF_R;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3916 if (dollar_vcol)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3917 curs_columns(FALSE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3918 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3919 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3920 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3921
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3922 /* Show a message about what (completion) mode we're in. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3923 showmode();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3924 if (edit_submode_extra != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3925 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3926 if (!p_smd)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3927 msg_attr(edit_submode_extra,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3928 edit_submode_highl < HLF_COUNT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3929 ? hl_attr(edit_submode_highl) : 0);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3930 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3931 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3932 msg_clr_cmdline(); /* necessary for "noshowmode" */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3933
540
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
3934 ins_compl_show_pum();
2df7f3a5eb96 updated for version 7.0153
vimboss
parents: 537
diff changeset
3935
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3936 return OK;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3937 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3938
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3939 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3940 * Looks in the first "len" chars. of "src" for search-metachars.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3941 * If dest is not NULL the chars. are copied there quoting (with
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3942 * a backslash) the metachars, and dest would be NUL terminated.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3943 * Returns the length (needed) of dest
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3944 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3945 static int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3946 quote_meta(dest, src, len)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3947 char_u *dest;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3948 char_u *src;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3949 int len;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3950 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3951 int m;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3952
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3953 for (m = len; --len >= 0; src++)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3954 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3955 switch (*src)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3956 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3957 case '.':
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3958 case '*':
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3959 case '[':
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3960 if (ctrl_x_mode == CTRL_X_DICTIONARY
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3961 || ctrl_x_mode == CTRL_X_THESAURUS)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3962 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3963 case '~':
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3964 if (!p_magic) /* quote these only if magic is set */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3965 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3966 case '\\':
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3967 if (ctrl_x_mode == CTRL_X_DICTIONARY
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3968 || ctrl_x_mode == CTRL_X_THESAURUS)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3969 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3970 case '^': /* currently it's not needed. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3971 case '$':
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3972 m++;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3973 if (dest != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3974 *dest++ = '\\';
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3975 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3976 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3977 if (dest != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3978 *dest++ = *src;
464
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
3979 # ifdef FEAT_MBYTE
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3980 /* Copy remaining bytes of a multibyte character. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3981 if (has_mbyte)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3982 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3983 int i, mb_len;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3984
474
a5fcf36ef512 updated for version 7.0127
vimboss
parents: 470
diff changeset
3985 mb_len = (*mb_ptr2len)(src) - 1;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3986 if (mb_len > 0 && len >= mb_len)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3987 for (i = 0; i < mb_len; ++i)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3988 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3989 --len;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3990 ++src;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3991 if (dest != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3992 *dest++ = *src;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3993 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3994 }
464
3b705e71c7b0 updated for version 7.0124
vimboss
parents: 452
diff changeset
3995 # endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3996 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3997 if (dest != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3998 *dest = NUL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3999
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4000 return m;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4001 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4002 #endif /* FEAT_INS_EXPAND */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4003
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4004 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4005 * Next character is interpreted literally.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4006 * A one, two or three digit decimal number is interpreted as its byte value.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4007 * If one or two digits are entered, the next character is given to vungetc().
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4008 * For Unicode a character > 255 may be returned.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4009 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4010 int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4011 get_literal()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4012 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4013 int cc;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4014 int nc;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4015 int i;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4016 int hex = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4017 int octal = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4018 #ifdef FEAT_MBYTE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4019 int unicode = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4020 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4021
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4022 if (got_int)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4023 return Ctrl_C;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4024
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4025 #ifdef FEAT_GUI
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4026 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4027 * In GUI there is no point inserting the internal code for a special key.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4028 * It is more useful to insert the string "<KEY>" instead. This would
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4029 * probably be useful in a text window too, but it would not be
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4030 * vi-compatible (maybe there should be an option for it?) -- webb
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4031 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4032 if (gui.in_use)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4033 ++allow_keys;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4034 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4035 #ifdef USE_ON_FLY_SCROLL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4036 dont_scroll = TRUE; /* disallow scrolling here */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4037 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4038 ++no_mapping; /* don't map the next key hits */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4039 cc = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4040 i = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4041 for (;;)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4042 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4043 do
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4044 nc = safe_vgetc();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4045 while (nc == K_IGNORE || nc == K_VER_SCROLLBAR
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4046 || nc == K_HOR_SCROLLBAR);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4047 #ifdef FEAT_CMDL_INFO
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4048 if (!(State & CMDLINE)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4049 # ifdef FEAT_MBYTE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4050 && MB_BYTE2LEN_CHECK(nc) == 1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4051 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4052 )
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4053 add_to_showcmd(nc);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4054 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4055 if (nc == 'x' || nc == 'X')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4056 hex = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4057 else if (nc == 'o' || nc == 'O')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4058 octal = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4059 #ifdef FEAT_MBYTE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4060 else if (nc == 'u' || nc == 'U')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4061 unicode = nc;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4062 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4063 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4064 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4065 if (hex
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4066 #ifdef FEAT_MBYTE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4067 || unicode != 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4068 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4069 )
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4070 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4071 if (!vim_isxdigit(nc))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4072 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4073 cc = cc * 16 + hex2nr(nc);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4074 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4075 else if (octal)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4076 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4077 if (nc < '0' || nc > '7')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4078 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4079 cc = cc * 8 + nc - '0';
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4080 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4081 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4082 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4083 if (!VIM_ISDIGIT(nc))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4084 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4085 cc = cc * 10 + nc - '0';
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4086 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4087
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4088 ++i;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4089 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4090
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4091 if (cc > 255
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4092 #ifdef FEAT_MBYTE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4093 && unicode == 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4094 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4095 )
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4096 cc = 255; /* limit range to 0-255 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4097 nc = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4098
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4099 if (hex) /* hex: up to two chars */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4100 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4101 if (i >= 2)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4102 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4103 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4104 #ifdef FEAT_MBYTE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4105 else if (unicode) /* Unicode: up to four or eight chars */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4106 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4107 if ((unicode == 'u' && i >= 4) || (unicode == 'U' && i >= 8))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4108 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4109 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4110 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4111 else if (i >= 3) /* decimal or octal: up to three chars */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4112 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4113 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4114 if (i == 0) /* no number entered */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4115 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4116 if (nc == K_ZERO) /* NUL is stored as NL */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4117 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4118 cc = '\n';
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4119 nc = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4120 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4121 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4122 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4123 cc = nc;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4124 nc = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4125 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4126 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4127
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4128 if (cc == 0) /* NUL is stored as NL */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4129 cc = '\n';
221
7fd4b5df33be updated for version 7.0062
vimboss
parents: 180
diff changeset
4130 #ifdef FEAT_MBYTE
7fd4b5df33be updated for version 7.0062
vimboss
parents: 180
diff changeset
4131 if (enc_dbcs && (cc & 0xff) == 0)
7fd4b5df33be updated for version 7.0062
vimboss
parents: 180
diff changeset
4132 cc = '?'; /* don't accept an illegal DBCS char, the NUL in the
7fd4b5df33be updated for version 7.0062
vimboss
parents: 180
diff changeset
4133 second byte will cause trouble! */
7fd4b5df33be updated for version 7.0062
vimboss
parents: 180
diff changeset
4134 #endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4135
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4136 --no_mapping;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4137 #ifdef FEAT_GUI
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4138 if (gui.in_use)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4139 --allow_keys;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4140 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4141 if (nc)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4142 vungetc(nc);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4143 got_int = FALSE; /* CTRL-C typed after CTRL-V is not an interrupt */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4144 return cc;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4145 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4146
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4147 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4148 * Insert character, taking care of special keys and mod_mask
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4149 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4150 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4151 insert_special(c, allow_modmask, ctrlv)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4152 int c;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4153 int allow_modmask;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4154 int ctrlv; /* c was typed after CTRL-V */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4155 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4156 char_u *p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4157 int len;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4158
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4159 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4160 * Special function key, translate into "<Key>". Up to the last '>' is
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4161 * inserted with ins_str(), so as not to replace characters in replace
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4162 * mode.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4163 * Only use mod_mask for special keys, to avoid things like <S-Space>,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4164 * unless 'allow_modmask' is TRUE.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4165 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4166 #ifdef MACOS
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4167 /* Command-key never produces a normal key */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4168 if (mod_mask & MOD_MASK_CMD)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4169 allow_modmask = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4170 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4171 if (IS_SPECIAL(c) || (mod_mask && allow_modmask))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4172 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4173 p = get_special_key_name(c, mod_mask);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4174 len = (int)STRLEN(p);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4175 c = p[len - 1];
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4176 if (len > 2)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4177 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4178 if (stop_arrow() == FAIL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4179 return;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4180 p[len - 1] = NUL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4181 ins_str(p);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4182 AppendToRedobuffLit(p);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4183 ctrlv = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4184 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4185 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4186 if (stop_arrow() == OK)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4187 insertchar(c, ctrlv ? INSCHAR_CTRLV : 0, -1);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4188 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4189
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4190 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4191 * Special characters in this context are those that need processing other
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4192 * than the simple insertion that can be performed here. This includes ESC
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4193 * which terminates the insert, and CR/NL which need special processing to
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4194 * open up a new line. This routine tries to optimize insertions performed by
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4195 * the "redo", "undo" or "put" commands, so it needs to know when it should
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4196 * stop and defer processing to the "normal" mechanism.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4197 * '0' and '^' are special, because they can be followed by CTRL-D.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4198 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4199 #ifdef EBCDIC
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4200 # define ISSPECIAL(c) ((c) < ' ' || (c) == '0' || (c) == '^')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4201 #else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4202 # define ISSPECIAL(c) ((c) < ' ' || (c) >= DEL || (c) == '0' || (c) == '^')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4203 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4204
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4205 #ifdef FEAT_MBYTE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4206 # 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
4207 #else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4208 # define WHITECHAR(cc) vim_iswhite(cc)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4209 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4210
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4211 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4212 insertchar(c, flags, second_indent)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4213 int c; /* character to insert or NUL */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4214 int flags; /* INSCHAR_FORMAT, etc. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4215 int second_indent; /* indent for second line if >= 0 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4216 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4217 int haveto_redraw = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4218 int textwidth;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4219 #ifdef FEAT_COMMENTS
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4220 colnr_T leader_len;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4221 char_u *p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4222 int no_leader = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4223 int do_comments = (flags & INSCHAR_DO_COM);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4224 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4225 int fo_white_par;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4226 int first_line = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4227 int fo_ins_blank;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4228 #ifdef FEAT_MBYTE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4229 int fo_multibyte;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4230 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4231 int save_char = NUL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4232 int cc;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4233
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4234 textwidth = comp_textwidth(flags & INSCHAR_FORMAT);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4235 fo_ins_blank = has_format_option(FO_INS_BLANK);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4236 #ifdef FEAT_MBYTE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4237 fo_multibyte = has_format_option(FO_MBYTE_BREAK);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4238 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4239 fo_white_par = has_format_option(FO_WHITE_PAR);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4240
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4241 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4242 * Try to break the line in two or more pieces when:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4243 * - Always do this if we have been called to do formatting only.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4244 * - Always do this when 'formatoptions' has the 'a' flag and the line
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4245 * ends in white space.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4246 * - Otherwise:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4247 * - Don't do this if inserting a blank
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4248 * - Don't do this if an existing character is being replaced, unless
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4249 * we're in VREPLACE mode.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4250 * - Do this if the cursor is not on the line where insert started
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4251 * or - 'formatoptions' doesn't have 'l' or the line was not too long
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4252 * before the insert.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4253 * - 'formatoptions' doesn't have 'b' or a blank was inserted at or
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4254 * before 'textwidth'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4255 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4256 if (textwidth
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4257 && ((flags & INSCHAR_FORMAT)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4258 || (!vim_iswhite(c)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4259 && !((State & REPLACE_FLAG)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4260 #ifdef FEAT_VREPLACE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4261 && !(State & VREPLACE_FLAG)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4262 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4263 && *ml_get_cursor() != NUL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4264 && (curwin->w_cursor.lnum != Insstart.lnum
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4265 || ((!has_format_option(FO_INS_LONG)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4266 || Insstart_textlen <= (colnr_T)textwidth)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4267 && (!fo_ins_blank
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4268 || Insstart_blank_vcol <= (colnr_T)textwidth
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4269 ))))))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4270 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4271 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4272 * When 'ai' is off we don't want a space under the cursor to be
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4273 * deleted. Replace it with an 'x' temporarily.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4274 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4275 if (!curbuf->b_p_ai)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4276 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4277 cc = gchar_cursor();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4278 if (vim_iswhite(cc))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4279 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4280 save_char = cc;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4281 pchar_cursor('x');
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4282 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4283 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4284
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4285 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4286 * Repeat breaking lines, until the current line is not too long.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4287 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4288 while (!got_int)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4289 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4290 int startcol; /* Cursor column at entry */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4291 int wantcol; /* column at textwidth border */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4292 int foundcol; /* column for start of spaces */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4293 int end_foundcol = 0; /* column for start of word */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4294 colnr_T len;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4295 colnr_T virtcol;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4296 #ifdef FEAT_VREPLACE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4297 int orig_col = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4298 char_u *saved_text = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4299 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4300 colnr_T col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4301
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4302 virtcol = get_nolist_virtcol();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4303 if (virtcol < (colnr_T)textwidth)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4304 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4305
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4306 #ifdef FEAT_COMMENTS
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4307 if (no_leader)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4308 do_comments = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4309 else if (!(flags & INSCHAR_FORMAT)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4310 && has_format_option(FO_WRAP_COMS))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4311 do_comments = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4312
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4313 /* Don't break until after the comment leader */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4314 if (do_comments)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4315 leader_len = get_leader_len(ml_get_curline(), NULL, FALSE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4316 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4317 leader_len = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4318
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4319 /* If the line doesn't start with a comment leader, then don't
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4320 * start one in a following broken line. Avoids that a %word
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4321 * moved to the start of the next line causes all following lines
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4322 * to start with %. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4323 if (leader_len == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4324 no_leader = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4325 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4326 if (!(flags & INSCHAR_FORMAT)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4327 #ifdef FEAT_COMMENTS
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4328 && leader_len == 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4329 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4330 && !has_format_option(FO_WRAP))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4331
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4332 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4333 textwidth = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4334 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4335 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4336 if ((startcol = curwin->w_cursor.col) == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4337 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4338
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4339 /* find column of textwidth border */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4340 coladvance((colnr_T)textwidth);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4341 wantcol = curwin->w_cursor.col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4342
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4343 curwin->w_cursor.col = startcol - 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4344 #ifdef FEAT_MBYTE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4345 /* Correct cursor for multi-byte character. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4346 if (has_mbyte)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4347 mb_adjust_cursor();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4348 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4349 foundcol = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4350
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4351 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4352 * Find position to break at.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4353 * Stop at first entered white when 'formatoptions' has 'v'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4354 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4355 while ((!fo_ins_blank && !has_format_option(FO_INS_VI))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4356 || curwin->w_cursor.lnum != Insstart.lnum
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4357 || curwin->w_cursor.col >= Insstart.col)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4358 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4359 cc = gchar_cursor();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4360 if (WHITECHAR(cc))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4361 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4362 /* remember position of blank just before text */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4363 end_foundcol = curwin->w_cursor.col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4364
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4365 /* find start of sequence of blanks */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4366 while (curwin->w_cursor.col > 0 && WHITECHAR(cc))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4367 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4368 dec_cursor();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4369 cc = gchar_cursor();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4370 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4371 if (curwin->w_cursor.col == 0 && WHITECHAR(cc))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4372 break; /* only spaces in front of text */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4373 #ifdef FEAT_COMMENTS
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4374 /* Don't break until after the comment leader */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4375 if (curwin->w_cursor.col < leader_len)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4376 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4377 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4378 if (has_format_option(FO_ONE_LETTER))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4379 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4380 /* do not break after one-letter words */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4381 if (curwin->w_cursor.col == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4382 break; /* one-letter word at begin */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4383
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4384 col = curwin->w_cursor.col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4385 dec_cursor();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4386 cc = gchar_cursor();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4387
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4388 if (WHITECHAR(cc))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4389 continue; /* one-letter, continue */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4390 curwin->w_cursor.col = col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4391 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4392 #ifdef FEAT_MBYTE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4393 if (has_mbyte)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4394 foundcol = curwin->w_cursor.col
474
a5fcf36ef512 updated for version 7.0127
vimboss
parents: 470
diff changeset
4395 + (*mb_ptr2len)(ml_get_cursor());
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4396 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4397 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4398 foundcol = curwin->w_cursor.col + 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4399 if (curwin->w_cursor.col < (colnr_T)wantcol)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4400 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4401 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4402 #ifdef FEAT_MBYTE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4403 else if (cc >= 0x100 && fo_multibyte
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4404 && curwin->w_cursor.col <= (colnr_T)wantcol)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4405 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4406 /* Break after or before a multi-byte character. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4407 foundcol = curwin->w_cursor.col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4408 if (curwin->w_cursor.col < (colnr_T)wantcol)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4409 foundcol += (*mb_char2len)(cc);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4410 end_foundcol = foundcol;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4411 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4412 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4413 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4414 if (curwin->w_cursor.col == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4415 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4416 dec_cursor();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4417 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4418
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4419 if (foundcol == 0) /* no spaces, cannot break line */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4420 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4421 curwin->w_cursor.col = startcol;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4422 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4423 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4424
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4425 /* Going to break the line, remove any "$" now. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4426 undisplay_dollar();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4427
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4428 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4429 * Offset between cursor position and line break is used by replace
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4430 * stack functions. VREPLACE does not use this, and backspaces
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4431 * over the text instead.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4432 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4433 #ifdef FEAT_VREPLACE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4434 if (State & VREPLACE_FLAG)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4435 orig_col = startcol; /* Will start backspacing from here */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4436 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4437 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4438 replace_offset = startcol - end_foundcol - 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4439
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4440 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4441 * adjust startcol for spaces that will be deleted and
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4442 * characters that will remain on top line
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4443 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4444 curwin->w_cursor.col = foundcol;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4445 while (cc = gchar_cursor(), WHITECHAR(cc))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4446 inc_cursor();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4447 startcol -= curwin->w_cursor.col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4448 if (startcol < 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4449 startcol = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4450
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4451 #ifdef FEAT_VREPLACE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4452 if (State & VREPLACE_FLAG)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4453 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4454 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4455 * In VREPLACE mode, we will backspace over the text to be
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4456 * wrapped, so save a copy now to put on the next line.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4457 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4458 saved_text = vim_strsave(ml_get_cursor());
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4459 curwin->w_cursor.col = orig_col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4460 if (saved_text == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4461 break; /* Can't do it, out of memory */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4462 saved_text[startcol] = NUL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4463
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4464 /* Backspace over characters that will move to the next line */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4465 if (!fo_white_par)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4466 backspace_until_column(foundcol);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4467 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4468 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4469 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4470 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4471 /* put cursor after pos. to break line */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4472 if (!fo_white_par)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4473 curwin->w_cursor.col = foundcol;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4474 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4475
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4476 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4477 * Split the line just before the margin.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4478 * Only insert/delete lines, but don't really redraw the window.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4479 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4480 open_line(FORWARD, OPENLINE_DELSPACES + OPENLINE_MARKFIX
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4481 + (fo_white_par ? OPENLINE_KEEPTRAIL : 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4482 #ifdef FEAT_COMMENTS
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4483 + (do_comments ? OPENLINE_DO_COM : 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4484 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4485 , old_indent);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4486 old_indent = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4487
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4488 replace_offset = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4489 if (first_line)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4490 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4491 if (second_indent < 0 && has_format_option(FO_Q_NUMBER))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4492 second_indent = get_number_indent(curwin->w_cursor.lnum -1);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4493 if (second_indent >= 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4494 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4495 #ifdef FEAT_VREPLACE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4496 if (State & VREPLACE_FLAG)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4497 change_indent(INDENT_SET, second_indent, FALSE, NUL);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4498 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4499 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4500 (void)set_indent(second_indent, SIN_CHANGED);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4501 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4502 first_line = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4503 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4504
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4505 #ifdef FEAT_VREPLACE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4506 if (State & VREPLACE_FLAG)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4507 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4508 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4509 * In VREPLACE mode we have backspaced over the text to be
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4510 * moved, now we re-insert it into the new line.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4511 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4512 ins_bytes(saved_text);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4513 vim_free(saved_text);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4514 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4515 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4516 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4517 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4518 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4519 * Check if cursor is not past the NUL off the line, cindent
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4520 * may have added or removed indent.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4521 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4522 curwin->w_cursor.col += startcol;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4523 len = (colnr_T)STRLEN(ml_get_curline());
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4524 if (curwin->w_cursor.col > len)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4525 curwin->w_cursor.col = len;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4526 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4527
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4528 haveto_redraw = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4529 #ifdef FEAT_CINDENT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4530 can_cindent = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4531 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4532 /* moved the cursor, don't autoindent or cindent now */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4533 did_ai = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4534 #ifdef FEAT_SMARTINDENT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4535 did_si = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4536 can_si = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4537 can_si_back = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4538 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4539 line_breakcheck();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4540 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4541
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4542 if (save_char) /* put back space after cursor */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4543 pchar_cursor(save_char);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4544
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4545 if (c == NUL) /* formatting only */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4546 return;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4547 if (haveto_redraw)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4548 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4549 update_topline();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4550 redraw_curbuf_later(VALID);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4551 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4552 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4553 if (c == NUL) /* only formatting was wanted */
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 #ifdef FEAT_COMMENTS
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4557 /* Check whether this character should end a comment. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4558 if (did_ai && (int)c == end_comment_pending)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4559 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4560 char_u *line;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4561 char_u lead_end[COM_MAX_LEN]; /* end-comment string */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4562 int middle_len, end_len;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4563 int i;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4564
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4565 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4566 * Need to remove existing (middle) comment leader and insert end
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4567 * comment leader. First, check what comment leader we can find.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4568 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4569 i = get_leader_len(line = ml_get_curline(), &p, FALSE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4570 if (i > 0 && vim_strchr(p, COM_MIDDLE) != NULL) /* Just checking */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4571 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4572 /* Skip middle-comment string */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4573 while (*p && p[-1] != ':') /* find end of middle flags */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4574 ++p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4575 middle_len = copy_option_part(&p, lead_end, COM_MAX_LEN, ",");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4576 /* Don't count trailing white space for middle_len */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4577 while (middle_len > 0 && vim_iswhite(lead_end[middle_len - 1]))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4578 --middle_len;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4579
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4580 /* Find the end-comment string */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4581 while (*p && p[-1] != ':') /* find end of end flags */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4582 ++p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4583 end_len = copy_option_part(&p, lead_end, COM_MAX_LEN, ",");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4584
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4585 /* Skip white space before the cursor */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4586 i = curwin->w_cursor.col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4587 while (--i >= 0 && vim_iswhite(line[i]))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4588 ;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4589 i++;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4590
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4591 /* Skip to before the middle leader */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4592 i -= middle_len;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4593
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4594 /* Check some expected things before we go on */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4595 if (i >= 0 && lead_end[end_len - 1] == end_comment_pending)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4596 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4597 /* Backspace over all the stuff we want to replace */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4598 backspace_until_column(i);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4599
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4600 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4601 * Insert the end-comment string, except for the last
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4602 * character, which will get inserted as normal later.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4603 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4604 ins_bytes_len(lead_end, end_len - 1);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4605 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4606 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4607 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4608 end_comment_pending = NUL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4609 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4610
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4611 did_ai = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4612 #ifdef FEAT_SMARTINDENT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4613 did_si = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4614 can_si = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4615 can_si_back = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4616 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4617
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4618 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4619 * If there's any pending input, grab up to INPUT_BUFLEN at once.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4620 * This speeds up normal text input considerably.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4621 * Don't do this when 'cindent' or 'indentexpr' is set, because we might
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4622 * need to re-indent at a ':', or any other character (but not what
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4623 * 'paste' is set)..
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4624 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4625 #ifdef USE_ON_FLY_SCROLL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4626 dont_scroll = FALSE; /* allow scrolling here */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4627 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4628
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4629 if ( !ISSPECIAL(c)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4630 #ifdef FEAT_MBYTE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4631 && (!has_mbyte || (*mb_char2len)(c) == 1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4632 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4633 && vpeekc() != NUL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4634 && !(State & REPLACE_FLAG)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4635 #ifdef FEAT_CINDENT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4636 && !cindent_on()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4637 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4638 #ifdef FEAT_RIGHTLEFT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4639 && !p_ri
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4640 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4641 )
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4642 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4643 #define INPUT_BUFLEN 100
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4644 char_u buf[INPUT_BUFLEN + 1];
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4645 int i;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4646 colnr_T virtcol = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4647
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4648 buf[0] = c;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4649 i = 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4650 if (textwidth)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4651 virtcol = get_nolist_virtcol();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4652 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4653 * Stop the string when:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4654 * - no more chars available
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4655 * - finding a special character (command key)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4656 * - buffer is full
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4657 * - running into the 'textwidth' boundary
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4658 * - need to check for abbreviation: A non-word char after a word-char
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4659 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4660 while ( (c = vpeekc()) != NUL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4661 && !ISSPECIAL(c)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4662 #ifdef FEAT_MBYTE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4663 && (!has_mbyte || MB_BYTE2LEN_CHECK(c) == 1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4664 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4665 && i < INPUT_BUFLEN
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4666 && (textwidth == 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4667 || (virtcol += byte2cells(buf[i - 1])) < (colnr_T)textwidth)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4668 && !(!no_abbr && !vim_iswordc(c) && vim_iswordc(buf[i - 1])))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4669 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4670 #ifdef FEAT_RIGHTLEFT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4671 c = vgetc();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4672 if (p_hkmap && KeyTyped)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4673 c = hkmap(c); /* Hebrew mode mapping */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4674 # ifdef FEAT_FKMAP
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4675 if (p_fkmap && KeyTyped)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4676 c = fkmap(c); /* Farsi mode mapping */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4677 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4678 buf[i++] = c;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4679 #else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4680 buf[i++] = vgetc();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4681 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4682 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4683
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4684 #ifdef FEAT_DIGRAPHS
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4685 do_digraph(-1); /* clear digraphs */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4686 do_digraph(buf[i-1]); /* may be the start of a digraph */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4687 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4688 buf[i] = NUL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4689 ins_str(buf);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4690 if (flags & INSCHAR_CTRLV)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4691 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4692 redo_literal(*buf);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4693 i = 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4694 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4695 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4696 i = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4697 if (buf[i] != NUL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4698 AppendToRedobuffLit(buf + i);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4699 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4700 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4701 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4702 #ifdef FEAT_MBYTE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4703 if (has_mbyte && (cc = (*mb_char2len)(c)) > 1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4704 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4705 char_u buf[MB_MAXBYTES + 1];
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4706
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4707 (*mb_char2bytes)(c, buf);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4708 buf[cc] = NUL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4709 ins_char_bytes(buf, cc);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4710 AppendCharToRedobuff(c);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4711 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4712 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4713 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4714 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4715 ins_char(c);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4716 if (flags & INSCHAR_CTRLV)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4717 redo_literal(c);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4718 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4719 AppendCharToRedobuff(c);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4720 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4721 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4722 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4723
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4724 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4725 * Called after inserting or deleting text: When 'formatoptions' includes the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4726 * 'a' flag format from the current line until the end of the paragraph.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4727 * Keep the cursor at the same position relative to the text.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4728 * The caller must have saved the cursor line for undo, following ones will be
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4729 * saved here.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4730 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4731 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4732 auto_format(trailblank, prev_line)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4733 int trailblank; /* when TRUE also format with trailing blank */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4734 int prev_line; /* may start in previous line */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4735 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4736 pos_T pos;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4737 colnr_T len;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4738 char_u *old;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4739 char_u *new, *pnew;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4740 int wasatend;
301
006e9c8a6a8a updated for version 7.0079
vimboss
parents: 298
diff changeset
4741 int cc;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4742
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4743 if (!has_format_option(FO_AUTO))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4744 return;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4745
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4746 pos = curwin->w_cursor;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4747 old = ml_get_curline();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4748
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4749 /* may remove added space */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4750 check_auto_format(FALSE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4751
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4752 /* 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
4753 * user might insert normal text next. Also skip formatting when "1" is
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4754 * in 'formatoptions' and there is a single character before the cursor.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4755 * Otherwise the line would be broken and when typing another non-white
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4756 * next they are not joined back together. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4757 wasatend = (pos.col == STRLEN(old));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4758 if (*old != NUL && !trailblank && wasatend)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4759 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4760 dec_cursor();
301
006e9c8a6a8a updated for version 7.0079
vimboss
parents: 298
diff changeset
4761 cc = gchar_cursor();
006e9c8a6a8a updated for version 7.0079
vimboss
parents: 298
diff changeset
4762 if (!WHITECHAR(cc) && curwin->w_cursor.col > 0
006e9c8a6a8a updated for version 7.0079
vimboss
parents: 298
diff changeset
4763 && has_format_option(FO_ONE_LETTER))
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4764 dec_cursor();
301
006e9c8a6a8a updated for version 7.0079
vimboss
parents: 298
diff changeset
4765 cc = gchar_cursor();
006e9c8a6a8a updated for version 7.0079
vimboss
parents: 298
diff changeset
4766 if (WHITECHAR(cc))
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4767 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4768 curwin->w_cursor = pos;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4769 return;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4770 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4771 curwin->w_cursor = pos;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4772 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4773
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4774 #ifdef FEAT_COMMENTS
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4775 /* With the 'c' flag in 'formatoptions' and 't' missing: only format
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4776 * comments. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4777 if (has_format_option(FO_WRAP_COMS) && !has_format_option(FO_WRAP)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4778 && get_leader_len(old, NULL, FALSE) == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4779 return;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4780 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4781
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4782 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4783 * May start formatting in a previous line, so that after "x" a word is
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4784 * 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
4785 * the start of a paragraph.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4786 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4787 if (prev_line && !paragraph_start(curwin->w_cursor.lnum))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4788 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4789 --curwin->w_cursor.lnum;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4790 if (u_save_cursor() == FAIL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4791 return;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4792 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4793
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4794 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4795 * Do the formatting and restore the cursor position. "saved_cursor" will
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4796 * be adjusted for the text formatting.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4797 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4798 saved_cursor = pos;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4799 format_lines((linenr_T)-1);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4800 curwin->w_cursor = saved_cursor;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4801 saved_cursor.lnum = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4802
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4803 if (curwin->w_cursor.lnum > curbuf->b_ml.ml_line_count)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4804 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4805 /* "cannot happen" */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4806 curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4807 coladvance((colnr_T)MAXCOL);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4808 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4809 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4810 check_cursor_col();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4811
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4812 /* 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
4813 * previously wasn't, the line was broken. Because of the rule above we
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4814 * need to add a space when 'w' is in 'formatoptions' to keep a paragraph
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4815 * formatted. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4816 if (!wasatend && has_format_option(FO_WHITE_PAR))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4817 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4818 new = ml_get_curline();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4819 len = STRLEN(new);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4820 if (curwin->w_cursor.col == len)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4821 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4822 pnew = vim_strnsave(new, len + 2);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4823 pnew[len] = ' ';
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4824 pnew[len + 1] = NUL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4825 ml_replace(curwin->w_cursor.lnum, pnew, FALSE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4826 /* remove the space later */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4827 did_add_space = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4828 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4829 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4830 /* may remove added space */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4831 check_auto_format(FALSE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4832 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4833
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4834 check_cursor();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4835 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4836
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4837 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4838 * When an extra space was added to continue a paragraph for auto-formatting,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4839 * delete it now. The space must be under the cursor, just after the insert
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4840 * position.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4841 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4842 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4843 check_auto_format(end_insert)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4844 int end_insert; /* TRUE when ending Insert mode */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4845 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4846 int c = ' ';
301
006e9c8a6a8a updated for version 7.0079
vimboss
parents: 298
diff changeset
4847 int cc;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4848
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4849 if (did_add_space)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4850 {
301
006e9c8a6a8a updated for version 7.0079
vimboss
parents: 298
diff changeset
4851 cc = gchar_cursor();
006e9c8a6a8a updated for version 7.0079
vimboss
parents: 298
diff changeset
4852 if (!WHITECHAR(cc))
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4853 /* Somehow the space was removed already. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4854 did_add_space = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4855 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4856 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4857 if (!end_insert)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4858 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4859 inc_cursor();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4860 c = gchar_cursor();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4861 dec_cursor();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4862 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4863 if (c != NUL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4864 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4865 /* The space is no longer at the end of the line, delete it. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4866 del_char(FALSE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4867 did_add_space = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4868 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4869 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4870 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4871 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4872
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4873 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4874 * Find out textwidth to be used for formatting:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4875 * if 'textwidth' option is set, use it
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4876 * else if 'wrapmargin' option is set, use W_WIDTH(curwin) - 'wrapmargin'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4877 * if invalid value, use 0.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4878 * Set default to window width (maximum 79) for "gq" operator.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4879 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4880 int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4881 comp_textwidth(ff)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4882 int ff; /* force formatting (for "Q" command) */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4883 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4884 int textwidth;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4885
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4886 textwidth = curbuf->b_p_tw;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4887 if (textwidth == 0 && curbuf->b_p_wm)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4888 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4889 /* The width is the window width minus 'wrapmargin' minus all the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4890 * things that add to the margin. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4891 textwidth = W_WIDTH(curwin) - curbuf->b_p_wm;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4892 #ifdef FEAT_CMDWIN
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4893 if (cmdwin_type != 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4894 textwidth -= 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4895 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4896 #ifdef FEAT_FOLDING
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4897 textwidth -= curwin->w_p_fdc;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4898 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4899 #ifdef FEAT_SIGNS
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4900 if (curwin->w_buffer->b_signlist != NULL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4901 # ifdef FEAT_NETBEANS_INTG
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4902 || usingNetbeans
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4903 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4904 )
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4905 textwidth -= 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4906 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4907 if (curwin->w_p_nu)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4908 textwidth -= 8;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4909 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4910 if (textwidth < 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4911 textwidth = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4912 if (ff && textwidth == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4913 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4914 textwidth = W_WIDTH(curwin) - 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4915 if (textwidth > 79)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4916 textwidth = 79;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4917 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4918 return textwidth;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4919 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4920
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4921 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4922 * Put a character in the redo buffer, for when just after a CTRL-V.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4923 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4924 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4925 redo_literal(c)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4926 int c;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4927 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4928 char_u buf[10];
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4929
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4930 /* Only digits need special treatment. Translate them into a string of
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4931 * three digits. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4932 if (VIM_ISDIGIT(c))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4933 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4934 sprintf((char *)buf, "%03d", c);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4935 AppendToRedobuff(buf);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4936 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4937 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4938 AppendCharToRedobuff(c);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4939 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4940
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4941 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4942 * 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
4943 * For undo/redo it resembles hitting the <ESC> key.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4944 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4945 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4946 start_arrow(end_insert_pos)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4947 pos_T *end_insert_pos;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4948 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4949 if (!arrow_used) /* something has been inserted */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4950 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4951 AppendToRedobuff(ESC_STR);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4952 stop_insert(end_insert_pos, FALSE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4953 arrow_used = TRUE; /* this means we stopped the current insert */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4954 }
221
7fd4b5df33be updated for version 7.0062
vimboss
parents: 180
diff changeset
4955 #ifdef FEAT_SYN_HL
7fd4b5df33be updated for version 7.0062
vimboss
parents: 180
diff changeset
4956 check_spell_redraw();
7fd4b5df33be updated for version 7.0062
vimboss
parents: 180
diff changeset
4957 #endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4958 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4959
221
7fd4b5df33be updated for version 7.0062
vimboss
parents: 180
diff changeset
4960 #ifdef FEAT_SYN_HL
7fd4b5df33be updated for version 7.0062
vimboss
parents: 180
diff changeset
4961 /*
7fd4b5df33be updated for version 7.0062
vimboss
parents: 180
diff changeset
4962 * If we skipped highlighting word at cursor, do it now.
7fd4b5df33be updated for version 7.0062
vimboss
parents: 180
diff changeset
4963 * It may be skipped again, thus reset spell_redraw_lnum first.
7fd4b5df33be updated for version 7.0062
vimboss
parents: 180
diff changeset
4964 */
7fd4b5df33be updated for version 7.0062
vimboss
parents: 180
diff changeset
4965 static void
7fd4b5df33be updated for version 7.0062
vimboss
parents: 180
diff changeset
4966 check_spell_redraw()
7fd4b5df33be updated for version 7.0062
vimboss
parents: 180
diff changeset
4967 {
7fd4b5df33be updated for version 7.0062
vimboss
parents: 180
diff changeset
4968 if (spell_redraw_lnum != 0)
7fd4b5df33be updated for version 7.0062
vimboss
parents: 180
diff changeset
4969 {
7fd4b5df33be updated for version 7.0062
vimboss
parents: 180
diff changeset
4970 linenr_T lnum = spell_redraw_lnum;
7fd4b5df33be updated for version 7.0062
vimboss
parents: 180
diff changeset
4971
7fd4b5df33be updated for version 7.0062
vimboss
parents: 180
diff changeset
4972 spell_redraw_lnum = 0;
7fd4b5df33be updated for version 7.0062
vimboss
parents: 180
diff changeset
4973 redrawWinline(lnum, FALSE);
7fd4b5df33be updated for version 7.0062
vimboss
parents: 180
diff changeset
4974 }
7fd4b5df33be updated for version 7.0062
vimboss
parents: 180
diff changeset
4975 }
484
f012c4ed8c38 updated for version 7.0132
vimboss
parents: 477
diff changeset
4976
f012c4ed8c38 updated for version 7.0132
vimboss
parents: 477
diff changeset
4977 /*
f012c4ed8c38 updated for version 7.0132
vimboss
parents: 477
diff changeset
4978 * Called when starting CTRL_X_SPELL mode: Move backwards to a previous badly
f012c4ed8c38 updated for version 7.0132
vimboss
parents: 477
diff changeset
4979 * spelled word, if there is one.
f012c4ed8c38 updated for version 7.0132
vimboss
parents: 477
diff changeset
4980 */
f012c4ed8c38 updated for version 7.0132
vimboss
parents: 477
diff changeset
4981 static void
f012c4ed8c38 updated for version 7.0132
vimboss
parents: 477
diff changeset
4982 spell_back_to_badword()
f012c4ed8c38 updated for version 7.0132
vimboss
parents: 477
diff changeset
4983 {
f012c4ed8c38 updated for version 7.0132
vimboss
parents: 477
diff changeset
4984 pos_T tpos = curwin->w_cursor;
f012c4ed8c38 updated for version 7.0132
vimboss
parents: 477
diff changeset
4985
499
08012a1ff8d4 updated for version 7.0137
vimboss
parents: 497
diff changeset
4986 spell_bad_len = spell_move_to(curwin, BACKWARD, TRUE, TRUE, NULL);
484
f012c4ed8c38 updated for version 7.0132
vimboss
parents: 477
diff changeset
4987 if (curwin->w_cursor.col != tpos.col)
f012c4ed8c38 updated for version 7.0132
vimboss
parents: 477
diff changeset
4988 start_arrow(&tpos);
f012c4ed8c38 updated for version 7.0132
vimboss
parents: 477
diff changeset
4989 }
221
7fd4b5df33be updated for version 7.0062
vimboss
parents: 180
diff changeset
4990 #endif
7fd4b5df33be updated for version 7.0062
vimboss
parents: 180
diff changeset
4991
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4992 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4993 * stop_arrow() is called before a change is made in insert mode.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4994 * If an arrow key has been used, start a new insertion.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4995 * Returns FAIL if undo is impossible, shouldn't insert then.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4996 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4997 int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4998 stop_arrow()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4999 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5000 if (arrow_used)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5001 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5002 if (u_save_cursor() == OK)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5003 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5004 arrow_used = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5005 ins_need_undo = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5006 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5007 Insstart = curwin->w_cursor; /* new insertion starts here */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5008 Insstart_textlen = linetabsize(ml_get_curline());
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5009 ai_col = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5010 #ifdef FEAT_VREPLACE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5011 if (State & VREPLACE_FLAG)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5012 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5013 orig_line_count = curbuf->b_ml.ml_line_count;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5014 vr_lines_changed = 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5015 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5016 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5017 ResetRedobuff();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5018 AppendToRedobuff((char_u *)"1i"); /* pretend we start an insertion */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5019 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5020 else if (ins_need_undo)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5021 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5022 if (u_save_cursor() == OK)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5023 ins_need_undo = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5024 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5025
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5026 #ifdef FEAT_FOLDING
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5027 /* Always open fold at the cursor line when inserting something. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5028 foldOpenCursor();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5029 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5030
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5031 return (arrow_used || ins_need_undo ? FAIL : OK);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5032 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5033
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5034 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5035 * do a few things to stop inserting
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5036 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5037 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5038 stop_insert(end_insert_pos, esc)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5039 pos_T *end_insert_pos; /* where insert ended */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5040 int esc; /* called by ins_esc() */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5041 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5042 int cc;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5043
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5044 stop_redo_ins();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5045 replace_flush(); /* abandon replace stack */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5046
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5047 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5048 * save the inserted text for later redo with ^@
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5049 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5050 vim_free(last_insert);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5051 last_insert = get_inserted();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5052 last_insert_skip = new_insert_skip;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5053
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5054 if (!arrow_used)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5055 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5056 /* Auto-format now. It may seem strange to do this when stopping an
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5057 * insertion (or moving the cursor), but it's required when appending
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5058 * 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
5059 * was actually inserted, otherwise undo won't work. */
10
4e2284e71352 updated for version 7.0002
vimboss
parents: 7
diff changeset
5060 if (!ins_need_undo && has_format_option(FO_AUTO))
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5061 {
10
4e2284e71352 updated for version 7.0002
vimboss
parents: 7
diff changeset
5062 pos_T tpos = curwin->w_cursor;
4e2284e71352 updated for version 7.0002
vimboss
parents: 7
diff changeset
5063
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5064 /* When the cursor is at the end of the line after a space the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5065 * formatting will move it to the following word. Avoid that by
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5066 * moving the cursor onto the space. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5067 cc = 'x';
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5068 if (curwin->w_cursor.col > 0 && gchar_cursor() == NUL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5069 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5070 dec_cursor();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5071 cc = gchar_cursor();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5072 if (!vim_iswhite(cc))
10
4e2284e71352 updated for version 7.0002
vimboss
parents: 7
diff changeset
5073 curwin->w_cursor = tpos;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5074 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5075
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5076 auto_format(TRUE, FALSE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5077
10
4e2284e71352 updated for version 7.0002
vimboss
parents: 7
diff changeset
5078 if (vim_iswhite(cc))
4e2284e71352 updated for version 7.0002
vimboss
parents: 7
diff changeset
5079 {
4e2284e71352 updated for version 7.0002
vimboss
parents: 7
diff changeset
5080 if (gchar_cursor() != NUL)
4e2284e71352 updated for version 7.0002
vimboss
parents: 7
diff changeset
5081 inc_cursor();
4e2284e71352 updated for version 7.0002
vimboss
parents: 7
diff changeset
5082 #ifdef FEAT_VIRTUALEDIT
4e2284e71352 updated for version 7.0002
vimboss
parents: 7
diff changeset
5083 /* If the cursor is still at the same character, also keep
4e2284e71352 updated for version 7.0002
vimboss
parents: 7
diff changeset
5084 * the "coladd". */
4e2284e71352 updated for version 7.0002
vimboss
parents: 7
diff changeset
5085 if (gchar_cursor() == NUL
4e2284e71352 updated for version 7.0002
vimboss
parents: 7
diff changeset
5086 && curwin->w_cursor.lnum == tpos.lnum
4e2284e71352 updated for version 7.0002
vimboss
parents: 7
diff changeset
5087 && curwin->w_cursor.col == tpos.col)
4e2284e71352 updated for version 7.0002
vimboss
parents: 7
diff changeset
5088 curwin->w_cursor.coladd = tpos.coladd;
4e2284e71352 updated for version 7.0002
vimboss
parents: 7
diff changeset
5089 #endif
4e2284e71352 updated for version 7.0002
vimboss
parents: 7
diff changeset
5090 }
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5091 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5092
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5093 /* If a space was inserted for auto-formatting, remove it now. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5094 check_auto_format(TRUE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5095
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5096 /* 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
5097 * of the line, and put the cursor back.
4e2284e71352 updated for version 7.0002
vimboss
parents: 7
diff changeset
5098 * Do this when ESC was used or moving the cursor up/down. */
4e2284e71352 updated for version 7.0002
vimboss
parents: 7
diff changeset
5099 if (did_ai && (esc || (vim_strchr(p_cpo, CPO_INDENT) == NULL
4e2284e71352 updated for version 7.0002
vimboss
parents: 7
diff changeset
5100 && curwin->w_cursor.lnum != end_insert_pos->lnum)))
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5101 {
10
4e2284e71352 updated for version 7.0002
vimboss
parents: 7
diff changeset
5102 pos_T tpos = curwin->w_cursor;
4e2284e71352 updated for version 7.0002
vimboss
parents: 7
diff changeset
5103
4e2284e71352 updated for version 7.0002
vimboss
parents: 7
diff changeset
5104 curwin->w_cursor = *end_insert_pos;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5105 if (gchar_cursor() == NUL && curwin->w_cursor.col > 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5106 --curwin->w_cursor.col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5107 while (cc = gchar_cursor(), vim_iswhite(cc))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5108 (void)del_char(TRUE);
10
4e2284e71352 updated for version 7.0002
vimboss
parents: 7
diff changeset
5109 if (curwin->w_cursor.lnum != tpos.lnum)
4e2284e71352 updated for version 7.0002
vimboss
parents: 7
diff changeset
5110 curwin->w_cursor = tpos;
4e2284e71352 updated for version 7.0002
vimboss
parents: 7
diff changeset
5111 else if (cc != NUL)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5112 ++curwin->w_cursor.col; /* put cursor back on the NUL */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5113
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5114 #ifdef FEAT_VISUAL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5115 /* <C-S-Right> may have started Visual mode, adjust the position for
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5116 * deleted characters. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5117 if (VIsual_active && VIsual.lnum == curwin->w_cursor.lnum)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5118 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5119 cc = STRLEN(ml_get_curline());
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5120 if (VIsual.col > (colnr_T)cc)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5121 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5122 VIsual.col = cc;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5123 # ifdef FEAT_VIRTUALEDIT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5124 VIsual.coladd = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5125 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5126 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5127 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5128 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5129 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5130 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5131 did_ai = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5132 #ifdef FEAT_SMARTINDENT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5133 did_si = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5134 can_si = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5135 can_si_back = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5136 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5137
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5138 /* set '[ and '] to the inserted text */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5139 curbuf->b_op_start = Insstart;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5140 curbuf->b_op_end = *end_insert_pos;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5141 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5142
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5143 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5144 * Set the last inserted text to a single character.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5145 * Used for the replace command.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5146 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5147 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5148 set_last_insert(c)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5149 int c;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5150 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5151 char_u *s;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5152
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5153 vim_free(last_insert);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5154 #ifdef FEAT_MBYTE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5155 last_insert = alloc(MB_MAXBYTES * 3 + 5);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5156 #else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5157 last_insert = alloc(6);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5158 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5159 if (last_insert != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5160 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5161 s = last_insert;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5162 /* Use the CTRL-V only when entering a special char */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5163 if (c < ' ' || c == DEL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5164 *s++ = Ctrl_V;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5165 s = add_char2buf(c, s);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5166 *s++ = ESC;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5167 *s++ = NUL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5168 last_insert_skip = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5169 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5170 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5171
359
6c62b9b939bd updated for version 7.0093
vimboss
parents: 301
diff changeset
5172 #if defined(EXITFREE) || defined(PROTO)
6c62b9b939bd updated for version 7.0093
vimboss
parents: 301
diff changeset
5173 void
6c62b9b939bd updated for version 7.0093
vimboss
parents: 301
diff changeset
5174 free_last_insert()
6c62b9b939bd updated for version 7.0093
vimboss
parents: 301
diff changeset
5175 {
6c62b9b939bd updated for version 7.0093
vimboss
parents: 301
diff changeset
5176 vim_free(last_insert);
6c62b9b939bd updated for version 7.0093
vimboss
parents: 301
diff changeset
5177 last_insert = NULL;
6c62b9b939bd updated for version 7.0093
vimboss
parents: 301
diff changeset
5178 }
6c62b9b939bd updated for version 7.0093
vimboss
parents: 301
diff changeset
5179 #endif
6c62b9b939bd updated for version 7.0093
vimboss
parents: 301
diff changeset
5180
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5181 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5182 * Add character "c" to buffer "s". Escape the special meaning of K_SPECIAL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5183 * and CSI. Handle multi-byte characters.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5184 * Returns a pointer to after the added bytes.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5185 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5186 char_u *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5187 add_char2buf(c, s)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5188 int c;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5189 char_u *s;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5190 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5191 #ifdef FEAT_MBYTE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5192 char_u temp[MB_MAXBYTES];
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5193 int i;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5194 int len;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5195
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5196 len = (*mb_char2bytes)(c, temp);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5197 for (i = 0; i < len; ++i)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5198 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5199 c = temp[i];
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5200 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5201 /* Need to escape K_SPECIAL and CSI like in the typeahead buffer. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5202 if (c == K_SPECIAL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5203 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5204 *s++ = K_SPECIAL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5205 *s++ = KS_SPECIAL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5206 *s++ = KE_FILLER;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5207 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5208 #ifdef FEAT_GUI
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5209 else if (c == CSI)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5210 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5211 *s++ = CSI;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5212 *s++ = KS_EXTRA;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5213 *s++ = (int)KE_CSI;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5214 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5215 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5216 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5217 *s++ = c;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5218 #ifdef FEAT_MBYTE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5219 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5220 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5221 return s;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5222 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5223
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5224 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5225 * move cursor to start of line
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5226 * if flags & BL_WHITE move to first non-white
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5227 * if flags & BL_SOL move to first non-white if startofline is set,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5228 * otherwise keep "curswant" column
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5229 * if flags & BL_FIX don't leave the cursor on a NUL.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5230 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5231 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5232 beginline(flags)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5233 int flags;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5234 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5235 if ((flags & BL_SOL) && !p_sol)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5236 coladvance(curwin->w_curswant);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5237 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5238 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5239 curwin->w_cursor.col = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5240 #ifdef FEAT_VIRTUALEDIT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5241 curwin->w_cursor.coladd = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5242 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5243
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5244 if (flags & (BL_WHITE | BL_SOL))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5245 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5246 char_u *ptr;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5247
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5248 for (ptr = ml_get_curline(); vim_iswhite(*ptr)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5249 && !((flags & BL_FIX) && ptr[1] == NUL); ++ptr)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5250 ++curwin->w_cursor.col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5251 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5252 curwin->w_set_curswant = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5253 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5254 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5255
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5256 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5257 * oneright oneleft cursor_down cursor_up
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5258 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5259 * Move one char {right,left,down,up}.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5260 * Doesn't move onto the NUL past the end of the line.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5261 * Return OK when successful, FAIL when we hit a line of file boundary.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5262 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5263
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5264 int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5265 oneright()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5266 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5267 char_u *ptr;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5268 #ifdef FEAT_MBYTE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5269 int l;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5270 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5271
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5272 #ifdef FEAT_VIRTUALEDIT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5273 if (virtual_active())
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5274 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5275 pos_T prevpos = curwin->w_cursor;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5276
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5277 /* Adjust for multi-wide char (excluding TAB) */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5278 ptr = ml_get_cursor();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5279 coladvance(getviscol() + ((*ptr != TAB && vim_isprintc(
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5280 #ifdef FEAT_MBYTE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5281 (*mb_ptr2char)(ptr)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5282 #else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5283 *ptr
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5284 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5285 ))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5286 ? ptr2cells(ptr) : 1));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5287 curwin->w_set_curswant = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5288 /* Return OK if the cursor moved, FAIL otherwise (at window edge). */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5289 return (prevpos.col != curwin->w_cursor.col
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5290 || prevpos.coladd != curwin->w_cursor.coladd) ? OK : FAIL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5291 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5292 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5293
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5294 ptr = ml_get_cursor();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5295 #ifdef FEAT_MBYTE
474
a5fcf36ef512 updated for version 7.0127
vimboss
parents: 470
diff changeset
5296 if (has_mbyte && (l = (*mb_ptr2len)(ptr)) > 1)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5297 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5298 /* The character under the cursor is a multi-byte character, move
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5299 * several bytes right, but don't end up on the NUL. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5300 if (ptr[l] == NUL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5301 return FAIL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5302 curwin->w_cursor.col += l;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5303 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5304 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5305 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5306 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5307 if (*ptr++ == NUL || *ptr == NUL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5308 return FAIL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5309 ++curwin->w_cursor.col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5310 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5311
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5312 curwin->w_set_curswant = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5313 return OK;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5314 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5315
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5316 int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5317 oneleft()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5318 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5319 #ifdef FEAT_VIRTUALEDIT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5320 if (virtual_active())
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5321 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5322 int width;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5323 int v = getviscol();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5324
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5325 if (v == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5326 return FAIL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5327
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5328 # ifdef FEAT_LINEBREAK
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5329 /* We might get stuck on 'showbreak', skip over it. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5330 width = 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5331 for (;;)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5332 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5333 coladvance(v - width);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5334 /* getviscol() is slow, skip it when 'showbreak' is empty and
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5335 * there are no multi-byte characters */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5336 if ((*p_sbr == NUL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5337 # ifdef FEAT_MBYTE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5338 && !has_mbyte
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5339 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5340 ) || getviscol() < v)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5341 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5342 ++width;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5343 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5344 # else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5345 coladvance(v - 1);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5346 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5347
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5348 if (curwin->w_cursor.coladd == 1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5349 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5350 char_u *ptr;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5351
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5352 /* Adjust for multi-wide char (not a TAB) */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5353 ptr = ml_get_cursor();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5354 if (*ptr != TAB && vim_isprintc(
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5355 # ifdef FEAT_MBYTE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5356 (*mb_ptr2char)(ptr)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5357 # else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5358 *ptr
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5359 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5360 ) && ptr2cells(ptr) > 1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5361 curwin->w_cursor.coladd = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5362 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5363
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5364 curwin->w_set_curswant = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5365 return OK;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5366 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5367 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5368
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5369 if (curwin->w_cursor.col == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5370 return FAIL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5371
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5372 curwin->w_set_curswant = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5373 --curwin->w_cursor.col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5374
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5375 #ifdef FEAT_MBYTE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5376 /* if the character on the left of the current cursor is a multi-byte
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5377 * character, move to its first byte */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5378 if (has_mbyte)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5379 mb_adjust_cursor();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5380 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5381 return OK;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5382 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5383
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5384 int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5385 cursor_up(n, upd_topline)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5386 long n;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5387 int upd_topline; /* When TRUE: update topline */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5388 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5389 linenr_T lnum;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5390
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5391 if (n > 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5392 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5393 lnum = curwin->w_cursor.lnum;
161
6df0106fc595 updated for version 7.0049
vimboss
parents: 140
diff changeset
5394 /* 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
5395 * is larger than the line number and '-' is in 'cpoptions' */
6df0106fc595 updated for version 7.0049
vimboss
parents: 140
diff changeset
5396 if (lnum <= 1 || (n >= lnum && vim_strchr(p_cpo, CPO_MINUS) != NULL))
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5397 return FAIL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5398 if (n >= lnum)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5399 lnum = 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5400 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5401 #ifdef FEAT_FOLDING
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5402 if (hasAnyFolding(curwin))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5403 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5404 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5405 * Count each sequence of folded lines as one logical line.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5406 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5407 /* go to the the start of the current fold */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5408 (void)hasFolding(lnum, &lnum, NULL);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5409
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5410 while (n--)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5411 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5412 /* move up one line */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5413 --lnum;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5414 if (lnum <= 1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5415 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5416 /* If we entered a fold, move to the beginning, unless in
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5417 * Insert mode or when 'foldopen' contains "all": it will open
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5418 * in a moment. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5419 if (n > 0 || !((State & INSERT) || (fdo_flags & FDO_ALL)))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5420 (void)hasFolding(lnum, &lnum, NULL);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5421 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5422 if (lnum < 1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5423 lnum = 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5424 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5425 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5426 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5427 lnum -= n;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5428 curwin->w_cursor.lnum = lnum;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5429 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5430
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5431 /* try to advance to the column we want to be at */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5432 coladvance(curwin->w_curswant);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5433
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5434 if (upd_topline)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5435 update_topline(); /* make sure curwin->w_topline is valid */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5436
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5437 return OK;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5438 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5439
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5440 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5441 * Cursor down a number of logical lines.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5442 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5443 int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5444 cursor_down(n, upd_topline)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5445 long n;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5446 int upd_topline; /* When TRUE: update topline */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5447 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5448 linenr_T lnum;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5449
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5450 if (n > 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5451 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5452 lnum = curwin->w_cursor.lnum;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5453 #ifdef FEAT_FOLDING
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5454 /* 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
5455 (void)hasFolding(lnum, NULL, &lnum);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5456 #endif
161
6df0106fc595 updated for version 7.0049
vimboss
parents: 140
diff changeset
5457 /* 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
5458 * beyound the last line and '-' is in 'cpoptions' */
6df0106fc595 updated for version 7.0049
vimboss
parents: 140
diff changeset
5459 if (lnum >= curbuf->b_ml.ml_line_count
6df0106fc595 updated for version 7.0049
vimboss
parents: 140
diff changeset
5460 || (lnum + n > curbuf->b_ml.ml_line_count
6df0106fc595 updated for version 7.0049
vimboss
parents: 140
diff changeset
5461 && vim_strchr(p_cpo, CPO_MINUS) != NULL))
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5462 return FAIL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5463 if (lnum + n >= curbuf->b_ml.ml_line_count)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5464 lnum = curbuf->b_ml.ml_line_count;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5465 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5466 #ifdef FEAT_FOLDING
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5467 if (hasAnyFolding(curwin))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5468 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5469 linenr_T last;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5470
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5471 /* count each sequence of folded lines as one logical line */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5472 while (n--)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5473 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5474 if (hasFolding(lnum, NULL, &last))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5475 lnum = last + 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5476 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5477 ++lnum;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5478 if (lnum >= curbuf->b_ml.ml_line_count)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5479 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5480 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5481 if (lnum > curbuf->b_ml.ml_line_count)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5482 lnum = curbuf->b_ml.ml_line_count;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5483 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5484 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5485 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5486 lnum += n;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5487 curwin->w_cursor.lnum = lnum;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5488 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5489
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5490 /* try to advance to the column we want to be at */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5491 coladvance(curwin->w_curswant);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5492
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5493 if (upd_topline)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5494 update_topline(); /* make sure curwin->w_topline is valid */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5495
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5496 return OK;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5497 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5498
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5499 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5500 * Stuff the last inserted text in the read buffer.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5501 * Last_insert actually is a copy of the redo buffer, so we
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5502 * first have to remove the command.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5503 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5504 int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5505 stuff_inserted(c, count, no_esc)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5506 int c; /* Command character to be inserted */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5507 long count; /* Repeat this many times */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5508 int no_esc; /* Don't add an ESC at the end */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5509 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5510 char_u *esc_ptr;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5511 char_u *ptr;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5512 char_u *last_ptr;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5513 char_u last = NUL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5514
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5515 ptr = get_last_insert();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5516 if (ptr == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5517 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5518 EMSG(_(e_noinstext));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5519 return FAIL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5520 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5521
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5522 /* may want to stuff the command character, to start Insert mode */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5523 if (c != NUL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5524 stuffcharReadbuff(c);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5525 if ((esc_ptr = (char_u *)vim_strrchr(ptr, ESC)) != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5526 *esc_ptr = NUL; /* remove the ESC */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5527
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5528 /* 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
5529 * comes after it OR if it will inserted more than once and "ptr"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5530 * starts with ^D. -- Acevedo
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5531 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5532 last_ptr = (esc_ptr ? esc_ptr : ptr + STRLEN(ptr)) - 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5533 if (last_ptr >= ptr && (*last_ptr == '0' || *last_ptr == '^')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5534 && (no_esc || (*ptr == Ctrl_D && count > 1)))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5535 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5536 last = *last_ptr;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5537 *last_ptr = NUL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5538 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5539
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5540 do
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5541 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5542 stuffReadbuff(ptr);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5543 /* a trailing "0" is inserted as "<C-V>048", "^" as "<C-V>^" */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5544 if (last)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5545 stuffReadbuff((char_u *)(last == '0'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5546 ? IF_EB("\026\060\064\070", CTRL_V_STR "xf0")
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5547 : IF_EB("\026^", CTRL_V_STR "^")));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5548 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5549 while (--count > 0);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5550
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5551 if (last)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5552 *last_ptr = last;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5553
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5554 if (esc_ptr != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5555 *esc_ptr = ESC; /* put the ESC back */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5556
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5557 /* may want to stuff a trailing ESC, to get out of Insert mode */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5558 if (!no_esc)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5559 stuffcharReadbuff(ESC);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5560
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5561 return OK;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5562 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5563
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5564 char_u *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5565 get_last_insert()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5566 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5567 if (last_insert == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5568 return NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5569 return last_insert + last_insert_skip;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5570 }
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 * Get last inserted string, and remove trailing <Esc>.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5574 * Returns pointer to allocated memory (must be freed) or NULL.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5575 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5576 char_u *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5577 get_last_insert_save()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5578 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5579 char_u *s;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5580 int len;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5581
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5582 if (last_insert == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5583 return NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5584 s = vim_strsave(last_insert + last_insert_skip);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5585 if (s != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5586 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5587 len = (int)STRLEN(s);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5588 if (len > 0 && s[len - 1] == ESC) /* remove trailing ESC */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5589 s[len - 1] = NUL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5590 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5591 return s;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5592 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5593
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5594 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5595 * Check the word in front of the cursor for an abbreviation.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5596 * Called when the non-id character "c" has been entered.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5597 * When an abbreviation is recognized it is removed from the text and
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5598 * the replacement string is inserted in typebuf.tb_buf[], followed by "c".
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5599 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5600 static int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5601 echeck_abbr(c)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5602 int c;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5603 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5604 /* Don't check for abbreviation in paste mode, when disabled and just
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5605 * after moving around with cursor keys. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5606 if (p_paste || no_abbr || arrow_used)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5607 return FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5608
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5609 return check_abbr(c, ml_get_curline(), curwin->w_cursor.col,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5610 curwin->w_cursor.lnum == Insstart.lnum ? Insstart.col : 0);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5611 }
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 * replace-stack functions
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5615 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5616 * When replacing characters, the replaced characters are remembered for each
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5617 * new character. This is used to re-insert the old text when backspacing.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5618 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5619 * There is a NUL headed list of characters for each character that is
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5620 * currently in the file after the insertion point. When BS is used, one NUL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5621 * headed list is put back for the deleted character.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5622 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5623 * For a newline, there are two NUL headed lists. One contains the characters
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5624 * that the NL replaced. The extra one stores the characters after the cursor
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5625 * that were deleted (always white space).
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5626 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5627 * Replace_offset is normally 0, in which case replace_push will add a new
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5628 * 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
5629 * characters will be left on the stack above the newly inserted character.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5630 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5631
298
f9de3e679a04 updated for version 7.0078
vimboss
parents: 278
diff changeset
5632 static char_u *replace_stack = NULL;
f9de3e679a04 updated for version 7.0078
vimboss
parents: 278
diff changeset
5633 static long replace_stack_nr = 0; /* next entry in replace stack */
f9de3e679a04 updated for version 7.0078
vimboss
parents: 278
diff changeset
5634 static long replace_stack_len = 0; /* max. number of entries */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5635
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5636 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5637 replace_push(c)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5638 int c; /* character that is replaced (NUL is none) */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5639 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5640 char_u *p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5641
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5642 if (replace_stack_nr < replace_offset) /* nothing to do */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5643 return;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5644 if (replace_stack_len <= replace_stack_nr)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5645 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5646 replace_stack_len += 50;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5647 p = lalloc(sizeof(char_u) * replace_stack_len, TRUE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5648 if (p == NULL) /* out of memory */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5649 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5650 replace_stack_len -= 50;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5651 return;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5652 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5653 if (replace_stack != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5654 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5655 mch_memmove(p, replace_stack,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5656 (size_t)(replace_stack_nr * sizeof(char_u)));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5657 vim_free(replace_stack);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5658 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5659 replace_stack = p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5660 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5661 p = replace_stack + replace_stack_nr - replace_offset;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5662 if (replace_offset)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5663 mch_memmove(p + 1, p, (size_t)(replace_offset * sizeof(char_u)));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5664 *p = c;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5665 ++replace_stack_nr;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5666 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5667
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5668 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5669 * call replace_push(c) with replace_offset set to the first NUL.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5670 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5671 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5672 replace_push_off(c)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5673 int c;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5674 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5675 char_u *p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5676
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5677 p = replace_stack + replace_stack_nr;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5678 for (replace_offset = 1; replace_offset < replace_stack_nr;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5679 ++replace_offset)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5680 if (*--p == NUL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5681 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5682 replace_push(c);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5683 replace_offset = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5684 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5685
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5686 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5687 * Pop one item from the replace stack.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5688 * return -1 if stack empty
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5689 * return replaced character or NUL otherwise
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5690 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5691 static int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5692 replace_pop()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5693 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5694 if (replace_stack_nr == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5695 return -1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5696 return (int)replace_stack[--replace_stack_nr];
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5697 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5698
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5699 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5700 * 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
5701 * encountered.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5702 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5703 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5704 replace_join(off)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5705 int off; /* offset for which NUL to remove */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5706 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5707 int i;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5708
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5709 for (i = replace_stack_nr; --i >= 0; )
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5710 if (replace_stack[i] == NUL && off-- <= 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5711 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5712 --replace_stack_nr;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5713 mch_memmove(replace_stack + i, replace_stack + i + 1,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5714 (size_t)(replace_stack_nr - i));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5715 return;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5716 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5717 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5718
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5719 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5720 * Pop bytes from the replace stack until a NUL is found, and insert them
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5721 * before the cursor. Can only be used in REPLACE or VREPLACE mode.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5722 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5723 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5724 replace_pop_ins()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5725 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5726 int cc;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5727 int oldState = State;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5728
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5729 State = NORMAL; /* don't want REPLACE here */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5730 while ((cc = replace_pop()) > 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5731 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5732 #ifdef FEAT_MBYTE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5733 mb_replace_pop_ins(cc);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5734 #else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5735 ins_char(cc);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5736 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5737 dec_cursor();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5738 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5739 State = oldState;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5740 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5741
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5742 #ifdef FEAT_MBYTE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5743 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5744 * Insert bytes popped from the replace stack. "cc" is the first byte. If it
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5745 * indicates a multi-byte char, pop the other bytes too.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5746 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5747 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5748 mb_replace_pop_ins(cc)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5749 int cc;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5750 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5751 int n;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5752 char_u buf[MB_MAXBYTES];
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5753 int i;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5754 int c;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5755
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5756 if (has_mbyte && (n = MB_BYTE2LEN(cc)) > 1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5757 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5758 buf[0] = cc;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5759 for (i = 1; i < n; ++i)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5760 buf[i] = replace_pop();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5761 ins_bytes_len(buf, n);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5762 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5763 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5764 ins_char(cc);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5765
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5766 if (enc_utf8)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5767 /* Handle composing chars. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5768 for (;;)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5769 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5770 c = replace_pop();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5771 if (c == -1) /* stack empty */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5772 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5773 if ((n = MB_BYTE2LEN(c)) == 1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5774 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5775 /* Not a multi-byte char, put it back. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5776 replace_push(c);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5777 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5778 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5779 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5780 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5781 buf[0] = c;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5782 for (i = 1; i < n; ++i)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5783 buf[i] = replace_pop();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5784 if (utf_iscomposing(utf_ptr2char(buf)))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5785 ins_bytes_len(buf, n);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5786 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5787 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5788 /* Not a composing char, put it back. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5789 for (i = n - 1; i >= 0; --i)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5790 replace_push(buf[i]);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5791 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5792 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5793 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5794 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5795 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5796 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5797
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5798 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5799 * make the replace stack empty
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5800 * (called when exiting replace mode)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5801 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5802 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5803 replace_flush()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5804 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5805 vim_free(replace_stack);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5806 replace_stack = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5807 replace_stack_len = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5808 replace_stack_nr = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5809 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5810
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5811 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5812 * Handle doing a BS for one character.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5813 * cc < 0: replace stack empty, just move cursor
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5814 * cc == 0: character was inserted, delete it
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5815 * cc > 0: character was replaced, put cc (first byte of original char) back
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5816 * and check for more characters to be put back
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5817 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5818 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5819 replace_do_bs()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5820 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5821 int cc;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5822 #ifdef FEAT_VREPLACE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5823 int orig_len = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5824 int ins_len;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5825 int orig_vcols = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5826 colnr_T start_vcol;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5827 char_u *p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5828 int i;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5829 int vcol;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5830 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5831
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5832 cc = replace_pop();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5833 if (cc > 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5834 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5835 #ifdef FEAT_VREPLACE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5836 if (State & VREPLACE_FLAG)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5837 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5838 /* Get the number of screen cells used by the character we are
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5839 * going to delete. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5840 getvcol(curwin, &curwin->w_cursor, NULL, &start_vcol, NULL);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5841 orig_vcols = chartabsize(ml_get_cursor(), start_vcol);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5842 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5843 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5844 #ifdef FEAT_MBYTE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5845 if (has_mbyte)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5846 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5847 del_char(FALSE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5848 # ifdef FEAT_VREPLACE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5849 if (State & VREPLACE_FLAG)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5850 orig_len = STRLEN(ml_get_cursor());
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5851 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5852 replace_push(cc);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5853 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5854 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5855 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5856 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5857 pchar_cursor(cc);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5858 #ifdef FEAT_VREPLACE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5859 if (State & VREPLACE_FLAG)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5860 orig_len = STRLEN(ml_get_cursor()) - 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5861 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5862 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5863 replace_pop_ins();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5864
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5865 #ifdef FEAT_VREPLACE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5866 if (State & VREPLACE_FLAG)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5867 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5868 /* Get the number of screen cells used by the inserted characters */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5869 p = ml_get_cursor();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5870 ins_len = STRLEN(p) - orig_len;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5871 vcol = start_vcol;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5872 for (i = 0; i < ins_len; ++i)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5873 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5874 vcol += chartabsize(p + i, vcol);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5875 #ifdef FEAT_MBYTE
474
a5fcf36ef512 updated for version 7.0127
vimboss
parents: 470
diff changeset
5876 i += (*mb_ptr2len)(p) - 1;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5877 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5878 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5879 vcol -= start_vcol;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5880
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5881 /* Delete spaces that were inserted after the cursor to keep the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5882 * text aligned. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5883 curwin->w_cursor.col += ins_len;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5884 while (vcol > orig_vcols && gchar_cursor() == ' ')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5885 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5886 del_char(FALSE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5887 ++orig_vcols;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5888 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5889 curwin->w_cursor.col -= ins_len;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5890 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5891 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5892
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5893 /* mark the buffer as changed and prepare for displaying */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5894 changed_bytes(curwin->w_cursor.lnum, curwin->w_cursor.col);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5895 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5896 else if (cc == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5897 (void)del_char(FALSE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5898 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5899
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5900 #ifdef FEAT_CINDENT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5901 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5902 * Return TRUE if C-indenting is on.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5903 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5904 static int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5905 cindent_on()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5906 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5907 return (!p_paste && (curbuf->b_p_cin
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5908 # ifdef FEAT_EVAL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5909 || *curbuf->b_p_inde != NUL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5910 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5911 ));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5912 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5913 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5914
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5915 #if defined(FEAT_LISP) || defined(FEAT_CINDENT) || defined(PROTO)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5916 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5917 * Re-indent the current line, based on the current contents of it and the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5918 * surrounding lines. Fixing the cursor position seems really easy -- I'm very
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5919 * 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
5920 * "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
5921 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5922
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5923 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5924 fixthisline(get_the_indent)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5925 int (*get_the_indent) __ARGS((void));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5926 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5927 change_indent(INDENT_SET, get_the_indent(), FALSE, 0);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5928 if (linewhite(curwin->w_cursor.lnum))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5929 did_ai = TRUE; /* delete the indent if the line stays empty */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5930 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5931
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5932 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5933 fix_indent()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5934 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5935 if (p_paste)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5936 return;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5937 # ifdef FEAT_LISP
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5938 if (curbuf->b_p_lisp && curbuf->b_p_ai)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5939 fixthisline(get_lisp_indent);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5940 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5941 # if defined(FEAT_LISP) && defined(FEAT_CINDENT)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5942 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5943 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5944 # ifdef FEAT_CINDENT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5945 if (cindent_on())
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5946 do_c_expr_indent();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5947 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5948 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5949
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5950 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5951
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5952 #ifdef FEAT_CINDENT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5953 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5954 * return TRUE if 'cinkeys' contains the key "keytyped",
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5955 * when == '*': Only if key is preceded with '*' (indent before insert)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5956 * when == '!': Only if key is prededed with '!' (don't insert)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5957 * when == ' ': Only if key is not preceded with '*'(indent afterwards)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5958 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5959 * "keytyped" can have a few special values:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5960 * KEY_OPEN_FORW
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5961 * KEY_OPEN_BACK
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5962 * KEY_COMPLETE just finished completion.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5963 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5964 * If line_is_empty is TRUE accept keys with '0' before them.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5965 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5966 int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5967 in_cinkeys(keytyped, when, line_is_empty)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5968 int keytyped;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5969 int when;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5970 int line_is_empty;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5971 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5972 char_u *look;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5973 int try_match;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5974 int try_match_word;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5975 char_u *p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5976 char_u *line;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5977 int icase;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5978 int i;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5979
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5980 #ifdef FEAT_EVAL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5981 if (*curbuf->b_p_inde != NUL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5982 look = curbuf->b_p_indk; /* 'indentexpr' set: use 'indentkeys' */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5983 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5984 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5985 look = curbuf->b_p_cink; /* 'indentexpr' empty: use 'cinkeys' */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5986 while (*look)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5987 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5988 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5989 * Find out if we want to try a match with this key, depending on
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5990 * 'when' and a '*' or '!' before the key.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5991 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5992 switch (when)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5993 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5994 case '*': try_match = (*look == '*'); break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5995 case '!': try_match = (*look == '!'); break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5996 default: try_match = (*look != '*'); break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5997 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5998 if (*look == '*' || *look == '!')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5999 ++look;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6000
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6001 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6002 * If there is a '0', only accept a match if the line is empty.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6003 * But may still match when typing last char of a word.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6004 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6005 if (*look == '0')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6006 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6007 try_match_word = try_match;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6008 if (!line_is_empty)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6009 try_match = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6010 ++look;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6011 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6012 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6013 try_match_word = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6014
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6015 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6016 * does it look like a control character?
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6017 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6018 if (*look == '^'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6019 #ifdef EBCDIC
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6020 && (Ctrl_chr(look[1]) != 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6021 #else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6022 && look[1] >= '?' && look[1] <= '_'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6023 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6024 )
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6025 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6026 if (try_match && keytyped == Ctrl_chr(look[1]))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6027 return TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6028 look += 2;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6029 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6030 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6031 * 'o' means "o" command, open forward.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6032 * 'O' means "O" command, open backward.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6033 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6034 else if (*look == 'o')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6035 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6036 if (try_match && keytyped == KEY_OPEN_FORW)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6037 return TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6038 ++look;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6039 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6040 else if (*look == 'O')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6041 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6042 if (try_match && keytyped == KEY_OPEN_BACK)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6043 return TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6044 ++look;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6045 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6046
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6047 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6048 * 'e' means to check for "else" at start of line and just before the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6049 * cursor.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6050 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6051 else if (*look == 'e')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6052 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6053 if (try_match && keytyped == 'e' && curwin->w_cursor.col >= 4)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6054 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6055 p = ml_get_curline();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6056 if (skipwhite(p) == p + curwin->w_cursor.col - 4 &&
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6057 STRNCMP(p + curwin->w_cursor.col - 4, "else", 4) == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6058 return TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6059 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6060 ++look;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6061 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6062
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6063 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6064 * ':' 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
6065 * statement, or when it was before typing the ':' (to fix
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6066 * class::method for C++).
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6067 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6068 else if (*look == ':')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6069 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6070 if (try_match && keytyped == ':')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6071 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6072 p = ml_get_curline();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6073 if (cin_iscase(p) || cin_isscopedecl(p) || cin_islabel(30))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6074 return TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6075 if (curwin->w_cursor.col > 2
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6076 && p[curwin->w_cursor.col - 1] == ':'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6077 && p[curwin->w_cursor.col - 2] == ':')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6078 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6079 p[curwin->w_cursor.col - 1] = ' ';
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6080 i = (cin_iscase(p) || cin_isscopedecl(p)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6081 || cin_islabel(30));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6082 p = ml_get_curline();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6083 p[curwin->w_cursor.col - 1] = ':';
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6084 if (i)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6085 return TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6086 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6087 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6088 ++look;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6089 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6090
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6091
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6092 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6093 * Is it a key in <>, maybe?
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6094 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6095 else if (*look == '<')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6096 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6097 if (try_match)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6098 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6099 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6100 * make up some named keys <o>, <O>, <e>, <0>, <>>, <<>, <*>,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6101 * <:> and <!> so that people can re-indent on o, O, e, 0, <,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6102 * >, *, : and ! keys if they really really want to.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6103 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6104 if (vim_strchr((char_u *)"<>!*oOe0:", look[1]) != NULL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6105 && keytyped == look[1])
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6106 return TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6107
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6108 if (keytyped == get_special_key_code(look + 1))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6109 return TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6110 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6111 while (*look && *look != '>')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6112 look++;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6113 while (*look == '>')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6114 look++;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6115 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6116
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6117 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6118 * Is it a word: "=word"?
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6119 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6120 else if (*look == '=' && look[1] != ',' && look[1] != NUL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6121 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6122 ++look;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6123 if (*look == '~')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6124 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6125 icase = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6126 ++look;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6127 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6128 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6129 icase = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6130 p = vim_strchr(look, ',');
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6131 if (p == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6132 p = look + STRLEN(look);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6133 if ((try_match || try_match_word)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6134 && curwin->w_cursor.col >= (colnr_T)(p - look))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6135 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6136 int match = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6137
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6138 #ifdef FEAT_INS_EXPAND
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6139 if (keytyped == KEY_COMPLETE)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6140 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6141 char_u *s;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6142
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6143 /* Just completed a word, check if it starts with "look".
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6144 * search back for the start of a word. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6145 line = ml_get_curline();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6146 # ifdef FEAT_MBYTE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6147 if (has_mbyte)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6148 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6149 char_u *n;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6150
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6151 for (s = line + curwin->w_cursor.col; s > line; s = n)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6152 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6153 n = mb_prevptr(line, s);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6154 if (!vim_iswordp(n))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6155 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6156 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6157 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6158 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6159 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6160 for (s = line + curwin->w_cursor.col; s > line; --s)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6161 if (!vim_iswordc(s[-1]))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6162 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6163 if (s + (p - look) <= line + curwin->w_cursor.col
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6164 && (icase
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6165 ? MB_STRNICMP(s, look, p - look)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6166 : STRNCMP(s, look, p - look)) == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6167 match = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6168 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6169 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6170 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6171 /* TODO: multi-byte */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6172 if (keytyped == (int)p[-1] || (icase && keytyped < 256
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6173 && TOLOWER_LOC(keytyped) == TOLOWER_LOC((int)p[-1])))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6174 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6175 line = ml_get_cursor();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6176 if ((curwin->w_cursor.col == (colnr_T)(p - look)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6177 || !vim_iswordc(line[-(p - look) - 1]))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6178 && (icase
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6179 ? MB_STRNICMP(line - (p - look), look, p - look)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6180 : STRNCMP(line - (p - look), look, p - look))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6181 == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6182 match = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6183 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6184 if (match && try_match_word && !try_match)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6185 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6186 /* "0=word": Check if there are only blanks before the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6187 * word. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6188 line = ml_get_curline();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6189 if ((int)(skipwhite(line) - line) !=
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6190 (int)(curwin->w_cursor.col - (p - look)))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6191 match = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6192 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6193 if (match)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6194 return TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6195 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6196 look = p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6197 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6198
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6199 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6200 * ok, it's a boring generic character.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6201 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6202 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6203 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6204 if (try_match && *look == keytyped)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6205 return TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6206 ++look;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6207 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6208
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6209 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6210 * Skip over ", ".
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6211 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6212 look = skip_to_option_part(look);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6213 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6214 return FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6215 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6216 #endif /* FEAT_CINDENT */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6217
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6218 #if defined(FEAT_RIGHTLEFT) || defined(PROTO)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6219 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6220 * Map Hebrew keyboard when in hkmap mode.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6221 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6222 int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6223 hkmap(c)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6224 int c;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6225 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6226 if (p_hkmapp) /* phonetic mapping, by Ilya Dogolazky */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6227 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6228 enum {hALEF=0, BET, GIMEL, DALET, HEI, VAV, ZAIN, HET, TET, IUD,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6229 KAFsofit, hKAF, LAMED, MEMsofit, MEM, NUNsofit, NUN, SAMEH, AIN,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6230 PEIsofit, PEI, ZADIsofit, ZADI, KOF, RESH, hSHIN, TAV};
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6231 static char_u map[26] =
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6232 {(char_u)hALEF/*a*/, (char_u)BET /*b*/, (char_u)hKAF /*c*/,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6233 (char_u)DALET/*d*/, (char_u)-1 /*e*/, (char_u)PEIsofit/*f*/,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6234 (char_u)GIMEL/*g*/, (char_u)HEI /*h*/, (char_u)IUD /*i*/,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6235 (char_u)HET /*j*/, (char_u)KOF /*k*/, (char_u)LAMED /*l*/,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6236 (char_u)MEM /*m*/, (char_u)NUN /*n*/, (char_u)SAMEH /*o*/,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6237 (char_u)PEI /*p*/, (char_u)-1 /*q*/, (char_u)RESH /*r*/,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6238 (char_u)ZAIN /*s*/, (char_u)TAV /*t*/, (char_u)TET /*u*/,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6239 (char_u)VAV /*v*/, (char_u)hSHIN/*w*/, (char_u)-1 /*x*/,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6240 (char_u)AIN /*y*/, (char_u)ZADI /*z*/};
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6241
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6242 if (c == 'N' || c == 'M' || c == 'P' || c == 'C' || c == 'Z')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6243 return (int)(map[CharOrd(c)] - 1 + p_aleph);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6244 /* '-1'='sofit' */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6245 else if (c == 'x')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6246 return 'X';
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6247 else if (c == 'q')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6248 return '\''; /* {geresh}={'} */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6249 else if (c == 246)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6250 return ' '; /* \"o --> ' ' for a german keyboard */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6251 else if (c == 228)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6252 return ' '; /* \"a --> ' ' -- / -- */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6253 else if (c == 252)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6254 return ' '; /* \"u --> ' ' -- / -- */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6255 #ifdef EBCDIC
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6256 else if (islower(c))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6257 #else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6258 /* NOTE: islower() does not do the right thing for us on Linux so we
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6259 * 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
6260 * all systems. Specifically, the e.g. Delete and Arrow keys are
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6261 * munged and won't work if e.g. searching for Hebrew text.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6262 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6263 else if (c >= 'a' && c <= 'z')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6264 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6265 return (int)(map[CharOrdLow(c)] + p_aleph);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6266 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6267 return c;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6268 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6269 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6270 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6271 switch (c)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6272 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6273 case '`': return ';';
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6274 case '/': return '.';
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6275 case '\'': return ',';
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6276 case 'q': return '/';
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6277 case 'w': return '\'';
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6278
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6279 /* Hebrew letters - set offset from 'a' */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6280 case ',': c = '{'; break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6281 case '.': c = 'v'; break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6282 case ';': c = 't'; break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6283 default: {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6284 static char str[] = "zqbcxlsjphmkwonu ydafe rig";
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6285
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6286 #ifdef EBCDIC
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6287 /* see note about islower() above */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6288 if (!islower(c))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6289 #else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6290 if (c < 'a' || c > 'z')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6291 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6292 return c;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6293 c = str[CharOrdLow(c)];
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6294 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6295 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6296 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6297
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6298 return (int)(CharOrdLow(c) + p_aleph);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6299 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6300 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6301 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6302
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6303 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6304 ins_reg()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6305 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6306 int need_redraw = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6307 int regname;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6308 int literally = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6309
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6310 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6311 * If we are going to wait for a character, show a '"'.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6312 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6313 pc_status = PC_STATUS_UNSET;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6314 if (redrawing() && !char_avail())
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6315 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6316 /* may need to redraw when no more chars available now */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6317 ins_redraw();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6318
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6319 edit_putchar('"', TRUE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6320 #ifdef FEAT_CMDL_INFO
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6321 add_to_showcmd_c(Ctrl_R);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6322 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6323 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6324
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6325 #ifdef USE_ON_FLY_SCROLL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6326 dont_scroll = TRUE; /* disallow scrolling here */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6327 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6328
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6329 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6330 * Don't map the register name. This also prevents the mode message to be
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6331 * deleted when ESC is hit.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6332 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6333 ++no_mapping;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6334 regname = safe_vgetc();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6335 #ifdef FEAT_LANGMAP
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6336 LANGMAP_ADJUST(regname, TRUE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6337 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6338 if (regname == Ctrl_R || regname == Ctrl_O || regname == Ctrl_P)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6339 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6340 /* Get a third key for literal register insertion */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6341 literally = regname;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6342 #ifdef FEAT_CMDL_INFO
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6343 add_to_showcmd_c(literally);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6344 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6345 regname = safe_vgetc();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6346 #ifdef FEAT_LANGMAP
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6347 LANGMAP_ADJUST(regname, TRUE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6348 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6349 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6350 --no_mapping;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6351
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6352 #ifdef FEAT_EVAL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6353 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6354 * Don't call u_sync() while getting the expression,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6355 * evaluating it or giving an error message for it!
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6356 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6357 ++no_u_sync;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6358 if (regname == '=')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6359 {
133
bcb347a8f934 updated for version 7.0044
vimboss
parents: 75
diff changeset
6360 # ifdef USE_IM_CONTROL
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6361 int im_on = im_get_status();
133
bcb347a8f934 updated for version 7.0044
vimboss
parents: 75
diff changeset
6362 # endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6363 regname = get_expr_register();
133
bcb347a8f934 updated for version 7.0044
vimboss
parents: 75
diff changeset
6364 # ifdef USE_IM_CONTROL
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6365 /* Restore the Input Method. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6366 if (im_on)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6367 im_set_active(TRUE);
133
bcb347a8f934 updated for version 7.0044
vimboss
parents: 75
diff changeset
6368 # endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6369 }
140
8ecb0db93e9a updated for version 7.0045
vimboss
parents: 133
diff changeset
6370 if (regname == NUL || !valid_yank_reg(regname, FALSE))
8ecb0db93e9a updated for version 7.0045
vimboss
parents: 133
diff changeset
6371 {
8ecb0db93e9a updated for version 7.0045
vimboss
parents: 133
diff changeset
6372 vim_beep();
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6373 need_redraw = TRUE; /* remove the '"' */
140
8ecb0db93e9a updated for version 7.0045
vimboss
parents: 133
diff changeset
6374 }
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6375 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6376 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6377 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6378 if (literally == Ctrl_O || literally == Ctrl_P)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6379 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6380 /* Append the command to the redo buffer. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6381 AppendCharToRedobuff(Ctrl_R);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6382 AppendCharToRedobuff(literally);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6383 AppendCharToRedobuff(regname);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6384
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6385 do_put(regname, BACKWARD, 1L,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6386 (literally == Ctrl_P ? PUT_FIXINDENT : 0) | PUT_CURSEND);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6387 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6388 else if (insert_reg(regname, literally) == FAIL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6389 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6390 vim_beep();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6391 need_redraw = TRUE; /* remove the '"' */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6392 }
133
bcb347a8f934 updated for version 7.0044
vimboss
parents: 75
diff changeset
6393 else if (stop_insert_mode)
bcb347a8f934 updated for version 7.0044
vimboss
parents: 75
diff changeset
6394 /* When the '=' register was used and a function was invoked that
bcb347a8f934 updated for version 7.0044
vimboss
parents: 75
diff changeset
6395 * did ":stopinsert" then stuff_empty() returns FALSE but we won't
bcb347a8f934 updated for version 7.0044
vimboss
parents: 75
diff changeset
6396 * insert anything, need to remove the '"' */
bcb347a8f934 updated for version 7.0044
vimboss
parents: 75
diff changeset
6397 need_redraw = TRUE;
bcb347a8f934 updated for version 7.0044
vimboss
parents: 75
diff changeset
6398
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6399 #ifdef FEAT_EVAL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6400 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6401 --no_u_sync;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6402 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6403 #ifdef FEAT_CMDL_INFO
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6404 clear_showcmd();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6405 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6406
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6407 /* If the inserted register is empty, we need to remove the '"' */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6408 if (need_redraw || stuff_empty())
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6409 edit_unputchar();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6410 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6411
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6412 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6413 * CTRL-G commands in Insert mode.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6414 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6415 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6416 ins_ctrl_g()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6417 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6418 int c;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6419
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6420 #ifdef FEAT_INS_EXPAND
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6421 /* Right after CTRL-X the cursor will be after the ruler. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6422 setcursor();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6423 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6424
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6425 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6426 * Don't map the second key. This also prevents the mode message to be
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6427 * deleted when ESC is hit.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6428 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6429 ++no_mapping;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6430 c = safe_vgetc();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6431 --no_mapping;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6432 switch (c)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6433 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6434 /* CTRL-G k and CTRL-G <Up>: cursor up to Insstart.col */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6435 case K_UP:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6436 case Ctrl_K:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6437 case 'k': ins_up(TRUE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6438 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6439
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6440 /* CTRL-G j and CTRL-G <Down>: cursor down to Insstart.col */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6441 case K_DOWN:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6442 case Ctrl_J:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6443 case 'j': ins_down(TRUE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6444 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6445
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6446 /* CTRL-G u: start new undoable edit */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6447 case 'u': u_sync();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6448 ins_need_undo = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6449 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6450
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6451 /* Unknown CTRL-G command, reserved for future expansion. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6452 default: vim_beep();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6453 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6454 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6455
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6456 /*
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
6457 * CTRL-^ in Insert mode.
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
6458 */
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
6459 static void
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
6460 ins_ctrl_hat()
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
6461 {
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
6462 if (map_to_exists_mode((char_u *)"", LANGMAP))
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
6463 {
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
6464 /* ":lmap" mappings exists, Toggle use of ":lmap" mappings. */
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
6465 if (State & LANGMAP)
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
6466 {
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
6467 curbuf->b_p_iminsert = B_IMODE_NONE;
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
6468 State &= ~LANGMAP;
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
6469 }
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
6470 else
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
6471 {
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
6472 curbuf->b_p_iminsert = B_IMODE_LMAP;
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
6473 State |= LANGMAP;
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
6474 #ifdef USE_IM_CONTROL
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
6475 im_set_active(FALSE);
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
6476 #endif
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
6477 }
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
6478 }
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
6479 #ifdef USE_IM_CONTROL
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
6480 else
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
6481 {
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
6482 /* There are no ":lmap" mappings, toggle IM */
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
6483 if (im_get_status())
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
6484 {
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
6485 curbuf->b_p_iminsert = B_IMODE_NONE;
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
6486 im_set_active(FALSE);
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
6487 }
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
6488 else
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
6489 {
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
6490 curbuf->b_p_iminsert = B_IMODE_IM;
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
6491 State &= ~LANGMAP;
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
6492 im_set_active(TRUE);
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
6493 }
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
6494 }
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
6495 #endif
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
6496 set_iminsert_global();
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
6497 showmode();
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
6498 #ifdef FEAT_GUI
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
6499 /* may show different cursor shape or color */
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
6500 if (gui.in_use)
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
6501 gui_update_cursor(TRUE, FALSE);
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
6502 #endif
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
6503 #if defined(FEAT_WINDOWS) && defined(FEAT_KEYMAP)
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
6504 /* Show/unshow value of 'keymap' in status lines. */
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
6505 status_redraw_curbuf();
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
6506 #endif
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
6507 }
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
6508
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
6509 /*
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6510 * Handle ESC in insert mode.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6511 * Returns TRUE when leaving insert mode, FALSE when going to repeat the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6512 * insert.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6513 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6514 static int
477
f8b75b8f1988 updated for version 7.0128
vimboss
parents: 474
diff changeset
6515 ins_esc(count, cmdchar, nomove)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6516 long *count;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6517 int cmdchar;
477
f8b75b8f1988 updated for version 7.0128
vimboss
parents: 474
diff changeset
6518 int nomove; /* don't move cursor */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6519 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6520 int temp;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6521 static int disabled_redraw = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6522
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
6523 #ifdef FEAT_SYN_HL
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
6524 check_spell_redraw();
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
6525 #endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6526 #if defined(FEAT_HANGULIN)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6527 # if defined(ESC_CHG_TO_ENG_MODE)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6528 hangul_input_state_set(0);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6529 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6530 if (composing_hangul)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6531 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6532 push_raw_key(composing_hangul_buffer, 2);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6533 composing_hangul = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6534 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6535 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6536 #if defined(FEAT_MBYTE) && defined(MACOS_CLASSIC)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6537 previous_script = GetScriptManagerVariable(smKeyScript);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6538 KeyScript(smKeyRoman); /* or smKeySysScript */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6539 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6540
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6541 temp = curwin->w_cursor.col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6542 if (disabled_redraw)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6543 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6544 --RedrawingDisabled;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6545 disabled_redraw = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6546 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6547 if (!arrow_used)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6548 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6549 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6550 * Don't append the ESC for "r<CR>" and "grx".
75
388f285bda1b updated for version 7.0031
vimboss
parents: 41
diff changeset
6551 * When 'insertmode' is set only CTRL-L stops Insert mode. Needed for
388f285bda1b updated for version 7.0031
vimboss
parents: 41
diff changeset
6552 * when "count" is non-zero.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6553 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6554 if (cmdchar != 'r' && cmdchar != 'v')
75
388f285bda1b updated for version 7.0031
vimboss
parents: 41
diff changeset
6555 AppendToRedobuff(p_im ? (char_u *)"\014" : ESC_STR);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6556
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6557 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6558 * Repeating insert may take a long time. Check for
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6559 * interrupt now and then.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6560 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6561 if (*count > 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6562 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6563 line_breakcheck();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6564 if (got_int)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6565 *count = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6566 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6567
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6568 if (--*count > 0) /* repeat what was typed */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6569 {
164
8b0ee9d57d7f updated for version 7.0050
vimboss
parents: 161
diff changeset
6570 /* Vi repeats the insert without replacing characters. */
8b0ee9d57d7f updated for version 7.0050
vimboss
parents: 161
diff changeset
6571 if (vim_strchr(p_cpo, CPO_REPLCNT) != NULL)
8b0ee9d57d7f updated for version 7.0050
vimboss
parents: 161
diff changeset
6572 State &= ~REPLACE_FLAG;
8b0ee9d57d7f updated for version 7.0050
vimboss
parents: 161
diff changeset
6573
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6574 (void)start_redo_ins();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6575 if (cmdchar == 'r' || cmdchar == 'v')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6576 stuffReadbuff(ESC_STR); /* no ESC in redo buffer */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6577 ++RedrawingDisabled;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6578 disabled_redraw = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6579 return FALSE; /* repeat the insert */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6580 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6581 stop_insert(&curwin->w_cursor, TRUE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6582 undisplay_dollar();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6583 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6584
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6585 /* When an autoindent was removed, curswant stays after the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6586 * indent */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6587 if (restart_edit == NUL && (colnr_T)temp == curwin->w_cursor.col)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6588 curwin->w_set_curswant = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6589
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6590 /* Remember the last Insert position in the '^ mark. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6591 if (!cmdmod.keepjumps)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6592 curbuf->b_last_insert = curwin->w_cursor;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6593
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6594 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6595 * The cursor should end up on the last inserted character.
477
f8b75b8f1988 updated for version 7.0128
vimboss
parents: 474
diff changeset
6596 * 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
6597 */
477
f8b75b8f1988 updated for version 7.0128
vimboss
parents: 474
diff changeset
6598 if (!nomove
f8b75b8f1988 updated for version 7.0128
vimboss
parents: 474
diff changeset
6599 && (curwin->w_cursor.col != 0
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6600 #ifdef FEAT_VIRTUALEDIT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6601 || curwin->w_cursor.coladd > 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6602 #endif
477
f8b75b8f1988 updated for version 7.0128
vimboss
parents: 474
diff changeset
6603 )
f8b75b8f1988 updated for version 7.0128
vimboss
parents: 474
diff changeset
6604 && (restart_edit == NUL
f8b75b8f1988 updated for version 7.0128
vimboss
parents: 474
diff changeset
6605 || (gchar_cursor() == NUL
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6606 #ifdef FEAT_VISUAL
477
f8b75b8f1988 updated for version 7.0128
vimboss
parents: 474
diff changeset
6607 && !VIsual_active
f8b75b8f1988 updated for version 7.0128
vimboss
parents: 474
diff changeset
6608 #endif
f8b75b8f1988 updated for version 7.0128
vimboss
parents: 474
diff changeset
6609 ))
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6610 #ifdef FEAT_RIGHTLEFT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6611 && !revins_on
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6612 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6613 )
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6614 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6615 #ifdef FEAT_VIRTUALEDIT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6616 if (curwin->w_cursor.coladd > 0 || ve_flags == VE_ALL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6617 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6618 oneleft();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6619 if (restart_edit != NUL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6620 ++curwin->w_cursor.coladd;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6621 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6622 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6623 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6624 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6625 --curwin->w_cursor.col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6626 #ifdef FEAT_MBYTE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6627 /* Correct cursor for multi-byte character. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6628 if (has_mbyte)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6629 mb_adjust_cursor();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6630 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6631 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6632 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6633
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6634 #ifdef USE_IM_CONTROL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6635 /* Disable IM to allow typing English directly for Normal mode commands.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6636 * When ":lmap" is enabled don't change 'iminsert' (IM can be enabled as
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6637 * well). */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6638 if (!(State & LANGMAP))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6639 im_save_status(&curbuf->b_p_iminsert);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6640 im_set_active(FALSE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6641 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6642
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6643 State = NORMAL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6644 /* need to position cursor again (e.g. when on a TAB ) */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6645 changed_cline_bef_curs();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6646
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6647 #ifdef FEAT_MOUSE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6648 setmouse();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6649 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6650 #ifdef CURSOR_SHAPE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6651 ui_cursor_shape(); /* may show different cursor shape */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6652 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6653
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6654 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6655 * When recording or for CTRL-O, need to display the new mode.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6656 * Otherwise remove the mode message.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6657 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6658 if (Recording || restart_edit != NUL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6659 showmode();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6660 else if (p_smd)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6661 MSG("");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6662
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6663 return TRUE; /* exit Insert mode */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6664 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6665
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6666 #ifdef FEAT_RIGHTLEFT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6667 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6668 * Toggle language: hkmap and revins_on.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6669 * Move to end of reverse inserted text.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6670 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6671 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6672 ins_ctrl_()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6673 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6674 if (revins_on && revins_chars && revins_scol >= 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6675 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6676 while (gchar_cursor() != NUL && revins_chars--)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6677 ++curwin->w_cursor.col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6678 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6679 p_ri = !p_ri;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6680 revins_on = (State == INSERT && p_ri);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6681 if (revins_on)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6682 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6683 revins_scol = curwin->w_cursor.col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6684 revins_legal++;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6685 revins_chars = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6686 undisplay_dollar();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6687 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6688 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6689 revins_scol = -1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6690 #ifdef FEAT_FKMAP
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6691 if (p_altkeymap)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6692 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6693 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6694 * to be consistent also for redo command, using '.'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6695 * set arrow_used to true and stop it - causing to redo
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6696 * characters entered in one mode (normal/reverse insert).
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6697 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6698 arrow_used = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6699 (void)stop_arrow();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6700 p_fkmap = curwin->w_p_rl ^ p_ri;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6701 if (p_fkmap && p_ri)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6702 State = INSERT;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6703 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6704 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6705 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6706 p_hkmap = curwin->w_p_rl ^ p_ri; /* be consistent! */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6707 showmode();
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 #ifdef FEAT_VISUAL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6712 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6713 * If 'keymodel' contains "startsel", may start selection.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6714 * Returns TRUE when a CTRL-O and other keys stuffed.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6715 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6716 static int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6717 ins_start_select(c)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6718 int c;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6719 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6720 if (km_startsel)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6721 switch (c)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6722 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6723 case K_KHOME:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6724 case K_KEND:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6725 case K_PAGEUP:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6726 case K_KPAGEUP:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6727 case K_PAGEDOWN:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6728 case K_KPAGEDOWN:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6729 # ifdef MACOS
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6730 case K_LEFT:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6731 case K_RIGHT:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6732 case K_UP:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6733 case K_DOWN:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6734 case K_END:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6735 case K_HOME:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6736 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6737 if (!(mod_mask & MOD_MASK_SHIFT))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6738 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6739 /* FALLTHROUGH */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6740 case K_S_LEFT:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6741 case K_S_RIGHT:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6742 case K_S_UP:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6743 case K_S_DOWN:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6744 case K_S_END:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6745 case K_S_HOME:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6746 /* Start selection right away, the cursor can move with
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6747 * CTRL-O when beyond the end of the line. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6748 start_selection();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6749
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6750 /* Execute the key in (insert) Select mode. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6751 stuffcharReadbuff(Ctrl_O);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6752 if (mod_mask)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6753 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6754 char_u buf[4];
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6755
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6756 buf[0] = K_SPECIAL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6757 buf[1] = KS_MODIFIER;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6758 buf[2] = mod_mask;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6759 buf[3] = NUL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6760 stuffReadbuff(buf);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6761 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6762 stuffcharReadbuff(c);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6763 return TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6764 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6765 return FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6766 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6767 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6768
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6769 /*
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
6770 * <Insert> key in Insert mode: toggle insert/remplace mode.
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
6771 */
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
6772 static void
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
6773 ins_insert(replaceState)
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
6774 int replaceState;
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
6775 {
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
6776 #ifdef FEAT_FKMAP
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
6777 if (p_fkmap && p_ri)
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
6778 {
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
6779 beep_flush();
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
6780 EMSG(farsi_text_3); /* encoded in Farsi */
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
6781 return;
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
6782 }
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
6783 #endif
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
6784
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
6785 #ifdef FEAT_AUTOCMD
532
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 523
diff changeset
6786 # ifdef FEAT_EVAL
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
6787 set_vim_var_string(VV_INSERTMODE,
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
6788 (char_u *)((State & REPLACE_FLAG) ? "i" :
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
6789 replaceState == VREPLACE ? "v" : "r"), 1);
532
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 523
diff changeset
6790 # endif
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
6791 apply_autocmds(EVENT_INSERTCHANGE, NULL, NULL, FALSE, curbuf);
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
6792 #endif
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
6793 if (State & REPLACE_FLAG)
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
6794 State = INSERT | (State & LANGMAP);
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
6795 else
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
6796 State = replaceState | (State & LANGMAP);
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
6797 AppendCharToRedobuff(K_INS);
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
6798 showmode();
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
6799 #ifdef CURSOR_SHAPE
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
6800 ui_cursor_shape(); /* may show different cursor shape */
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
6801 #endif
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
6802 }
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
6803
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
6804 /*
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
6805 * Pressed CTRL-O in Insert mode.
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
6806 */
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
6807 static void
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
6808 ins_ctrl_o()
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
6809 {
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
6810 #ifdef FEAT_VREPLACE
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
6811 if (State & VREPLACE_FLAG)
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
6812 restart_edit = 'V';
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
6813 else
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
6814 #endif
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
6815 if (State & REPLACE_FLAG)
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
6816 restart_edit = 'R';
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
6817 else
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
6818 restart_edit = 'I';
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
6819 #ifdef FEAT_VIRTUALEDIT
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
6820 if (virtual_active())
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
6821 ins_at_eol = FALSE; /* cursor always keeps its column */
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
6822 else
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
6823 #endif
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
6824 ins_at_eol = (gchar_cursor() == NUL);
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
6825 }
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
6826
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
6827 /*
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6828 * If the cursor is on an indent, ^T/^D insert/delete one
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6829 * shiftwidth. Otherwise ^T/^D behave like a "<<" or ">>".
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6830 * Always round the indent to 'shiftwith', this is compatible
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6831 * with vi. But vi only supports ^T and ^D after an
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6832 * autoindent, we support it everywhere.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6833 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6834 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6835 ins_shift(c, lastc)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6836 int c;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6837 int lastc;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6838 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6839 if (stop_arrow() == FAIL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6840 return;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6841 AppendCharToRedobuff(c);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6842
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6843 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6844 * 0^D and ^^D: remove all indent.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6845 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6846 if ((lastc == '0' || lastc == '^') && curwin->w_cursor.col)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6847 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6848 --curwin->w_cursor.col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6849 (void)del_char(FALSE); /* delete the '^' or '0' */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6850 /* In Replace mode, restore the characters that '^' or '0' replaced. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6851 if (State & REPLACE_FLAG)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6852 replace_pop_ins();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6853 if (lastc == '^')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6854 old_indent = get_indent(); /* remember curr. indent */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6855 change_indent(INDENT_SET, 0, TRUE, 0);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6856 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6857 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6858 change_indent(c == Ctrl_D ? INDENT_DEC : INDENT_INC, 0, TRUE, 0);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6859
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6860 if (did_ai && *skipwhite(ml_get_curline()) != NUL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6861 did_ai = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6862 #ifdef FEAT_SMARTINDENT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6863 did_si = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6864 can_si = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6865 can_si_back = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6866 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6867 #ifdef FEAT_CINDENT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6868 can_cindent = FALSE; /* no cindenting after ^D or ^T */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6869 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6870 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6871
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6872 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6873 ins_del()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6874 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6875 int temp;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6876
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6877 if (stop_arrow() == FAIL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6878 return;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6879 if (gchar_cursor() == NUL) /* delete newline */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6880 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6881 temp = curwin->w_cursor.col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6882 if (!can_bs(BS_EOL) /* only if "eol" included */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6883 || u_save((linenr_T)(curwin->w_cursor.lnum - 1),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6884 (linenr_T)(curwin->w_cursor.lnum + 2)) == FAIL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6885 || do_join(FALSE) == FAIL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6886 vim_beep();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6887 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6888 curwin->w_cursor.col = temp;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6889 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6890 else if (del_char(FALSE) == FAIL) /* delete char under cursor */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6891 vim_beep();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6892 did_ai = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6893 #ifdef FEAT_SMARTINDENT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6894 did_si = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6895 can_si = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6896 can_si_back = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6897 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6898 AppendCharToRedobuff(K_DEL);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6899 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6900
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6901 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6902 * Handle Backspace, delete-word and delete-line in Insert mode.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6903 * Return TRUE when backspace was actually used.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6904 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6905 static int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6906 ins_bs(c, mode, inserted_space_p)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6907 int c;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6908 int mode;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6909 int *inserted_space_p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6910 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6911 linenr_T lnum;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6912 int cc;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6913 int temp = 0; /* init for GCC */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6914 colnr_T mincol;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6915 int did_backspace = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6916 int in_indent;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6917 int oldState;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6918 #ifdef FEAT_MBYTE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6919 int p1, p2;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6920 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6921
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6922 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6923 * can't delete anything in an empty file
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6924 * can't backup past first character in buffer
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6925 * can't backup past starting point unless 'backspace' > 1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6926 * can backup to a previous line if 'backspace' == 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6927 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6928 if ( bufempty()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6929 || (
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6930 #ifdef FEAT_RIGHTLEFT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6931 !revins_on &&
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6932 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6933 ((curwin->w_cursor.lnum == 1 && curwin->w_cursor.col == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6934 || (!can_bs(BS_START)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6935 && (arrow_used
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6936 || (curwin->w_cursor.lnum == Insstart.lnum
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6937 && curwin->w_cursor.col <= Insstart.col)))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6938 || (!can_bs(BS_INDENT) && !arrow_used && ai_col > 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6939 && curwin->w_cursor.col <= ai_col)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6940 || (!can_bs(BS_EOL) && curwin->w_cursor.col == 0))))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6941 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6942 vim_beep();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6943 return FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6944 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6945
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6946 if (stop_arrow() == FAIL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6947 return FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6948 in_indent = inindent(0);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6949 #ifdef FEAT_CINDENT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6950 if (in_indent)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6951 can_cindent = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6952 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6953 #ifdef FEAT_COMMENTS
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6954 end_comment_pending = NUL; /* After BS, don't auto-end comment */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6955 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6956 #ifdef FEAT_RIGHTLEFT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6957 if (revins_on) /* put cursor after last inserted char */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6958 inc_cursor();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6959 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6960
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6961 #ifdef FEAT_VIRTUALEDIT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6962 /* Virtualedit:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6963 * BACKSPACE_CHAR eats a virtual space
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6964 * BACKSPACE_WORD eats all coladd
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6965 * BACKSPACE_LINE eats all coladd and keeps going
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6966 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6967 if (curwin->w_cursor.coladd > 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6968 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6969 if (mode == BACKSPACE_CHAR)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6970 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6971 --curwin->w_cursor.coladd;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6972 return TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6973 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6974 if (mode == BACKSPACE_WORD)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6975 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6976 curwin->w_cursor.coladd = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6977 return TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6978 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6979 curwin->w_cursor.coladd = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6980 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6981 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6982
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6983 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6984 * delete newline!
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6985 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6986 if (curwin->w_cursor.col == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6987 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6988 lnum = Insstart.lnum;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6989 if (curwin->w_cursor.lnum == Insstart.lnum
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6990 #ifdef FEAT_RIGHTLEFT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6991 || revins_on
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6992 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6993 )
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6994 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6995 if (u_save((linenr_T)(curwin->w_cursor.lnum - 2),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6996 (linenr_T)(curwin->w_cursor.lnum + 1)) == FAIL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6997 return FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6998 --Insstart.lnum;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6999 Insstart.col = MAXCOL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7000 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7001 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7002 * In replace mode:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7003 * cc < 0: NL was inserted, delete it
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7004 * cc >= 0: NL was replaced, put original characters back
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7005 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7006 cc = -1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7007 if (State & REPLACE_FLAG)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7008 cc = replace_pop(); /* returns -1 if NL was inserted */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7009 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7010 * In replace mode, in the line we started replacing, we only move the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7011 * cursor.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7012 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7013 if ((State & REPLACE_FLAG) && curwin->w_cursor.lnum <= lnum)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7014 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7015 dec_cursor();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7016 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7017 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7018 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7019 #ifdef FEAT_VREPLACE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7020 if (!(State & VREPLACE_FLAG)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7021 || curwin->w_cursor.lnum > orig_line_count)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7022 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7023 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7024 temp = gchar_cursor(); /* remember current char */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7025 --curwin->w_cursor.lnum;
278
a7e59720a155 updated for version 7.0074
vimboss
parents: 274
diff changeset
7026
a7e59720a155 updated for version 7.0074
vimboss
parents: 274
diff changeset
7027 /* When "aw" is in 'formatoptions' we must delete the space at
a7e59720a155 updated for version 7.0074
vimboss
parents: 274
diff changeset
7028 * the end of the line, otherwise the line will be broken
a7e59720a155 updated for version 7.0074
vimboss
parents: 274
diff changeset
7029 * again when auto-formatting. */
a7e59720a155 updated for version 7.0074
vimboss
parents: 274
diff changeset
7030 if (has_format_option(FO_AUTO)
a7e59720a155 updated for version 7.0074
vimboss
parents: 274
diff changeset
7031 && has_format_option(FO_WHITE_PAR))
a7e59720a155 updated for version 7.0074
vimboss
parents: 274
diff changeset
7032 {
a7e59720a155 updated for version 7.0074
vimboss
parents: 274
diff changeset
7033 char_u *ptr = ml_get_buf(curbuf, curwin->w_cursor.lnum,
a7e59720a155 updated for version 7.0074
vimboss
parents: 274
diff changeset
7034 TRUE);
a7e59720a155 updated for version 7.0074
vimboss
parents: 274
diff changeset
7035 int len;
a7e59720a155 updated for version 7.0074
vimboss
parents: 274
diff changeset
7036
a7e59720a155 updated for version 7.0074
vimboss
parents: 274
diff changeset
7037 len = STRLEN(ptr);
a7e59720a155 updated for version 7.0074
vimboss
parents: 274
diff changeset
7038 if (len > 0 && ptr[len - 1] == ' ')
a7e59720a155 updated for version 7.0074
vimboss
parents: 274
diff changeset
7039 ptr[len - 1] = NUL;
a7e59720a155 updated for version 7.0074
vimboss
parents: 274
diff changeset
7040 }
a7e59720a155 updated for version 7.0074
vimboss
parents: 274
diff changeset
7041
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7042 (void)do_join(FALSE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7043 if (temp == NUL && gchar_cursor() != NUL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7044 inc_cursor();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7045 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7046 #ifdef FEAT_VREPLACE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7047 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7048 dec_cursor();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7049 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7050
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7051 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7052 * In REPLACE mode we have to put back the text that was replaced
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7053 * by the NL. On the replace stack is first a NUL-terminated
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7054 * sequence of characters that were deleted and then the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7055 * characters that NL replaced.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7056 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7057 if (State & REPLACE_FLAG)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7058 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7059 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7060 * Do the next ins_char() in NORMAL state, to
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7061 * prevent ins_char() from replacing characters and
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7062 * avoiding showmatch().
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7063 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7064 oldState = State;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7065 State = NORMAL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7066 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7067 * restore characters (blanks) deleted after cursor
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7068 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7069 while (cc > 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7070 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7071 temp = curwin->w_cursor.col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7072 #ifdef FEAT_MBYTE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7073 mb_replace_pop_ins(cc);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7074 #else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7075 ins_char(cc);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7076 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7077 curwin->w_cursor.col = temp;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7078 cc = replace_pop();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7079 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7080 /* restore the characters that NL replaced */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7081 replace_pop_ins();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7082 State = oldState;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7083 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7084 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7085 did_ai = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7086 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7087 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7088 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7089 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7090 * Delete character(s) before the cursor.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7091 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7092 #ifdef FEAT_RIGHTLEFT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7093 if (revins_on) /* put cursor on last inserted char */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7094 dec_cursor();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7095 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7096 mincol = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7097 /* keep indent */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7098 if (mode == BACKSPACE_LINE && curbuf->b_p_ai
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7099 #ifdef FEAT_RIGHTLEFT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7100 && !revins_on
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7101 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7102 )
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7103 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7104 temp = curwin->w_cursor.col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7105 beginline(BL_WHITE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7106 if (curwin->w_cursor.col < (colnr_T)temp)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7107 mincol = curwin->w_cursor.col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7108 curwin->w_cursor.col = temp;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7109 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7110
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7111 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7112 * Handle deleting one 'shiftwidth' or 'softtabstop'.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7113 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7114 if ( mode == BACKSPACE_CHAR
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7115 && ((p_sta && in_indent)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7116 || (curbuf->b_p_sts
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7117 && (*(ml_get_cursor() - 1) == TAB
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7118 || (*(ml_get_cursor() - 1) == ' '
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7119 && (!*inserted_space_p
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7120 || arrow_used))))))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7121 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7122 int ts;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7123 colnr_T vcol;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7124 colnr_T want_vcol;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7125 int extra = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7126
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7127 *inserted_space_p = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7128 if (p_sta)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7129 ts = curbuf->b_p_sw;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7130 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7131 ts = curbuf->b_p_sts;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7132 /* Compute the virtual column where we want to be. Since
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7133 * 'showbreak' may get in the way, need to get the last column of
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7134 * the previous character. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7135 getvcol(curwin, &curwin->w_cursor, &vcol, NULL, NULL);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7136 dec_cursor();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7137 getvcol(curwin, &curwin->w_cursor, NULL, NULL, &want_vcol);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7138 inc_cursor();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7139 want_vcol = (want_vcol / ts) * ts;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7140
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7141 /* delete characters until we are at or before want_vcol */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7142 while (vcol > want_vcol
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7143 && (cc = *(ml_get_cursor() - 1), vim_iswhite(cc)))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7144 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7145 dec_cursor();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7146 getvcol(curwin, &curwin->w_cursor, &vcol, NULL, NULL);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7147 if (State & REPLACE_FLAG)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7148 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7149 /* Don't delete characters before the insert point when in
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7150 * Replace mode */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7151 if (curwin->w_cursor.lnum != Insstart.lnum
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7152 || curwin->w_cursor.col >= Insstart.col)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7153 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7154 #if 0 /* what was this for? It causes problems when sw != ts. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7155 if (State == REPLACE && (int)vcol < want_vcol)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7156 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7157 (void)del_char(FALSE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7158 extra = 2; /* don't pop too much */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7159 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7160 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7161 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7162 replace_do_bs();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7163 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7164 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7165 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7166 (void)del_char(FALSE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7167 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7168
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7169 /* insert extra spaces until we are at want_vcol */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7170 while (vcol < want_vcol)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7171 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7172 /* Remember the first char we inserted */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7173 if (curwin->w_cursor.lnum == Insstart.lnum
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7174 && curwin->w_cursor.col < Insstart.col)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7175 Insstart.col = curwin->w_cursor.col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7176
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7177 #ifdef FEAT_VREPLACE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7178 if (State & VREPLACE_FLAG)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7179 ins_char(' ');
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7180 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7181 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7182 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7183 ins_str((char_u *)" ");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7184 if ((State & REPLACE_FLAG) && extra <= 1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7185 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7186 if (extra)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7187 replace_push_off(NUL);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7188 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7189 replace_push(NUL);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7190 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7191 if (extra == 2)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7192 extra = 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7193 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7194 getvcol(curwin, &curwin->w_cursor, &vcol, NULL, NULL);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7195 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7196 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7197
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7198 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7199 * Delete upto starting point, start of line or previous word.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7200 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7201 else do
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7202 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7203 #ifdef FEAT_RIGHTLEFT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7204 if (!revins_on) /* put cursor on char to be deleted */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7205 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7206 dec_cursor();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7207
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7208 /* start of word? */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7209 if (mode == BACKSPACE_WORD && !vim_isspace(gchar_cursor()))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7210 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7211 mode = BACKSPACE_WORD_NOT_SPACE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7212 temp = vim_iswordc(gchar_cursor());
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7213 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7214 /* end of word? */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7215 else if (mode == BACKSPACE_WORD_NOT_SPACE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7216 && (vim_isspace(cc = gchar_cursor())
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7217 || vim_iswordc(cc) != temp))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7218 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7219 #ifdef FEAT_RIGHTLEFT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7220 if (!revins_on)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7221 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7222 inc_cursor();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7223 #ifdef FEAT_RIGHTLEFT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7224 else if (State & REPLACE_FLAG)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7225 dec_cursor();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7226 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7227 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7228 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7229 if (State & REPLACE_FLAG)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7230 replace_do_bs();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7231 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7232 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7233 #ifdef FEAT_MBYTE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7234 if (enc_utf8 && p_deco)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7235 (void)utfc_ptr2char(ml_get_cursor(), &p1, &p2);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7236 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7237 (void)del_char(FALSE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7238 #ifdef FEAT_MBYTE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7239 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7240 * If p1 or p2 is non-zero, there are combining characters we
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7241 * need to take account of. Don't back up before the base
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7242 * character.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7243 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7244 if (enc_utf8 && p_deco && (p1 != NUL || p2 != NUL))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7245 inc_cursor();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7246 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7247 #ifdef FEAT_RIGHTLEFT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7248 if (revins_chars)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7249 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7250 revins_chars--;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7251 revins_legal++;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7252 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7253 if (revins_on && gchar_cursor() == NUL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7254 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7255 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7256 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7257 /* Just a single backspace?: */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7258 if (mode == BACKSPACE_CHAR)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7259 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7260 } while (
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7261 #ifdef FEAT_RIGHTLEFT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7262 revins_on ||
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7263 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7264 (curwin->w_cursor.col > mincol
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7265 && (curwin->w_cursor.lnum != Insstart.lnum
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7266 || curwin->w_cursor.col != Insstart.col)));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7267 did_backspace = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7268 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7269 #ifdef FEAT_SMARTINDENT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7270 did_si = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7271 can_si = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7272 can_si_back = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7273 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7274 if (curwin->w_cursor.col <= 1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7275 did_ai = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7276 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7277 * It's a little strange to put backspaces into the redo
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7278 * buffer, but it makes auto-indent a lot easier to deal
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7279 * with.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7280 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7281 AppendCharToRedobuff(c);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7282
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7283 /* If deleted before the insertion point, adjust it */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7284 if (curwin->w_cursor.lnum == Insstart.lnum
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7285 && curwin->w_cursor.col < Insstart.col)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7286 Insstart.col = curwin->w_cursor.col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7287
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7288 /* vi behaviour: the cursor moves backward but the character that
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7289 * was there remains visible
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7290 * Vim behaviour: the cursor moves backward and the character that
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7291 * was there is erased from the screen.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7292 * We can emulate the vi behaviour by pretending there is a dollar
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7293 * displayed even when there isn't.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7294 * --pkv Sun Jan 19 01:56:40 EST 2003 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7295 if (vim_strchr(p_cpo, CPO_BACKSPACE) != NULL && dollar_vcol == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7296 dollar_vcol = curwin->w_virtcol;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7297
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7298 return did_backspace;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7299 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7300
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7301 #ifdef FEAT_MOUSE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7302 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7303 ins_mouse(c)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7304 int c;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7305 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7306 pos_T tpos;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7307
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7308 # ifdef FEAT_GUI
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7309 /* When GUI is active, also move/paste when 'mouse' is empty */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7310 if (!gui.in_use)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7311 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7312 if (!mouse_has(MOUSE_INSERT))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7313 return;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7314
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7315 undisplay_dollar();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7316 tpos = curwin->w_cursor;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7317 if (do_mouse(NULL, c, BACKWARD, 1L, 0))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7318 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7319 start_arrow(&tpos);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7320 # ifdef FEAT_CINDENT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7321 can_cindent = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7322 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7323 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7324
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7325 #ifdef FEAT_WINDOWS
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7326 /* redraw status lines (in case another window became active) */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7327 redraw_statuslines();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7328 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7329 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7330
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7331 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7332 ins_mousescroll(up)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7333 int up;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7334 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7335 pos_T tpos;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7336 # if defined(FEAT_GUI) && defined(FEAT_WINDOWS)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7337 win_T *old_curwin;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7338 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7339
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7340 tpos = curwin->w_cursor;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7341
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7342 # if defined(FEAT_GUI) && defined(FEAT_WINDOWS)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7343 old_curwin = curwin;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7344
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7345 /* Currently the mouse coordinates are only known in the GUI. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7346 if (gui.in_use && mouse_row >= 0 && mouse_col >= 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7347 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7348 int row, col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7349
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7350 row = mouse_row;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7351 col = mouse_col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7352
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7353 /* find the window at the pointer coordinates */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7354 curwin = mouse_find_win(&row, &col);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7355 curbuf = curwin->w_buffer;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7356 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7357 if (curwin == old_curwin)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7358 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7359 undisplay_dollar();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7360
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7361 if (mod_mask & (MOD_MASK_SHIFT | MOD_MASK_CTRL))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7362 scroll_redraw(up, (long)(curwin->w_botline - curwin->w_topline));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7363 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7364 scroll_redraw(up, 3L);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7365
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7366 # if defined(FEAT_GUI) && defined(FEAT_WINDOWS)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7367 curwin->w_redr_status = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7368
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7369 curwin = old_curwin;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7370 curbuf = curwin->w_buffer;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7371 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7372
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7373 if (!equalpos(curwin->w_cursor, tpos))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7374 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7375 start_arrow(&tpos);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7376 # ifdef FEAT_CINDENT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7377 can_cindent = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7378 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7379 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7380 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7381 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7382
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7383 #ifdef FEAT_GUI
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7384 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7385 ins_scroll()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7386 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7387 pos_T tpos;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7388
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7389 undisplay_dollar();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7390 tpos = curwin->w_cursor;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7391 if (gui_do_scroll())
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7392 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7393 start_arrow(&tpos);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7394 # ifdef FEAT_CINDENT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7395 can_cindent = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7396 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7397 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7398 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7399
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7400 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7401 ins_horscroll()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7402 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7403 pos_T tpos;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7404
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7405 undisplay_dollar();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7406 tpos = curwin->w_cursor;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7407 if (gui_do_horiz_scroll())
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7408 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7409 start_arrow(&tpos);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7410 # ifdef FEAT_CINDENT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7411 can_cindent = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7412 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7413 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7414 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7415 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7416
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7417 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7418 ins_left()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7419 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7420 pos_T tpos;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7421
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7422 #ifdef FEAT_FOLDING
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7423 if ((fdo_flags & FDO_HOR) && KeyTyped)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7424 foldOpenCursor();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7425 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7426 undisplay_dollar();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7427 tpos = curwin->w_cursor;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7428 if (oneleft() == OK)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7429 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7430 start_arrow(&tpos);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7431 #ifdef FEAT_RIGHTLEFT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7432 /* If exit reversed string, position is fixed */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7433 if (revins_scol != -1 && (int)curwin->w_cursor.col >= revins_scol)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7434 revins_legal++;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7435 revins_chars++;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7436 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7437 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7438
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7439 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7440 * if 'whichwrap' set for cursor in insert mode may go to
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7441 * previous line
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7442 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7443 else if (vim_strchr(p_ww, '[') != NULL && curwin->w_cursor.lnum > 1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7444 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7445 start_arrow(&tpos);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7446 --(curwin->w_cursor.lnum);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7447 coladvance((colnr_T)MAXCOL);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7448 curwin->w_set_curswant = TRUE; /* so we stay at the end */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7449 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7450 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7451 vim_beep();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7452 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7453
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7454 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7455 ins_home(c)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7456 int c;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7457 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7458 pos_T tpos;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7459
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7460 #ifdef FEAT_FOLDING
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7461 if ((fdo_flags & FDO_HOR) && KeyTyped)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7462 foldOpenCursor();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7463 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7464 undisplay_dollar();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7465 tpos = curwin->w_cursor;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7466 if (c == K_C_HOME)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7467 curwin->w_cursor.lnum = 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7468 curwin->w_cursor.col = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7469 #ifdef FEAT_VIRTUALEDIT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7470 curwin->w_cursor.coladd = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7471 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7472 curwin->w_curswant = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7473 start_arrow(&tpos);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7474 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7475
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7476 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7477 ins_end(c)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7478 int c;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7479 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7480 pos_T tpos;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7481
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7482 #ifdef FEAT_FOLDING
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7483 if ((fdo_flags & FDO_HOR) && KeyTyped)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7484 foldOpenCursor();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7485 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7486 undisplay_dollar();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7487 tpos = curwin->w_cursor;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7488 if (c == K_C_END)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7489 curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7490 coladvance((colnr_T)MAXCOL);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7491 curwin->w_curswant = MAXCOL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7492
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7493 start_arrow(&tpos);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7494 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7495
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7496 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7497 ins_s_left()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7498 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7499 #ifdef FEAT_FOLDING
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7500 if ((fdo_flags & FDO_HOR) && KeyTyped)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7501 foldOpenCursor();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7502 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7503 undisplay_dollar();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7504 if (curwin->w_cursor.lnum > 1 || curwin->w_cursor.col > 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7505 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7506 start_arrow(&curwin->w_cursor);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7507 (void)bck_word(1L, FALSE, FALSE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7508 curwin->w_set_curswant = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7509 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7510 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7511 vim_beep();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7512 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7513
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7514 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7515 ins_right()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7516 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7517 #ifdef FEAT_FOLDING
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7518 if ((fdo_flags & FDO_HOR) && KeyTyped)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7519 foldOpenCursor();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7520 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7521 undisplay_dollar();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7522 if (gchar_cursor() != NUL || virtual_active()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7523 )
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7524 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7525 start_arrow(&curwin->w_cursor);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7526 curwin->w_set_curswant = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7527 #ifdef FEAT_VIRTUALEDIT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7528 if (virtual_active())
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7529 oneright();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7530 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7531 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7532 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7533 #ifdef FEAT_MBYTE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7534 if (has_mbyte)
474
a5fcf36ef512 updated for version 7.0127
vimboss
parents: 470
diff changeset
7535 curwin->w_cursor.col += (*mb_ptr2len)(ml_get_cursor());
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7536 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7537 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7538 ++curwin->w_cursor.col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7539 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7540
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7541 #ifdef FEAT_RIGHTLEFT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7542 revins_legal++;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7543 if (revins_chars)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7544 revins_chars--;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7545 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7546 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7547 /* if 'whichwrap' set for cursor in insert mode, may move the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7548 * cursor to the next line */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7549 else if (vim_strchr(p_ww, ']') != NULL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7550 && curwin->w_cursor.lnum < curbuf->b_ml.ml_line_count)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7551 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7552 start_arrow(&curwin->w_cursor);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7553 curwin->w_set_curswant = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7554 ++curwin->w_cursor.lnum;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7555 curwin->w_cursor.col = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7556 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7557 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7558 vim_beep();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7559 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7560
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7561 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7562 ins_s_right()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7563 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7564 #ifdef FEAT_FOLDING
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7565 if ((fdo_flags & FDO_HOR) && KeyTyped)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7566 foldOpenCursor();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7567 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7568 undisplay_dollar();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7569 if (curwin->w_cursor.lnum < curbuf->b_ml.ml_line_count
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7570 || gchar_cursor() != NUL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7571 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7572 start_arrow(&curwin->w_cursor);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7573 (void)fwd_word(1L, FALSE, 0);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7574 curwin->w_set_curswant = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7575 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7576 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7577 vim_beep();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7578 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7579
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7580 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7581 ins_up(startcol)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7582 int startcol; /* when TRUE move to Insstart.col */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7583 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7584 pos_T tpos;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7585 linenr_T old_topline = curwin->w_topline;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7586 #ifdef FEAT_DIFF
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7587 int old_topfill = curwin->w_topfill;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7588 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7589
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7590 undisplay_dollar();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7591 tpos = curwin->w_cursor;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7592 if (cursor_up(1L, TRUE) == OK)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7593 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7594 if (startcol)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7595 coladvance(getvcol_nolist(&Insstart));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7596 if (old_topline != curwin->w_topline
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7597 #ifdef FEAT_DIFF
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7598 || old_topfill != curwin->w_topfill
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7599 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7600 )
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7601 redraw_later(VALID);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7602 start_arrow(&tpos);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7603 #ifdef FEAT_CINDENT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7604 can_cindent = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7605 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7606 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7607 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7608 vim_beep();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7609 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7610
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7611 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7612 ins_pageup()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7613 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7614 pos_T tpos;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7615
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7616 undisplay_dollar();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7617 tpos = curwin->w_cursor;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7618 if (onepage(BACKWARD, 1L) == OK)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7619 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7620 start_arrow(&tpos);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7621 #ifdef FEAT_CINDENT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7622 can_cindent = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7623 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7624 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7625 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7626 vim_beep();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7627 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7628
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7629 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7630 ins_down(startcol)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7631 int startcol; /* when TRUE move to Insstart.col */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7632 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7633 pos_T tpos;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7634 linenr_T old_topline = curwin->w_topline;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7635 #ifdef FEAT_DIFF
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7636 int old_topfill = curwin->w_topfill;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7637 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7638
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7639 undisplay_dollar();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7640 tpos = curwin->w_cursor;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7641 if (cursor_down(1L, TRUE) == OK)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7642 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7643 if (startcol)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7644 coladvance(getvcol_nolist(&Insstart));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7645 if (old_topline != curwin->w_topline
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7646 #ifdef FEAT_DIFF
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7647 || old_topfill != curwin->w_topfill
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7648 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7649 )
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7650 redraw_later(VALID);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7651 start_arrow(&tpos);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7652 #ifdef FEAT_CINDENT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7653 can_cindent = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7654 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7655 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7656 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7657 vim_beep();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7658 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7659
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7660 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7661 ins_pagedown()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7662 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7663 pos_T tpos;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7664
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7665 undisplay_dollar();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7666 tpos = curwin->w_cursor;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7667 if (onepage(FORWARD, 1L) == OK)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7668 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7669 start_arrow(&tpos);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7670 #ifdef FEAT_CINDENT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7671 can_cindent = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7672 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7673 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7674 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7675 vim_beep();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7676 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7677
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7678 #ifdef FEAT_DND
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7679 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7680 ins_drop()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7681 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7682 do_put('~', BACKWARD, 1L, PUT_CURSEND);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7683 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7684 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7685
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7686 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7687 * Handle TAB in Insert or Replace mode.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7688 * Return TRUE when the TAB needs to be inserted like a normal character.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7689 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7690 static int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7691 ins_tab()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7692 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7693 int ind;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7694 int i;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7695 int temp;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7696
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7697 if (Insstart_blank_vcol == MAXCOL && curwin->w_cursor.lnum == Insstart.lnum)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7698 Insstart_blank_vcol = get_nolist_virtcol();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7699 if (echeck_abbr(TAB + ABBR_OFF))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7700 return FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7701
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7702 ind = inindent(0);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7703 #ifdef FEAT_CINDENT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7704 if (ind)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7705 can_cindent = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7706 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7707
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7708 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7709 * When nothing special, insert TAB like a normal character
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7710 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7711 if (!curbuf->b_p_et
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7712 && !(p_sta && ind && curbuf->b_p_ts != curbuf->b_p_sw)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7713 && curbuf->b_p_sts == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7714 return TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7715
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7716 if (stop_arrow() == FAIL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7717 return TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7718
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7719 did_ai = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7720 #ifdef FEAT_SMARTINDENT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7721 did_si = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7722 can_si = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7723 can_si_back = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7724 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7725 AppendToRedobuff((char_u *)"\t");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7726
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7727 if (p_sta && ind) /* insert tab in indent, use 'shiftwidth' */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7728 temp = (int)curbuf->b_p_sw;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7729 else if (curbuf->b_p_sts > 0) /* use 'softtabstop' when set */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7730 temp = (int)curbuf->b_p_sts;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7731 else /* otherwise use 'tabstop' */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7732 temp = (int)curbuf->b_p_ts;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7733 temp -= get_nolist_virtcol() % temp;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7734
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7735 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7736 * Insert the first space with ins_char(). It will delete one char in
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7737 * replace mode. Insert the rest with ins_str(); it will not delete any
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7738 * chars. For VREPLACE mode, we use ins_char() for all characters.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7739 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7740 ins_char(' ');
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7741 while (--temp > 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7742 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7743 #ifdef FEAT_VREPLACE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7744 if (State & VREPLACE_FLAG)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7745 ins_char(' ');
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7746 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7747 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7748 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7749 ins_str((char_u *)" ");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7750 if (State & REPLACE_FLAG) /* no char replaced */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7751 replace_push(NUL);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7752 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7753 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7754
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7755 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7756 * When 'expandtab' not set: Replace spaces by TABs where possible.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7757 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7758 if (!curbuf->b_p_et && (curbuf->b_p_sts || (p_sta && ind)))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7759 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7760 char_u *ptr;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7761 #ifdef FEAT_VREPLACE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7762 char_u *saved_line = NULL; /* init for GCC */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7763 pos_T pos;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7764 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7765 pos_T fpos;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7766 pos_T *cursor;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7767 colnr_T want_vcol, vcol;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7768 int change_col = -1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7769 int save_list = curwin->w_p_list;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7770
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7771 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7772 * Get the current line. For VREPLACE mode, don't make real changes
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7773 * yet, just work on a copy of the line.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7774 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7775 #ifdef FEAT_VREPLACE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7776 if (State & VREPLACE_FLAG)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7777 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7778 pos = curwin->w_cursor;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7779 cursor = &pos;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7780 saved_line = vim_strsave(ml_get_curline());
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7781 if (saved_line == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7782 return FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7783 ptr = saved_line + pos.col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7784 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7785 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7786 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7787 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7788 ptr = ml_get_cursor();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7789 cursor = &curwin->w_cursor;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7790 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7791
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7792 /* When 'L' is not in 'cpoptions' a tab always takes up 'ts' spaces. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7793 if (vim_strchr(p_cpo, CPO_LISTWM) == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7794 curwin->w_p_list = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7795
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7796 /* Find first white before the cursor */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7797 fpos = curwin->w_cursor;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7798 while (fpos.col > 0 && vim_iswhite(ptr[-1]))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7799 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7800 --fpos.col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7801 --ptr;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7802 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7803
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7804 /* In Replace mode, don't change characters before the insert point. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7805 if ((State & REPLACE_FLAG)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7806 && fpos.lnum == Insstart.lnum
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7807 && fpos.col < Insstart.col)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7808 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7809 ptr += Insstart.col - fpos.col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7810 fpos.col = Insstart.col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7811 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7812
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7813 /* compute virtual column numbers of first white and cursor */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7814 getvcol(curwin, &fpos, &vcol, NULL, NULL);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7815 getvcol(curwin, cursor, &want_vcol, NULL, NULL);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7816
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7817 /* Use as many TABs as possible. Beware of 'showbreak' and
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7818 * 'linebreak' adding extra virtual columns. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7819 while (vim_iswhite(*ptr))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7820 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7821 i = lbr_chartabsize((char_u *)"\t", vcol);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7822 if (vcol + i > want_vcol)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7823 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7824 if (*ptr != TAB)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7825 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7826 *ptr = TAB;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7827 if (change_col < 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7828 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7829 change_col = fpos.col; /* Column of first change */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7830 /* May have to adjust Insstart */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7831 if (fpos.lnum == Insstart.lnum && fpos.col < Insstart.col)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7832 Insstart.col = fpos.col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7833 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7834 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7835 ++fpos.col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7836 ++ptr;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7837 vcol += i;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7838 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7839
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7840 if (change_col >= 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7841 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7842 int repl_off = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7843
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7844 /* Skip over the spaces we need. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7845 while (vcol < want_vcol && *ptr == ' ')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7846 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7847 vcol += lbr_chartabsize(ptr, vcol);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7848 ++ptr;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7849 ++repl_off;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7850 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7851 if (vcol > want_vcol)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7852 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7853 /* Must have a char with 'showbreak' just before it. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7854 --ptr;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7855 --repl_off;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7856 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7857 fpos.col += repl_off;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7858
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7859 /* Delete following spaces. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7860 i = cursor->col - fpos.col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7861 if (i > 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7862 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7863 mch_memmove(ptr, ptr + i, STRLEN(ptr + i) + 1);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7864 /* correct replace stack. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7865 if ((State & REPLACE_FLAG)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7866 #ifdef FEAT_VREPLACE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7867 && !(State & VREPLACE_FLAG)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7868 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7869 )
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7870 for (temp = i; --temp >= 0; )
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7871 replace_join(repl_off);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7872 }
33
f6033dcbaf31 updated for version 7.0020
vimboss
parents: 20
diff changeset
7873 #ifdef FEAT_NETBEANS_INTG
f6033dcbaf31 updated for version 7.0020
vimboss
parents: 20
diff changeset
7874 if (usingNetbeans)
f6033dcbaf31 updated for version 7.0020
vimboss
parents: 20
diff changeset
7875 {
f6033dcbaf31 updated for version 7.0020
vimboss
parents: 20
diff changeset
7876 netbeans_removed(curbuf, fpos.lnum, cursor->col,
f6033dcbaf31 updated for version 7.0020
vimboss
parents: 20
diff changeset
7877 (long)(i + 1));
f6033dcbaf31 updated for version 7.0020
vimboss
parents: 20
diff changeset
7878 netbeans_inserted(curbuf, fpos.lnum, cursor->col,
f6033dcbaf31 updated for version 7.0020
vimboss
parents: 20
diff changeset
7879 (char_u *)"\t", 1);
f6033dcbaf31 updated for version 7.0020
vimboss
parents: 20
diff changeset
7880 }
f6033dcbaf31 updated for version 7.0020
vimboss
parents: 20
diff changeset
7881 #endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7882 cursor->col -= i;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7883
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7884 #ifdef FEAT_VREPLACE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7885 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7886 * In VREPLACE mode, we haven't changed anything yet. Do it now by
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7887 * backspacing over the changed spacing and then inserting the new
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7888 * spacing.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7889 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7890 if (State & VREPLACE_FLAG)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7891 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7892 /* Backspace from real cursor to change_col */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7893 backspace_until_column(change_col);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7894
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7895 /* Insert each char in saved_line from changed_col to
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7896 * ptr-cursor */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7897 ins_bytes_len(saved_line + change_col,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7898 cursor->col - change_col);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7899 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7900 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7901 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7902
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7903 #ifdef FEAT_VREPLACE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7904 if (State & VREPLACE_FLAG)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7905 vim_free(saved_line);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7906 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7907 curwin->w_p_list = save_list;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7908 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7909
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7910 return FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7911 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7912
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7913 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7914 * Handle CR or NL in insert mode.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7915 * Return TRUE when out of memory or can't undo.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7916 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7917 static int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7918 ins_eol(c)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7919 int c;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7920 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7921 int i;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7922
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7923 if (echeck_abbr(c + ABBR_OFF))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7924 return FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7925 if (stop_arrow() == FAIL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7926 return TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7927 undisplay_dollar();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7928
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7929 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7930 * Strange Vi behaviour: In Replace mode, typing a NL will not delete the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7931 * character under the cursor. Only push a NUL on the replace stack,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7932 * nothing to put back when the NL is deleted.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7933 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7934 if ((State & REPLACE_FLAG)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7935 #ifdef FEAT_VREPLACE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7936 && !(State & VREPLACE_FLAG)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7937 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7938 )
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7939 replace_push(NUL);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7940
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7941 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7942 * In VREPLACE mode, a NL replaces the rest of the line, and starts
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7943 * replacing the next line, so we push all of the characters left on the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7944 * line onto the replace stack. This is not done here though, it is done
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7945 * in open_line().
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7946 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7947
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7948 #ifdef FEAT_RIGHTLEFT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7949 # ifdef FEAT_FKMAP
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7950 if (p_altkeymap && p_fkmap)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7951 fkmap(NL);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7952 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7953 /* NL in reverse insert will always start in the end of
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7954 * current line. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7955 if (revins_on)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7956 curwin->w_cursor.col += (colnr_T)STRLEN(ml_get_cursor());
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7957 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7958
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7959 AppendToRedobuff(NL_STR);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7960 i = open_line(FORWARD,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7961 #ifdef FEAT_COMMENTS
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7962 has_format_option(FO_RET_COMS) ? OPENLINE_DO_COM :
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7963 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7964 0, old_indent);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7965 old_indent = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7966 #ifdef FEAT_CINDENT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7967 can_cindent = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7968 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7969
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7970 return (!i);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7971 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7972
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7973 #ifdef FEAT_DIGRAPHS
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7974 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7975 * Handle digraph in insert mode.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7976 * Returns character still to be inserted, or NUL when nothing remaining to be
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7977 * done.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7978 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7979 static int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7980 ins_digraph()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7981 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7982 int c;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7983 int cc;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7984
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7985 pc_status = PC_STATUS_UNSET;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7986 if (redrawing() && !char_avail())
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7987 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7988 /* may need to redraw when no more chars available now */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7989 ins_redraw();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7990
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7991 edit_putchar('?', TRUE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7992 #ifdef FEAT_CMDL_INFO
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7993 add_to_showcmd_c(Ctrl_K);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7994 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7995 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7996
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7997 #ifdef USE_ON_FLY_SCROLL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7998 dont_scroll = TRUE; /* disallow scrolling here */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7999 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8000
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8001 /* don't map the digraph chars. This also prevents the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8002 * mode message to be deleted when ESC is hit */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8003 ++no_mapping;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8004 ++allow_keys;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8005 c = safe_vgetc();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8006 --no_mapping;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8007 --allow_keys;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8008 if (IS_SPECIAL(c) || mod_mask) /* special key */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8009 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8010 #ifdef FEAT_CMDL_INFO
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8011 clear_showcmd();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8012 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8013 insert_special(c, TRUE, FALSE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8014 return NUL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8015 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8016 if (c != ESC)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8017 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8018 if (redrawing() && !char_avail())
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8019 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8020 /* may need to redraw when no more chars available now */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8021 ins_redraw();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8022
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8023 if (char2cells(c) == 1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8024 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8025 /* first remove the '?', otherwise it's restored when typing
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8026 * an ESC next */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8027 edit_unputchar();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8028 ins_redraw();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8029 edit_putchar(c, TRUE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8030 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8031 #ifdef FEAT_CMDL_INFO
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8032 add_to_showcmd_c(c);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8033 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8034 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8035 ++no_mapping;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8036 ++allow_keys;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8037 cc = safe_vgetc();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8038 --no_mapping;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8039 --allow_keys;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8040 if (cc != ESC)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8041 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8042 AppendToRedobuff((char_u *)CTRL_V_STR);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8043 c = getdigraph(c, cc, TRUE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8044 #ifdef FEAT_CMDL_INFO
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8045 clear_showcmd();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8046 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8047 return c;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8048 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8049 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8050 edit_unputchar();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8051 #ifdef FEAT_CMDL_INFO
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8052 clear_showcmd();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8053 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8054 return NUL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8055 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8056 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8057
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8058 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8059 * Handle CTRL-E and CTRL-Y in Insert mode: copy char from other line.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8060 * Returns the char to be inserted, or NUL if none found.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8061 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8062 static int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8063 ins_copychar(lnum)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8064 linenr_T lnum;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8065 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8066 int c;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8067 int temp;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8068 char_u *ptr, *prev_ptr;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8069
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8070 if (lnum < 1 || lnum > curbuf->b_ml.ml_line_count)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8071 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8072 vim_beep();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8073 return NUL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8074 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8075
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8076 /* try to advance to the cursor column */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8077 temp = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8078 ptr = ml_get(lnum);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8079 prev_ptr = ptr;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8080 validate_virtcol();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8081 while ((colnr_T)temp < curwin->w_virtcol && *ptr != NUL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8082 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8083 prev_ptr = ptr;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8084 temp += lbr_chartabsize_adv(&ptr, (colnr_T)temp);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8085 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8086 if ((colnr_T)temp > curwin->w_virtcol)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8087 ptr = prev_ptr;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8088
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8089 #ifdef FEAT_MBYTE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8090 c = (*mb_ptr2char)(ptr);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8091 #else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8092 c = *ptr;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8093 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8094 if (c == NUL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8095 vim_beep();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8096 return c;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8097 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8098
449
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
8099 /*
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
8100 * CTRL-Y or CTRL-E typed in Insert mode.
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
8101 */
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
8102 static int
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
8103 ins_ctrl_ey(tc)
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
8104 int tc;
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
8105 {
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
8106 int c = tc;
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
8107
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
8108 #ifdef FEAT_INS_EXPAND
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
8109 if (ctrl_x_mode == CTRL_X_SCROLL)
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
8110 {
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
8111 if (c == Ctrl_Y)
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
8112 scrolldown_clamp();
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
8113 else
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
8114 scrollup_clamp();
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
8115 redraw_later(VALID);
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
8116 }
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
8117 else
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
8118 #endif
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
8119 {
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
8120 c = ins_copychar(curwin->w_cursor.lnum + (c == Ctrl_Y ? -1 : 1));
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
8121 if (c != NUL)
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
8122 {
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
8123 long tw_save;
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
8124
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
8125 /* The character must be taken literally, insert like it
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
8126 * was typed after a CTRL-V, and pretend 'textwidth'
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
8127 * wasn't set. Digits, 'o' and 'x' are special after a
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
8128 * CTRL-V, don't use it for these. */
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
8129 if (c < 256 && !isalnum(c))
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
8130 AppendToRedobuff((char_u *)CTRL_V_STR); /* CTRL-V */
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
8131 tw_save = curbuf->b_p_tw;
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
8132 curbuf->b_p_tw = -1;
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
8133 insert_special(c, TRUE, FALSE);
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
8134 curbuf->b_p_tw = tw_save;
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
8135 #ifdef FEAT_RIGHTLEFT
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
8136 revins_chars++;
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
8137 revins_legal++;
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
8138 #endif
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
8139 c = Ctrl_V; /* pretend CTRL-V is last character */
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
8140 auto_format(FALSE, TRUE);
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
8141 }
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
8142 }
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
8143 return c;
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
8144 }
3709cf52b9b5 updated for version 7.0119
vimboss
parents: 431
diff changeset
8145
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8146 #ifdef FEAT_SMARTINDENT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8147 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8148 * Try to do some very smart auto-indenting.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8149 * Used when inserting a "normal" character.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8150 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8151 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8152 ins_try_si(c)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8153 int c;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8154 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8155 pos_T *pos, old_pos;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8156 char_u *ptr;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8157 int i;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8158 int temp;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8159
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8160 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8161 * do some very smart indenting when entering '{' or '}'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8162 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8163 if (((did_si || can_si_back) && c == '{') || (can_si && c == '}'))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8164 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8165 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8166 * for '}' set indent equal to indent of line containing matching '{'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8167 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8168 if (c == '}' && (pos = findmatch(NULL, '{')) != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8169 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8170 old_pos = curwin->w_cursor;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8171 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8172 * If the matching '{' has a ')' immediately before it (ignoring
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8173 * white-space), then line up with the start of the line
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8174 * containing the matching '(' if there is one. This handles the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8175 * case where an "if (..\n..) {" statement continues over multiple
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8176 * lines -- webb
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8177 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8178 ptr = ml_get(pos->lnum);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8179 i = pos->col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8180 if (i > 0) /* skip blanks before '{' */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8181 while (--i > 0 && vim_iswhite(ptr[i]))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8182 ;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8183 curwin->w_cursor.lnum = pos->lnum;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8184 curwin->w_cursor.col = i;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8185 if (ptr[i] == ')' && (pos = findmatch(NULL, '(')) != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8186 curwin->w_cursor = *pos;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8187 i = get_indent();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8188 curwin->w_cursor = old_pos;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8189 #ifdef FEAT_VREPLACE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8190 if (State & VREPLACE_FLAG)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8191 change_indent(INDENT_SET, i, FALSE, NUL);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8192 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8193 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8194 (void)set_indent(i, SIN_CHANGED);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8195 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8196 else if (curwin->w_cursor.col > 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8197 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8198 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8199 * when inserting '{' after "O" reduce indent, but not
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8200 * more than indent of previous line
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8201 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8202 temp = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8203 if (c == '{' && can_si_back && curwin->w_cursor.lnum > 1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8204 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8205 old_pos = curwin->w_cursor;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8206 i = get_indent();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8207 while (curwin->w_cursor.lnum > 1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8208 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8209 ptr = skipwhite(ml_get(--(curwin->w_cursor.lnum)));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8210
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8211 /* ignore empty lines and lines starting with '#'. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8212 if (*ptr != '#' && *ptr != NUL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8213 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8214 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8215 if (get_indent() >= i)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8216 temp = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8217 curwin->w_cursor = old_pos;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8218 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8219 if (temp)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8220 shift_line(TRUE, FALSE, 1);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8221 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8222 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8223
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8224 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8225 * set indent of '#' always to 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8226 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8227 if (curwin->w_cursor.col > 0 && can_si && c == '#')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8228 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8229 /* remember current indent for next line */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8230 old_indent = get_indent();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8231 (void)set_indent(0, SIN_CHANGED);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8232 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8233
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8234 /* Adjust ai_col, the char at this position can be deleted. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8235 if (ai_col > curwin->w_cursor.col)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8236 ai_col = curwin->w_cursor.col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8237 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8238 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8239
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8240 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8241 * Get the value that w_virtcol would have when 'list' is off.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8242 * Unless 'cpo' contains the 'L' flag.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8243 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8244 static colnr_T
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8245 get_nolist_virtcol()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8246 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8247 if (curwin->w_p_list && vim_strchr(p_cpo, CPO_LISTWM) == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8248 return getvcol_nolist(&curwin->w_cursor);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8249 validate_virtcol();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8250 return curwin->w_virtcol;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8251 }