annotate src/edit.c @ 51:8c25f10d49e7 v7.0028

updated for version 7.0028
author vimboss
date Sun, 02 Jan 2005 11:43:19 +0000
parents f529edb9bab3
children 388f285bda1b
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
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
34
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
35 #define CHECK_KEYS_TIME 30
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
36
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
37 #define CTRL_X_MSG(i) ctrl_x_msgs[(i) & ~CTRL_X_WANT_IDENT]
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
38
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
39 static char *ctrl_x_msgs[] =
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
40 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
41 N_(" Keyword completion (^N^P)"), /* ctrl_x_mode == 0, ^P/^N compl. */
12
bdeee1504ac1 updated for version 7.0004
vimboss
parents: 11
diff changeset
42 N_(" ^X mode (^E^Y^L^]^F^I^K^D^U^V^N^P)"),
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
43 /* Scroll has it's own msgs, in it's place there is the msg for local
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
44 * ctrl_x_mode = 0 (eg continue_status & CONT_LOCAL) -- Acevedo */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
45 N_(" Keyword Local completion (^N^P)"),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
46 N_(" Whole line completion (^L^N^P)"),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
47 N_(" File name completion (^F^N^P)"),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
48 N_(" Tag completion (^]^N^P)"),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
49 N_(" Path pattern completion (^N^P)"),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
50 N_(" Definition completion (^D^N^P)"),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
51 NULL,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
52 N_(" Dictionary completion (^K^N^P)"),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
53 N_(" Thesaurus completion (^T^N^P)"),
12
bdeee1504ac1 updated for version 7.0004
vimboss
parents: 11
diff changeset
54 N_(" Command-line completion (^V^N^P)"),
bdeee1504ac1 updated for version 7.0004
vimboss
parents: 11
diff changeset
55 N_(" User defined completion (^U^N^P)"),
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
56 };
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
57
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
58 static char_u e_hitend[] = N_("Hit end of paragraph");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
59
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
60 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
61 * Structure used to store one match for insert completion.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
62 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
63 struct Completion
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
64 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
65 struct Completion *next;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
66 struct Completion *prev;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
67 char_u *str; /* matched text */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
68 char_u *fname; /* file containing the match */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
69 int original; /* ORIGINAL_TEXT, CONT_S_IPOS or FREE_FNAME */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
70 int number; /* sequence number */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
71 };
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
72
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
73 /* the original text when the expansion begun */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
74 #define ORIGINAL_TEXT (1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
75 #define FREE_FNAME (2)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
76
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
77 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
78 * All the current matches are stored in a list.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
79 * "first_match" points to the start of the list.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
80 * "curr_match" points to the currently selected entry.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
81 * "shown_match" is different from curr_match during ins_compl_get_exp().
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
82 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
83 static struct Completion *first_match = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
84 static struct Completion *curr_match = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
85 static struct Completion *shown_match = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
86
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
87 static int started_completion = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
88 static int completion_matches = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
89 static char_u *complete_pat = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
90 static int complete_direction = FORWARD;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
91 static int shown_direction = FORWARD;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
92 static int completion_pending = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
93 static pos_T initial_pos;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
94 static colnr_T complete_col = 0; /* column where the text starts
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
95 that is being completed */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
96 static int save_sm;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
97 static char_u *original_text = NULL; /* text before completion */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
98 static int continue_mode = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
99 static expand_T complete_xp;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
100
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
101 static int ins_compl_add __ARGS((char_u *str, int len, char_u *, int dir, int reuse));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
102 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
103 static int ins_compl_make_cyclic __ARGS((void));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
104 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
105 static void ins_compl_free __ARGS((void));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
106 static void ins_compl_clear __ARGS((void));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
107 static void ins_compl_prep __ARGS((int c));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
108 static buf_T *ins_compl_next_buf __ARGS((buf_T *buf, int flag));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
109 static int ins_compl_get_exp __ARGS((pos_T *ini, int dir));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
110 static void ins_compl_delete __ARGS((void));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
111 static void ins_compl_insert __ARGS((void));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
112 static int ins_compl_next __ARGS((int allow_get_expansion));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
113 static int ins_complete __ARGS((int c));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
114 static int quote_meta __ARGS((char_u *dest, char_u *str, int len));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
115 #endif /* FEAT_INS_EXPAND */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
116
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
117 #define BACKSPACE_CHAR 1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
118 #define BACKSPACE_WORD 2
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
119 #define BACKSPACE_WORD_NOT_SPACE 3
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
120 #define BACKSPACE_LINE 4
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
121
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
122 static void ins_redraw __ARGS((void));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
123 static void ins_ctrl_v __ARGS((void));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
124 static void undisplay_dollar __ARGS((void));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
125 static void insert_special __ARGS((int, int, int));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
126 static void check_auto_format __ARGS((int));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
127 static void redo_literal __ARGS((int c));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
128 static void start_arrow __ARGS((pos_T *end_insert_pos));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
129 static void stop_insert __ARGS((pos_T *end_insert_pos, int esc));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
130 static int echeck_abbr __ARGS((int));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
131 static void replace_push_off __ARGS((int c));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
132 static int replace_pop __ARGS((void));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
133 static void replace_join __ARGS((int off));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
134 static void replace_pop_ins __ARGS((void));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
135 #ifdef FEAT_MBYTE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
136 static void mb_replace_pop_ins __ARGS((int cc));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
137 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
138 static void replace_flush __ARGS((void));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
139 static void replace_do_bs __ARGS((void));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
140 #ifdef FEAT_CINDENT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
141 static int cindent_on __ARGS((void));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
142 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
143 static void ins_reg __ARGS((void));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
144 static void ins_ctrl_g __ARGS((void));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
145 static int ins_esc __ARGS((long *count, int cmdchar));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
146 #ifdef FEAT_RIGHTLEFT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
147 static void ins_ctrl_ __ARGS((void));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
148 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
149 #ifdef FEAT_VISUAL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
150 static int ins_start_select __ARGS((int c));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
151 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
152 static void ins_shift __ARGS((int c, int lastc));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
153 static void ins_del __ARGS((void));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
154 static int ins_bs __ARGS((int c, int mode, int *inserted_space_p));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
155 #ifdef FEAT_MOUSE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
156 static void ins_mouse __ARGS((int c));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
157 static void ins_mousescroll __ARGS((int up));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
158 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
159 static void ins_left __ARGS((void));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
160 static void ins_home __ARGS((int c));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
161 static void ins_end __ARGS((int c));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
162 static void ins_s_left __ARGS((void));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
163 static void ins_right __ARGS((void));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
164 static void ins_s_right __ARGS((void));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
165 static void ins_up __ARGS((int startcol));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
166 static void ins_pageup __ARGS((void));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
167 static void ins_down __ARGS((int startcol));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
168 static void ins_pagedown __ARGS((void));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
169 #ifdef FEAT_DND
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
170 static void ins_drop __ARGS((void));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
171 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
172 static int ins_tab __ARGS((void));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
173 static int ins_eol __ARGS((int c));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
174 #ifdef FEAT_DIGRAPHS
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
175 static int ins_digraph __ARGS((void));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
176 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
177 static int ins_copychar __ARGS((linenr_T lnum));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
178 #ifdef FEAT_SMARTINDENT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
179 static void ins_try_si __ARGS((int c));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
180 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
181 static colnr_T get_nolist_virtcol __ARGS((void));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
182
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
183 static colnr_T Insstart_textlen; /* length of line when insert started */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
184 static colnr_T Insstart_blank_vcol; /* vcol for first inserted blank */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
185
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
186 static char_u *last_insert = NULL; /* the text of the previous insert,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
187 K_SPECIAL and CSI are escaped */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
188 static int last_insert_skip; /* nr of chars in front of previous insert */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
189 static int new_insert_skip; /* nr of chars in front of current insert */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
190
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
191 #ifdef FEAT_CINDENT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
192 static int can_cindent; /* may do cindenting on this line */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
193 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
194
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
195 static int old_indent = 0; /* for ^^D command in insert mode */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
196
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
197 #ifdef FEAT_RIGHTLEFT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
198 int revins_on; /* reverse insert mode on */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
199 int revins_chars; /* how much to skip after edit */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
200 int revins_legal; /* was the last char 'legal'? */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
201 int revins_scol; /* start column of revins session */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
202 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
203
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
204 #if defined(FEAT_MBYTE) && defined(MACOS_CLASSIC)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
205 static short previous_script = smRoman;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
206 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
207
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
208 static int ins_need_undo; /* call u_save() before inserting a
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
209 char. Set when edit() is called.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
210 after that arrow_used is used. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
211
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
212 static int did_add_space = FALSE; /* auto_format() added an extra space
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
213 under the cursor */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
214
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
215 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
216 * edit(): Start inserting text.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
217 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
218 * "cmdchar" can be:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
219 * 'i' normal insert command
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
220 * 'a' normal append command
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
221 * 'R' replace command
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
222 * 'r' "r<CR>" command: insert one <CR>. Note: count can be > 1, for redo,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
223 * but still only one <CR> is inserted. The <Esc> is not used for redo.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
224 * 'g' "gI" command.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
225 * 'V' "gR" command for Virtual Replace mode.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
226 * 'v' "gr" command for single character Virtual Replace mode.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
227 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
228 * This function is not called recursively. For CTRL-O commands, it returns
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
229 * and lets the caller handle the Normal-mode command.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
230 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
231 * Return TRUE if a CTRL-O command caused the return (insert mode pending).
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
232 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
233 int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
234 edit(cmdchar, startln, count)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
235 int cmdchar;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
236 int startln; /* if set, insert at start of line */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
237 long count;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
238 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
239 int c = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
240 char_u *ptr;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
241 int lastc;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
242 colnr_T mincol;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
243 static linenr_T o_lnum = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
244 static int o_eol = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
245 int i;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
246 int did_backspace = TRUE; /* previous char was backspace */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
247 #ifdef FEAT_CINDENT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
248 int line_is_white = FALSE; /* line is empty before insert */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
249 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
250 linenr_T old_topline = 0; /* topline before insertion */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
251 #ifdef FEAT_DIFF
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
252 int old_topfill = -1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
253 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
254 int inserted_space = FALSE; /* just inserted a space */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
255 int replaceState = REPLACE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
256 int did_restart_edit = restart_edit;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
257
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
258 /* sleep before redrawing, needed for "CTRL-O :" that results in an
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
259 * error message */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
260 check_for_delay(TRUE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
261
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
262 #ifdef HAVE_SANDBOX
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
263 /* Don't allow inserting in the sandbox. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
264 if (sandbox != 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
265 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
266 EMSG(_(e_sandbox));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
267 return FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
268 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
269 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
270
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
271 #ifdef FEAT_INS_EXPAND
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
272 ins_compl_clear(); /* clear stuff for CTRL-X mode */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
273 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
274
11
4424b47a0797 updated for version 7.0003
vimboss
parents: 10
diff changeset
275 #ifdef FEAT_AUTOCMD
4424b47a0797 updated for version 7.0003
vimboss
parents: 10
diff changeset
276 /*
4424b47a0797 updated for version 7.0003
vimboss
parents: 10
diff changeset
277 * Trigger InsertEnter autocommands. Do not do this for "r<CR>" or "grx".
4424b47a0797 updated for version 7.0003
vimboss
parents: 10
diff changeset
278 */
4424b47a0797 updated for version 7.0003
vimboss
parents: 10
diff changeset
279 if (cmdchar != 'r' && cmdchar != 'v')
4424b47a0797 updated for version 7.0003
vimboss
parents: 10
diff changeset
280 {
4424b47a0797 updated for version 7.0003
vimboss
parents: 10
diff changeset
281 if (cmdchar == 'R')
4424b47a0797 updated for version 7.0003
vimboss
parents: 10
diff changeset
282 ptr = (char_u *)"r";
4424b47a0797 updated for version 7.0003
vimboss
parents: 10
diff changeset
283 else if (cmdchar == 'V')
4424b47a0797 updated for version 7.0003
vimboss
parents: 10
diff changeset
284 ptr = (char_u *)"v";
4424b47a0797 updated for version 7.0003
vimboss
parents: 10
diff changeset
285 else
4424b47a0797 updated for version 7.0003
vimboss
parents: 10
diff changeset
286 ptr = (char_u *)"i";
4424b47a0797 updated for version 7.0003
vimboss
parents: 10
diff changeset
287 set_vim_var_string(VV_INSERTMODE, ptr, 1);
4424b47a0797 updated for version 7.0003
vimboss
parents: 10
diff changeset
288 apply_autocmds(EVENT_INSERTENTER, NULL, NULL, FALSE, curbuf);
4424b47a0797 updated for version 7.0003
vimboss
parents: 10
diff changeset
289 }
4424b47a0797 updated for version 7.0003
vimboss
parents: 10
diff changeset
290 #endif
4424b47a0797 updated for version 7.0003
vimboss
parents: 10
diff changeset
291
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
292 #ifdef FEAT_MOUSE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
293 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
294 * When doing a paste with the middle mouse button, Insstart is set to
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
295 * where the paste started.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
296 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
297 if (where_paste_started.lnum != 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
298 Insstart = where_paste_started;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
299 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
300 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
301 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
302 Insstart = curwin->w_cursor;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
303 if (startln)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
304 Insstart.col = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
305 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
306 Insstart_textlen = linetabsize(ml_get_curline());
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
307 Insstart_blank_vcol = MAXCOL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
308 if (!did_ai)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
309 ai_col = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
310
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
311 if (cmdchar != NUL && restart_edit == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
312 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
313 ResetRedobuff();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
314 AppendNumberToRedobuff(count);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
315 #ifdef FEAT_VREPLACE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
316 if (cmdchar == 'V' || cmdchar == 'v')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
317 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
318 /* "gR" or "gr" command */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
319 AppendCharToRedobuff('g');
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
320 AppendCharToRedobuff((cmdchar == 'v') ? 'r' : 'R');
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
321 }
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 AppendCharToRedobuff(cmdchar);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
326 if (cmdchar == 'g') /* "gI" command */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
327 AppendCharToRedobuff('I');
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
328 else if (cmdchar == 'r') /* "r<CR>" command */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
329 count = 1; /* insert only one <CR> */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
330 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
331 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
332
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
333 if (cmdchar == 'R')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
334 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
335 #ifdef FEAT_FKMAP
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
336 if (p_fkmap && p_ri)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
337 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
338 beep_flush();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
339 EMSG(farsi_text_3); /* encoded in Farsi */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
340 State = INSERT;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
341 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
342 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
343 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
344 State = REPLACE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
345 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
346 #ifdef FEAT_VREPLACE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
347 else if (cmdchar == 'V' || cmdchar == 'v')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
348 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
349 State = VREPLACE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
350 replaceState = VREPLACE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
351 orig_line_count = curbuf->b_ml.ml_line_count;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
352 vr_lines_changed = 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
353 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
354 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
355 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
356 State = INSERT;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
357
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
358 stop_insert_mode = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
359
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
360 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
361 * Need to recompute the cursor position, it might move when the cursor is
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
362 * on a TAB or special character.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
363 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
364 curs_columns(TRUE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
365
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
366 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
367 * Enable langmap or IME, indicated by 'iminsert'.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
368 * Note that IME may enabled/disabled without us noticing here, thus the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
369 * 'iminsert' value may not reflect what is actually used. It is updated
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
370 * when hitting <Esc>.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
371 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
372 if (curbuf->b_p_iminsert == B_IMODE_LMAP)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
373 State |= LANGMAP;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
374 #ifdef USE_IM_CONTROL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
375 im_set_active(curbuf->b_p_iminsert == B_IMODE_IM);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
376 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
377
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
378 #if defined(FEAT_MBYTE) && defined(MACOS_CLASSIC)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
379 KeyScript(previous_script);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
380 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
381
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
382 #ifdef FEAT_MOUSE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
383 setmouse();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
384 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
385 #ifdef FEAT_CMDL_INFO
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
386 clear_showcmd();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
387 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
388 #ifdef FEAT_RIGHTLEFT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
389 /* there is no reverse replace mode */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
390 revins_on = (State == INSERT && p_ri);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
391 if (revins_on)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
392 undisplay_dollar();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
393 revins_chars = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
394 revins_legal = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
395 revins_scol = -1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
396 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
397
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
398 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
399 * Handle restarting Insert mode.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
400 * Don't do this for "CTRL-O ." (repeat an insert): we get here with
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
401 * restart_edit non-zero, and something in the stuff buffer.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
402 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
403 if (restart_edit != 0 && stuff_empty())
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 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
407 * After a paste we consider text typed to be part of the insert for
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
408 * the pasted text. You can backspace over the pasted text too.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
409 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
410 if (where_paste_started.lnum)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
411 arrow_used = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
412 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
413 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
414 arrow_used = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
415 restart_edit = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
416
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
417 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
418 * 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
419 * 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
420 * correct in very rare cases).
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
421 * Also do this if curswant is greater than the current virtual
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
422 * column. Eg after "^O$" or "^O80|".
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
423 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
424 validate_virtcol();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
425 update_curswant();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
426 if (((o_eol && curwin->w_cursor.lnum == o_lnum)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
427 || curwin->w_curswant > curwin->w_virtcol)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
428 && *(ptr = ml_get_curline() + curwin->w_cursor.col) != NUL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
429 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
430 if (ptr[1] == NUL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
431 ++curwin->w_cursor.col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
432 #ifdef FEAT_MBYTE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
433 else if (has_mbyte)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
434 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
435 i = (*mb_ptr2len_check)(ptr);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
436 if (ptr[i] == NUL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
437 curwin->w_cursor.col += i;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
438 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
439 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
440 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
441 o_eol = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
442 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
443 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
444 arrow_used = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
445
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
446 /* we are in insert mode now, don't need to start it anymore */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
447 need_start_insertmode = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
448
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
449 /* Need to save the line for undo before inserting the first char. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
450 ins_need_undo = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
451
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
452 #ifdef FEAT_MOUSE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
453 where_paste_started.lnum = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
454 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
455 #ifdef FEAT_CINDENT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
456 can_cindent = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
457 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
458 #ifdef FEAT_FOLDING
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
459 /* The cursor line is not in a closed fold, unless 'insertmode' is set or
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
460 * restarting. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
461 if (!p_im && did_restart_edit == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
462 foldOpenCursor();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
463 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
464
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
465 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
466 * If 'showmode' is set, show the current (insert/replace/..) mode.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
467 * A warning message for changing a readonly file is given here, before
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
468 * actually changing anything. It's put after the mode, if any.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
469 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
470 i = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
471 if (p_smd)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
472 i = showmode();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
473
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
474 if (!p_im && did_restart_edit == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
475 change_warning(i + 1);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
476
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
477 #ifdef CURSOR_SHAPE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
478 ui_cursor_shape(); /* may show different cursor shape */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
479 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
480 #ifdef FEAT_DIGRAPHS
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
481 do_digraph(-1); /* clear digraphs */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
482 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
483
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
484 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
485 * Get the current length of the redo buffer, those characters have to be
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
486 * skipped if we want to get to the inserted characters.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
487 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
488 ptr = get_inserted();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
489 if (ptr == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
490 new_insert_skip = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
491 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
492 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
493 new_insert_skip = (int)STRLEN(ptr);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
494 vim_free(ptr);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
495 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
496
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
497 old_indent = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
498
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
499 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
500 * Main loop in Insert mode: repeat until Insert mode is left.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
501 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
502 for (;;)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
503 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
504 #ifdef FEAT_RIGHTLEFT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
505 if (!revins_legal)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
506 revins_scol = -1; /* reset on illegal motions */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
507 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
508 revins_legal = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
509 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
510 if (arrow_used) /* don't repeat insert when arrow key used */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
511 count = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
512
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
513 if (stop_insert_mode)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
514 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
515 /* ":stopinsert" used or 'insertmode' reset */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
516 count = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
517 goto doESCkey;
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 /* set curwin->w_curswant for next K_DOWN or K_UP */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
521 if (!arrow_used)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
522 curwin->w_set_curswant = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
523
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
524 /* If there is no typeahead may check for timestamps (e.g., for when a
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
525 * menu invoked a shell command). */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
526 if (stuff_empty())
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
527 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
528 did_check_timestamps = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
529 if (need_check_timestamps)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
530 check_timestamps(FALSE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
531 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
532
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
533 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
534 * When emsg() was called msg_scroll will have been set.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
535 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
536 msg_scroll = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
537
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
538 #ifdef FEAT_GUI
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
539 /* When 'mousefocus' is set a mouse movement may have taken us to
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
540 * another window. "need_mouse_correct" may then be set because of an
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
541 * autocommand. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
542 if (need_mouse_correct)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
543 gui_mouse_correct();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
544 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
545
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
546 #ifdef FEAT_FOLDING
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
547 /* Open fold at the cursor line, according to 'foldopen'. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
548 if (fdo_flags & FDO_INSERT)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
549 foldOpenCursor();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
550 /* Close folds where the cursor isn't, according to 'foldclose' */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
551 if (!char_avail())
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
552 foldCheckClose();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
553 #endif
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 * If we inserted a character at the last position of the last line in
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
557 * the window, scroll the window one line up. This avoids an extra
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
558 * redraw.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
559 * This is detected when the cursor column is smaller after inserting
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
560 * something.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
561 * Don't do this when the topline changed already, it has
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
562 * already been adjusted (by insertchar() calling open_line())).
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
563 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
564 if (curbuf->b_mod_set
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
565 && curwin->w_p_wrap
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
566 && !did_backspace
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
567 && curwin->w_topline == old_topline
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
568 #ifdef FEAT_DIFF
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
569 && curwin->w_topfill == old_topfill
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
570 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
571 )
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
572 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
573 mincol = curwin->w_wcol;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
574 validate_cursor_col();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
575
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
576 if ((int)curwin->w_wcol < (int)mincol - curbuf->b_p_ts
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
577 && curwin->w_wrow == W_WINROW(curwin)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
578 + curwin->w_height - 1 - p_so
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
579 && (curwin->w_cursor.lnum != curwin->w_topline
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
580 #ifdef FEAT_DIFF
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
581 || curwin->w_topfill > 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
582 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
583 ))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
584 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
585 #ifdef FEAT_DIFF
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
586 if (curwin->w_topfill > 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
587 --curwin->w_topfill;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
588 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
589 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
590 #ifdef FEAT_FOLDING
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
591 if (hasFolding(curwin->w_topline, NULL, &old_topline))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
592 set_topline(curwin, old_topline + 1);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
593 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
594 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
595 set_topline(curwin, curwin->w_topline + 1);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
596 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
597 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
598
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
599 /* May need to adjust w_topline to show the cursor. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
600 update_topline();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
601
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
602 did_backspace = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
603
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
604 validate_cursor(); /* may set must_redraw */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
605
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
606 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
607 * Redraw the display when no characters are waiting.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
608 * Also shows mode, ruler and positions cursor.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
609 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
610 ins_redraw();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
611
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
612 #ifdef FEAT_SCROLLBIND
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
613 if (curwin->w_p_scb)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
614 do_check_scrollbind(TRUE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
615 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
616
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
617 update_curswant();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
618 old_topline = curwin->w_topline;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
619 #ifdef FEAT_DIFF
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
620 old_topfill = curwin->w_topfill;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
621 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
622
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
623 #ifdef USE_ON_FLY_SCROLL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
624 dont_scroll = FALSE; /* allow scrolling here */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
625 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
626
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
627 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
628 * Get a character for Insert mode.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
629 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
630 lastc = c; /* remember previous char for CTRL-D */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
631 c = safe_vgetc();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
632
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
633 #ifdef FEAT_RIGHTLEFT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
634 if (p_hkmap && KeyTyped)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
635 c = hkmap(c); /* Hebrew mode mapping */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
636 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
637 #ifdef FEAT_FKMAP
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
638 if (p_fkmap && KeyTyped)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
639 c = fkmap(c); /* Farsi mode mapping */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
640 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
641
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
642 #ifdef FEAT_INS_EXPAND
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
643 /* Prepare for or stop CTRL-X mode. This doesn't do completion, but
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
644 * it does fix up the text when finishing completion. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
645 ins_compl_prep(c);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
646 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
647
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
648 /* CTRL-\ CTRL-N goes to Normal mode, CTRL-\ CTRL-G goes to mode
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
649 * selected with 'insertmode'. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
650 if (c == Ctrl_BSL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
651 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
652 /* may need to redraw when no more chars available now */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
653 ins_redraw();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
654 ++no_mapping;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
655 ++allow_keys;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
656 c = safe_vgetc();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
657 --no_mapping;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
658 --allow_keys;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
659 if (c != Ctrl_N && c != Ctrl_G) /* it's something else */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
660 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
661 vungetc(c);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
662 c = Ctrl_BSL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
663 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
664 else if (c == Ctrl_G && p_im)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
665 continue;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
666 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
667 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
668 count = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
669 goto doESCkey;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
670 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
671 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
672
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
673 #ifdef FEAT_DIGRAPHS
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
674 c = do_digraph(c);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
675 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
676
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
677 #ifdef FEAT_INS_EXPAND
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
678 if ((c == Ctrl_V || c == Ctrl_Q) && ctrl_x_mode == CTRL_X_CMDLINE)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
679 goto docomplete;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
680 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
681 if (c == Ctrl_V || c == Ctrl_Q)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
682 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
683 ins_ctrl_v();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
684 c = Ctrl_V; /* pretend CTRL-V is last typed character */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
685 continue;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
686 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
687
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
688 #ifdef FEAT_CINDENT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
689 if (cindent_on()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
690 # ifdef FEAT_INS_EXPAND
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
691 && ctrl_x_mode == 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
692 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
693 )
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
694 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
695 /* A key name preceded by a bang means this key is not to be
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
696 * inserted. Skip ahead to the re-indenting below.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
697 * A key name preceded by a star means that indenting has to be
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
698 * done before inserting the key. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
699 line_is_white = inindent(0);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
700 if (in_cinkeys(c, '!', line_is_white))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
701 goto force_cindent;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
702 if (can_cindent && in_cinkeys(c, '*', line_is_white)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
703 && stop_arrow() == OK)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
704 do_c_expr_indent();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
705 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
706 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
707
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
708 #ifdef FEAT_RIGHTLEFT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
709 if (curwin->w_p_rl)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
710 switch (c)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
711 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
712 case K_LEFT: c = K_RIGHT; break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
713 case K_S_LEFT: c = K_S_RIGHT; break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
714 case K_C_LEFT: c = K_C_RIGHT; break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
715 case K_RIGHT: c = K_LEFT; break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
716 case K_S_RIGHT: c = K_S_LEFT; break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
717 case K_C_RIGHT: c = K_C_LEFT; break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
718 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
719 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
720
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
721 #ifdef FEAT_VISUAL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
722 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
723 * If 'keymodel' contains "startsel", may start selection. If it
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
724 * does, a CTRL-O and c will be stuffed, we need to get these
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
725 * characters.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
726 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
727 if (ins_start_select(c))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
728 continue;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
729 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
730
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
731 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
732 * The big switch to handle a character in insert mode.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
733 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
734 switch (c)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
735 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
736 /* toggle insert/replace mode */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
737 case K_INS:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
738 case K_KINS:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
739 #ifdef FEAT_FKMAP
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
740 if (p_fkmap && p_ri)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
741 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
742 beep_flush();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
743 EMSG(farsi_text_3); /* encoded in Farsi */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
744 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
745 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
746 #endif
11
4424b47a0797 updated for version 7.0003
vimboss
parents: 10
diff changeset
747 #ifdef FEAT_AUTOCMD
4424b47a0797 updated for version 7.0003
vimboss
parents: 10
diff changeset
748 set_vim_var_string(VV_INSERTMODE,
4424b47a0797 updated for version 7.0003
vimboss
parents: 10
diff changeset
749 (char_u *)((State & REPLACE_FLAG) ? "i" :
4424b47a0797 updated for version 7.0003
vimboss
parents: 10
diff changeset
750 replaceState == VREPLACE ? "v" : "r"), 1);
4424b47a0797 updated for version 7.0003
vimboss
parents: 10
diff changeset
751 apply_autocmds(EVENT_INSERTCHANGE, NULL, NULL, FALSE, curbuf);
4424b47a0797 updated for version 7.0003
vimboss
parents: 10
diff changeset
752 #endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
753 if (State & REPLACE_FLAG)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
754 State = INSERT | (State & LANGMAP);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
755 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
756 State = replaceState | (State & LANGMAP);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
757 AppendCharToRedobuff(K_INS);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
758 showmode();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
759 #ifdef CURSOR_SHAPE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
760 ui_cursor_shape(); /* may show different cursor shape */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
761 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
762 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
763
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
764 #ifdef FEAT_INS_EXPAND
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
765 /* Enter CTRL-X mode */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
766 case Ctrl_X:
12
bdeee1504ac1 updated for version 7.0004
vimboss
parents: 11
diff changeset
767 /* CTRL-X after CTRL-X CTRL-V doesn't do anything, so that CTRL-X
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
768 * CTRL-V works like CTRL-N */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
769 if (ctrl_x_mode != CTRL_X_CMDLINE)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
770 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
771 /* if the next ^X<> won't ADD nothing, then reset
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
772 * continue_status */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
773 if (continue_status & CONT_N_ADDS)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
774 continue_status = (continue_status | CONT_INTRPT);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
775 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
776 continue_status = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
777 /* We're not sure which CTRL-X mode it will be yet */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
778 ctrl_x_mode = CTRL_X_NOT_DEFINED_YET;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
779 edit_submode = (char_u *)_(CTRL_X_MSG(ctrl_x_mode));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
780 edit_submode_pre = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
781 showmode();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
782 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
783 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
784 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
785
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
786 /* end of Select mode mapping - ignore */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
787 case K_SELECT:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
788 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
789
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
790 /* suspend when 'insertmode' set */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
791 case Ctrl_Z:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
792 if (!p_im)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
793 goto normalchar; /* insert CTRL-Z as normal char */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
794 stuffReadbuff((char_u *)":st\r");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
795 c = Ctrl_O;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
796 /*FALLTHROUGH*/
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
797
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
798 /* execute one command */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
799 case Ctrl_O:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
800 if (echeck_abbr(Ctrl_O + ABBR_OFF))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
801 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
802 count = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
803 #ifdef FEAT_VREPLACE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
804 if (State & VREPLACE_FLAG)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
805 restart_edit = 'V';
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
806 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
807 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
808 if (State & REPLACE_FLAG)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
809 restart_edit = 'R';
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
810 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
811 restart_edit = 'I';
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
812 #ifdef FEAT_VIRTUALEDIT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
813 if (virtual_active())
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
814 o_eol = FALSE; /* cursor always keeps its column */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
815 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
816 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
817 o_eol = (gchar_cursor() == NUL);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
818 goto doESCkey;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
819
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
820 #ifdef FEAT_SNIFF
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
821 case K_SNIFF:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
822 stuffcharReadbuff(K_SNIFF);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
823 goto doESCkey;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
824 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
825
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
826 /* Hitting the help key in insert mode is like <ESC> <Help> */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
827 case K_HELP:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
828 case K_F1:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
829 case K_XF1:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
830 stuffcharReadbuff(K_HELP);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
831 if (p_im)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
832 need_start_insertmode = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
833 goto doESCkey;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
834
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
835 #ifdef FEAT_NETBEANS_INTG
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
836 case K_F21:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
837 ++no_mapping; /* don't map the next key hits */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
838 i = safe_vgetc();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
839 --no_mapping;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
840 netbeans_keycommand(i);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
841 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
842 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
843
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
844 /* an escape ends input mode */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
845 case ESC:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
846 if (echeck_abbr(ESC + ABBR_OFF))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
847 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
848 /*FALLTHROUGH*/
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
849
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
850 case Ctrl_C:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
851 #ifdef FEAT_CMDWIN
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
852 if (c == Ctrl_C && cmdwin_type != 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
853 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
854 /* Close the cmdline window. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
855 cmdwin_result = K_IGNORE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
856 got_int = FALSE; /* don't stop executing autocommands et al. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
857 goto doESCkey;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
858 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
859 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
860
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
861 #ifdef UNIX
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
862 do_intr:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
863 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
864 /* when 'insertmode' set, and not halfway a mapping, don't leave
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
865 * Insert mode */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
866 if (goto_im())
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
867 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
868 if (got_int)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
869 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
870 (void)vgetc(); /* flush all buffers */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
871 got_int = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
872 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
873 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
874 vim_beep();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
875 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
876 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
877 doESCkey:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
878 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
879 * This is the ONLY return from edit()!
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
880 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
881 /* Always update o_lnum, so that a "CTRL-O ." that adds a line
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
882 * still puts the cursor back after the inserted text. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
883 if (o_eol && gchar_cursor() == NUL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
884 o_lnum = curwin->w_cursor.lnum;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
885
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
886 if (ins_esc(&count, cmdchar))
11
4424b47a0797 updated for version 7.0003
vimboss
parents: 10
diff changeset
887 {
4424b47a0797 updated for version 7.0003
vimboss
parents: 10
diff changeset
888 #ifdef FEAT_AUTOCMD
4424b47a0797 updated for version 7.0003
vimboss
parents: 10
diff changeset
889 if (cmdchar != 'r' && cmdchar != 'v')
4424b47a0797 updated for version 7.0003
vimboss
parents: 10
diff changeset
890 apply_autocmds(EVENT_INSERTLEAVE, NULL, NULL,
4424b47a0797 updated for version 7.0003
vimboss
parents: 10
diff changeset
891 FALSE, curbuf);
4424b47a0797 updated for version 7.0003
vimboss
parents: 10
diff changeset
892 #endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
893 return (c == Ctrl_O);
11
4424b47a0797 updated for version 7.0003
vimboss
parents: 10
diff changeset
894 }
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
895 continue;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
896
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
897 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
898 * Insert the previously inserted text.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
899 * For ^@ the trailing ESC will end the insert, unless there is an
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
900 * error.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
901 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
902 case K_ZERO:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
903 case NUL:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
904 case Ctrl_A:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
905 if (stuff_inserted(NUL, 1L, (c == Ctrl_A)) == FAIL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
906 && c != Ctrl_A && !p_im)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
907 goto doESCkey; /* quit insert mode */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
908 inserted_space = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
909 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
910
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
911 /* insert the contents of a register */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
912 case Ctrl_R:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
913 ins_reg();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
914 auto_format(FALSE, TRUE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
915 inserted_space = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
916 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
917
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
918 case Ctrl_G:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
919 ins_ctrl_g();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
920 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
921
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
922 case Ctrl_HAT:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
923 if (map_to_exists_mode((char_u *)"", LANGMAP))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
924 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
925 /* ":lmap" mappings exists, Toggle use of ":lmap" mappings. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
926 if (State & LANGMAP)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
927 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
928 curbuf->b_p_iminsert = B_IMODE_NONE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
929 State &= ~LANGMAP;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
930 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
931 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
932 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
933 curbuf->b_p_iminsert = B_IMODE_LMAP;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
934 State |= LANGMAP;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
935 #ifdef USE_IM_CONTROL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
936 im_set_active(FALSE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
937 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
938 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
939 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
940 #ifdef USE_IM_CONTROL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
941 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
942 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
943 /* There are no ":lmap" mappings, toggle IM */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
944 if (im_get_status())
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
945 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
946 curbuf->b_p_iminsert = B_IMODE_NONE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
947 im_set_active(FALSE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
948 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
949 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
950 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
951 curbuf->b_p_iminsert = B_IMODE_IM;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
952 State &= ~LANGMAP;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
953 im_set_active(TRUE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
954 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
955 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
956 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
957 set_iminsert_global();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
958 showmode();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
959 #ifdef FEAT_GUI
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
960 /* may show different cursor shape or color */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
961 if (gui.in_use)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
962 gui_update_cursor(TRUE, FALSE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
963 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
964 #if defined(FEAT_WINDOWS) && defined(FEAT_KEYMAP)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
965 /* Show/unshow value of 'keymap' in status lines. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
966 status_redraw_curbuf();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
967 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
968 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
969
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
970 #ifdef FEAT_RIGHTLEFT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
971 case Ctrl__:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
972 if (!p_ari)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
973 goto normalchar;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
974 ins_ctrl_();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
975 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
976 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
977
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
978 /* Make indent one shiftwidth smaller. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
979 case Ctrl_D:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
980 #if defined(FEAT_INS_EXPAND) && defined(FEAT_FIND_ID)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
981 if (ctrl_x_mode == CTRL_X_PATH_DEFINES)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
982 goto docomplete;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
983 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
984 /* FALLTHROUGH */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
985
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
986 /* Make indent one shiftwidth greater. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
987 case Ctrl_T:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
988 # ifdef FEAT_INS_EXPAND
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
989 if (c == Ctrl_T && ctrl_x_mode == CTRL_X_THESAURUS)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
990 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
991 if (*curbuf->b_p_tsr == NUL && *p_tsr == NUL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
992 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
993 ctrl_x_mode = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
994 msg_attr((char_u *)_("'thesaurus' option is empty"),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
995 hl_attr(HLF_E));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
996 if (emsg_silent == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
997 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
998 vim_beep();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
999 setcursor();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1000 out_flush();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1001 ui_delay(2000L, FALSE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1002 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1003 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1004 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1005 goto docomplete;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1006 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1007 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1008 ins_shift(c, lastc);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1009 auto_format(FALSE, TRUE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1010 inserted_space = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1011 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1012
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1013 /* delete character under the cursor */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1014 case K_DEL:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1015 case K_KDEL:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1016 ins_del();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1017 auto_format(FALSE, TRUE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1018 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1019
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1020 /* delete character before the cursor */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1021 case K_BS:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1022 case Ctrl_H:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1023 did_backspace = ins_bs(c, BACKSPACE_CHAR, &inserted_space);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1024 auto_format(FALSE, TRUE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1025 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1026
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1027 /* delete word before the cursor */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1028 case Ctrl_W:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1029 did_backspace = ins_bs(c, BACKSPACE_WORD, &inserted_space);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1030 auto_format(FALSE, TRUE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1031 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1032
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1033 /* delete all inserted text in current line */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1034 case Ctrl_U:
12
bdeee1504ac1 updated for version 7.0004
vimboss
parents: 11
diff changeset
1035 # ifdef FEAT_COMPL_FUNC
bdeee1504ac1 updated for version 7.0004
vimboss
parents: 11
diff changeset
1036 /* CTRL-X CTRL-U completes with 'completefunc'. */
bdeee1504ac1 updated for version 7.0004
vimboss
parents: 11
diff changeset
1037 if (ctrl_x_mode == CTRL_X_NOT_DEFINED_YET
bdeee1504ac1 updated for version 7.0004
vimboss
parents: 11
diff changeset
1038 || ctrl_x_mode == CTRL_X_FUNCTION)
bdeee1504ac1 updated for version 7.0004
vimboss
parents: 11
diff changeset
1039 goto docomplete;
bdeee1504ac1 updated for version 7.0004
vimboss
parents: 11
diff changeset
1040 # endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1041 did_backspace = ins_bs(c, BACKSPACE_LINE, &inserted_space);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1042 auto_format(FALSE, TRUE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1043 inserted_space = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1044 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1045
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1046 #ifdef FEAT_MOUSE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1047 case K_LEFTMOUSE:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1048 case K_LEFTMOUSE_NM:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1049 case K_LEFTDRAG:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1050 case K_LEFTRELEASE:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1051 case K_LEFTRELEASE_NM:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1052 case K_MIDDLEMOUSE:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1053 case K_MIDDLEDRAG:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1054 case K_MIDDLERELEASE:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1055 case K_RIGHTMOUSE:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1056 case K_RIGHTDRAG:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1057 case K_RIGHTRELEASE:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1058 case K_X1MOUSE:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1059 case K_X1DRAG:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1060 case K_X1RELEASE:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1061 case K_X2MOUSE:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1062 case K_X2DRAG:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1063 case K_X2RELEASE:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1064 ins_mouse(c);
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 /* Default action for scroll wheel up: scroll up */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1068 case K_MOUSEDOWN:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1069 ins_mousescroll(FALSE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1070 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1071
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1072 /* Default action for scroll wheel down: scroll down */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1073 case K_MOUSEUP:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1074 ins_mousescroll(TRUE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1075 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1076 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1077
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1078 case K_IGNORE:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1079 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1080
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1081 #ifdef FEAT_GUI
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1082 case K_VER_SCROLLBAR:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1083 ins_scroll();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1084 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1085
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1086 case K_HOR_SCROLLBAR:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1087 ins_horscroll();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1088 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1089 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1090
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1091 case K_HOME:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1092 case K_KHOME:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1093 case K_XHOME:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1094 case K_S_HOME:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1095 case K_C_HOME:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1096 ins_home(c);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1097 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1098
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1099 case K_END:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1100 case K_KEND:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1101 case K_XEND:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1102 case K_S_END:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1103 case K_C_END:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1104 ins_end(c);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1105 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1106
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1107 case K_LEFT:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1108 ins_left();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1109 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1110
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1111 case K_S_LEFT:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1112 case K_C_LEFT:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1113 ins_s_left();
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 case K_RIGHT:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1117 ins_right();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1118 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1119
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1120 case K_S_RIGHT:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1121 case K_C_RIGHT:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1122 ins_s_right();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1123 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1124
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1125 case K_UP:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1126 ins_up(FALSE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1127 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1128
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1129 case K_S_UP:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1130 case K_PAGEUP:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1131 case K_KPAGEUP:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1132 ins_pageup();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1133 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1134
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1135 case K_DOWN:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1136 ins_down(FALSE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1137 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1138
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1139 case K_S_DOWN:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1140 case K_PAGEDOWN:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1141 case K_KPAGEDOWN:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1142 ins_pagedown();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1143 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1144
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1145 #ifdef FEAT_DND
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1146 case K_DROP:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1147 ins_drop();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1148 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1149 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1150
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1151 /* When <S-Tab> isn't mapped, use it like a normal TAB */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1152 case K_S_TAB:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1153 c = TAB;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1154 /* FALLTHROUGH */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1155
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1156 /* TAB or Complete patterns along path */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1157 case TAB:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1158 #if defined(FEAT_INS_EXPAND) && defined(FEAT_FIND_ID)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1159 if (ctrl_x_mode == CTRL_X_PATH_PATTERNS)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1160 goto docomplete;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1161 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1162 inserted_space = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1163 if (ins_tab())
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1164 goto normalchar; /* insert TAB as a normal char */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1165 auto_format(FALSE, TRUE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1166 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1167
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1168 case K_KENTER:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1169 c = CAR;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1170 /* FALLTHROUGH */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1171 case CAR:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1172 case NL:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1173 #if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1174 /* In a quickfix window a <CR> jumps to the error under the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1175 * cursor. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1176 if (bt_quickfix(curbuf) && c == CAR)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1177 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1178 do_cmdline_cmd((char_u *)".cc");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1179 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1180 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1181 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1182 #ifdef FEAT_CMDWIN
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1183 if (cmdwin_type != 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1184 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1185 /* Execute the command in the cmdline window. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1186 cmdwin_result = CAR;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1187 goto doESCkey;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1188 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1189 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1190 if (ins_eol(c) && !p_im)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1191 goto doESCkey; /* out of memory */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1192 auto_format(FALSE, FALSE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1193 inserted_space = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1194 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1195
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1196 #if defined(FEAT_DIGRAPHS) || defined (FEAT_INS_EXPAND)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1197 case Ctrl_K:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1198 # ifdef FEAT_INS_EXPAND
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1199 if (ctrl_x_mode == CTRL_X_DICTIONARY)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1200 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1201 if (*curbuf->b_p_dict == NUL && *p_dict == NUL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1202 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1203 ctrl_x_mode = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1204 msg_attr((char_u *)_("'dictionary' option is empty"),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1205 hl_attr(HLF_E));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1206 if (emsg_silent == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1207 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1208 vim_beep();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1209 setcursor();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1210 out_flush();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1211 ui_delay(2000L, FALSE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1212 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1213 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1214 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1215 goto docomplete;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1216 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1217 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1218 # ifdef FEAT_DIGRAPHS
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1219 c = ins_digraph();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1220 if (c == NUL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1221 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1222 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1223 goto normalchar;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1224 #endif /* FEAT_DIGRAPHS || FEAT_INS_EXPAND */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1225
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1226 #ifdef FEAT_INS_EXPAND
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1227 case Ctrl_RSB: /* Tag name completion after ^X */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1228 if (ctrl_x_mode != CTRL_X_TAGS)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1229 goto normalchar;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1230 goto docomplete;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1231
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1232 case Ctrl_F: /* File name completion after ^X */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1233 if (ctrl_x_mode != CTRL_X_FILES)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1234 goto normalchar;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1235 goto docomplete;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1236 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1237
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1238 case Ctrl_L: /* Whole line completion after ^X */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1239 #ifdef FEAT_INS_EXPAND
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1240 if (ctrl_x_mode != CTRL_X_WHOLE_LINE)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1241 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1242 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1243 /* CTRL-L with 'insertmode' set: Leave Insert mode */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1244 if (p_im)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1245 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1246 if (echeck_abbr(Ctrl_L + ABBR_OFF))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1247 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1248 goto doESCkey;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1249 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1250 goto normalchar;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1251 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1252 #ifdef FEAT_INS_EXPAND
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1253 /* FALLTHROUGH */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1254
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1255 /* Do previous/next pattern completion */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1256 case Ctrl_P:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1257 case Ctrl_N:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1258 /* if 'complete' is empty then plain ^P is no longer special,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1259 * but it is under other ^X modes */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1260 if (*curbuf->b_p_cpt == NUL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1261 && ctrl_x_mode != 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1262 && !(continue_status & CONT_LOCAL))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1263 goto normalchar;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1264
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1265 docomplete:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1266 if (ins_complete(c) == FAIL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1267 continue_status = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1268 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1269 #endif /* FEAT_INS_EXPAND */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1270
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1271 case Ctrl_Y: /* copy from previous line or scroll down */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1272 case Ctrl_E: /* copy from next line or scroll up */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1273 #ifdef FEAT_INS_EXPAND
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1274 if (ctrl_x_mode == CTRL_X_SCROLL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1275 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1276 if (c == Ctrl_Y)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1277 scrolldown_clamp();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1278 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1279 scrollup_clamp();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1280 redraw_later(VALID);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1281 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1282 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1283 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1284 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1285 c = ins_copychar(curwin->w_cursor.lnum
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1286 + (c == Ctrl_Y ? -1 : 1));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1287 if (c != NUL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1288 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1289 long tw_save;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1290
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1291 /* The character must be taken literally, insert like it
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1292 * was typed after a CTRL-V, and pretend 'textwidth'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1293 * wasn't set. Digits, 'o' and 'x' are special after a
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1294 * CTRL-V, don't use it for these. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1295 if (c < 256 && !isalnum(c))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1296 AppendToRedobuff((char_u *)CTRL_V_STR); /* CTRL-V */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1297 tw_save = curbuf->b_p_tw;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1298 curbuf->b_p_tw = -1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1299 insert_special(c, TRUE, FALSE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1300 curbuf->b_p_tw = tw_save;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1301 #ifdef FEAT_RIGHTLEFT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1302 revins_chars++;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1303 revins_legal++;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1304 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1305 c = Ctrl_V; /* pretend CTRL-V is last character */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1306 auto_format(FALSE, TRUE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1307 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1308 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1309 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1310
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1311 default:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1312 #ifdef UNIX
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1313 if (c == intr_char) /* special interrupt char */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1314 goto do_intr;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1315 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1316
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1317 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1318 * Insert a nomal character.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1319 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1320 normalchar:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1321 #ifdef FEAT_SMARTINDENT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1322 /* Try to perform smart-indenting. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1323 ins_try_si(c);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1324 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1325
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1326 if (c == ' ')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1327 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1328 inserted_space = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1329 #ifdef FEAT_CINDENT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1330 if (inindent(0))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1331 can_cindent = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1332 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1333 if (Insstart_blank_vcol == MAXCOL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1334 && curwin->w_cursor.lnum == Insstart.lnum)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1335 Insstart_blank_vcol = get_nolist_virtcol();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1336 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1337
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1338 if (vim_iswordc(c) || !echeck_abbr(
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1339 #ifdef FEAT_MBYTE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1340 /* Add ABBR_OFF for characters above 0x100, this is
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1341 * what check_abbr() expects. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1342 (has_mbyte && c >= 0x100) ? (c + ABBR_OFF) :
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1343 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1344 c))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1345 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1346 insert_special(c, FALSE, FALSE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1347 #ifdef FEAT_RIGHTLEFT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1348 revins_legal++;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1349 revins_chars++;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1350 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1351 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1352
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1353 auto_format(FALSE, TRUE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1354
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1355 #ifdef FEAT_FOLDING
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1356 /* When inserting a character the cursor line must never be in a
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1357 * closed fold. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1358 foldOpenCursor();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1359 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1360 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1361 } /* end of switch (c) */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1362
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1363 /* If the cursor was moved we didn't just insert a space */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1364 if (arrow_used)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1365 inserted_space = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1366
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1367 #ifdef FEAT_CINDENT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1368 if (can_cindent && cindent_on()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1369 # ifdef FEAT_INS_EXPAND
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1370 && ctrl_x_mode == 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1371 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1372 )
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1373 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1374 force_cindent:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1375 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1376 * Indent now if a key was typed that is in 'cinkeys'.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1377 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1378 if (in_cinkeys(c, ' ', line_is_white))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1379 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1380 if (stop_arrow() == OK)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1381 /* re-indent the current line */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1382 do_c_expr_indent();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1383 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1384 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1385 #endif /* FEAT_CINDENT */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1386
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1387 } /* for (;;) */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1388 /* NOTREACHED */
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 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1392 * Redraw for Insert mode.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1393 * This is postponed until getting the next character to make '$' in the 'cpo'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1394 * option work correctly.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1395 * Only redraw when there are no characters available. This speeds up
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1396 * inserting sequences of characters (e.g., for CTRL-R).
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1397 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1398 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1399 ins_redraw()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1400 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1401 if (!char_avail())
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1402 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1403 if (must_redraw)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1404 update_screen(0);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1405 else if (clear_cmdline || redraw_cmdline)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1406 showmode(); /* clear cmdline and show mode */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1407 showruler(FALSE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1408 setcursor();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1409 emsg_on_display = FALSE; /* may remove error message now */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1410 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1411 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1412
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1413 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1414 * Handle a CTRL-V or CTRL-Q typed in Insert mode.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1415 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1416 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1417 ins_ctrl_v()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1418 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1419 int c;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1420
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1421 /* may need to redraw when no more chars available now */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1422 ins_redraw();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1423
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1424 if (redrawing() && !char_avail())
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1425 edit_putchar('^', TRUE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1426 AppendToRedobuff((char_u *)CTRL_V_STR); /* CTRL-V */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1427
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1428 #ifdef FEAT_CMDL_INFO
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1429 add_to_showcmd_c(Ctrl_V);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1430 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1431
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1432 c = get_literal();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1433 #ifdef FEAT_CMDL_INFO
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1434 clear_showcmd();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1435 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1436 insert_special(c, FALSE, TRUE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1437 #ifdef FEAT_RIGHTLEFT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1438 revins_chars++;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1439 revins_legal++;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1440 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1441 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1442
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1443 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1444 * Put a character directly onto the screen. It's not stored in a buffer.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1445 * Used while handling CTRL-K, CTRL-V, etc. in Insert mode.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1446 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1447 static int pc_status;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1448 #define PC_STATUS_UNSET 0 /* pc_bytes was not set */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1449 #define PC_STATUS_RIGHT 1 /* right halve of double-wide char */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1450 #define PC_STATUS_LEFT 2 /* left halve of double-wide char */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1451 #define PC_STATUS_SET 3 /* pc_bytes was filled */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1452 #ifdef FEAT_MBYTE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1453 static char_u pc_bytes[MB_MAXBYTES + 1]; /* saved bytes */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1454 #else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1455 static char_u pc_bytes[2]; /* saved bytes */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1456 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1457 static int pc_attr;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1458 static int pc_row;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1459 static int pc_col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1460
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1461 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1462 edit_putchar(c, highlight)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1463 int c;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1464 int highlight;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1465 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1466 int attr;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1467
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1468 if (ScreenLines != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1469 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1470 update_topline(); /* just in case w_topline isn't valid */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1471 validate_cursor();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1472 if (highlight)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1473 attr = hl_attr(HLF_8);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1474 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1475 attr = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1476 pc_row = W_WINROW(curwin) + curwin->w_wrow;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1477 pc_col = W_WINCOL(curwin);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1478 #if defined(FEAT_RIGHTLEFT) || defined(FEAT_MBYTE)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1479 pc_status = PC_STATUS_UNSET;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1480 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1481 #ifdef FEAT_RIGHTLEFT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1482 if (curwin->w_p_rl)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1483 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1484 pc_col += W_WIDTH(curwin) - 1 - curwin->w_wcol;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1485 # ifdef FEAT_MBYTE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1486 if (has_mbyte)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1487 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1488 int fix_col = mb_fix_col(pc_col, pc_row);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1489
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1490 if (fix_col != pc_col)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1491 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1492 screen_putchar(' ', pc_row, fix_col, attr);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1493 --curwin->w_wcol;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1494 pc_status = PC_STATUS_RIGHT;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1495 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1496 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1497 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1498 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1499 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1500 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1501 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1502 pc_col += curwin->w_wcol;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1503 #ifdef FEAT_MBYTE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1504 if (mb_lefthalve(pc_row, pc_col))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1505 pc_status = PC_STATUS_LEFT;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1506 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1507 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1508
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1509 /* save the character to be able to put it back */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1510 #if defined(FEAT_RIGHTLEFT) || defined(FEAT_MBYTE)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1511 if (pc_status == PC_STATUS_UNSET)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1512 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1513 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1514 screen_getbytes(pc_row, pc_col, pc_bytes, &pc_attr);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1515 pc_status = PC_STATUS_SET;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1516 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1517 screen_putchar(c, pc_row, pc_col, attr);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1518 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1519 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1520
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1521 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1522 * Undo the previous edit_putchar().
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1523 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1524 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1525 edit_unputchar()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1526 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1527 if (pc_status != PC_STATUS_UNSET && pc_row >= msg_scrolled)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1528 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1529 #if defined(FEAT_MBYTE)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1530 if (pc_status == PC_STATUS_RIGHT)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1531 ++curwin->w_wcol;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1532 if (pc_status == PC_STATUS_RIGHT || pc_status == PC_STATUS_LEFT)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1533 redrawWinline(curwin->w_cursor.lnum, FALSE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1534 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1535 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1536 screen_puts(pc_bytes, pc_row - msg_scrolled, pc_col, pc_attr);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1537 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1538 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1539
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1540 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1541 * 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
1542 * Only works when cursor is in the line that changes.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1543 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1544 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1545 display_dollar(col)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1546 colnr_T col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1547 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1548 colnr_T save_col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1549
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1550 if (!redrawing())
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1551 return;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1552
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1553 cursor_off();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1554 save_col = curwin->w_cursor.col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1555 curwin->w_cursor.col = col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1556 #ifdef FEAT_MBYTE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1557 if (has_mbyte)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1558 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1559 char_u *p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1560
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1561 /* If on the last byte of a multi-byte move to the first byte. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1562 p = ml_get_curline();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1563 curwin->w_cursor.col -= (*mb_head_off)(p, p + col);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1564 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1565 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1566 curs_columns(FALSE); /* recompute w_wrow and w_wcol */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1567 if (curwin->w_wcol < W_WIDTH(curwin))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1568 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1569 edit_putchar('$', FALSE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1570 dollar_vcol = curwin->w_virtcol;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1571 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1572 curwin->w_cursor.col = save_col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1573 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1574
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1575 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1576 * Call this function before moving the cursor from the normal insert position
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1577 * in insert mode.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1578 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1579 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1580 undisplay_dollar()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1581 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1582 if (dollar_vcol)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1583 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1584 dollar_vcol = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1585 redrawWinline(curwin->w_cursor.lnum, FALSE);
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
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1589 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1590 * 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
1591 * Keep the cursor on the same character.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1592 * type == INDENT_INC increase indent (for CTRL-T or <Tab>)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1593 * type == INDENT_DEC decrease indent (for CTRL-D)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1594 * type == INDENT_SET set indent to "amount"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1595 * if round is TRUE, round the indent to 'shiftwidth' (only with _INC and _Dec).
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1596 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1597 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1598 change_indent(type, amount, round, replaced)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1599 int type;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1600 int amount;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1601 int round;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1602 int replaced; /* replaced character, put on replace stack */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1603 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1604 int vcol;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1605 int last_vcol;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1606 int insstart_less; /* reduction for Insstart.col */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1607 int new_cursor_col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1608 int i;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1609 char_u *ptr;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1610 int save_p_list;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1611 int start_col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1612 colnr_T vc;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1613 #ifdef FEAT_VREPLACE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1614 colnr_T orig_col = 0; /* init for GCC */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1615 char_u *new_line, *orig_line = NULL; /* init for GCC */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1616
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1617 /* VREPLACE mode needs to know what the line was like before changing */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1618 if (State & VREPLACE_FLAG)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1619 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1620 orig_line = vim_strsave(ml_get_curline()); /* Deal with NULL below */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1621 orig_col = curwin->w_cursor.col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1622 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1623 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1624
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1625 /* for the following tricks we don't want list mode */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1626 save_p_list = curwin->w_p_list;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1627 curwin->w_p_list = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1628 vc = getvcol_nolist(&curwin->w_cursor);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1629 vcol = vc;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1630
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1631 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1632 * For Replace mode we need to fix the replace stack later, which is only
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1633 * possible when the cursor is in the indent. Remember the number of
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1634 * characters before the cursor if it's possible.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1635 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1636 start_col = curwin->w_cursor.col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1637
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1638 /* determine offset from first non-blank */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1639 new_cursor_col = curwin->w_cursor.col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1640 beginline(BL_WHITE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1641 new_cursor_col -= curwin->w_cursor.col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1642
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1643 insstart_less = curwin->w_cursor.col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1644
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1645 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1646 * If the cursor is in the indent, compute how many screen columns the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1647 * cursor is to the left of the first non-blank.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1648 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1649 if (new_cursor_col < 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1650 vcol = get_indent() - vcol;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1651
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1652 if (new_cursor_col > 0) /* can't fix replace stack */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1653 start_col = -1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1654
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1655 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1656 * Set the new indent. The cursor will be put on the first non-blank.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1657 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1658 if (type == INDENT_SET)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1659 (void)set_indent(amount, SIN_CHANGED);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1660 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1661 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1662 #ifdef FEAT_VREPLACE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1663 int save_State = State;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1664
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1665 /* Avoid being called recursively. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1666 if (State & VREPLACE_FLAG)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1667 State = INSERT;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1668 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1669 shift_line(type == INDENT_DEC, round, 1);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1670 #ifdef FEAT_VREPLACE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1671 State = save_State;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1672 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1673 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1674 insstart_less -= curwin->w_cursor.col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1675
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1676 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1677 * Try to put cursor on same character.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1678 * If the cursor is at or after the first non-blank in the line,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1679 * compute the cursor column relative to the column of the first
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1680 * non-blank character.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1681 * 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
1682 * If the cursor is before the first non-blank, position it relative
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1683 * to the first non-blank, counted in screen columns.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1684 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1685 if (new_cursor_col >= 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1686 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1687 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1688 * When changing the indent while the cursor is touching it, reset
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1689 * Insstart_col to 0.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1690 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1691 if (new_cursor_col == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1692 insstart_less = MAXCOL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1693 new_cursor_col += curwin->w_cursor.col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1694 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1695 else if (!(State & INSERT))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1696 new_cursor_col = curwin->w_cursor.col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1697 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1698 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1699 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1700 * Compute the screen column where the cursor should be.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1701 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1702 vcol = get_indent() - vcol;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1703 curwin->w_virtcol = (vcol < 0) ? 0 : vcol;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1704
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1705 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1706 * Advance the cursor until we reach the right screen column.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1707 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1708 vcol = last_vcol = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1709 new_cursor_col = -1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1710 ptr = ml_get_curline();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1711 while (vcol <= (int)curwin->w_virtcol)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1712 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1713 last_vcol = vcol;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1714 #ifdef FEAT_MBYTE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1715 if (has_mbyte && new_cursor_col >= 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1716 new_cursor_col += (*mb_ptr2len_check)(ptr + new_cursor_col);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1717 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1718 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1719 ++new_cursor_col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1720 vcol += lbr_chartabsize(ptr + new_cursor_col, (colnr_T)vcol);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1721 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1722 vcol = last_vcol;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1723
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1724 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1725 * May need to insert spaces to be able to position the cursor on
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1726 * the right screen column.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1727 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1728 if (vcol != (int)curwin->w_virtcol)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1729 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1730 curwin->w_cursor.col = new_cursor_col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1731 i = (int)curwin->w_virtcol - vcol;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1732 ptr = alloc(i + 1);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1733 if (ptr != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1734 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1735 new_cursor_col += i;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1736 ptr[i] = NUL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1737 while (--i >= 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1738 ptr[i] = ' ';
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1739 ins_str(ptr);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1740 vim_free(ptr);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1741 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1742 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1743
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1744 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1745 * When changing the indent while the cursor is in it, reset
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1746 * Insstart_col to 0.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1747 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1748 insstart_less = MAXCOL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1749 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1750
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1751 curwin->w_p_list = save_p_list;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1752
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1753 if (new_cursor_col <= 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1754 curwin->w_cursor.col = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1755 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1756 curwin->w_cursor.col = new_cursor_col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1757 curwin->w_set_curswant = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1758 changed_cline_bef_curs();
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 * May have to adjust the start of the insert.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1762 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1763 if (State & INSERT)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1764 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1765 if (curwin->w_cursor.lnum == Insstart.lnum && Insstart.col != 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1766 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1767 if ((int)Insstart.col <= insstart_less)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1768 Insstart.col = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1769 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1770 Insstart.col -= insstart_less;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1771 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1772 if ((int)ai_col <= insstart_less)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1773 ai_col = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1774 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1775 ai_col -= insstart_less;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1776 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1777
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1778 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1779 * For REPLACE mode, may have to fix the replace stack, if it's possible.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1780 * If the number of characters before the cursor decreased, need to pop a
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1781 * few characters from the replace stack.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1782 * If the number of characters before the cursor increased, need to push a
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1783 * few NULs onto the replace stack.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1784 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1785 if (REPLACE_NORMAL(State) && start_col >= 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1786 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1787 while (start_col > (int)curwin->w_cursor.col)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1788 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1789 replace_join(0); /* remove a NUL from the replace stack */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1790 --start_col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1791 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1792 while (start_col < (int)curwin->w_cursor.col || replaced)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1793 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1794 replace_push(NUL);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1795 if (replaced)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1796 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1797 replace_push(replaced);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1798 replaced = NUL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1799 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1800 ++start_col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1801 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1802 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1803
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1804 #ifdef FEAT_VREPLACE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1805 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1806 * For VREPLACE mode, we also have to fix the replace stack. In this case
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1807 * it is always possible because we backspace over the whole line and then
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1808 * put it back again the way we wanted it.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1809 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1810 if (State & VREPLACE_FLAG)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1811 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1812 /* If orig_line didn't allocate, just return. At least we did the job,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1813 * even if you can't backspace. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1814 if (orig_line == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1815 return;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1816
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1817 /* Save new line */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1818 new_line = vim_strsave(ml_get_curline());
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1819 if (new_line == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1820 return;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1821
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1822 /* We only put back the new line up to the cursor */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1823 new_line[curwin->w_cursor.col] = NUL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1824
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1825 /* Put back original line */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1826 ml_replace(curwin->w_cursor.lnum, orig_line, FALSE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1827 curwin->w_cursor.col = orig_col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1828
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1829 /* Backspace from cursor to start of line */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1830 backspace_until_column(0);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1831
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1832 /* Insert new stuff into line again */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1833 ins_bytes(new_line);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1834
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1835 vim_free(new_line);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1836 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1837 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1838 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1839
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1840 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1841 * 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
1842 * insert mode. It handles fixing the replace stack for REPLACE and VREPLACE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1843 * modes.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1844 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1845 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1846 truncate_spaces(line)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1847 char_u *line;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1848 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1849 int i;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1850
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1851 /* find start of trailing white space */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1852 for (i = (int)STRLEN(line) - 1; i >= 0 && vim_iswhite(line[i]); i--)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1853 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1854 if (State & REPLACE_FLAG)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1855 replace_join(0); /* remove a NUL from the replace stack */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1856 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1857 line[i + 1] = NUL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1858 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1859
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1860 #if defined(FEAT_VREPLACE) || defined(FEAT_INS_EXPAND) \
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1861 || defined(FEAT_COMMENTS) || defined(PROTO)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1862 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1863 * Backspace the cursor until the given column. Handles REPLACE and VREPLACE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1864 * modes correctly. May also be used when not in insert mode at all.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1865 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1866 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1867 backspace_until_column(col)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1868 int col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1869 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1870 while ((int)curwin->w_cursor.col > col)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1871 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1872 curwin->w_cursor.col--;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1873 if (State & REPLACE_FLAG)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1874 replace_do_bs();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1875 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1876 (void)del_char(FALSE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1877 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1878 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1879 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1880
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1881 #if defined(FEAT_INS_EXPAND) || defined(PROTO)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1882 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1883 * 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
1884 * This depends on the current mode.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1885 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1886 int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1887 vim_is_ctrl_x_key(c)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1888 int c;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1889 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1890 /* Always allow ^R - let it's results then be checked */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1891 if (c == Ctrl_R)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1892 return TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1893
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1894 switch (ctrl_x_mode)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1895 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1896 case 0: /* Not in any CTRL-X mode */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1897 return (c == Ctrl_N || c == Ctrl_P || c == Ctrl_X);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1898 case CTRL_X_NOT_DEFINED_YET:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1899 return ( c == Ctrl_X || c == Ctrl_Y || c == Ctrl_E
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1900 || c == Ctrl_L || c == Ctrl_F || c == Ctrl_RSB
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1901 || c == Ctrl_I || c == Ctrl_D || c == Ctrl_P
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1902 || c == Ctrl_N || c == Ctrl_T || c == Ctrl_V
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1903 || c == Ctrl_Q);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1904 case CTRL_X_SCROLL:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1905 return (c == Ctrl_Y || c == Ctrl_E);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1906 case CTRL_X_WHOLE_LINE:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1907 return (c == Ctrl_L || c == Ctrl_P || c == Ctrl_N);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1908 case CTRL_X_FILES:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1909 return (c == Ctrl_F || c == Ctrl_P || c == Ctrl_N);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1910 case CTRL_X_DICTIONARY:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1911 return (c == Ctrl_K || c == Ctrl_P || c == Ctrl_N);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1912 case CTRL_X_THESAURUS:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1913 return (c == Ctrl_T || c == Ctrl_P || c == Ctrl_N);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1914 case CTRL_X_TAGS:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1915 return (c == Ctrl_RSB || c == Ctrl_P || c == Ctrl_N);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1916 #ifdef FEAT_FIND_ID
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1917 case CTRL_X_PATH_PATTERNS:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1918 return (c == Ctrl_P || c == Ctrl_N);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1919 case CTRL_X_PATH_DEFINES:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1920 return (c == Ctrl_D || c == Ctrl_P || c == Ctrl_N);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1921 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1922 case CTRL_X_CMDLINE:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1923 return (c == Ctrl_V || c == Ctrl_Q || c == Ctrl_P || c == Ctrl_N
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1924 || c == Ctrl_X);
12
bdeee1504ac1 updated for version 7.0004
vimboss
parents: 11
diff changeset
1925 #ifdef FEAT_COMPL_FUNC
bdeee1504ac1 updated for version 7.0004
vimboss
parents: 11
diff changeset
1926 case CTRL_X_FUNCTION:
bdeee1504ac1 updated for version 7.0004
vimboss
parents: 11
diff changeset
1927 return (c == Ctrl_U || c == Ctrl_P || c == Ctrl_N || c == Ctrl_X);
bdeee1504ac1 updated for version 7.0004
vimboss
parents: 11
diff changeset
1928 #endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1929 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1930 EMSG(_(e_internal));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1931 return FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1932 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1933
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1934 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1935 * 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
1936 * case of the originally typed text is used, and the case of the completed
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1937 * text is infered, ie this tries to work out what case you probably wanted
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1938 * the rest of the word to be in -- webb
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1939 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1940 int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1941 ins_compl_add_infercase(str, len, fname, dir, reuse)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1942 char_u *str;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1943 int len;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1944 char_u *fname;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1945 int dir;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1946 int reuse;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1947 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1948 int has_lower = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1949 int was_letter = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1950 int idx;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1951
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1952 if (p_ic && curbuf->b_p_inf && len < IOSIZE)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1953 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1954 /* Infer case of completed part -- webb */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1955 /* Use IObuff, str would change text in buffer! */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1956 STRNCPY(IObuff, str, len);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1957 IObuff[len] = NUL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1958
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1959 /* Rule 1: Were any chars converted to lower? */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1960 for (idx = 0; idx < completion_length; ++idx)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1961 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1962 if (islower(original_text[idx]))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1963 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1964 has_lower = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1965 if (isupper(IObuff[idx]))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1966 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1967 /* Rule 1 is satisfied */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1968 for (idx = completion_length; idx < len; ++idx)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1969 IObuff[idx] = TOLOWER_LOC(IObuff[idx]);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1970 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1971 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1972 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1973 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1974
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1975 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1976 * Rule 2: No lower case, 2nd consecutive letter converted to
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1977 * upper case.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1978 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1979 if (!has_lower)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1980 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1981 for (idx = 0; idx < completion_length; ++idx)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1982 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1983 if (was_letter && isupper(original_text[idx])
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1984 && islower(IObuff[idx]))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1985 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1986 /* Rule 2 is satisfied */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1987 for (idx = completion_length; idx < len; ++idx)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1988 IObuff[idx] = TOUPPER_LOC(IObuff[idx]);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1989 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1990 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1991 was_letter = isalpha(original_text[idx]);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1992 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1993 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1994
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1995 /* Copy the original case of the part we typed */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1996 STRNCPY(IObuff, original_text, completion_length);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1997
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1998 return ins_compl_add(IObuff, len, fname, dir, reuse);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1999 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2000 return ins_compl_add(str, len, fname, dir, reuse);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2001 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2002
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2003 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2004 * Add a match to the list of matches.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2005 * If the given string is already in the list of completions, then return
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2006 * FAIL, otherwise add it to the list and return OK. If there is an error,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2007 * maybe because alloc returns NULL, then RET_ERROR is returned -- webb.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2008 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2009 static int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2010 ins_compl_add(str, len, fname, dir, reuse)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2011 char_u *str;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2012 int len;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2013 char_u *fname;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2014 int dir;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2015 int reuse;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2016 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2017 struct Completion *match;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2018
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2019 ui_breakcheck();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2020 if (got_int)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2021 return RET_ERROR;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2022 if (len < 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2023 len = (int)STRLEN(str);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2024
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2025 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2026 * If the same match is already present, don't add it.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2027 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2028 if (first_match != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2029 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2030 match = first_match;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2031 do
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2032 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2033 if ( !(match->original & ORIGINAL_TEXT)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2034 && STRNCMP(match->str, str, (size_t)len) == 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2035 && match->str[len] == NUL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2036 return FAIL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2037 match = match->next;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2038 } while (match != NULL && match != first_match);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2039 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2040
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2041 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2042 * Allocate a new match structure.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2043 * Copy the values to the new match structure.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2044 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2045 match = (struct Completion *)alloc((unsigned)sizeof(struct Completion));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2046 if (match == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2047 return RET_ERROR;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2048 match->number = -1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2049 if (reuse & ORIGINAL_TEXT)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2050 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2051 match->number = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2052 match->str = original_text;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2053 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2054 else if ((match->str = vim_strnsave(str, len)) == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2055 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2056 vim_free(match);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2057 return RET_ERROR;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2058 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2059 /* match-fname is:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2060 * - curr_match->fname if it is a string equal to fname.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2061 * - a copy of fname, FREE_FNAME is set to free later THE allocated mem.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2062 * - NULL otherwise. --Acevedo */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2063 if (fname && curr_match && curr_match->fname
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2064 && STRCMP(fname, curr_match->fname) == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2065 match->fname = curr_match->fname;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2066 else if (fname && (match->fname = vim_strsave(fname)) != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2067 reuse |= FREE_FNAME;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2068 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2069 match->fname = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2070 match->original = reuse;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2071
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2072 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2073 * Link the new match structure in the list of matches.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2074 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2075 if (first_match == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2076 match->next = match->prev = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2077 else if (dir == FORWARD)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2078 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2079 match->next = curr_match->next;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2080 match->prev = curr_match;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2081 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2082 else /* BACKWARD */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2083 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2084 match->next = curr_match;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2085 match->prev = curr_match->prev;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2086 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2087 if (match->next)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2088 match->next->prev = match;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2089 if (match->prev)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2090 match->prev->next = match;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2091 else /* if there's nothing before, it is the first match */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2092 first_match = match;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2093 curr_match = match;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2094
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2095 return OK;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2096 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2097
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2098 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2099 * Add an array of matches to the list of matches.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2100 * Frees matches[].
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2101 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2102 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2103 ins_compl_add_matches(num_matches, matches, dir)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2104 int num_matches;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2105 char_u **matches;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2106 int dir;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2107 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2108 int i;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2109 int add_r = OK;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2110 int ldir = dir;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2111
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2112 for (i = 0; i < num_matches && add_r != RET_ERROR; i++)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2113 if ((add_r = ins_compl_add(matches[i], -1, NULL, ldir, 0)) == OK)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2114 /* if dir was BACKWARD then honor it just once */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2115 ldir = FORWARD;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2116 FreeWild(num_matches, matches);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2117 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2118
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2119 /* Make the completion list cyclic.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2120 * Return the number of matches (excluding the original).
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2121 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2122 static int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2123 ins_compl_make_cyclic()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2124 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2125 struct Completion *match;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2126 int count = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2127
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2128 if (first_match != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2129 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2130 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2131 * Find the end of the list.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2132 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2133 match = first_match;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2134 /* there's always an entry for the original_text, it doesn't count. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2135 while (match->next != NULL && match->next != first_match)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2136 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2137 match = match->next;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2138 ++count;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2139 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2140 match->next = first_match;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2141 first_match->prev = match;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2142 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2143 return count;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2144 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2145
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2146 #define DICT_FIRST (1) /* use just first element in "dict" */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2147 #define DICT_EXACT (2) /* "dict" is the exact name of a file */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2148 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2149 * Add any identifiers that match the given pattern to the list of
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2150 * completions.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2151 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2152 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2153 ins_compl_dictionaries(dict, pat, dir, flags, thesaurus)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2154 char_u *dict;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2155 char_u *pat;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2156 int dir;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2157 int flags;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2158 int thesaurus;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2159 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2160 char_u *ptr;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2161 char_u *buf;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2162 FILE *fp;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2163 regmatch_T regmatch;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2164 int add_r;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2165 char_u **files;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2166 int count;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2167 int i;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2168 int save_p_scs;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2169
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2170 buf = alloc(LSIZE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2171 /* If 'infercase' is set, don't use 'smartcase' here */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2172 save_p_scs = p_scs;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2173 if (curbuf->b_p_inf)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2174 p_scs = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2175 regmatch.regprog = vim_regcomp(pat, p_magic ? RE_MAGIC : 0);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2176 /* ignore case depends on 'ignorecase', 'smartcase' and "pat" */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2177 regmatch.rm_ic = ignorecase(pat);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2178 while (buf != NULL && regmatch.regprog != NULL && *dict != NUL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2179 && !got_int && !completion_interrupted)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2180 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2181 /* copy one dictionary file name into buf */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2182 if (flags == DICT_EXACT)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2183 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2184 count = 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2185 files = &dict;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2186 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2187 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2188 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2189 /* Expand wildcards in the dictionary name, but do not allow
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2190 * backticks (for security, the 'dict' option may have been set in
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2191 * a modeline). */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2192 copy_option_part(&dict, buf, LSIZE, ",");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2193 if (vim_strchr(buf, '`') != NULL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2194 || expand_wildcards(1, &buf, &count, &files,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2195 EW_FILE|EW_SILENT) != OK)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2196 count = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2197 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2198
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2199 for (i = 0; i < count && !got_int && !completion_interrupted; i++)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2200 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2201 fp = mch_fopen((char *)files[i], "r"); /* open dictionary file */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2202 if (flags != DICT_EXACT)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2203 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2204 sprintf((char*)IObuff, _("Scanning dictionary: %s"),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2205 (char *)files[i]);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2206 msg_trunc_attr(IObuff, TRUE, hl_attr(HLF_R));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2207 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2208
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2209 if (fp != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2210 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2211 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2212 * Read dictionary file line by line.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2213 * Check each line for a match.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2214 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2215 while (!got_int && !completion_interrupted
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2216 && !vim_fgets(buf, LSIZE, fp))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2217 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2218 ptr = buf;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2219 while (vim_regexec(&regmatch, buf, (colnr_T)(ptr - buf)))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2220 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2221 ptr = regmatch.startp[0];
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2222 ptr = find_word_end(ptr);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2223 add_r = ins_compl_add_infercase(regmatch.startp[0],
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2224 (int)(ptr - regmatch.startp[0]),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2225 files[i], dir, 0);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2226 if (thesaurus)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2227 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2228 char_u *wstart;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2229
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2230 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2231 * Add the other matches on the line
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2232 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2233 while (!got_int)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2234 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2235 /* Find start of the next word. Skip white
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2236 * space and punctuation. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2237 ptr = find_word_start(ptr);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2238 if (*ptr == NUL || *ptr == NL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2239 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2240 wstart = ptr;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2241
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2242 /* Find end of the word and add it. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2243 #ifdef FEAT_MBYTE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2244 if (has_mbyte)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2245 /* Japanese words may have characters in
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2246 * different classes, only separate words
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2247 * with single-byte non-word characters. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2248 while (*ptr != NUL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2249 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2250 int l = (*mb_ptr2len_check)(ptr);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2251
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2252 if (l < 2 && !vim_iswordc(*ptr))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2253 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2254 ptr += l;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2255 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2256 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2257 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2258 ptr = find_word_end(ptr);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2259 add_r = ins_compl_add_infercase(wstart,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2260 (int)(ptr - wstart), files[i], dir, 0);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2261 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2262 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2263 if (add_r == OK)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2264 /* if dir was BACKWARD then honor it just once */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2265 dir = FORWARD;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2266 else if (add_r == RET_ERROR)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2267 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2268 /* avoid expensive call to vim_regexec() when at end
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2269 * of line */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2270 if (*ptr == '\n' || got_int)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2271 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2272 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2273 line_breakcheck();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2274 ins_compl_check_keys();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2275 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2276 fclose(fp);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2277 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2278 }
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 FreeWild(count, files);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2281 if (flags)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2282 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2283 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2284 p_scs = save_p_scs;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2285 vim_free(regmatch.regprog);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2286 vim_free(buf);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2287 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2288
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2289 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2290 * Find the start of the next word.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2291 * 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
2292 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2293 char_u *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2294 find_word_start(ptr)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2295 char_u *ptr;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2296 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2297 #ifdef FEAT_MBYTE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2298 if (has_mbyte)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2299 while (*ptr != NUL && *ptr != '\n' && mb_get_class(ptr) <= 1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2300 ptr += (*mb_ptr2len_check)(ptr);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2301 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2302 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2303 while (*ptr != NUL && *ptr != '\n' && !vim_iswordc(*ptr))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2304 ++ptr;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2305 return ptr;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2306 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2307
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2308 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2309 * Find the end of the word. Assumes it starts inside a word.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2310 * Returns a pointer to just after the word.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2311 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2312 char_u *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2313 find_word_end(ptr)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2314 char_u *ptr;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2315 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2316 #ifdef FEAT_MBYTE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2317 int start_class;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2318
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2319 if (has_mbyte)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2320 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2321 start_class = mb_get_class(ptr);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2322 if (start_class > 1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2323 while (*ptr != NUL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2324 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2325 ptr += (*mb_ptr2len_check)(ptr);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2326 if (mb_get_class(ptr) != start_class)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2327 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2328 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2329 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2330 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2331 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2332 while (vim_iswordc(*ptr))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2333 ++ptr;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2334 return ptr;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2335 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2336
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2337 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2338 * Free the list of completions
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2339 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2340 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2341 ins_compl_free()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2342 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2343 struct Completion *match;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2344
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2345 vim_free(complete_pat);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2346 complete_pat = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2347
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2348 if (first_match == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2349 return;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2350 curr_match = first_match;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2351 do
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2352 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2353 match = curr_match;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2354 curr_match = curr_match->next;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2355 vim_free(match->str);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2356 /* several entries may use the same fname, free it just once. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2357 if (match->original & FREE_FNAME)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2358 vim_free(match->fname);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2359 vim_free(match);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2360 } while (curr_match != NULL && curr_match != first_match);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2361 first_match = curr_match = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2362 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2363
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2364 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2365 ins_compl_clear()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2366 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2367 continue_status = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2368 started_completion = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2369 completion_matches = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2370 vim_free(complete_pat);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2371 complete_pat = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2372 save_sm = -1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2373 edit_submode_extra = NULL;
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 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2377 * Prepare for Insert mode completion, or stop it.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2378 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2379 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2380 ins_compl_prep(c)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2381 int c;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2382 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2383 char_u *ptr;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2384 char_u *tmp_ptr;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2385 int temp;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2386 int want_cindent;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2387
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2388 /* Forget any previous 'special' messages if this is actually
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2389 * 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
2390 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2391 if (c != Ctrl_R && vim_is_ctrl_x_key(c))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2392 edit_submode_extra = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2393
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2394 /* Ignore end of Select mode mapping */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2395 if (c == K_SELECT)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2396 return;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2397
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2398 if (ctrl_x_mode == CTRL_X_NOT_DEFINED_YET)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2399 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2400 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2401 * 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
2402 * it will be yet. Now we decide.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2403 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2404 switch (c)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2405 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2406 case Ctrl_E:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2407 case Ctrl_Y:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2408 ctrl_x_mode = CTRL_X_SCROLL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2409 if (!(State & REPLACE_FLAG))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2410 edit_submode = (char_u *)_(" (insert) Scroll (^E/^Y)");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2411 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2412 edit_submode = (char_u *)_(" (replace) Scroll (^E/^Y)");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2413 edit_submode_pre = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2414 showmode();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2415 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2416 case Ctrl_L:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2417 ctrl_x_mode = CTRL_X_WHOLE_LINE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2418 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2419 case Ctrl_F:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2420 ctrl_x_mode = CTRL_X_FILES;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2421 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2422 case Ctrl_K:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2423 ctrl_x_mode = CTRL_X_DICTIONARY;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2424 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2425 case Ctrl_R:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2426 /* Simply allow ^R to happen without affecting ^X mode */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2427 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2428 case Ctrl_T:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2429 ctrl_x_mode = CTRL_X_THESAURUS;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2430 break;
12
bdeee1504ac1 updated for version 7.0004
vimboss
parents: 11
diff changeset
2431 #ifdef FEAT_COMPL_FUNC
bdeee1504ac1 updated for version 7.0004
vimboss
parents: 11
diff changeset
2432 case Ctrl_U:
bdeee1504ac1 updated for version 7.0004
vimboss
parents: 11
diff changeset
2433 ctrl_x_mode = CTRL_X_FUNCTION;
bdeee1504ac1 updated for version 7.0004
vimboss
parents: 11
diff changeset
2434 break;
bdeee1504ac1 updated for version 7.0004
vimboss
parents: 11
diff changeset
2435 #endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2436 case Ctrl_RSB:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2437 ctrl_x_mode = CTRL_X_TAGS;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2438 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2439 #ifdef FEAT_FIND_ID
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2440 case Ctrl_I:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2441 case K_S_TAB:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2442 ctrl_x_mode = CTRL_X_PATH_PATTERNS;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2443 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2444 case Ctrl_D:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2445 ctrl_x_mode = CTRL_X_PATH_DEFINES;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2446 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2447 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2448 case Ctrl_V:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2449 case Ctrl_Q:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2450 ctrl_x_mode = CTRL_X_CMDLINE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2451 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2452 case Ctrl_P:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2453 case Ctrl_N:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2454 /* ^X^P means LOCAL expansion if nothing interrupted (eg we
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2455 * just started ^X mode, or there were enough ^X's to cancel
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2456 * 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
2457 * do normal expansion when interrupting a different mode (say
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2458 * ^X^F^X^P or ^P^X^X^P, see below)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2459 * nothing changes if interrupting mode 0, (eg, the flag
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2460 * doesn't change when going to ADDING mode -- Acevedo */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2461 if (!(continue_status & CONT_INTRPT))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2462 continue_status |= CONT_LOCAL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2463 else if (continue_mode != 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2464 continue_status &= ~CONT_LOCAL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2465 /* FALLTHROUGH */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2466 default:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2467 /* if we have typed at least 2 ^X's... for modes != 0, we set
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2468 * continue_status = 0 (eg, as if we had just started ^X mode)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2469 * for mode 0, we set continue_mode to an impossible value, in
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2470 * both cases ^X^X can be used to restart the same mode
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2471 * (avoiding ADDING mode). Undocumented feature:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2472 * In a mode != 0 ^X^P and ^X^X^P start 'complete' and local
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2473 * ^P expansions respectively. In mode 0 an extra ^X is
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2474 * needed since ^X^P goes to ADDING mode -- Acevedo */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2475 if (c == Ctrl_X)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2476 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2477 if (continue_mode != 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2478 continue_status = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2479 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2480 continue_mode = CTRL_X_NOT_DEFINED_YET;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2481 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2482 ctrl_x_mode = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2483 edit_submode = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2484 showmode();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2485 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2486 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2487 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2488 else if (ctrl_x_mode != 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2489 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2490 /* We're already in CTRL-X mode, do we stay in it? */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2491 if (!vim_is_ctrl_x_key(c))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2492 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2493 if (ctrl_x_mode == CTRL_X_SCROLL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2494 ctrl_x_mode = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2495 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2496 ctrl_x_mode = CTRL_X_FINISHED;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2497 edit_submode = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2498 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2499 showmode();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2500 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2501
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2502 if (started_completion || ctrl_x_mode == CTRL_X_FINISHED)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2503 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2504 /* Show error message from attempted keyword completion (probably
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2505 * 'Pattern not found') until another key is hit, then go back to
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2506 * showing what mode we are in.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2507 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2508 showmode();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2509 if ((ctrl_x_mode == 0 && c != Ctrl_N && c != Ctrl_P && c != Ctrl_R)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2510 || ctrl_x_mode == CTRL_X_FINISHED)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2511 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2512 /* Get here when we have finished typing a sequence of ^N and
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2513 * ^P or other completion characters in CTRL-X mode. Free up
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2514 * memory that was used, and make sure we can redo the insert.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2515 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2516 if (curr_match != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2517 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2518 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2519 * If any of the original typed text has been changed,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2520 * eg when ignorecase is set, we must add back-spaces to
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2521 * the redo buffer. We add as few as necessary to delete
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2522 * just the part of the original text that has changed.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2523 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2524 ptr = curr_match->str;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2525 tmp_ptr = original_text;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2526 while (*tmp_ptr && *tmp_ptr == *ptr)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2527 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2528 ++tmp_ptr;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2529 ++ptr;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2530 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2531 for (temp = 0; tmp_ptr[temp]; ++temp)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2532 AppendCharToRedobuff(K_BS);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2533 AppendToRedobuffLit(ptr);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2534 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2535
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2536 #ifdef FEAT_CINDENT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2537 want_cindent = (can_cindent && cindent_on());
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2538 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2539 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2540 * When completing whole lines: fix indent for 'cindent'.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2541 * Otherwise, break line if it's too long.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2542 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2543 if (continue_mode == CTRL_X_WHOLE_LINE)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2544 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2545 #ifdef FEAT_CINDENT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2546 /* re-indent the current line */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2547 if (want_cindent)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2548 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2549 do_c_expr_indent();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2550 want_cindent = FALSE; /* don't do it again */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2551 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2552 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2553 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2554 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2555 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2556 /* put the cursor on the last char, for 'tw' formatting */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2557 curwin->w_cursor.col--;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2558 if (stop_arrow() == OK)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2559 insertchar(NUL, 0, -1);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2560 curwin->w_cursor.col++;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2561 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2562
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2563 auto_format(FALSE, TRUE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2564
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2565 ins_compl_free();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2566 started_completion = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2567 completion_matches = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2568 msg_clr_cmdline(); /* necessary for "noshowmode" */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2569 ctrl_x_mode = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2570 p_sm = save_sm;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2571 if (edit_submode != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2572 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2573 edit_submode = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2574 showmode();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2575 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2576
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2577 #ifdef FEAT_CINDENT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2578 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2579 * Indent now if a key was typed that is in 'cinkeys'.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2580 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2581 if (want_cindent && in_cinkeys(KEY_COMPLETE, ' ', inindent(0)))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2582 do_c_expr_indent();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2583 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2584 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2585 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2586
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2587 /* reset continue_* if we left expansion-mode, if we stay they'll be
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2588 * (re)set properly in ins_complete() */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2589 if (!vim_is_ctrl_x_key(c))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2590 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2591 continue_status = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2592 continue_mode = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2593 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2594 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2595
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2596 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2597 * Loops through the list of windows, loaded-buffers or non-loaded-buffers
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2598 * (depending on flag) starting from buf and looking for a non-scanned
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2599 * buffer (other than curbuf). curbuf is special, if it is called with
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2600 * 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
2601 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2602 * Returns the buffer to scan, if any, otherwise returns curbuf -- Acevedo
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2603 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2604 static buf_T *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2605 ins_compl_next_buf(buf, flag)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2606 buf_T *buf;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2607 int flag;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2608 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2609 #ifdef FEAT_WINDOWS
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2610 static win_T *wp;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2611 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2612
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2613 if (flag == 'w') /* just windows */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2614 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2615 #ifdef FEAT_WINDOWS
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2616 if (buf == curbuf) /* first call for this flag/expansion */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2617 wp = curwin;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2618 while ((wp = wp->w_next != NULL ? wp->w_next : firstwin) != curwin
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2619 && wp->w_buffer->b_scanned)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2620 ;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2621 buf = wp->w_buffer;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2622 #else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2623 buf = curbuf;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2624 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2625 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2626 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2627 /* 'b' (just loaded buffers), 'u' (just non-loaded buffers) or 'U'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2628 * (unlisted buffers)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2629 * When completing whole lines skip unloaded buffers. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2630 while ((buf = buf->b_next != NULL ? buf->b_next : firstbuf) != curbuf
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2631 && ((flag == 'U'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2632 ? buf->b_p_bl
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2633 : (!buf->b_p_bl
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2634 || (buf->b_ml.ml_mfp == NULL) != (flag == 'u')))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2635 || buf->b_scanned
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2636 || (buf->b_ml.ml_mfp == NULL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2637 && ctrl_x_mode == CTRL_X_WHOLE_LINE)))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2638 ;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2639 return buf;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2640 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2641
12
bdeee1504ac1 updated for version 7.0004
vimboss
parents: 11
diff changeset
2642 #ifdef FEAT_COMPL_FUNC
bdeee1504ac1 updated for version 7.0004
vimboss
parents: 11
diff changeset
2643 static char_u *call_completefunc __ARGS((char_u *line, char_u *base, int col, int preproc));
20
4ac1dce8dd5e updated for version 7.0012
vimboss
parents: 12
diff changeset
2644 static int expand_by_function __ARGS((linenr_T lnum, int col, char_u *base, char_u ***matches));
12
bdeee1504ac1 updated for version 7.0004
vimboss
parents: 11
diff changeset
2645
bdeee1504ac1 updated for version 7.0004
vimboss
parents: 11
diff changeset
2646 /*
bdeee1504ac1 updated for version 7.0004
vimboss
parents: 11
diff changeset
2647 * Execute user defined complete function 'completefunc'.
bdeee1504ac1 updated for version 7.0004
vimboss
parents: 11
diff changeset
2648 * Return NULL if some error occurs.
bdeee1504ac1 updated for version 7.0004
vimboss
parents: 11
diff changeset
2649 */
bdeee1504ac1 updated for version 7.0004
vimboss
parents: 11
diff changeset
2650 static char_u *
bdeee1504ac1 updated for version 7.0004
vimboss
parents: 11
diff changeset
2651 call_completefunc(line, base, col, preproc)
bdeee1504ac1 updated for version 7.0004
vimboss
parents: 11
diff changeset
2652 char_u *line;
bdeee1504ac1 updated for version 7.0004
vimboss
parents: 11
diff changeset
2653 char_u *base;
bdeee1504ac1 updated for version 7.0004
vimboss
parents: 11
diff changeset
2654 int col;
bdeee1504ac1 updated for version 7.0004
vimboss
parents: 11
diff changeset
2655 int preproc;
bdeee1504ac1 updated for version 7.0004
vimboss
parents: 11
diff changeset
2656 {
bdeee1504ac1 updated for version 7.0004
vimboss
parents: 11
diff changeset
2657 char_u colbuf[30];
bdeee1504ac1 updated for version 7.0004
vimboss
parents: 11
diff changeset
2658 char_u *args[4];
bdeee1504ac1 updated for version 7.0004
vimboss
parents: 11
diff changeset
2659
bdeee1504ac1 updated for version 7.0004
vimboss
parents: 11
diff changeset
2660 /* Return NULL when 'completefunc' isn't set. */
bdeee1504ac1 updated for version 7.0004
vimboss
parents: 11
diff changeset
2661 if (*curbuf->b_p_cfu == NUL)
bdeee1504ac1 updated for version 7.0004
vimboss
parents: 11
diff changeset
2662 return NULL;
bdeee1504ac1 updated for version 7.0004
vimboss
parents: 11
diff changeset
2663
bdeee1504ac1 updated for version 7.0004
vimboss
parents: 11
diff changeset
2664 sprintf((char *)colbuf, "%d", col + (base ? (int)STRLEN(base) : 0));
bdeee1504ac1 updated for version 7.0004
vimboss
parents: 11
diff changeset
2665 args[0] = line;
bdeee1504ac1 updated for version 7.0004
vimboss
parents: 11
diff changeset
2666 args[1] = base;
bdeee1504ac1 updated for version 7.0004
vimboss
parents: 11
diff changeset
2667 args[2] = colbuf;
20
4ac1dce8dd5e updated for version 7.0012
vimboss
parents: 12
diff changeset
2668 args[3] = (char_u *)(preproc ? "1" : "0");
12
bdeee1504ac1 updated for version 7.0004
vimboss
parents: 11
diff changeset
2669 return call_vim_function(curbuf->b_p_cfu, 4, args, FALSE);
bdeee1504ac1 updated for version 7.0004
vimboss
parents: 11
diff changeset
2670 }
bdeee1504ac1 updated for version 7.0004
vimboss
parents: 11
diff changeset
2671
bdeee1504ac1 updated for version 7.0004
vimboss
parents: 11
diff changeset
2672 /*
bdeee1504ac1 updated for version 7.0004
vimboss
parents: 11
diff changeset
2673 * Execute user defined complete function 'completefunc', and get candidates
bdeee1504ac1 updated for version 7.0004
vimboss
parents: 11
diff changeset
2674 * are separeted with "\n". Return value is number of candidates and array
bdeee1504ac1 updated for version 7.0004
vimboss
parents: 11
diff changeset
2675 * of candidates as "matches".
bdeee1504ac1 updated for version 7.0004
vimboss
parents: 11
diff changeset
2676 */
bdeee1504ac1 updated for version 7.0004
vimboss
parents: 11
diff changeset
2677 static int
bdeee1504ac1 updated for version 7.0004
vimboss
parents: 11
diff changeset
2678 expand_by_function(lnum, col, base, matches)
20
4ac1dce8dd5e updated for version 7.0012
vimboss
parents: 12
diff changeset
2679 linenr_T lnum;
12
bdeee1504ac1 updated for version 7.0004
vimboss
parents: 11
diff changeset
2680 int col;
bdeee1504ac1 updated for version 7.0004
vimboss
parents: 11
diff changeset
2681 char_u *base;
bdeee1504ac1 updated for version 7.0004
vimboss
parents: 11
diff changeset
2682 char_u ***matches;
bdeee1504ac1 updated for version 7.0004
vimboss
parents: 11
diff changeset
2683 {
bdeee1504ac1 updated for version 7.0004
vimboss
parents: 11
diff changeset
2684 char_u *matchstr = NULL;
bdeee1504ac1 updated for version 7.0004
vimboss
parents: 11
diff changeset
2685
bdeee1504ac1 updated for version 7.0004
vimboss
parents: 11
diff changeset
2686 /* Execute 'completefunc' and get the result */
bdeee1504ac1 updated for version 7.0004
vimboss
parents: 11
diff changeset
2687 matchstr = call_completefunc(ml_get_buf(curbuf, lnum, FALSE), base, col, 0);
bdeee1504ac1 updated for version 7.0004
vimboss
parents: 11
diff changeset
2688
bdeee1504ac1 updated for version 7.0004
vimboss
parents: 11
diff changeset
2689 /* Parse returned string */
bdeee1504ac1 updated for version 7.0004
vimboss
parents: 11
diff changeset
2690 if (matchstr != NULL)
bdeee1504ac1 updated for version 7.0004
vimboss
parents: 11
diff changeset
2691 {
bdeee1504ac1 updated for version 7.0004
vimboss
parents: 11
diff changeset
2692 garray_T ga;
bdeee1504ac1 updated for version 7.0004
vimboss
parents: 11
diff changeset
2693 char_u *p, *pnext;
bdeee1504ac1 updated for version 7.0004
vimboss
parents: 11
diff changeset
2694
bdeee1504ac1 updated for version 7.0004
vimboss
parents: 11
diff changeset
2695 ga_init2(&ga, (int)sizeof(char*), 8);
bdeee1504ac1 updated for version 7.0004
vimboss
parents: 11
diff changeset
2696 for (p = matchstr; *p != NUL; p = pnext)
bdeee1504ac1 updated for version 7.0004
vimboss
parents: 11
diff changeset
2697 {
bdeee1504ac1 updated for version 7.0004
vimboss
parents: 11
diff changeset
2698 int len;
bdeee1504ac1 updated for version 7.0004
vimboss
parents: 11
diff changeset
2699
bdeee1504ac1 updated for version 7.0004
vimboss
parents: 11
diff changeset
2700 pnext = vim_strchr(p, '\n');
bdeee1504ac1 updated for version 7.0004
vimboss
parents: 11
diff changeset
2701 if (pnext == NULL)
bdeee1504ac1 updated for version 7.0004
vimboss
parents: 11
diff changeset
2702 pnext = p + STRLEN(p);
bdeee1504ac1 updated for version 7.0004
vimboss
parents: 11
diff changeset
2703 len = pnext - p;
bdeee1504ac1 updated for version 7.0004
vimboss
parents: 11
diff changeset
2704 if (len > 0)
bdeee1504ac1 updated for version 7.0004
vimboss
parents: 11
diff changeset
2705 {
bdeee1504ac1 updated for version 7.0004
vimboss
parents: 11
diff changeset
2706 if (ga_grow(&ga, 1) == FAIL)
bdeee1504ac1 updated for version 7.0004
vimboss
parents: 11
diff changeset
2707 break;
bdeee1504ac1 updated for version 7.0004
vimboss
parents: 11
diff changeset
2708 ((char_u **)ga.ga_data)[ga.ga_len] = vim_strnsave(p, len);
bdeee1504ac1 updated for version 7.0004
vimboss
parents: 11
diff changeset
2709 ++ga.ga_len;
bdeee1504ac1 updated for version 7.0004
vimboss
parents: 11
diff changeset
2710 }
bdeee1504ac1 updated for version 7.0004
vimboss
parents: 11
diff changeset
2711 if (*pnext != NUL)
bdeee1504ac1 updated for version 7.0004
vimboss
parents: 11
diff changeset
2712 ++pnext;
bdeee1504ac1 updated for version 7.0004
vimboss
parents: 11
diff changeset
2713 }
bdeee1504ac1 updated for version 7.0004
vimboss
parents: 11
diff changeset
2714 vim_free(matchstr);
bdeee1504ac1 updated for version 7.0004
vimboss
parents: 11
diff changeset
2715 if (ga.ga_len > 0)
bdeee1504ac1 updated for version 7.0004
vimboss
parents: 11
diff changeset
2716 *matches = (char_u**)ga.ga_data;
bdeee1504ac1 updated for version 7.0004
vimboss
parents: 11
diff changeset
2717 return ga.ga_len;
bdeee1504ac1 updated for version 7.0004
vimboss
parents: 11
diff changeset
2718 }
bdeee1504ac1 updated for version 7.0004
vimboss
parents: 11
diff changeset
2719 return 0;
bdeee1504ac1 updated for version 7.0004
vimboss
parents: 11
diff changeset
2720 }
bdeee1504ac1 updated for version 7.0004
vimboss
parents: 11
diff changeset
2721 #endif /* FEAT_COMPL_FUNC */
bdeee1504ac1 updated for version 7.0004
vimboss
parents: 11
diff changeset
2722
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2723 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2724 * Get the next expansion(s) for the text starting at the initial curbuf
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2725 * position "ini" and in the direction dir.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2726 * Return the total of matches or -1 if still unknown -- Acevedo
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2727 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2728 static int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2729 ins_compl_get_exp(ini, dir)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2730 pos_T *ini;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2731 int dir;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2732 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2733 static pos_T first_match_pos;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2734 static pos_T last_match_pos;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2735 static char_u *e_cpt = (char_u *)""; /* curr. entry in 'complete' */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2736 static int found_all = FALSE; /* Found all matches. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2737 static buf_T *ins_buf = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2738
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2739 pos_T *pos;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2740 char_u **matches;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2741 int save_p_scs;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2742 int save_p_ws;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2743 int save_p_ic;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2744 int i;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2745 int num_matches;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2746 int len;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2747 int found_new_match;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2748 int type = ctrl_x_mode;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2749 char_u *ptr;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2750 char_u *tmp_ptr;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2751 char_u *dict = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2752 int dict_f = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2753 struct Completion *old_match;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2754
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2755 if (!started_completion)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2756 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2757 for (ins_buf = firstbuf; ins_buf != NULL; ins_buf = ins_buf->b_next)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2758 ins_buf->b_scanned = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2759 found_all = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2760 ins_buf = curbuf;
12
bdeee1504ac1 updated for version 7.0004
vimboss
parents: 11
diff changeset
2761 e_cpt = (continue_status & CONT_LOCAL)
bdeee1504ac1 updated for version 7.0004
vimboss
parents: 11
diff changeset
2762 ? (char_u *)"." : curbuf->b_p_cpt;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2763 last_match_pos = first_match_pos = *ini;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2764 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2765
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2766 old_match = curr_match; /* remember the last current match */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2767 pos = (dir == FORWARD) ? &last_match_pos : &first_match_pos;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2768 /* For ^N/^P loop over all the flags/windows/buffers in 'complete' */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2769 for (;;)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2770 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2771 found_new_match = FAIL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2772
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2773 /* For ^N/^P pick a new entry from e_cpt if started_completion is off,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2774 * 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
2775 * entries from 'complete' that look in loaded buffers. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2776 if ((ctrl_x_mode == 0 || ctrl_x_mode == CTRL_X_WHOLE_LINE)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2777 && (!started_completion || found_all))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2778 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2779 found_all = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2780 while (*e_cpt == ',' || *e_cpt == ' ')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2781 e_cpt++;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2782 if (*e_cpt == '.' && !curbuf->b_scanned)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2783 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2784 ins_buf = curbuf;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2785 first_match_pos = *ini;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2786 /* So that ^N can match word immediately after cursor */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2787 if (ctrl_x_mode == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2788 dec(&first_match_pos);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2789 last_match_pos = first_match_pos;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2790 type = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2791 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2792 else if (vim_strchr((char_u *)"buwU", *e_cpt) != NULL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2793 && (ins_buf = ins_compl_next_buf(ins_buf, *e_cpt)) != curbuf)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2794 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2795 /* Scan a buffer, but not the current one. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2796 if (ins_buf->b_ml.ml_mfp != NULL) /* loaded buffer */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2797 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2798 started_completion = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2799 first_match_pos.col = last_match_pos.col = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2800 first_match_pos.lnum = ins_buf->b_ml.ml_line_count + 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2801 last_match_pos.lnum = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2802 type = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2803 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2804 else /* unloaded buffer, scan like dictionary */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2805 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2806 found_all = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2807 if (ins_buf->b_fname == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2808 continue;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2809 type = CTRL_X_DICTIONARY;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2810 dict = ins_buf->b_fname;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2811 dict_f = DICT_EXACT;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2812 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2813 sprintf((char *)IObuff, _("Scanning: %s"),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2814 ins_buf->b_fname == NULL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2815 ? buf_spname(ins_buf)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2816 : ins_buf->b_sfname == NULL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2817 ? (char *)ins_buf->b_fname
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2818 : (char *)ins_buf->b_sfname);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2819 msg_trunc_attr(IObuff, TRUE, hl_attr(HLF_R));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2820 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2821 else if (*e_cpt == NUL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2822 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2823 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2824 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2825 if (ctrl_x_mode == CTRL_X_WHOLE_LINE)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2826 type = -1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2827 else if (*e_cpt == 'k' || *e_cpt == 's')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2828 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2829 if (*e_cpt == 'k')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2830 type = CTRL_X_DICTIONARY;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2831 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2832 type = CTRL_X_THESAURUS;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2833 if (*++e_cpt != ',' && *e_cpt != NUL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2834 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2835 dict = e_cpt;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2836 dict_f = DICT_FIRST;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2837 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2838 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2839 #ifdef FEAT_FIND_ID
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2840 else if (*e_cpt == 'i')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2841 type = CTRL_X_PATH_PATTERNS;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2842 else if (*e_cpt == 'd')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2843 type = CTRL_X_PATH_DEFINES;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2844 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2845 else if (*e_cpt == ']' || *e_cpt == 't')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2846 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2847 type = CTRL_X_TAGS;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2848 sprintf((char*)IObuff, _("Scanning tags."));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2849 msg_trunc_attr(IObuff, TRUE, hl_attr(HLF_R));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2850 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2851 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2852 type = -1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2853
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2854 /* in any case e_cpt is advanced to the next entry */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2855 (void)copy_option_part(&e_cpt, IObuff, IOSIZE, ",");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2856
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2857 found_all = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2858 if (type == -1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2859 continue;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2860 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2861 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2862
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2863 switch (type)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2864 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2865 case -1:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2866 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2867 #ifdef FEAT_FIND_ID
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2868 case CTRL_X_PATH_PATTERNS:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2869 case CTRL_X_PATH_DEFINES:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2870 find_pattern_in_path(complete_pat, dir,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2871 (int)STRLEN(complete_pat), FALSE, FALSE,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2872 (type == CTRL_X_PATH_DEFINES
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2873 && !(continue_status & CONT_SOL))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2874 ? FIND_DEFINE : FIND_ANY, 1L, ACTION_EXPAND,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2875 (linenr_T)1, (linenr_T)MAXLNUM);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2876 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2877 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2878
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2879 case CTRL_X_DICTIONARY:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2880 case CTRL_X_THESAURUS:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2881 ins_compl_dictionaries(
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2882 dict ? dict
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2883 : (type == CTRL_X_THESAURUS
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2884 ? (*curbuf->b_p_tsr == NUL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2885 ? p_tsr
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2886 : curbuf->b_p_tsr)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2887 : (*curbuf->b_p_dict == NUL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2888 ? p_dict
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2889 : curbuf->b_p_dict)),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2890 complete_pat, dir,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2891 dict ? dict_f : 0, type == CTRL_X_THESAURUS);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2892 dict = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2893 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2894
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2895 case CTRL_X_TAGS:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2896 /* set p_ic according to p_ic, p_scs and pat for find_tags(). */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2897 save_p_ic = p_ic;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2898 p_ic = ignorecase(complete_pat);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2899
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2900 /* Find up to TAG_MANY matches. Avoids that an enourmous number
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2901 * of matches is found when complete_pat is empty */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2902 if (find_tags(complete_pat, &num_matches, &matches,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2903 TAG_REGEXP | TAG_NAMES | TAG_NOIC |
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2904 TAG_INS_COMP | (ctrl_x_mode ? TAG_VERBOSE : 0),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2905 TAG_MANY, curbuf->b_ffname) == OK && num_matches > 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2906 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2907 ins_compl_add_matches(num_matches, matches, dir);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2908 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2909 p_ic = save_p_ic;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2910 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2911
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2912 case CTRL_X_FILES:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2913 if (expand_wildcards(1, &complete_pat, &num_matches, &matches,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2914 EW_FILE|EW_DIR|EW_ADDSLASH|EW_SILENT) == OK)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2915 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2916
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2917 /* May change home directory back to "~". */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2918 tilde_replace(complete_pat, num_matches, matches);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2919 ins_compl_add_matches(num_matches, matches, dir);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2920 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2921 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2922
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2923 case CTRL_X_CMDLINE:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2924 if (expand_cmdline(&complete_xp, complete_pat,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2925 (int)STRLEN(complete_pat),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2926 &num_matches, &matches) == EXPAND_OK)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2927 ins_compl_add_matches(num_matches, matches, dir);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2928 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2929
12
bdeee1504ac1 updated for version 7.0004
vimboss
parents: 11
diff changeset
2930 #ifdef FEAT_COMPL_FUNC
bdeee1504ac1 updated for version 7.0004
vimboss
parents: 11
diff changeset
2931 case CTRL_X_FUNCTION:
bdeee1504ac1 updated for version 7.0004
vimboss
parents: 11
diff changeset
2932 num_matches = expand_by_function(first_match_pos.lnum,
bdeee1504ac1 updated for version 7.0004
vimboss
parents: 11
diff changeset
2933 first_match_pos.col, complete_pat, &matches);
bdeee1504ac1 updated for version 7.0004
vimboss
parents: 11
diff changeset
2934 if (num_matches > 0)
bdeee1504ac1 updated for version 7.0004
vimboss
parents: 11
diff changeset
2935 ins_compl_add_matches(num_matches, matches, dir);
bdeee1504ac1 updated for version 7.0004
vimboss
parents: 11
diff changeset
2936 break;
bdeee1504ac1 updated for version 7.0004
vimboss
parents: 11
diff changeset
2937 #endif
bdeee1504ac1 updated for version 7.0004
vimboss
parents: 11
diff changeset
2938
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2939 default: /* normal ^P/^N and ^X^L */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2940 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2941 * If 'infercase' is set, don't use 'smartcase' here
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2942 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2943 save_p_scs = p_scs;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2944 if (ins_buf->b_p_inf)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2945 p_scs = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2946 /* buffers other than curbuf are scanned from the beginning or the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2947 * end but never from the middle, thus setting nowrapscan in this
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2948 * buffers is a good idea, on the other hand, we always set
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2949 * wrapscan for curbuf to avoid missing matches -- Acevedo,Webb */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2950 save_p_ws = p_ws;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2951 if (ins_buf != curbuf)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2952 p_ws = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2953 else if (*e_cpt == '.')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2954 p_ws = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2955 for (;;)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2956 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2957 int reuse = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2958
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2959 /* ctrl_x_mode == CTRL_X_WHOLE_LINE || word-wise search that has
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2960 * added a word that was at the beginning of the line */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2961 if ( ctrl_x_mode == CTRL_X_WHOLE_LINE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2962 || (continue_status & CONT_SOL))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2963 found_new_match = search_for_exact_line(ins_buf, pos,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2964 dir, complete_pat);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2965 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2966 found_new_match = searchit(NULL, ins_buf, pos, dir,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2967 complete_pat, 1L, SEARCH_KEEP + SEARCH_NFMSG,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2968 RE_LAST);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2969 if (!started_completion)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2970 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2971 /* set started_completion even on fail */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2972 started_completion = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2973 first_match_pos = *pos;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2974 last_match_pos = *pos;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2975 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2976 else if (first_match_pos.lnum == last_match_pos.lnum
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2977 && first_match_pos.col == last_match_pos.col)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2978 found_new_match = FAIL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2979 if (found_new_match == FAIL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2980 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2981 if (ins_buf == curbuf)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2982 found_all = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2983 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2984 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2985
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2986 /* when ADDING, the text before the cursor matches, skip it */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2987 if ( (continue_status & CONT_ADDING) && ins_buf == curbuf
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2988 && ini->lnum == pos->lnum
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2989 && ini->col == pos->col)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2990 continue;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2991 ptr = ml_get_buf(ins_buf, pos->lnum, FALSE) + pos->col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2992 if (ctrl_x_mode == CTRL_X_WHOLE_LINE)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2993 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2994 if (continue_status & CONT_ADDING)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2995 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2996 if (pos->lnum >= ins_buf->b_ml.ml_line_count)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2997 continue;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2998 ptr = ml_get_buf(ins_buf, pos->lnum + 1, FALSE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2999 if (!p_paste)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3000 ptr = skipwhite(ptr);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3001 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3002 len = (int)STRLEN(ptr);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3003 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3004 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3005 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3006 tmp_ptr = ptr;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3007 if (continue_status & CONT_ADDING)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3008 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3009 tmp_ptr += completion_length;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3010 /* Skip if already inside a word. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3011 if (vim_iswordp(tmp_ptr))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3012 continue;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3013 /* Find start of next word. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3014 tmp_ptr = find_word_start(tmp_ptr);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3015 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3016 /* Find end of this word. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3017 tmp_ptr = find_word_end(tmp_ptr);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3018 len = (int)(tmp_ptr - ptr);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3019
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3020 if ((continue_status & CONT_ADDING)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3021 && len == completion_length)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3022 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3023 if (pos->lnum < ins_buf->b_ml.ml_line_count)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3024 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3025 /* Try next line, if any. the new word will be
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3026 * "join" as if the normal command "J" was used.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3027 * IOSIZE is always greater than
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3028 * completion_length, so the next STRNCPY always
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3029 * works -- Acevedo */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3030 STRNCPY(IObuff, ptr, len);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3031 ptr = ml_get_buf(ins_buf, pos->lnum + 1, FALSE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3032 tmp_ptr = ptr = skipwhite(ptr);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3033 /* Find start of next word. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3034 tmp_ptr = find_word_start(tmp_ptr);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3035 /* Find end of next word. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3036 tmp_ptr = find_word_end(tmp_ptr);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3037 if (tmp_ptr > ptr)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3038 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3039 if (*ptr != ')' && IObuff[len-1] != TAB)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3040 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3041 if (IObuff[len-1] != ' ')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3042 IObuff[len++] = ' ';
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3043 /* IObuf =~ "\k.* ", thus len >= 2 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3044 if (p_js
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3045 && (IObuff[len-2] == '.'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3046 || (vim_strchr(p_cpo, CPO_JOINSP)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3047 == NULL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3048 && (IObuff[len-2] == '?'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3049 || IObuff[len-2] == '!'))))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3050 IObuff[len++] = ' ';
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3051 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3052 /* copy as much as posible of the new word */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3053 if (tmp_ptr - ptr >= IOSIZE - len)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3054 tmp_ptr = ptr + IOSIZE - len - 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3055 STRNCPY(IObuff + len, ptr, tmp_ptr - ptr);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3056 len += (int)(tmp_ptr - ptr);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3057 reuse |= CONT_S_IPOS;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3058 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3059 IObuff[len] = NUL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3060 ptr = IObuff;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3061 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3062 if (len == completion_length)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3063 continue;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3064 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3065 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3066 if (ins_compl_add_infercase(ptr, len,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3067 ins_buf == curbuf ? NULL : ins_buf->b_sfname,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3068 dir, reuse) != FAIL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3069 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3070 found_new_match = OK;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3071 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3072 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3073 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3074 p_scs = save_p_scs;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3075 p_ws = save_p_ws;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3076 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3077 /* check if curr_match has changed, (e.g. other type of expansion
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3078 * added somenthing) */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3079 if (curr_match != old_match)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3080 found_new_match = OK;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3081
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3082 /* break the loop for specialized modes (use 'complete' just for the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3083 * generic ctrl_x_mode == 0) or when we've found a new match */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3084 if ((ctrl_x_mode != 0 && ctrl_x_mode != CTRL_X_WHOLE_LINE)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3085 || found_new_match != FAIL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3086 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3087
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3088 /* Mark a buffer scanned when it has been scanned completely */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3089 if (type == 0 || type == CTRL_X_PATH_PATTERNS)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3090 ins_buf->b_scanned = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3091
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3092 started_completion = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3093 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3094 started_completion = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3095
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3096 if ((ctrl_x_mode == 0 || ctrl_x_mode == CTRL_X_WHOLE_LINE)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3097 && *e_cpt == NUL) /* Got to end of 'complete' */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3098 found_new_match = FAIL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3099
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3100 i = -1; /* total of matches, unknown */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3101 if (found_new_match == FAIL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3102 || (ctrl_x_mode != 0 && ctrl_x_mode != CTRL_X_WHOLE_LINE))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3103 i = ins_compl_make_cyclic();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3104
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3105 /* If several matches were added (FORWARD) or the search failed and has
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3106 * just been made cyclic then we have to move curr_match to the next or
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3107 * previous entry (if any) -- Acevedo */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3108 curr_match = dir == FORWARD ? old_match->next : old_match->prev;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3109 if (curr_match == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3110 curr_match = old_match;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3111 return i;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3112 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3113
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3114 /* Delete the old text being completed. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3115 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3116 ins_compl_delete()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3117 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3118 int i;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3119
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3120 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3121 * In insert mode: Delete the typed part.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3122 * In replace mode: Put the old characters back, if any.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3123 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3124 i = complete_col + (continue_status & CONT_ADDING ? completion_length : 0);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3125 backspace_until_column(i);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3126 changed_cline_bef_curs();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3127 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3128
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3129 /* Insert the new text being completed. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3130 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3131 ins_compl_insert()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3132 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3133 ins_bytes(shown_match->str + curwin->w_cursor.col - complete_col);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3134 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3135
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3136 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3137 * Fill in the next completion in the current direction.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3138 * If allow_get_expansion is TRUE, then we may call ins_compl_get_exp() to get
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3139 * more completions. If it is FALSE, then we just do nothing when there are
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3140 * no more completions in a given direction. The latter case is used when we
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3141 * are still in the middle of finding completions, to allow browsing through
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3142 * the ones found so far.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3143 * Return the total number of matches, or -1 if still unknown -- webb.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3144 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3145 * curr_match is currently being used by ins_compl_get_exp(), so we use
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3146 * shown_match here.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3147 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3148 * Note that this function may be called recursively once only. First with
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3149 * allow_get_expansion TRUE, which calls ins_compl_get_exp(), which in turn
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3150 * calls this function with allow_get_expansion FALSE.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3151 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3152 static int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3153 ins_compl_next(allow_get_expansion)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3154 int allow_get_expansion;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3155 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3156 int num_matches = -1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3157 int i;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3158
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3159 if (allow_get_expansion)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3160 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3161 /* Delete old text to be replaced */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3162 ins_compl_delete();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3163 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3164 completion_pending = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3165 if (shown_direction == FORWARD && shown_match->next != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3166 shown_match = shown_match->next;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3167 else if (shown_direction == BACKWARD && shown_match->prev != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3168 shown_match = shown_match->prev;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3169 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3170 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3171 completion_pending = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3172 if (allow_get_expansion)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3173 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3174 num_matches = ins_compl_get_exp(&initial_pos, complete_direction);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3175 if (completion_pending)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3176 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3177 if (complete_direction == shown_direction)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3178 shown_match = curr_match;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3179 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3180 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3181 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3182 return -1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3183 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3184
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3185 /* Insert the text of the new completion */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3186 ins_compl_insert();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3187
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3188 if (!allow_get_expansion)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3189 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3190 /* Display the current match. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3191 update_screen(0);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3192
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3193 /* Delete old text to be replaced, since we're still searching and
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3194 * don't want to match ourselves! */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3195 ins_compl_delete();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3196 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3197
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3198 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3199 * Show the file name for the match (if any)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3200 * Truncate the file name to avoid a wait for return.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3201 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3202 if (shown_match->fname != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3203 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3204 STRCPY(IObuff, "match in file ");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3205 i = (vim_strsize(shown_match->fname) + 16) - sc_col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3206 if (i <= 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3207 i = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3208 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3209 STRCAT(IObuff, "<");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3210 STRCAT(IObuff, shown_match->fname + i);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3211 msg(IObuff);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3212 redraw_cmdline = FALSE; /* don't overwrite! */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3213 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3214
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3215 return num_matches;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3216 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3217
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3218 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3219 * Call this while finding completions, to check whether the user has hit a key
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3220 * that should change the currently displayed completion, or exit completion
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3221 * mode. Also, when completion_pending is TRUE, show a completion as soon as
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3222 * possible. -- webb
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3223 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3224 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3225 ins_compl_check_keys()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3226 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3227 static int count = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3228
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3229 int c;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3230
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3231 /* Don't check when reading keys from a script. That would break the test
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3232 * scripts */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3233 if (using_script())
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3234 return;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3235
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3236 /* Only do this at regular intervals */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3237 if (++count < CHECK_KEYS_TIME)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3238 return;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3239 count = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3240
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3241 ++no_mapping;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3242 c = vpeekc_any();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3243 --no_mapping;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3244 if (c != NUL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3245 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3246 if (vim_is_ctrl_x_key(c) && c != Ctrl_X && c != Ctrl_R)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3247 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3248 c = safe_vgetc(); /* Eat the character */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3249 if (c == Ctrl_P || c == Ctrl_L)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3250 shown_direction = BACKWARD;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3251 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3252 shown_direction = FORWARD;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3253 (void)ins_compl_next(FALSE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3254 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3255 else if (c != Ctrl_R)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3256 completion_interrupted = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3257 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3258 if (completion_pending && !got_int)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3259 (void)ins_compl_next(FALSE);
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 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3263 * Do Insert mode completion.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3264 * Called when character "c" was typed, which has a meaning for completion.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3265 * Returns OK if completion was done, FAIL if something failed (out of mem).
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3266 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3267 static int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3268 ins_complete(c)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3269 int c;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3270 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3271 char_u *line;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3272 char_u *tmp_ptr = NULL; /* init for gcc */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3273 int temp = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3274
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3275 if (c == Ctrl_P || c == Ctrl_L)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3276 complete_direction = BACKWARD;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3277 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3278 complete_direction = FORWARD;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3279 if (!started_completion)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3280 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3281 /* First time we hit ^N or ^P (in a row, I mean) */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3282
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3283 /* Turn off 'sm' so we don't show matches with ^X^L */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3284 save_sm = p_sm;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3285 p_sm = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3286
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3287 did_ai = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3288 #ifdef FEAT_SMARTINDENT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3289 did_si = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3290 can_si = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3291 can_si_back = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3292 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3293 if (stop_arrow() == FAIL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3294 return FAIL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3295
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3296 line = ml_get(curwin->w_cursor.lnum);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3297 complete_col = curwin->w_cursor.col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3298
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3299 /* if this same ctrl_x_mode has been interrupted use the text from
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3300 * "initial_pos" to the cursor as a pattern to add a new word instead
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3301 * of expand the one before the cursor, in word-wise if "initial_pos"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3302 * 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
3303 * been split because it was longer than 'tw'). if SOL is set then
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3304 * skip the previous pattern, a word at the beginning of the line has
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3305 * been inserted, we'll look for that -- Acevedo. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3306 if ((continue_status & CONT_INTRPT) && continue_mode == ctrl_x_mode)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3307 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3308 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3309 * it is a continued search
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3310 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3311 continue_status &= ~CONT_INTRPT; /* remove INTRPT */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3312 if (ctrl_x_mode == 0 || ctrl_x_mode == CTRL_X_PATH_PATTERNS
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3313 || ctrl_x_mode == CTRL_X_PATH_DEFINES)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3314 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3315 if (initial_pos.lnum != curwin->w_cursor.lnum)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3316 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3317 /* line (probably) wrapped, set initial_pos to the first
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3318 * non_blank in the line, if it is not a wordchar include
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3319 * it to get a better pattern, but then we don't want the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3320 * "\\<" prefix, check it bellow */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3321 tmp_ptr = skipwhite(line);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3322 initial_pos.col = (colnr_T) (tmp_ptr - line);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3323 initial_pos.lnum = curwin->w_cursor.lnum;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3324 continue_status &= ~CONT_SOL; /* clear SOL if present */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3325 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3326 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3327 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3328 /* S_IPOS was set when we inserted a word that was at the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3329 * beginning of the line, which means that we'll go to SOL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3330 * mode but first we need to redefine initial_pos */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3331 if (continue_status & CONT_S_IPOS)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3332 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3333 continue_status |= CONT_SOL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3334 initial_pos.col = (colnr_T) (skipwhite(line + completion_length +
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3335 initial_pos.col) - line);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3336 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3337 tmp_ptr = line + initial_pos.col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3338 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3339 temp = curwin->w_cursor.col - (int)(tmp_ptr - line);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3340 /* IObuf is used to add a "word from the next line" would we
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3341 * have enough space? just being paranoic */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3342 #define MIN_SPACE 75
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3343 if (temp > (IOSIZE - MIN_SPACE))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3344 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3345 continue_status &= ~CONT_SOL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3346 temp = (IOSIZE - MIN_SPACE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3347 tmp_ptr = line + curwin->w_cursor.col - temp;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3348 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3349 continue_status |= CONT_ADDING | CONT_N_ADDS;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3350 if (temp < 1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3351 continue_status &= CONT_LOCAL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3352 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3353 else if (ctrl_x_mode == CTRL_X_WHOLE_LINE)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3354 continue_status = CONT_ADDING | CONT_N_ADDS;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3355 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3356 continue_status = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3357 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3358 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3359 continue_status &= CONT_LOCAL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3360
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3361 if (!(continue_status & CONT_ADDING)) /* normal expansion */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3362 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3363 continue_mode = ctrl_x_mode;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3364 if (ctrl_x_mode != 0) /* Remove LOCAL if ctrl_x_mode != 0 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3365 continue_status = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3366 continue_status |= CONT_N_ADDS;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3367 initial_pos = curwin->w_cursor;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3368 temp = (int)complete_col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3369 tmp_ptr = line;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3370 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3371
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3372 /* Work out completion pattern and original text -- webb */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3373 if (ctrl_x_mode == 0 || (ctrl_x_mode & CTRL_X_WANT_IDENT))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3374 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3375 if ( (continue_status & CONT_SOL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3376 || ctrl_x_mode == CTRL_X_PATH_DEFINES)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3377 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3378 if (!(continue_status & CONT_ADDING))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3379 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3380 while (--temp >= 0 && vim_isIDc(line[temp]))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3381 ;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3382 tmp_ptr += ++temp;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3383 temp = complete_col - temp;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3384 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3385 if (p_ic)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3386 complete_pat = str_foldcase(tmp_ptr, temp);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3387 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3388 complete_pat = vim_strnsave(tmp_ptr, temp);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3389 if (complete_pat == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3390 return FAIL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3391 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3392 else if (continue_status & CONT_ADDING)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3393 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3394 char_u *prefix = (char_u *)"\\<";
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3395
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3396 /* we need 3 extra chars, 1 for the NUL and
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3397 * 2 >= strlen(prefix) -- Acevedo */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3398 complete_pat = alloc(quote_meta(NULL, tmp_ptr, temp) + 3);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3399 if (complete_pat == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3400 return FAIL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3401 if (!vim_iswordp(tmp_ptr)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3402 || (tmp_ptr > line
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3403 && (
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3404 #ifdef FEAT_MBYTE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3405 vim_iswordp(mb_prevptr(line, tmp_ptr))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3406 #else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3407 vim_iswordc(*(tmp_ptr - 1))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3408 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3409 )))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3410 prefix = (char_u *)"";
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3411 STRCPY((char *)complete_pat, prefix);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3412 (void)quote_meta(complete_pat + STRLEN(prefix), tmp_ptr, temp);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3413 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3414 else if (
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3415 #ifdef FEAT_MBYTE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3416 --temp < 0 || !vim_iswordp(mb_prevptr(line,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3417 line + temp + 1))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3418 #else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3419 --temp < 0 || !vim_iswordc(line[temp])
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3420 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3421 )
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3422 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3423 /* Match any word of at least two chars */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3424 complete_pat = vim_strsave((char_u *)"\\<\\k\\k");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3425 if (complete_pat == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3426 return FAIL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3427 tmp_ptr += complete_col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3428 temp = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3429 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3430 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3431 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3432 #ifdef FEAT_MBYTE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3433 /* Search the point of change class of multibyte character
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3434 * or not a word single byte character backward. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3435 if (has_mbyte)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3436 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3437 int base_class;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3438 int head_off;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3439
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3440 temp -= (*mb_head_off)(line, line + temp);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3441 base_class = mb_get_class(line + temp);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3442 while (--temp >= 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3443 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3444 head_off = (*mb_head_off)(line, line + temp);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3445 if (base_class != mb_get_class(line + temp - head_off))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3446 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3447 temp -= head_off;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3448 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3449 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3450 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3451 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3452 while (--temp >= 0 && vim_iswordc(line[temp]))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3453 ;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3454 tmp_ptr += ++temp;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3455 if ((temp = (int)complete_col - temp) == 1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3456 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3457 /* Only match word with at least two chars -- webb
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3458 * there's no need to call quote_meta,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3459 * alloc(7) is enough -- Acevedo
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3460 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3461 complete_pat = alloc(7);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3462 if (complete_pat == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3463 return FAIL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3464 STRCPY((char *)complete_pat, "\\<");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3465 (void)quote_meta(complete_pat + 2, tmp_ptr, 1);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3466 STRCAT((char *)complete_pat, "\\k");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3467 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3468 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3469 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3470 complete_pat = alloc(quote_meta(NULL, tmp_ptr, temp) + 3);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3471 if (complete_pat == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3472 return FAIL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3473 STRCPY((char *)complete_pat, "\\<");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3474 (void)quote_meta(complete_pat + 2, tmp_ptr, temp);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3475 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3476 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3477 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3478 else if (ctrl_x_mode == CTRL_X_WHOLE_LINE)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3479 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3480 tmp_ptr = skipwhite(line);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3481 temp = (int)complete_col - (int)(tmp_ptr - line);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3482 if (temp < 0) /* cursor in indent: empty pattern */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3483 temp = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3484 if (p_ic)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3485 complete_pat = str_foldcase(tmp_ptr, temp);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3486 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3487 complete_pat = vim_strnsave(tmp_ptr, temp);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3488 if (complete_pat == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3489 return FAIL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3490 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3491 else if (ctrl_x_mode == CTRL_X_FILES)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3492 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3493 while (--temp >= 0 && vim_isfilec(line[temp]))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3494 ;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3495 tmp_ptr += ++temp;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3496 temp = (int)complete_col - temp;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3497 complete_pat = addstar(tmp_ptr, temp, EXPAND_FILES);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3498 if (complete_pat == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3499 return FAIL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3500 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3501 else if (ctrl_x_mode == CTRL_X_CMDLINE)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3502 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3503 complete_pat = vim_strnsave(line, complete_col);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3504 if (complete_pat == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3505 return FAIL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3506 set_cmd_context(&complete_xp, complete_pat,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3507 (int)STRLEN(complete_pat), complete_col);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3508 if (complete_xp.xp_context == EXPAND_UNSUCCESSFUL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3509 || complete_xp.xp_context == EXPAND_NOTHING)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3510 return FAIL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3511 temp = (int)(complete_xp.xp_pattern - complete_pat);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3512 tmp_ptr = line + temp;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3513 temp = complete_col - temp;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3514 }
12
bdeee1504ac1 updated for version 7.0004
vimboss
parents: 11
diff changeset
3515 #ifdef FEAT_COMPL_FUNC
bdeee1504ac1 updated for version 7.0004
vimboss
parents: 11
diff changeset
3516 else if (ctrl_x_mode == CTRL_X_FUNCTION)
bdeee1504ac1 updated for version 7.0004
vimboss
parents: 11
diff changeset
3517 {
bdeee1504ac1 updated for version 7.0004
vimboss
parents: 11
diff changeset
3518 /*
bdeee1504ac1 updated for version 7.0004
vimboss
parents: 11
diff changeset
3519 * Call user defined function 'completefunc' with line content,
bdeee1504ac1 updated for version 7.0004
vimboss
parents: 11
diff changeset
3520 * cursor column number and preproc is 1. Obtain length of text
bdeee1504ac1 updated for version 7.0004
vimboss
parents: 11
diff changeset
3521 * to use for completion.
bdeee1504ac1 updated for version 7.0004
vimboss
parents: 11
diff changeset
3522 */
bdeee1504ac1 updated for version 7.0004
vimboss
parents: 11
diff changeset
3523 char_u *lenstr;
bdeee1504ac1 updated for version 7.0004
vimboss
parents: 11
diff changeset
3524 int keeplen = 0;
bdeee1504ac1 updated for version 7.0004
vimboss
parents: 11
diff changeset
3525
bdeee1504ac1 updated for version 7.0004
vimboss
parents: 11
diff changeset
3526 /* Call 'completefunc' and get pattern length as a string */
bdeee1504ac1 updated for version 7.0004
vimboss
parents: 11
diff changeset
3527 lenstr = call_completefunc(line, NULL, complete_col, 1);
bdeee1504ac1 updated for version 7.0004
vimboss
parents: 11
diff changeset
3528 if (lenstr == NULL)
bdeee1504ac1 updated for version 7.0004
vimboss
parents: 11
diff changeset
3529 return FAIL;
20
4ac1dce8dd5e updated for version 7.0012
vimboss
parents: 12
diff changeset
3530 keeplen = atoi((char *)lenstr);
12
bdeee1504ac1 updated for version 7.0004
vimboss
parents: 11
diff changeset
3531 vim_free(lenstr);
bdeee1504ac1 updated for version 7.0004
vimboss
parents: 11
diff changeset
3532 if (keeplen < 0)
bdeee1504ac1 updated for version 7.0004
vimboss
parents: 11
diff changeset
3533 return FAIL;
bdeee1504ac1 updated for version 7.0004
vimboss
parents: 11
diff changeset
3534 if ((colnr_T)keeplen > complete_col)
bdeee1504ac1 updated for version 7.0004
vimboss
parents: 11
diff changeset
3535 keeplen = complete_col;
bdeee1504ac1 updated for version 7.0004
vimboss
parents: 11
diff changeset
3536
bdeee1504ac1 updated for version 7.0004
vimboss
parents: 11
diff changeset
3537 /* Setup variables for completion */
bdeee1504ac1 updated for version 7.0004
vimboss
parents: 11
diff changeset
3538 tmp_ptr = line + keeplen;
bdeee1504ac1 updated for version 7.0004
vimboss
parents: 11
diff changeset
3539 temp = complete_col - keeplen;
bdeee1504ac1 updated for version 7.0004
vimboss
parents: 11
diff changeset
3540 complete_pat = vim_strnsave(tmp_ptr, temp);
bdeee1504ac1 updated for version 7.0004
vimboss
parents: 11
diff changeset
3541 if (complete_pat == NULL)
bdeee1504ac1 updated for version 7.0004
vimboss
parents: 11
diff changeset
3542 return FAIL;
bdeee1504ac1 updated for version 7.0004
vimboss
parents: 11
diff changeset
3543 }
bdeee1504ac1 updated for version 7.0004
vimboss
parents: 11
diff changeset
3544 #endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3545 complete_col = (colnr_T) (tmp_ptr - line);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3546
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3547 if (continue_status & CONT_ADDING)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3548 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3549 edit_submode_pre = (char_u *)_(" Adding");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3550 if (ctrl_x_mode == CTRL_X_WHOLE_LINE)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3551 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3552 /* Insert a new line, keep indentation but ignore 'comments' */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3553 #ifdef FEAT_COMMENTS
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3554 char_u *old = curbuf->b_p_com;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3555
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3556 curbuf->b_p_com = (char_u *)"";
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3557 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3558 initial_pos.lnum = curwin->w_cursor.lnum;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3559 initial_pos.col = complete_col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3560 ins_eol('\r');
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3561 #ifdef FEAT_COMMENTS
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3562 curbuf->b_p_com = old;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3563 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3564 tmp_ptr = (char_u *)"";
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3565 temp = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3566 complete_col = curwin->w_cursor.col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3567 }
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 edit_submode_pre = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3572 initial_pos.col = complete_col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3573 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3574
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3575 if (continue_status & CONT_LOCAL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3576 edit_submode = (char_u *)_(ctrl_x_msgs[2]);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3577 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3578 edit_submode = (char_u *)_(CTRL_X_MSG(ctrl_x_mode));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3579
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3580 completion_length = temp;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3581
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3582 /* Always add completion for the original text. Note that
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3583 * "original_text" itself (not a copy) is added, it will be freed when
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3584 * the list of matches is freed. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3585 if ((original_text = vim_strnsave(tmp_ptr, temp)) == NULL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3586 || ins_compl_add(original_text, -1, NULL, 0, ORIGINAL_TEXT) != OK)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3587 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3588 vim_free(complete_pat);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3589 complete_pat = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3590 vim_free(original_text);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3591 return FAIL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3592 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3593
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3594 /* showmode might reset the internal line pointers, so it must
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3595 * be called before line = ml_get(), or when this address is no
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3596 * longer needed. -- Acevedo.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3597 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3598 edit_submode_extra = (char_u *)_("-- Searching...");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3599 edit_submode_highl = HLF_COUNT;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3600 showmode();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3601 edit_submode_extra = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3602 out_flush();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3603 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3604
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3605 shown_match = curr_match;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3606 shown_direction = complete_direction;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3607
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3608 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3609 * Find next match.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3610 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3611 temp = ins_compl_next(TRUE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3612
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3613 if (temp > 1) /* all matches have been found */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3614 completion_matches = temp;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3615 curr_match = shown_match;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3616 complete_direction = shown_direction;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3617 completion_interrupted = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3618
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3619 /* eat the ESC to avoid leaving insert mode */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3620 if (got_int && !global_busy)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3621 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3622 (void)vgetc();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3623 got_int = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3624 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3625
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3626 /* we found no match if the list has only the original_text-entry */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3627 if (first_match == first_match->next)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3628 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3629 edit_submode_extra = (continue_status & CONT_ADDING)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3630 && completion_length > 1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3631 ? (char_u *)_(e_hitend) : (char_u *)_(e_patnotf);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3632 edit_submode_highl = HLF_E;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3633 /* 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
3634 * because we couldn't expand anything at first place, but if we used
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3635 * ^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
3636 * (such as M in M'exico) if not tried already. -- Acevedo */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3637 if ( completion_length > 1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3638 || (continue_status & CONT_ADDING)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3639 || (ctrl_x_mode != 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3640 && ctrl_x_mode != CTRL_X_PATH_PATTERNS
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3641 && ctrl_x_mode != CTRL_X_PATH_DEFINES))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3642 continue_status &= ~CONT_N_ADDS;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3643 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3644
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3645 if (curr_match->original & CONT_S_IPOS)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3646 continue_status |= CONT_S_IPOS;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3647 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3648 continue_status &= ~CONT_S_IPOS;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3649
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3650 if (edit_submode_extra == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3651 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3652 if (curr_match->original & ORIGINAL_TEXT)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3653 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3654 edit_submode_extra = (char_u *)_("Back at original");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3655 edit_submode_highl = HLF_W;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3656 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3657 else if (continue_status & CONT_S_IPOS)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3658 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3659 edit_submode_extra = (char_u *)_("Word from other line");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3660 edit_submode_highl = HLF_COUNT;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3661 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3662 else if (curr_match->next == curr_match->prev)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3663 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3664 edit_submode_extra = (char_u *)_("The only match");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3665 edit_submode_highl = HLF_COUNT;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3666 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3667 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3668 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3669 /* Update completion sequence number when needed. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3670 if (curr_match->number == -1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3671 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3672 int number = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3673 struct Completion *match;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3674
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3675 if (complete_direction == FORWARD)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3676 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3677 /* search backwards for the first valid (!= -1) number.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3678 * This should normally succeed already at the first loop
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3679 * cycle, so it's fast! */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3680 for (match = curr_match->prev; match != NULL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3681 && match != first_match; match = match->prev)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3682 if (match->number != -1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3683 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3684 number = match->number;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3685 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3686 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3687 if (match != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3688 /* go up and assign all numbers which are not assigned
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3689 * yet */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3690 for (match = match->next; match
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3691 && match->number == -1; match = match->next)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3692 match->number = ++number;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3693 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3694 else /* BACKWARD */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3695 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3696 /* search forwards (upwards) for the first valid (!= -1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3697 * number. This should normally succeed already at the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3698 * first loop cycle, so it's fast! */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3699 for (match = curr_match->next; match != NULL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3700 && match != first_match; match = match->next)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3701 if (match->number != -1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3702 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3703 number = match->number;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3704 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3705 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3706 if (match != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3707 /* go down and assign all numbers which are not
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3708 * assigned yet */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3709 for (match = match->prev; match
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3710 && match->number == -1; match = match->prev)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3711 match->number = ++number;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3712 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3713 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3714
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3715 /* The match should always have a sequnce number now, this is just
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3716 * a safety check. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3717 if (curr_match->number != -1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3718 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3719 /* Space for 10 text chars. + 2x10-digit no.s */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3720 static char_u match_ref[31];
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3721
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3722 if (completion_matches > 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3723 sprintf((char *)IObuff, _("match %d of %d"),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3724 curr_match->number, completion_matches);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3725 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3726 sprintf((char *)IObuff, _("match %d"), curr_match->number);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3727 STRNCPY(match_ref, IObuff, 30 );
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3728 match_ref[30] = '\0';
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3729 edit_submode_extra = match_ref;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3730 edit_submode_highl = HLF_R;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3731 if (dollar_vcol)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3732 curs_columns(FALSE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3733 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3734 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3735 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3736
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3737 /* Show a message about what (completion) mode we're in. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3738 showmode();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3739 if (edit_submode_extra != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3740 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3741 if (!p_smd)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3742 msg_attr(edit_submode_extra,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3743 edit_submode_highl < HLF_COUNT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3744 ? hl_attr(edit_submode_highl) : 0);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3745 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3746 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3747 msg_clr_cmdline(); /* necessary for "noshowmode" */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3748
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3749 return OK;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3750 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3751
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3752 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3753 * Looks in the first "len" chars. of "src" for search-metachars.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3754 * If dest is not NULL the chars. are copied there quoting (with
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3755 * a backslash) the metachars, and dest would be NUL terminated.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3756 * Returns the length (needed) of dest
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3757 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3758 static int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3759 quote_meta(dest, src, len)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3760 char_u *dest;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3761 char_u *src;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3762 int len;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3763 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3764 int m;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3765
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3766 for (m = len; --len >= 0; src++)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3767 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3768 switch (*src)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3769 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3770 case '.':
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3771 case '*':
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3772 case '[':
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3773 if (ctrl_x_mode == CTRL_X_DICTIONARY
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3774 || ctrl_x_mode == CTRL_X_THESAURUS)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3775 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3776 case '~':
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3777 if (!p_magic) /* quote these only if magic is set */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3778 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3779 case '\\':
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3780 if (ctrl_x_mode == CTRL_X_DICTIONARY
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3781 || ctrl_x_mode == CTRL_X_THESAURUS)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3782 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3783 case '^': /* currently it's not needed. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3784 case '$':
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3785 m++;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3786 if (dest != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3787 *dest++ = '\\';
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3788 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3789 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3790 if (dest != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3791 *dest++ = *src;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3792 #ifdef FEAT_MBYTE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3793 /* Copy remaining bytes of a multibyte character. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3794 if (has_mbyte)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3795 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3796 int i, mb_len;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3797
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3798 mb_len = (*mb_ptr2len_check)(src) - 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3799 if (mb_len > 0 && len >= mb_len)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3800 for (i = 0; i < mb_len; ++i)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3801 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3802 --len;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3803 ++src;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3804 if (dest != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3805 *dest++ = *src;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3806 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3807 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3808 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3809 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3810 if (dest != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3811 *dest = NUL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3812
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3813 return m;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3814 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3815 #endif /* FEAT_INS_EXPAND */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3816
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3817 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3818 * Next character is interpreted literally.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3819 * A one, two or three digit decimal number is interpreted as its byte value.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3820 * If one or two digits are entered, the next character is given to vungetc().
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3821 * For Unicode a character > 255 may be returned.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3822 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3823 int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3824 get_literal()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3825 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3826 int cc;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3827 int nc;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3828 int i;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3829 int hex = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3830 int octal = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3831 #ifdef FEAT_MBYTE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3832 int unicode = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3833 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3834
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3835 if (got_int)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3836 return Ctrl_C;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3837
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3838 #ifdef FEAT_GUI
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3839 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3840 * In GUI there is no point inserting the internal code for a special key.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3841 * It is more useful to insert the string "<KEY>" instead. This would
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3842 * probably be useful in a text window too, but it would not be
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3843 * vi-compatible (maybe there should be an option for it?) -- webb
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3844 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3845 if (gui.in_use)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3846 ++allow_keys;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3847 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3848 #ifdef USE_ON_FLY_SCROLL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3849 dont_scroll = TRUE; /* disallow scrolling here */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3850 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3851 ++no_mapping; /* don't map the next key hits */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3852 cc = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3853 i = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3854 for (;;)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3855 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3856 do
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3857 nc = safe_vgetc();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3858 while (nc == K_IGNORE || nc == K_VER_SCROLLBAR
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3859 || nc == K_HOR_SCROLLBAR);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3860 #ifdef FEAT_CMDL_INFO
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3861 if (!(State & CMDLINE)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3862 # ifdef FEAT_MBYTE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3863 && MB_BYTE2LEN_CHECK(nc) == 1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3864 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3865 )
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3866 add_to_showcmd(nc);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3867 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3868 if (nc == 'x' || nc == 'X')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3869 hex = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3870 else if (nc == 'o' || nc == 'O')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3871 octal = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3872 #ifdef FEAT_MBYTE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3873 else if (nc == 'u' || nc == 'U')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3874 unicode = nc;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3875 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3876 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3877 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3878 if (hex
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3879 #ifdef FEAT_MBYTE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3880 || unicode != 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3881 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3882 )
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3883 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3884 if (!vim_isxdigit(nc))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3885 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3886 cc = cc * 16 + hex2nr(nc);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3887 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3888 else if (octal)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3889 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3890 if (nc < '0' || nc > '7')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3891 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3892 cc = cc * 8 + nc - '0';
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3893 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3894 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3895 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3896 if (!VIM_ISDIGIT(nc))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3897 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3898 cc = cc * 10 + nc - '0';
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3899 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3900
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3901 ++i;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3902 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3903
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3904 if (cc > 255
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3905 #ifdef FEAT_MBYTE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3906 && unicode == 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3907 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3908 )
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3909 cc = 255; /* limit range to 0-255 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3910 nc = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3911
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3912 if (hex) /* hex: up to two chars */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3913 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3914 if (i >= 2)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3915 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3916 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3917 #ifdef FEAT_MBYTE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3918 else if (unicode) /* Unicode: up to four or eight chars */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3919 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3920 if ((unicode == 'u' && i >= 4) || (unicode == 'U' && i >= 8))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3921 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3922 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3923 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3924 else if (i >= 3) /* decimal or octal: up to three chars */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3925 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3926 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3927 if (i == 0) /* no number entered */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3928 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3929 if (nc == K_ZERO) /* NUL is stored as NL */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3930 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3931 cc = '\n';
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3932 nc = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3933 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3934 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3935 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3936 cc = nc;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3937 nc = 0;
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
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3941 if (cc == 0) /* NUL is stored as NL */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3942 cc = '\n';
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3943
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3944 --no_mapping;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3945 #ifdef FEAT_GUI
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3946 if (gui.in_use)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3947 --allow_keys;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3948 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3949 if (nc)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3950 vungetc(nc);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3951 got_int = FALSE; /* CTRL-C typed after CTRL-V is not an interrupt */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3952 return cc;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3953 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3954
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3955 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3956 * Insert character, taking care of special keys and mod_mask
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3957 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3958 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3959 insert_special(c, allow_modmask, ctrlv)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3960 int c;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3961 int allow_modmask;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3962 int ctrlv; /* c was typed after CTRL-V */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3963 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3964 char_u *p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3965 int len;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3966
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3967 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3968 * Special function key, translate into "<Key>". Up to the last '>' is
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3969 * inserted with ins_str(), so as not to replace characters in replace
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3970 * mode.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3971 * Only use mod_mask for special keys, to avoid things like <S-Space>,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3972 * unless 'allow_modmask' is TRUE.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3973 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3974 #ifdef MACOS
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3975 /* Command-key never produces a normal key */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3976 if (mod_mask & MOD_MASK_CMD)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3977 allow_modmask = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3978 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3979 if (IS_SPECIAL(c) || (mod_mask && allow_modmask))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3980 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3981 p = get_special_key_name(c, mod_mask);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3982 len = (int)STRLEN(p);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3983 c = p[len - 1];
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3984 if (len > 2)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3985 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3986 if (stop_arrow() == FAIL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3987 return;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3988 p[len - 1] = NUL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3989 ins_str(p);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3990 AppendToRedobuffLit(p);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3991 ctrlv = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3992 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3993 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3994 if (stop_arrow() == OK)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3995 insertchar(c, ctrlv ? INSCHAR_CTRLV : 0, -1);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3996 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3997
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3998 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3999 * Special characters in this context are those that need processing other
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4000 * than the simple insertion that can be performed here. This includes ESC
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4001 * which terminates the insert, and CR/NL which need special processing to
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4002 * open up a new line. This routine tries to optimize insertions performed by
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4003 * the "redo", "undo" or "put" commands, so it needs to know when it should
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4004 * stop and defer processing to the "normal" mechanism.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4005 * '0' and '^' are special, because they can be followed by CTRL-D.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4006 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4007 #ifdef EBCDIC
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4008 # define ISSPECIAL(c) ((c) < ' ' || (c) == '0' || (c) == '^')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4009 #else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4010 # define ISSPECIAL(c) ((c) < ' ' || (c) >= DEL || (c) == '0' || (c) == '^')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4011 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4012
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4013 #ifdef FEAT_MBYTE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4014 # 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
4015 #else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4016 # define WHITECHAR(cc) vim_iswhite(cc)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4017 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4018
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4019 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4020 insertchar(c, flags, second_indent)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4021 int c; /* character to insert or NUL */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4022 int flags; /* INSCHAR_FORMAT, etc. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4023 int second_indent; /* indent for second line if >= 0 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4024 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4025 int haveto_redraw = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4026 int textwidth;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4027 #ifdef FEAT_COMMENTS
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4028 colnr_T leader_len;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4029 char_u *p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4030 int no_leader = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4031 int do_comments = (flags & INSCHAR_DO_COM);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4032 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4033 int fo_white_par;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4034 int first_line = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4035 int fo_ins_blank;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4036 #ifdef FEAT_MBYTE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4037 int fo_multibyte;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4038 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4039 int save_char = NUL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4040 int cc;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4041
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4042 textwidth = comp_textwidth(flags & INSCHAR_FORMAT);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4043 fo_ins_blank = has_format_option(FO_INS_BLANK);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4044 #ifdef FEAT_MBYTE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4045 fo_multibyte = has_format_option(FO_MBYTE_BREAK);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4046 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4047 fo_white_par = has_format_option(FO_WHITE_PAR);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4048
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4049 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4050 * Try to break the line in two or more pieces when:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4051 * - Always do this if we have been called to do formatting only.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4052 * - Always do this when 'formatoptions' has the 'a' flag and the line
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4053 * ends in white space.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4054 * - Otherwise:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4055 * - Don't do this if inserting a blank
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4056 * - Don't do this if an existing character is being replaced, unless
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4057 * we're in VREPLACE mode.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4058 * - Do this if the cursor is not on the line where insert started
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4059 * or - 'formatoptions' doesn't have 'l' or the line was not too long
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4060 * before the insert.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4061 * - 'formatoptions' doesn't have 'b' or a blank was inserted at or
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4062 * before 'textwidth'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4063 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4064 if (textwidth
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4065 && ((flags & INSCHAR_FORMAT)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4066 || (!vim_iswhite(c)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4067 && !((State & REPLACE_FLAG)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4068 #ifdef FEAT_VREPLACE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4069 && !(State & VREPLACE_FLAG)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4070 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4071 && *ml_get_cursor() != NUL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4072 && (curwin->w_cursor.lnum != Insstart.lnum
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4073 || ((!has_format_option(FO_INS_LONG)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4074 || Insstart_textlen <= (colnr_T)textwidth)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4075 && (!fo_ins_blank
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4076 || Insstart_blank_vcol <= (colnr_T)textwidth
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4077 ))))))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4078 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4079 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4080 * 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
4081 * deleted. Replace it with an 'x' temporarily.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4082 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4083 if (!curbuf->b_p_ai)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4084 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4085 cc = gchar_cursor();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4086 if (vim_iswhite(cc))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4087 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4088 save_char = cc;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4089 pchar_cursor('x');
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4090 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4091 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4092
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4093 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4094 * Repeat breaking lines, until the current line is not too long.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4095 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4096 while (!got_int)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4097 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4098 int startcol; /* Cursor column at entry */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4099 int wantcol; /* column at textwidth border */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4100 int foundcol; /* column for start of spaces */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4101 int end_foundcol = 0; /* column for start of word */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4102 colnr_T len;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4103 colnr_T virtcol;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4104 #ifdef FEAT_VREPLACE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4105 int orig_col = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4106 char_u *saved_text = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4107 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4108 colnr_T col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4109
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4110 virtcol = get_nolist_virtcol();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4111 if (virtcol < (colnr_T)textwidth)
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 #ifdef FEAT_COMMENTS
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4115 if (no_leader)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4116 do_comments = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4117 else if (!(flags & INSCHAR_FORMAT)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4118 && has_format_option(FO_WRAP_COMS))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4119 do_comments = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4120
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4121 /* Don't break until after the comment leader */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4122 if (do_comments)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4123 leader_len = get_leader_len(ml_get_curline(), NULL, FALSE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4124 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4125 leader_len = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4126
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4127 /* If the line doesn't start with a comment leader, then don't
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4128 * start one in a following broken line. Avoids that a %word
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4129 * moved to the start of the next line causes all following lines
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4130 * to start with %. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4131 if (leader_len == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4132 no_leader = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4133 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4134 if (!(flags & INSCHAR_FORMAT)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4135 #ifdef FEAT_COMMENTS
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4136 && leader_len == 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4137 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4138 && !has_format_option(FO_WRAP))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4139
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4140 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4141 textwidth = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4142 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4143 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4144 if ((startcol = curwin->w_cursor.col) == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4145 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4146
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4147 /* find column of textwidth border */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4148 coladvance((colnr_T)textwidth);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4149 wantcol = curwin->w_cursor.col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4150
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4151 curwin->w_cursor.col = startcol - 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4152 #ifdef FEAT_MBYTE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4153 /* Correct cursor for multi-byte character. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4154 if (has_mbyte)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4155 mb_adjust_cursor();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4156 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4157 foundcol = 0;
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 * Find position to break at.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4161 * Stop at first entered white when 'formatoptions' has 'v'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4162 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4163 while ((!fo_ins_blank && !has_format_option(FO_INS_VI))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4164 || curwin->w_cursor.lnum != Insstart.lnum
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4165 || curwin->w_cursor.col >= Insstart.col)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4166 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4167 cc = gchar_cursor();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4168 if (WHITECHAR(cc))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4169 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4170 /* remember position of blank just before text */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4171 end_foundcol = curwin->w_cursor.col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4172
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4173 /* find start of sequence of blanks */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4174 while (curwin->w_cursor.col > 0 && WHITECHAR(cc))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4175 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4176 dec_cursor();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4177 cc = gchar_cursor();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4178 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4179 if (curwin->w_cursor.col == 0 && WHITECHAR(cc))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4180 break; /* only spaces in front of text */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4181 #ifdef FEAT_COMMENTS
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4182 /* Don't break until after the comment leader */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4183 if (curwin->w_cursor.col < leader_len)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4184 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4185 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4186 if (has_format_option(FO_ONE_LETTER))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4187 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4188 /* do not break after one-letter words */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4189 if (curwin->w_cursor.col == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4190 break; /* one-letter word at begin */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4191
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4192 col = curwin->w_cursor.col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4193 dec_cursor();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4194 cc = gchar_cursor();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4195
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4196 if (WHITECHAR(cc))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4197 continue; /* one-letter, continue */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4198 curwin->w_cursor.col = col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4199 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4200 #ifdef FEAT_MBYTE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4201 if (has_mbyte)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4202 foundcol = curwin->w_cursor.col
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4203 + (*mb_ptr2len_check)(ml_get_cursor());
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4204 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4205 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4206 foundcol = curwin->w_cursor.col + 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4207 if (curwin->w_cursor.col < (colnr_T)wantcol)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4208 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4209 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4210 #ifdef FEAT_MBYTE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4211 else if (cc >= 0x100 && fo_multibyte
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4212 && curwin->w_cursor.col <= (colnr_T)wantcol)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4213 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4214 /* Break after or before a multi-byte character. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4215 foundcol = curwin->w_cursor.col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4216 if (curwin->w_cursor.col < (colnr_T)wantcol)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4217 foundcol += (*mb_char2len)(cc);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4218 end_foundcol = foundcol;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4219 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4220 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4221 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4222 if (curwin->w_cursor.col == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4223 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4224 dec_cursor();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4225 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4226
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4227 if (foundcol == 0) /* no spaces, cannot break line */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4228 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4229 curwin->w_cursor.col = startcol;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4230 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4231 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4232
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4233 /* Going to break the line, remove any "$" now. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4234 undisplay_dollar();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4235
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4236 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4237 * Offset between cursor position and line break is used by replace
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4238 * stack functions. VREPLACE does not use this, and backspaces
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4239 * over the text instead.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4240 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4241 #ifdef FEAT_VREPLACE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4242 if (State & VREPLACE_FLAG)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4243 orig_col = startcol; /* Will start backspacing from here */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4244 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4245 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4246 replace_offset = startcol - end_foundcol - 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4247
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4248 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4249 * adjust startcol for spaces that will be deleted and
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4250 * characters that will remain on top line
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4251 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4252 curwin->w_cursor.col = foundcol;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4253 while (cc = gchar_cursor(), WHITECHAR(cc))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4254 inc_cursor();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4255 startcol -= curwin->w_cursor.col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4256 if (startcol < 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4257 startcol = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4258
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4259 #ifdef FEAT_VREPLACE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4260 if (State & VREPLACE_FLAG)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4261 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4262 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4263 * In VREPLACE mode, we will backspace over the text to be
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4264 * wrapped, so save a copy now to put on the next line.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4265 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4266 saved_text = vim_strsave(ml_get_cursor());
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4267 curwin->w_cursor.col = orig_col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4268 if (saved_text == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4269 break; /* Can't do it, out of memory */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4270 saved_text[startcol] = NUL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4271
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4272 /* Backspace over characters that will move to the next line */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4273 if (!fo_white_par)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4274 backspace_until_column(foundcol);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4275 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4276 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4277 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4278 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4279 /* put cursor after pos. to break line */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4280 if (!fo_white_par)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4281 curwin->w_cursor.col = foundcol;
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 * Split the line just before the margin.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4286 * Only insert/delete lines, but don't really redraw the window.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4287 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4288 open_line(FORWARD, OPENLINE_DELSPACES + OPENLINE_MARKFIX
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4289 + (fo_white_par ? OPENLINE_KEEPTRAIL : 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4290 #ifdef FEAT_COMMENTS
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4291 + (do_comments ? OPENLINE_DO_COM : 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4292 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4293 , old_indent);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4294 old_indent = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4295
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4296 replace_offset = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4297 if (first_line)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4298 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4299 if (second_indent < 0 && has_format_option(FO_Q_NUMBER))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4300 second_indent = get_number_indent(curwin->w_cursor.lnum -1);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4301 if (second_indent >= 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4302 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4303 #ifdef FEAT_VREPLACE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4304 if (State & VREPLACE_FLAG)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4305 change_indent(INDENT_SET, second_indent, FALSE, NUL);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4306 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4307 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4308 (void)set_indent(second_indent, SIN_CHANGED);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4309 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4310 first_line = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4311 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4312
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4313 #ifdef FEAT_VREPLACE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4314 if (State & VREPLACE_FLAG)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4315 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4316 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4317 * In VREPLACE mode we have backspaced over the text to be
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4318 * moved, now we re-insert it into the new line.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4319 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4320 ins_bytes(saved_text);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4321 vim_free(saved_text);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4322 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4323 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4324 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4325 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4326 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4327 * Check if cursor is not past the NUL off the line, cindent
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4328 * may have added or removed indent.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4329 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4330 curwin->w_cursor.col += startcol;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4331 len = (colnr_T)STRLEN(ml_get_curline());
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4332 if (curwin->w_cursor.col > len)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4333 curwin->w_cursor.col = len;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4334 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4335
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4336 haveto_redraw = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4337 #ifdef FEAT_CINDENT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4338 can_cindent = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4339 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4340 /* moved the cursor, don't autoindent or cindent now */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4341 did_ai = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4342 #ifdef FEAT_SMARTINDENT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4343 did_si = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4344 can_si = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4345 can_si_back = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4346 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4347 line_breakcheck();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4348 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4349
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4350 if (save_char) /* put back space after cursor */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4351 pchar_cursor(save_char);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4352
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4353 if (c == NUL) /* formatting only */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4354 return;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4355 if (haveto_redraw)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4356 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4357 update_topline();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4358 redraw_curbuf_later(VALID);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4359 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4360 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4361 if (c == NUL) /* only formatting was wanted */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4362 return;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4363
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4364 #ifdef FEAT_COMMENTS
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4365 /* Check whether this character should end a comment. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4366 if (did_ai && (int)c == end_comment_pending)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4367 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4368 char_u *line;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4369 char_u lead_end[COM_MAX_LEN]; /* end-comment string */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4370 int middle_len, end_len;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4371 int i;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4372
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4373 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4374 * Need to remove existing (middle) comment leader and insert end
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4375 * comment leader. First, check what comment leader we can find.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4376 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4377 i = get_leader_len(line = ml_get_curline(), &p, FALSE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4378 if (i > 0 && vim_strchr(p, COM_MIDDLE) != NULL) /* Just checking */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4379 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4380 /* Skip middle-comment string */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4381 while (*p && p[-1] != ':') /* find end of middle flags */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4382 ++p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4383 middle_len = copy_option_part(&p, lead_end, COM_MAX_LEN, ",");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4384 /* Don't count trailing white space for middle_len */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4385 while (middle_len > 0 && vim_iswhite(lead_end[middle_len - 1]))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4386 --middle_len;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4387
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4388 /* Find the end-comment string */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4389 while (*p && p[-1] != ':') /* find end of end flags */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4390 ++p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4391 end_len = copy_option_part(&p, lead_end, COM_MAX_LEN, ",");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4392
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4393 /* Skip white space before the cursor */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4394 i = curwin->w_cursor.col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4395 while (--i >= 0 && vim_iswhite(line[i]))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4396 ;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4397 i++;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4398
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4399 /* Skip to before the middle leader */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4400 i -= middle_len;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4401
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4402 /* Check some expected things before we go on */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4403 if (i >= 0 && lead_end[end_len - 1] == end_comment_pending)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4404 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4405 /* Backspace over all the stuff we want to replace */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4406 backspace_until_column(i);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4407
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4408 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4409 * Insert the end-comment string, except for the last
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4410 * character, which will get inserted as normal later.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4411 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4412 ins_bytes_len(lead_end, end_len - 1);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4413 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4414 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4415 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4416 end_comment_pending = NUL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4417 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4418
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4419 did_ai = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4420 #ifdef FEAT_SMARTINDENT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4421 did_si = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4422 can_si = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4423 can_si_back = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4424 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4425
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4426 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4427 * If there's any pending input, grab up to INPUT_BUFLEN at once.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4428 * This speeds up normal text input considerably.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4429 * Don't do this when 'cindent' or 'indentexpr' is set, because we might
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4430 * need to re-indent at a ':', or any other character (but not what
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4431 * 'paste' is set)..
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4432 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4433 #ifdef USE_ON_FLY_SCROLL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4434 dont_scroll = FALSE; /* allow scrolling here */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4435 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4436
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4437 if ( !ISSPECIAL(c)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4438 #ifdef FEAT_MBYTE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4439 && (!has_mbyte || (*mb_char2len)(c) == 1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4440 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4441 && vpeekc() != NUL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4442 && !(State & REPLACE_FLAG)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4443 #ifdef FEAT_CINDENT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4444 && !cindent_on()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4445 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4446 #ifdef FEAT_RIGHTLEFT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4447 && !p_ri
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4448 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4449 )
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4450 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4451 #define INPUT_BUFLEN 100
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4452 char_u buf[INPUT_BUFLEN + 1];
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4453 int i;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4454 colnr_T virtcol = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4455
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4456 buf[0] = c;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4457 i = 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4458 if (textwidth)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4459 virtcol = get_nolist_virtcol();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4460 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4461 * Stop the string when:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4462 * - no more chars available
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4463 * - finding a special character (command key)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4464 * - buffer is full
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4465 * - running into the 'textwidth' boundary
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4466 * - need to check for abbreviation: A non-word char after a word-char
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4467 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4468 while ( (c = vpeekc()) != NUL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4469 && !ISSPECIAL(c)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4470 #ifdef FEAT_MBYTE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4471 && (!has_mbyte || MB_BYTE2LEN_CHECK(c) == 1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4472 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4473 && i < INPUT_BUFLEN
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4474 && (textwidth == 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4475 || (virtcol += byte2cells(buf[i - 1])) < (colnr_T)textwidth)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4476 && !(!no_abbr && !vim_iswordc(c) && vim_iswordc(buf[i - 1])))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4477 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4478 #ifdef FEAT_RIGHTLEFT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4479 c = vgetc();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4480 if (p_hkmap && KeyTyped)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4481 c = hkmap(c); /* Hebrew mode mapping */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4482 # ifdef FEAT_FKMAP
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4483 if (p_fkmap && KeyTyped)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4484 c = fkmap(c); /* Farsi mode mapping */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4485 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4486 buf[i++] = c;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4487 #else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4488 buf[i++] = vgetc();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4489 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4490 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4491
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4492 #ifdef FEAT_DIGRAPHS
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4493 do_digraph(-1); /* clear digraphs */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4494 do_digraph(buf[i-1]); /* may be the start of a digraph */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4495 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4496 buf[i] = NUL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4497 ins_str(buf);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4498 if (flags & INSCHAR_CTRLV)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4499 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4500 redo_literal(*buf);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4501 i = 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4502 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4503 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4504 i = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4505 if (buf[i] != NUL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4506 AppendToRedobuffLit(buf + i);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4507 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4508 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4509 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4510 #ifdef FEAT_MBYTE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4511 if (has_mbyte && (cc = (*mb_char2len)(c)) > 1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4512 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4513 char_u buf[MB_MAXBYTES + 1];
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4514
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4515 (*mb_char2bytes)(c, buf);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4516 buf[cc] = NUL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4517 ins_char_bytes(buf, cc);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4518 AppendCharToRedobuff(c);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4519 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4520 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4521 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4522 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4523 ins_char(c);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4524 if (flags & INSCHAR_CTRLV)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4525 redo_literal(c);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4526 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4527 AppendCharToRedobuff(c);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4528 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4529 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4530 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4531
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4532 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4533 * Called after inserting or deleting text: When 'formatoptions' includes the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4534 * 'a' flag format from the current line until the end of the paragraph.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4535 * Keep the cursor at the same position relative to the text.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4536 * The caller must have saved the cursor line for undo, following ones will be
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4537 * saved here.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4538 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4539 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4540 auto_format(trailblank, prev_line)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4541 int trailblank; /* when TRUE also format with trailing blank */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4542 int prev_line; /* may start in previous line */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4543 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4544 pos_T pos;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4545 colnr_T len;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4546 char_u *old;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4547 char_u *new, *pnew;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4548 int wasatend;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4549
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4550 if (!has_format_option(FO_AUTO))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4551 return;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4552
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4553 pos = curwin->w_cursor;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4554 old = ml_get_curline();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4555
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4556 /* may remove added space */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4557 check_auto_format(FALSE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4558
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4559 /* 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
4560 * user might insert normal text next. Also skip formatting when "1" is
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4561 * in 'formatoptions' and there is a single character before the cursor.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4562 * Otherwise the line would be broken and when typing another non-white
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4563 * next they are not joined back together. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4564 wasatend = (pos.col == STRLEN(old));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4565 if (*old != NUL && !trailblank && wasatend)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4566 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4567 dec_cursor();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4568 if (!WHITECHAR(gchar_cursor())
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4569 && curwin->w_cursor.col > 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4570 && has_format_option(FO_ONE_LETTER))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4571 dec_cursor();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4572 if (WHITECHAR(gchar_cursor()))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4573 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4574 curwin->w_cursor = pos;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4575 return;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4576 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4577 curwin->w_cursor = pos;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4578 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4579
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4580 #ifdef FEAT_COMMENTS
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4581 /* With the 'c' flag in 'formatoptions' and 't' missing: only format
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4582 * comments. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4583 if (has_format_option(FO_WRAP_COMS) && !has_format_option(FO_WRAP)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4584 && get_leader_len(old, NULL, FALSE) == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4585 return;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4586 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4587
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4588 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4589 * May start formatting in a previous line, so that after "x" a word is
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4590 * 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
4591 * the start of a paragraph.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4592 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4593 if (prev_line && !paragraph_start(curwin->w_cursor.lnum))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4594 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4595 --curwin->w_cursor.lnum;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4596 if (u_save_cursor() == FAIL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4597 return;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4598 }
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 * Do the formatting and restore the cursor position. "saved_cursor" will
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4602 * be adjusted for the text formatting.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4603 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4604 saved_cursor = pos;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4605 format_lines((linenr_T)-1);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4606 curwin->w_cursor = saved_cursor;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4607 saved_cursor.lnum = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4608
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4609 if (curwin->w_cursor.lnum > curbuf->b_ml.ml_line_count)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4610 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4611 /* "cannot happen" */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4612 curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4613 coladvance((colnr_T)MAXCOL);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4614 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4615 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4616 check_cursor_col();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4617
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4618 /* 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
4619 * previously wasn't, the line was broken. Because of the rule above we
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4620 * need to add a space when 'w' is in 'formatoptions' to keep a paragraph
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4621 * formatted. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4622 if (!wasatend && has_format_option(FO_WHITE_PAR))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4623 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4624 new = ml_get_curline();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4625 len = STRLEN(new);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4626 if (curwin->w_cursor.col == len)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4627 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4628 pnew = vim_strnsave(new, len + 2);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4629 pnew[len] = ' ';
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4630 pnew[len + 1] = NUL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4631 ml_replace(curwin->w_cursor.lnum, pnew, FALSE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4632 /* remove the space later */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4633 did_add_space = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4634 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4635 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4636 /* may remove added space */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4637 check_auto_format(FALSE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4638 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4639
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4640 check_cursor();
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 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4644 * When an extra space was added to continue a paragraph for auto-formatting,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4645 * delete it now. The space must be under the cursor, just after the insert
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4646 * position.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4647 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4648 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4649 check_auto_format(end_insert)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4650 int end_insert; /* TRUE when ending Insert mode */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4651 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4652 int c = ' ';
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4653
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4654 if (did_add_space)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4655 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4656 if (!WHITECHAR(gchar_cursor()))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4657 /* Somehow the space was removed already. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4658 did_add_space = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4659 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4660 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4661 if (!end_insert)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4662 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4663 inc_cursor();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4664 c = gchar_cursor();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4665 dec_cursor();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4666 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4667 if (c != NUL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4668 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4669 /* The space is no longer at the end of the line, delete it. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4670 del_char(FALSE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4671 did_add_space = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4672 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4673 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4674 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4675 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4676
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4677 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4678 * Find out textwidth to be used for formatting:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4679 * if 'textwidth' option is set, use it
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4680 * else if 'wrapmargin' option is set, use W_WIDTH(curwin) - 'wrapmargin'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4681 * if invalid value, use 0.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4682 * Set default to window width (maximum 79) for "gq" operator.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4683 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4684 int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4685 comp_textwidth(ff)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4686 int ff; /* force formatting (for "Q" command) */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4687 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4688 int textwidth;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4689
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4690 textwidth = curbuf->b_p_tw;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4691 if (textwidth == 0 && curbuf->b_p_wm)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4692 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4693 /* The width is the window width minus 'wrapmargin' minus all the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4694 * things that add to the margin. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4695 textwidth = W_WIDTH(curwin) - curbuf->b_p_wm;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4696 #ifdef FEAT_CMDWIN
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4697 if (cmdwin_type != 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4698 textwidth -= 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4699 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4700 #ifdef FEAT_FOLDING
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4701 textwidth -= curwin->w_p_fdc;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4702 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4703 #ifdef FEAT_SIGNS
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4704 if (curwin->w_buffer->b_signlist != NULL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4705 # ifdef FEAT_NETBEANS_INTG
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4706 || usingNetbeans
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4707 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4708 )
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4709 textwidth -= 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4710 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4711 if (curwin->w_p_nu)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4712 textwidth -= 8;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4713 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4714 if (textwidth < 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4715 textwidth = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4716 if (ff && textwidth == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4717 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4718 textwidth = W_WIDTH(curwin) - 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4719 if (textwidth > 79)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4720 textwidth = 79;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4721 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4722 return textwidth;
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 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4726 * Put a character in the redo buffer, for when just after a CTRL-V.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4727 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4728 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4729 redo_literal(c)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4730 int c;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4731 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4732 char_u buf[10];
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4733
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4734 /* Only digits need special treatment. Translate them into a string of
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4735 * three digits. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4736 if (VIM_ISDIGIT(c))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4737 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4738 sprintf((char *)buf, "%03d", c);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4739 AppendToRedobuff(buf);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4740 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4741 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4742 AppendCharToRedobuff(c);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4743 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4744
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4745 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4746 * start_arrow() is called when an arrow key is used in insert mode.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4747 * It resembles hitting the <ESC> key.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4748 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4749 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4750 start_arrow(end_insert_pos)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4751 pos_T *end_insert_pos;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4752 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4753 if (!arrow_used) /* something has been inserted */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4754 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4755 AppendToRedobuff(ESC_STR);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4756 stop_insert(end_insert_pos, FALSE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4757 arrow_used = TRUE; /* this means we stopped the current insert */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4758 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4759 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4760
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4761 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4762 * stop_arrow() is called before a change is made in insert mode.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4763 * If an arrow key has been used, start a new insertion.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4764 * Returns FAIL if undo is impossible, shouldn't insert then.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4765 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4766 int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4767 stop_arrow()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4768 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4769 if (arrow_used)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4770 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4771 if (u_save_cursor() == OK)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4772 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4773 arrow_used = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4774 ins_need_undo = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4775 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4776 Insstart = curwin->w_cursor; /* new insertion starts here */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4777 Insstart_textlen = linetabsize(ml_get_curline());
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4778 ai_col = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4779 #ifdef FEAT_VREPLACE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4780 if (State & VREPLACE_FLAG)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4781 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4782 orig_line_count = curbuf->b_ml.ml_line_count;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4783 vr_lines_changed = 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4784 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4785 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4786 ResetRedobuff();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4787 AppendToRedobuff((char_u *)"1i"); /* pretend we start an insertion */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4788 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4789 else if (ins_need_undo)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4790 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4791 if (u_save_cursor() == OK)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4792 ins_need_undo = FALSE;
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 #ifdef FEAT_FOLDING
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4796 /* Always open fold at the cursor line when inserting something. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4797 foldOpenCursor();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4798 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4799
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4800 return (arrow_used || ins_need_undo ? FAIL : OK);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4801 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4802
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4803 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4804 * do a few things to stop inserting
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4805 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4806 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4807 stop_insert(end_insert_pos, esc)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4808 pos_T *end_insert_pos; /* where insert ended */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4809 int esc; /* called by ins_esc() */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4810 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4811 int cc;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4812
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4813 stop_redo_ins();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4814 replace_flush(); /* abandon replace stack */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4815
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4816 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4817 * save the inserted text for later redo with ^@
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4818 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4819 vim_free(last_insert);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4820 last_insert = get_inserted();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4821 last_insert_skip = new_insert_skip;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4822
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4823 if (!arrow_used)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4824 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4825 /* Auto-format now. It may seem strange to do this when stopping an
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4826 * insertion (or moving the cursor), but it's required when appending
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4827 * 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
4828 * was actually inserted, otherwise undo won't work. */
10
4e2284e71352 updated for version 7.0002
vimboss
parents: 7
diff changeset
4829 if (!ins_need_undo && has_format_option(FO_AUTO))
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4830 {
10
4e2284e71352 updated for version 7.0002
vimboss
parents: 7
diff changeset
4831 pos_T tpos = curwin->w_cursor;
4e2284e71352 updated for version 7.0002
vimboss
parents: 7
diff changeset
4832
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4833 /* When the cursor is at the end of the line after a space the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4834 * formatting will move it to the following word. Avoid that by
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4835 * moving the cursor onto the space. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4836 cc = 'x';
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4837 if (curwin->w_cursor.col > 0 && gchar_cursor() == NUL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4838 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4839 dec_cursor();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4840 cc = gchar_cursor();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4841 if (!vim_iswhite(cc))
10
4e2284e71352 updated for version 7.0002
vimboss
parents: 7
diff changeset
4842 curwin->w_cursor = tpos;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4843 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4844
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4845 auto_format(TRUE, FALSE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4846
10
4e2284e71352 updated for version 7.0002
vimboss
parents: 7
diff changeset
4847 if (vim_iswhite(cc))
4e2284e71352 updated for version 7.0002
vimboss
parents: 7
diff changeset
4848 {
4e2284e71352 updated for version 7.0002
vimboss
parents: 7
diff changeset
4849 if (gchar_cursor() != NUL)
4e2284e71352 updated for version 7.0002
vimboss
parents: 7
diff changeset
4850 inc_cursor();
4e2284e71352 updated for version 7.0002
vimboss
parents: 7
diff changeset
4851 #ifdef FEAT_VIRTUALEDIT
4e2284e71352 updated for version 7.0002
vimboss
parents: 7
diff changeset
4852 /* If the cursor is still at the same character, also keep
4e2284e71352 updated for version 7.0002
vimboss
parents: 7
diff changeset
4853 * the "coladd". */
4e2284e71352 updated for version 7.0002
vimboss
parents: 7
diff changeset
4854 if (gchar_cursor() == NUL
4e2284e71352 updated for version 7.0002
vimboss
parents: 7
diff changeset
4855 && curwin->w_cursor.lnum == tpos.lnum
4e2284e71352 updated for version 7.0002
vimboss
parents: 7
diff changeset
4856 && curwin->w_cursor.col == tpos.col)
4e2284e71352 updated for version 7.0002
vimboss
parents: 7
diff changeset
4857 curwin->w_cursor.coladd = tpos.coladd;
4e2284e71352 updated for version 7.0002
vimboss
parents: 7
diff changeset
4858 #endif
4e2284e71352 updated for version 7.0002
vimboss
parents: 7
diff changeset
4859 }
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4860 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4861
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4862 /* If a space was inserted for auto-formatting, remove it now. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4863 check_auto_format(TRUE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4864
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4865 /* 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
4866 * of the line, and put the cursor back.
4e2284e71352 updated for version 7.0002
vimboss
parents: 7
diff changeset
4867 * Do this when ESC was used or moving the cursor up/down. */
4e2284e71352 updated for version 7.0002
vimboss
parents: 7
diff changeset
4868 if (did_ai && (esc || (vim_strchr(p_cpo, CPO_INDENT) == NULL
4e2284e71352 updated for version 7.0002
vimboss
parents: 7
diff changeset
4869 && curwin->w_cursor.lnum != end_insert_pos->lnum)))
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4870 {
10
4e2284e71352 updated for version 7.0002
vimboss
parents: 7
diff changeset
4871 pos_T tpos = curwin->w_cursor;
4e2284e71352 updated for version 7.0002
vimboss
parents: 7
diff changeset
4872
4e2284e71352 updated for version 7.0002
vimboss
parents: 7
diff changeset
4873 curwin->w_cursor = *end_insert_pos;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4874 if (gchar_cursor() == NUL && curwin->w_cursor.col > 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4875 --curwin->w_cursor.col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4876 while (cc = gchar_cursor(), vim_iswhite(cc))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4877 (void)del_char(TRUE);
10
4e2284e71352 updated for version 7.0002
vimboss
parents: 7
diff changeset
4878 if (curwin->w_cursor.lnum != tpos.lnum)
4e2284e71352 updated for version 7.0002
vimboss
parents: 7
diff changeset
4879 curwin->w_cursor = tpos;
4e2284e71352 updated for version 7.0002
vimboss
parents: 7
diff changeset
4880 else if (cc != NUL)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4881 ++curwin->w_cursor.col; /* put cursor back on the NUL */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4882
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4883 #ifdef FEAT_VISUAL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4884 /* <C-S-Right> may have started Visual mode, adjust the position for
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4885 * deleted characters. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4886 if (VIsual_active && VIsual.lnum == curwin->w_cursor.lnum)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4887 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4888 cc = STRLEN(ml_get_curline());
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4889 if (VIsual.col > (colnr_T)cc)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4890 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4891 VIsual.col = cc;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4892 # ifdef FEAT_VIRTUALEDIT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4893 VIsual.coladd = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4894 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4895 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4896 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4897 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4898 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4899 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4900 did_ai = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4901 #ifdef FEAT_SMARTINDENT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4902 did_si = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4903 can_si = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4904 can_si_back = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4905 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4906
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4907 /* set '[ and '] to the inserted text */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4908 curbuf->b_op_start = Insstart;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4909 curbuf->b_op_end = *end_insert_pos;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4910 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4911
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4912 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4913 * Set the last inserted text to a single character.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4914 * Used for the replace command.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4915 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4916 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4917 set_last_insert(c)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4918 int c;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4919 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4920 char_u *s;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4921
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4922 vim_free(last_insert);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4923 #ifdef FEAT_MBYTE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4924 last_insert = alloc(MB_MAXBYTES * 3 + 5);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4925 #else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4926 last_insert = alloc(6);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4927 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4928 if (last_insert != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4929 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4930 s = last_insert;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4931 /* Use the CTRL-V only when entering a special char */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4932 if (c < ' ' || c == DEL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4933 *s++ = Ctrl_V;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4934 s = add_char2buf(c, s);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4935 *s++ = ESC;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4936 *s++ = NUL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4937 last_insert_skip = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4938 }
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 * Add character "c" to buffer "s". Escape the special meaning of K_SPECIAL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4943 * and CSI. Handle multi-byte characters.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4944 * Returns a pointer to after the added bytes.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4945 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4946 char_u *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4947 add_char2buf(c, s)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4948 int c;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4949 char_u *s;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4950 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4951 #ifdef FEAT_MBYTE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4952 char_u temp[MB_MAXBYTES];
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4953 int i;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4954 int len;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4955
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4956 len = (*mb_char2bytes)(c, temp);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4957 for (i = 0; i < len; ++i)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4958 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4959 c = temp[i];
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4960 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4961 /* Need to escape K_SPECIAL and CSI like in the typeahead buffer. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4962 if (c == K_SPECIAL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4963 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4964 *s++ = K_SPECIAL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4965 *s++ = KS_SPECIAL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4966 *s++ = KE_FILLER;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4967 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4968 #ifdef FEAT_GUI
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4969 else if (c == CSI)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4970 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4971 *s++ = CSI;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4972 *s++ = KS_EXTRA;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4973 *s++ = (int)KE_CSI;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4974 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4975 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4976 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4977 *s++ = c;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4978 #ifdef FEAT_MBYTE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4979 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4980 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4981 return s;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4982 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4983
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4984 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4985 * move cursor to start of line
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4986 * if flags & BL_WHITE move to first non-white
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4987 * if flags & BL_SOL move to first non-white if startofline is set,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4988 * otherwise keep "curswant" column
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4989 * if flags & BL_FIX don't leave the cursor on a NUL.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4990 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4991 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4992 beginline(flags)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4993 int flags;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4994 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4995 if ((flags & BL_SOL) && !p_sol)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4996 coladvance(curwin->w_curswant);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4997 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4998 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4999 curwin->w_cursor.col = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5000 #ifdef FEAT_VIRTUALEDIT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5001 curwin->w_cursor.coladd = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5002 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5003
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5004 if (flags & (BL_WHITE | BL_SOL))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5005 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5006 char_u *ptr;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5007
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5008 for (ptr = ml_get_curline(); vim_iswhite(*ptr)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5009 && !((flags & BL_FIX) && ptr[1] == NUL); ++ptr)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5010 ++curwin->w_cursor.col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5011 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5012 curwin->w_set_curswant = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5013 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5014 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5015
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5016 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5017 * oneright oneleft cursor_down cursor_up
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5018 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5019 * Move one char {right,left,down,up}.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5020 * Doesn't move onto the NUL past the end of the line.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5021 * Return OK when successful, FAIL when we hit a line of file boundary.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5022 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5023
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5024 int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5025 oneright()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5026 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5027 char_u *ptr;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5028 #ifdef FEAT_MBYTE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5029 int l;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5030 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5031
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5032 #ifdef FEAT_VIRTUALEDIT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5033 if (virtual_active())
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5034 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5035 pos_T prevpos = curwin->w_cursor;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5036
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5037 /* Adjust for multi-wide char (excluding TAB) */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5038 ptr = ml_get_cursor();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5039 coladvance(getviscol() + ((*ptr != TAB && vim_isprintc(
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5040 #ifdef FEAT_MBYTE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5041 (*mb_ptr2char)(ptr)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5042 #else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5043 *ptr
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5044 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5045 ))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5046 ? ptr2cells(ptr) : 1));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5047 curwin->w_set_curswant = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5048 /* Return OK if the cursor moved, FAIL otherwise (at window edge). */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5049 return (prevpos.col != curwin->w_cursor.col
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5050 || prevpos.coladd != curwin->w_cursor.coladd) ? OK : FAIL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5051 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5052 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5053
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5054 ptr = ml_get_cursor();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5055 #ifdef FEAT_MBYTE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5056 if (has_mbyte && (l = (*mb_ptr2len_check)(ptr)) > 1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5057 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5058 /* The character under the cursor is a multi-byte character, move
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5059 * several bytes right, but don't end up on the NUL. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5060 if (ptr[l] == NUL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5061 return FAIL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5062 curwin->w_cursor.col += l;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5063 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5064 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5065 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5066 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5067 if (*ptr++ == NUL || *ptr == NUL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5068 return FAIL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5069 ++curwin->w_cursor.col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5070 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5071
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5072 curwin->w_set_curswant = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5073 return OK;
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 int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5077 oneleft()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5078 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5079 #ifdef FEAT_VIRTUALEDIT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5080 if (virtual_active())
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5081 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5082 int width;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5083 int v = getviscol();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5084
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5085 if (v == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5086 return FAIL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5087
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5088 # ifdef FEAT_LINEBREAK
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5089 /* We might get stuck on 'showbreak', skip over it. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5090 width = 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5091 for (;;)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5092 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5093 coladvance(v - width);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5094 /* getviscol() is slow, skip it when 'showbreak' is empty and
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5095 * there are no multi-byte characters */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5096 if ((*p_sbr == NUL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5097 # ifdef FEAT_MBYTE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5098 && !has_mbyte
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5099 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5100 ) || getviscol() < v)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5101 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5102 ++width;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5103 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5104 # else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5105 coladvance(v - 1);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5106 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5107
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5108 if (curwin->w_cursor.coladd == 1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5109 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5110 char_u *ptr;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5111
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5112 /* Adjust for multi-wide char (not a TAB) */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5113 ptr = ml_get_cursor();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5114 if (*ptr != TAB && vim_isprintc(
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5115 # ifdef FEAT_MBYTE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5116 (*mb_ptr2char)(ptr)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5117 # else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5118 *ptr
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5119 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5120 ) && ptr2cells(ptr) > 1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5121 curwin->w_cursor.coladd = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5122 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5123
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5124 curwin->w_set_curswant = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5125 return OK;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5126 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5127 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5128
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5129 if (curwin->w_cursor.col == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5130 return FAIL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5131
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5132 curwin->w_set_curswant = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5133 --curwin->w_cursor.col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5134
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5135 #ifdef FEAT_MBYTE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5136 /* if the character on the left of the current cursor is a multi-byte
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5137 * character, move to its first byte */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5138 if (has_mbyte)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5139 mb_adjust_cursor();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5140 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5141 return OK;
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 int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5145 cursor_up(n, upd_topline)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5146 long n;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5147 int upd_topline; /* When TRUE: update topline */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5148 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5149 linenr_T lnum;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5150
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5151 if (n > 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5152 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5153 lnum = curwin->w_cursor.lnum;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5154 if (lnum <= 1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5155 return FAIL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5156 if (n >= lnum)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5157 lnum = 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5158 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5159 #ifdef FEAT_FOLDING
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5160 if (hasAnyFolding(curwin))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5161 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5162 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5163 * Count each sequence of folded lines as one logical line.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5164 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5165 /* go to the the start of the current fold */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5166 (void)hasFolding(lnum, &lnum, NULL);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5167
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5168 while (n--)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5169 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5170 /* move up one line */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5171 --lnum;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5172 if (lnum <= 1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5173 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5174 /* If we entered a fold, move to the beginning, unless in
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5175 * Insert mode or when 'foldopen' contains "all": it will open
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5176 * in a moment. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5177 if (n > 0 || !((State & INSERT) || (fdo_flags & FDO_ALL)))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5178 (void)hasFolding(lnum, &lnum, NULL);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5179 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5180 if (lnum < 1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5181 lnum = 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5182 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5183 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5184 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5185 lnum -= n;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5186 curwin->w_cursor.lnum = lnum;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5187 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5188
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5189 /* try to advance to the column we want to be at */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5190 coladvance(curwin->w_curswant);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5191
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5192 if (upd_topline)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5193 update_topline(); /* make sure curwin->w_topline is valid */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5194
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5195 return OK;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5196 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5197
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5198 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5199 * Cursor down a number of logical lines.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5200 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5201 int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5202 cursor_down(n, upd_topline)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5203 long n;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5204 int upd_topline; /* When TRUE: update topline */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5205 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5206 linenr_T lnum;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5207
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5208 if (n > 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5209 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5210 lnum = curwin->w_cursor.lnum;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5211 #ifdef FEAT_FOLDING
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5212 /* 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
5213 (void)hasFolding(lnum, NULL, &lnum);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5214 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5215 if (lnum >= curbuf->b_ml.ml_line_count)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5216 return FAIL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5217 if (lnum + n >= curbuf->b_ml.ml_line_count)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5218 lnum = curbuf->b_ml.ml_line_count;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5219 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5220 #ifdef FEAT_FOLDING
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5221 if (hasAnyFolding(curwin))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5222 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5223 linenr_T last;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5224
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5225 /* count each sequence of folded lines as one logical line */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5226 while (n--)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5227 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5228 if (hasFolding(lnum, NULL, &last))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5229 lnum = last + 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5230 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5231 ++lnum;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5232 if (lnum >= curbuf->b_ml.ml_line_count)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5233 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5234 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5235 if (lnum > curbuf->b_ml.ml_line_count)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5236 lnum = curbuf->b_ml.ml_line_count;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5237 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5238 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5239 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5240 lnum += n;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5241 curwin->w_cursor.lnum = lnum;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5242 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5243
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5244 /* try to advance to the column we want to be at */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5245 coladvance(curwin->w_curswant);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5246
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5247 if (upd_topline)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5248 update_topline(); /* make sure curwin->w_topline is valid */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5249
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5250 return OK;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5251 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5252
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5253 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5254 * Stuff the last inserted text in the read buffer.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5255 * Last_insert actually is a copy of the redo buffer, so we
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5256 * first have to remove the command.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5257 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5258 int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5259 stuff_inserted(c, count, no_esc)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5260 int c; /* Command character to be inserted */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5261 long count; /* Repeat this many times */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5262 int no_esc; /* Don't add an ESC at the end */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5263 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5264 char_u *esc_ptr;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5265 char_u *ptr;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5266 char_u *last_ptr;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5267 char_u last = NUL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5268
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5269 ptr = get_last_insert();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5270 if (ptr == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5271 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5272 EMSG(_(e_noinstext));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5273 return FAIL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5274 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5275
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5276 /* may want to stuff the command character, to start Insert mode */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5277 if (c != NUL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5278 stuffcharReadbuff(c);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5279 if ((esc_ptr = (char_u *)vim_strrchr(ptr, ESC)) != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5280 *esc_ptr = NUL; /* remove the ESC */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5281
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5282 /* 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
5283 * comes after it OR if it will inserted more than once and "ptr"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5284 * starts with ^D. -- Acevedo
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5285 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5286 last_ptr = (esc_ptr ? esc_ptr : ptr + STRLEN(ptr)) - 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5287 if (last_ptr >= ptr && (*last_ptr == '0' || *last_ptr == '^')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5288 && (no_esc || (*ptr == Ctrl_D && count > 1)))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5289 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5290 last = *last_ptr;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5291 *last_ptr = NUL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5292 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5293
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5294 do
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5295 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5296 stuffReadbuff(ptr);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5297 /* a trailing "0" is inserted as "<C-V>048", "^" as "<C-V>^" */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5298 if (last)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5299 stuffReadbuff((char_u *)(last == '0'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5300 ? IF_EB("\026\060\064\070", CTRL_V_STR "xf0")
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5301 : IF_EB("\026^", CTRL_V_STR "^")));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5302 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5303 while (--count > 0);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5304
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5305 if (last)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5306 *last_ptr = last;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5307
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5308 if (esc_ptr != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5309 *esc_ptr = ESC; /* put the ESC back */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5310
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5311 /* may want to stuff a trailing ESC, to get out of Insert mode */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5312 if (!no_esc)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5313 stuffcharReadbuff(ESC);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5314
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5315 return OK;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5316 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5317
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5318 char_u *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5319 get_last_insert()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5320 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5321 if (last_insert == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5322 return NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5323 return last_insert + last_insert_skip;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5324 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5325
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5326 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5327 * Get last inserted string, and remove trailing <Esc>.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5328 * Returns pointer to allocated memory (must be freed) or NULL.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5329 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5330 char_u *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5331 get_last_insert_save()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5332 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5333 char_u *s;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5334 int len;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5335
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5336 if (last_insert == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5337 return NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5338 s = vim_strsave(last_insert + last_insert_skip);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5339 if (s != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5340 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5341 len = (int)STRLEN(s);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5342 if (len > 0 && s[len - 1] == ESC) /* remove trailing ESC */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5343 s[len - 1] = NUL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5344 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5345 return s;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5346 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5347
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5348 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5349 * Check the word in front of the cursor for an abbreviation.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5350 * Called when the non-id character "c" has been entered.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5351 * When an abbreviation is recognized it is removed from the text and
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5352 * the replacement string is inserted in typebuf.tb_buf[], followed by "c".
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5353 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5354 static int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5355 echeck_abbr(c)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5356 int c;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5357 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5358 /* Don't check for abbreviation in paste mode, when disabled and just
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5359 * after moving around with cursor keys. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5360 if (p_paste || no_abbr || arrow_used)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5361 return FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5362
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5363 return check_abbr(c, ml_get_curline(), curwin->w_cursor.col,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5364 curwin->w_cursor.lnum == Insstart.lnum ? Insstart.col : 0);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5365 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5366
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5367 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5368 * replace-stack functions
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5369 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5370 * When replacing characters, the replaced characters are remembered for each
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5371 * new character. This is used to re-insert the old text when backspacing.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5372 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5373 * There is a NUL headed list of characters for each character that is
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5374 * currently in the file after the insertion point. When BS is used, one NUL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5375 * headed list is put back for the deleted character.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5376 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5377 * For a newline, there are two NUL headed lists. One contains the characters
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5378 * that the NL replaced. The extra one stores the characters after the cursor
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5379 * that were deleted (always white space).
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5380 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5381 * Replace_offset is normally 0, in which case replace_push will add a new
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5382 * 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
5383 * characters will be left on the stack above the newly inserted character.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5384 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5385
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5386 char_u *replace_stack = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5387 long replace_stack_nr = 0; /* next entry in replace stack */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5388 long replace_stack_len = 0; /* max. number of entries */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5389
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5390 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5391 replace_push(c)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5392 int c; /* character that is replaced (NUL is none) */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5393 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5394 char_u *p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5395
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5396 if (replace_stack_nr < replace_offset) /* nothing to do */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5397 return;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5398 if (replace_stack_len <= replace_stack_nr)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5399 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5400 replace_stack_len += 50;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5401 p = lalloc(sizeof(char_u) * replace_stack_len, TRUE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5402 if (p == NULL) /* out of memory */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5403 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5404 replace_stack_len -= 50;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5405 return;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5406 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5407 if (replace_stack != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5408 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5409 mch_memmove(p, replace_stack,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5410 (size_t)(replace_stack_nr * sizeof(char_u)));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5411 vim_free(replace_stack);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5412 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5413 replace_stack = p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5414 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5415 p = replace_stack + replace_stack_nr - replace_offset;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5416 if (replace_offset)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5417 mch_memmove(p + 1, p, (size_t)(replace_offset * sizeof(char_u)));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5418 *p = c;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5419 ++replace_stack_nr;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5420 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5421
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5422 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5423 * call replace_push(c) with replace_offset set to the first NUL.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5424 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5425 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5426 replace_push_off(c)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5427 int c;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5428 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5429 char_u *p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5430
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5431 p = replace_stack + replace_stack_nr;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5432 for (replace_offset = 1; replace_offset < replace_stack_nr;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5433 ++replace_offset)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5434 if (*--p == NUL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5435 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5436 replace_push(c);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5437 replace_offset = 0;
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 * Pop one item from the replace stack.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5442 * return -1 if stack empty
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5443 * return replaced character or NUL otherwise
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5444 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5445 static int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5446 replace_pop()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5447 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5448 if (replace_stack_nr == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5449 return -1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5450 return (int)replace_stack[--replace_stack_nr];
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5451 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5452
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5453 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5454 * 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
5455 * encountered.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5456 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5457 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5458 replace_join(off)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5459 int off; /* offset for which NUL to remove */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5460 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5461 int i;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5462
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5463 for (i = replace_stack_nr; --i >= 0; )
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5464 if (replace_stack[i] == NUL && off-- <= 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5465 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5466 --replace_stack_nr;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5467 mch_memmove(replace_stack + i, replace_stack + i + 1,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5468 (size_t)(replace_stack_nr - i));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5469 return;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5470 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5471 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5472
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5473 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5474 * Pop bytes from the replace stack until a NUL is found, and insert them
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5475 * before the cursor. Can only be used in REPLACE or VREPLACE mode.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5476 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5477 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5478 replace_pop_ins()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5479 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5480 int cc;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5481 int oldState = State;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5482
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5483 State = NORMAL; /* don't want REPLACE here */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5484 while ((cc = replace_pop()) > 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5485 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5486 #ifdef FEAT_MBYTE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5487 mb_replace_pop_ins(cc);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5488 #else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5489 ins_char(cc);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5490 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5491 dec_cursor();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5492 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5493 State = oldState;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5494 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5495
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5496 #ifdef FEAT_MBYTE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5497 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5498 * Insert bytes popped from the replace stack. "cc" is the first byte. If it
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5499 * indicates a multi-byte char, pop the other bytes too.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5500 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5501 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5502 mb_replace_pop_ins(cc)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5503 int cc;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5504 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5505 int n;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5506 char_u buf[MB_MAXBYTES];
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5507 int i;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5508 int c;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5509
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5510 if (has_mbyte && (n = MB_BYTE2LEN(cc)) > 1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5511 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5512 buf[0] = cc;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5513 for (i = 1; i < n; ++i)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5514 buf[i] = replace_pop();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5515 ins_bytes_len(buf, n);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5516 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5517 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5518 ins_char(cc);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5519
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5520 if (enc_utf8)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5521 /* Handle composing chars. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5522 for (;;)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5523 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5524 c = replace_pop();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5525 if (c == -1) /* stack empty */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5526 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5527 if ((n = MB_BYTE2LEN(c)) == 1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5528 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5529 /* Not a multi-byte char, put it back. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5530 replace_push(c);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5531 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5532 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5533 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5534 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5535 buf[0] = c;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5536 for (i = 1; i < n; ++i)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5537 buf[i] = replace_pop();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5538 if (utf_iscomposing(utf_ptr2char(buf)))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5539 ins_bytes_len(buf, n);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5540 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5541 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5542 /* Not a composing char, put it back. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5543 for (i = n - 1; i >= 0; --i)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5544 replace_push(buf[i]);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5545 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5546 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5547 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5548 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5549 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5550 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5551
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5552 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5553 * make the replace stack empty
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5554 * (called when exiting replace mode)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5555 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5556 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5557 replace_flush()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5558 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5559 vim_free(replace_stack);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5560 replace_stack = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5561 replace_stack_len = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5562 replace_stack_nr = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5563 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5564
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5565 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5566 * Handle doing a BS for one character.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5567 * cc < 0: replace stack empty, just move cursor
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5568 * cc == 0: character was inserted, delete it
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5569 * cc > 0: character was replaced, put cc (first byte of original char) back
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5570 * and check for more characters to be put back
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5571 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5572 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5573 replace_do_bs()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5574 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5575 int cc;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5576 #ifdef FEAT_VREPLACE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5577 int orig_len = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5578 int ins_len;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5579 int orig_vcols = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5580 colnr_T start_vcol;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5581 char_u *p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5582 int i;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5583 int vcol;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5584 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5585
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5586 cc = replace_pop();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5587 if (cc > 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5588 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5589 #ifdef FEAT_VREPLACE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5590 if (State & VREPLACE_FLAG)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5591 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5592 /* Get the number of screen cells used by the character we are
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5593 * going to delete. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5594 getvcol(curwin, &curwin->w_cursor, NULL, &start_vcol, NULL);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5595 orig_vcols = chartabsize(ml_get_cursor(), start_vcol);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5596 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5597 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5598 #ifdef FEAT_MBYTE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5599 if (has_mbyte)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5600 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5601 del_char(FALSE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5602 # ifdef FEAT_VREPLACE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5603 if (State & VREPLACE_FLAG)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5604 orig_len = STRLEN(ml_get_cursor());
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5605 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5606 replace_push(cc);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5607 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5608 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5609 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5610 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5611 pchar_cursor(cc);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5612 #ifdef FEAT_VREPLACE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5613 if (State & VREPLACE_FLAG)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5614 orig_len = STRLEN(ml_get_cursor()) - 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5615 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5616 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5617 replace_pop_ins();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5618
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5619 #ifdef FEAT_VREPLACE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5620 if (State & VREPLACE_FLAG)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5621 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5622 /* Get the number of screen cells used by the inserted characters */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5623 p = ml_get_cursor();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5624 ins_len = STRLEN(p) - orig_len;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5625 vcol = start_vcol;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5626 for (i = 0; i < ins_len; ++i)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5627 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5628 vcol += chartabsize(p + i, vcol);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5629 #ifdef FEAT_MBYTE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5630 i += (*mb_ptr2len_check)(p) - 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5631 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5632 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5633 vcol -= start_vcol;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5634
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5635 /* Delete spaces that were inserted after the cursor to keep the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5636 * text aligned. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5637 curwin->w_cursor.col += ins_len;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5638 while (vcol > orig_vcols && gchar_cursor() == ' ')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5639 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5640 del_char(FALSE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5641 ++orig_vcols;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5642 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5643 curwin->w_cursor.col -= ins_len;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5644 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5645 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5646
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5647 /* mark the buffer as changed and prepare for displaying */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5648 changed_bytes(curwin->w_cursor.lnum, curwin->w_cursor.col);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5649 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5650 else if (cc == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5651 (void)del_char(FALSE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5652 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5653
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5654 #ifdef FEAT_CINDENT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5655 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5656 * Return TRUE if C-indenting is on.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5657 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5658 static int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5659 cindent_on()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5660 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5661 return (!p_paste && (curbuf->b_p_cin
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5662 # ifdef FEAT_EVAL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5663 || *curbuf->b_p_inde != NUL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5664 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5665 ));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5666 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5667 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5668
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5669 #if defined(FEAT_LISP) || defined(FEAT_CINDENT) || defined(PROTO)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5670 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5671 * Re-indent the current line, based on the current contents of it and the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5672 * surrounding lines. Fixing the cursor position seems really easy -- I'm very
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5673 * 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
5674 * "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
5675 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5676
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5677 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5678 fixthisline(get_the_indent)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5679 int (*get_the_indent) __ARGS((void));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5680 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5681 change_indent(INDENT_SET, get_the_indent(), FALSE, 0);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5682 if (linewhite(curwin->w_cursor.lnum))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5683 did_ai = TRUE; /* delete the indent if the line stays empty */
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 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5687 fix_indent()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5688 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5689 if (p_paste)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5690 return;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5691 # ifdef FEAT_LISP
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5692 if (curbuf->b_p_lisp && curbuf->b_p_ai)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5693 fixthisline(get_lisp_indent);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5694 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5695 # if defined(FEAT_LISP) && defined(FEAT_CINDENT)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5696 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5697 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5698 # ifdef FEAT_CINDENT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5699 if (cindent_on())
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5700 do_c_expr_indent();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5701 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5702 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5703
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5704 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5705
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5706 #ifdef FEAT_CINDENT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5707 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5708 * return TRUE if 'cinkeys' contains the key "keytyped",
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5709 * when == '*': Only if key is preceded with '*' (indent before insert)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5710 * when == '!': Only if key is prededed with '!' (don't insert)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5711 * when == ' ': Only if key is not preceded with '*'(indent afterwards)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5712 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5713 * "keytyped" can have a few special values:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5714 * KEY_OPEN_FORW
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5715 * KEY_OPEN_BACK
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5716 * KEY_COMPLETE just finished completion.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5717 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5718 * If line_is_empty is TRUE accept keys with '0' before them.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5719 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5720 int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5721 in_cinkeys(keytyped, when, line_is_empty)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5722 int keytyped;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5723 int when;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5724 int line_is_empty;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5725 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5726 char_u *look;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5727 int try_match;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5728 int try_match_word;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5729 char_u *p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5730 char_u *line;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5731 int icase;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5732 int i;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5733
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5734 #ifdef FEAT_EVAL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5735 if (*curbuf->b_p_inde != NUL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5736 look = curbuf->b_p_indk; /* 'indentexpr' set: use 'indentkeys' */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5737 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5738 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5739 look = curbuf->b_p_cink; /* 'indentexpr' empty: use 'cinkeys' */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5740 while (*look)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5741 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5742 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5743 * Find out if we want to try a match with this key, depending on
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5744 * 'when' and a '*' or '!' before the key.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5745 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5746 switch (when)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5747 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5748 case '*': try_match = (*look == '*'); break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5749 case '!': try_match = (*look == '!'); break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5750 default: try_match = (*look != '*'); break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5751 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5752 if (*look == '*' || *look == '!')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5753 ++look;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5754
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5755 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5756 * If there is a '0', only accept a match if the line is empty.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5757 * But may still match when typing last char of a word.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5758 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5759 if (*look == '0')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5760 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5761 try_match_word = try_match;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5762 if (!line_is_empty)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5763 try_match = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5764 ++look;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5765 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5766 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5767 try_match_word = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5768
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5769 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5770 * does it look like a control character?
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5771 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5772 if (*look == '^'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5773 #ifdef EBCDIC
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5774 && (Ctrl_chr(look[1]) != 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5775 #else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5776 && look[1] >= '?' && look[1] <= '_'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5777 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5778 )
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5779 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5780 if (try_match && keytyped == Ctrl_chr(look[1]))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5781 return TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5782 look += 2;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5783 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5784 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5785 * 'o' means "o" command, open forward.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5786 * 'O' means "O" command, open backward.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5787 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5788 else if (*look == 'o')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5789 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5790 if (try_match && keytyped == KEY_OPEN_FORW)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5791 return TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5792 ++look;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5793 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5794 else if (*look == 'O')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5795 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5796 if (try_match && keytyped == KEY_OPEN_BACK)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5797 return TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5798 ++look;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5799 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5800
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5801 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5802 * 'e' means to check for "else" at start of line and just before the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5803 * cursor.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5804 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5805 else if (*look == 'e')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5806 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5807 if (try_match && keytyped == 'e' && curwin->w_cursor.col >= 4)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5808 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5809 p = ml_get_curline();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5810 if (skipwhite(p) == p + curwin->w_cursor.col - 4 &&
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5811 STRNCMP(p + curwin->w_cursor.col - 4, "else", 4) == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5812 return TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5813 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5814 ++look;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5815 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5816
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5817 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5818 * ':' 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
5819 * statement, or when it was before typing the ':' (to fix
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5820 * class::method for C++).
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5821 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5822 else if (*look == ':')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5823 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5824 if (try_match && keytyped == ':')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5825 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5826 p = ml_get_curline();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5827 if (cin_iscase(p) || cin_isscopedecl(p) || cin_islabel(30))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5828 return TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5829 if (curwin->w_cursor.col > 2
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5830 && p[curwin->w_cursor.col - 1] == ':'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5831 && p[curwin->w_cursor.col - 2] == ':')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5832 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5833 p[curwin->w_cursor.col - 1] = ' ';
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5834 i = (cin_iscase(p) || cin_isscopedecl(p)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5835 || cin_islabel(30));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5836 p = ml_get_curline();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5837 p[curwin->w_cursor.col - 1] = ':';
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5838 if (i)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5839 return TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5840 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5841 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5842 ++look;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5843 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5844
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5845
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5846 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5847 * Is it a key in <>, maybe?
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5848 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5849 else if (*look == '<')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5850 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5851 if (try_match)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5852 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5853 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5854 * make up some named keys <o>, <O>, <e>, <0>, <>>, <<>, <*>,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5855 * <:> and <!> so that people can re-indent on o, O, e, 0, <,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5856 * >, *, : and ! keys if they really really want to.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5857 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5858 if (vim_strchr((char_u *)"<>!*oOe0:", look[1]) != NULL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5859 && keytyped == look[1])
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5860 return TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5861
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5862 if (keytyped == get_special_key_code(look + 1))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5863 return TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5864 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5865 while (*look && *look != '>')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5866 look++;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5867 while (*look == '>')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5868 look++;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5869 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5870
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5871 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5872 * Is it a word: "=word"?
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5873 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5874 else if (*look == '=' && look[1] != ',' && look[1] != NUL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5875 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5876 ++look;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5877 if (*look == '~')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5878 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5879 icase = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5880 ++look;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5881 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5882 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5883 icase = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5884 p = vim_strchr(look, ',');
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5885 if (p == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5886 p = look + STRLEN(look);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5887 if ((try_match || try_match_word)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5888 && curwin->w_cursor.col >= (colnr_T)(p - look))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5889 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5890 int match = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5891
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5892 #ifdef FEAT_INS_EXPAND
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5893 if (keytyped == KEY_COMPLETE)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5894 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5895 char_u *s;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5896
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5897 /* Just completed a word, check if it starts with "look".
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5898 * search back for the start of a word. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5899 line = ml_get_curline();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5900 # ifdef FEAT_MBYTE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5901 if (has_mbyte)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5902 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5903 char_u *n;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5904
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5905 for (s = line + curwin->w_cursor.col; s > line; s = n)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5906 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5907 n = mb_prevptr(line, s);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5908 if (!vim_iswordp(n))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5909 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5910 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5911 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5912 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5913 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5914 for (s = line + curwin->w_cursor.col; s > line; --s)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5915 if (!vim_iswordc(s[-1]))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5916 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5917 if (s + (p - look) <= line + curwin->w_cursor.col
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5918 && (icase
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5919 ? MB_STRNICMP(s, look, p - look)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5920 : STRNCMP(s, look, p - look)) == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5921 match = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5922 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5923 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5924 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5925 /* TODO: multi-byte */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5926 if (keytyped == (int)p[-1] || (icase && keytyped < 256
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5927 && TOLOWER_LOC(keytyped) == TOLOWER_LOC((int)p[-1])))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5928 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5929 line = ml_get_cursor();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5930 if ((curwin->w_cursor.col == (colnr_T)(p - look)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5931 || !vim_iswordc(line[-(p - look) - 1]))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5932 && (icase
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5933 ? MB_STRNICMP(line - (p - look), look, p - look)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5934 : STRNCMP(line - (p - look), look, p - look))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5935 == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5936 match = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5937 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5938 if (match && try_match_word && !try_match)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5939 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5940 /* "0=word": Check if there are only blanks before the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5941 * word. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5942 line = ml_get_curline();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5943 if ((int)(skipwhite(line) - line) !=
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5944 (int)(curwin->w_cursor.col - (p - look)))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5945 match = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5946 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5947 if (match)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5948 return TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5949 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5950 look = p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5951 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5952
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5953 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5954 * ok, it's a boring generic character.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5955 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5956 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5957 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5958 if (try_match && *look == keytyped)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5959 return TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5960 ++look;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5961 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5962
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5963 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5964 * Skip over ", ".
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5965 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5966 look = skip_to_option_part(look);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5967 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5968 return FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5969 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5970 #endif /* FEAT_CINDENT */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5971
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5972 #if defined(FEAT_RIGHTLEFT) || defined(PROTO)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5973 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5974 * Map Hebrew keyboard when in hkmap mode.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5975 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5976 int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5977 hkmap(c)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5978 int c;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5979 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5980 if (p_hkmapp) /* phonetic mapping, by Ilya Dogolazky */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5981 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5982 enum {hALEF=0, BET, GIMEL, DALET, HEI, VAV, ZAIN, HET, TET, IUD,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5983 KAFsofit, hKAF, LAMED, MEMsofit, MEM, NUNsofit, NUN, SAMEH, AIN,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5984 PEIsofit, PEI, ZADIsofit, ZADI, KOF, RESH, hSHIN, TAV};
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5985 static char_u map[26] =
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5986 {(char_u)hALEF/*a*/, (char_u)BET /*b*/, (char_u)hKAF /*c*/,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5987 (char_u)DALET/*d*/, (char_u)-1 /*e*/, (char_u)PEIsofit/*f*/,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5988 (char_u)GIMEL/*g*/, (char_u)HEI /*h*/, (char_u)IUD /*i*/,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5989 (char_u)HET /*j*/, (char_u)KOF /*k*/, (char_u)LAMED /*l*/,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5990 (char_u)MEM /*m*/, (char_u)NUN /*n*/, (char_u)SAMEH /*o*/,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5991 (char_u)PEI /*p*/, (char_u)-1 /*q*/, (char_u)RESH /*r*/,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5992 (char_u)ZAIN /*s*/, (char_u)TAV /*t*/, (char_u)TET /*u*/,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5993 (char_u)VAV /*v*/, (char_u)hSHIN/*w*/, (char_u)-1 /*x*/,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5994 (char_u)AIN /*y*/, (char_u)ZADI /*z*/};
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5995
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5996 if (c == 'N' || c == 'M' || c == 'P' || c == 'C' || c == 'Z')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5997 return (int)(map[CharOrd(c)] - 1 + p_aleph);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5998 /* '-1'='sofit' */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5999 else if (c == 'x')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6000 return 'X';
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6001 else if (c == 'q')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6002 return '\''; /* {geresh}={'} */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6003 else if (c == 246)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6004 return ' '; /* \"o --> ' ' for a german keyboard */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6005 else if (c == 228)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6006 return ' '; /* \"a --> ' ' -- / -- */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6007 else if (c == 252)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6008 return ' '; /* \"u --> ' ' -- / -- */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6009 #ifdef EBCDIC
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6010 else if (islower(c))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6011 #else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6012 /* NOTE: islower() does not do the right thing for us on Linux so we
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6013 * 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
6014 * all systems. Specifically, the e.g. Delete and Arrow keys are
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6015 * munged and won't work if e.g. searching for Hebrew text.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6016 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6017 else if (c >= 'a' && c <= 'z')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6018 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6019 return (int)(map[CharOrdLow(c)] + p_aleph);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6020 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6021 return c;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6022 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6023 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6024 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6025 switch (c)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6026 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6027 case '`': return ';';
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6028 case '/': return '.';
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6029 case '\'': return ',';
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6030 case 'q': return '/';
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6031 case 'w': return '\'';
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6032
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6033 /* Hebrew letters - set offset from 'a' */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6034 case ',': c = '{'; break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6035 case '.': c = 'v'; break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6036 case ';': c = 't'; break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6037 default: {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6038 static char str[] = "zqbcxlsjphmkwonu ydafe rig";
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6039
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6040 #ifdef EBCDIC
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6041 /* see note about islower() above */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6042 if (!islower(c))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6043 #else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6044 if (c < 'a' || c > 'z')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6045 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6046 return c;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6047 c = str[CharOrdLow(c)];
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6048 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6049 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6050 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6051
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6052 return (int)(CharOrdLow(c) + p_aleph);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6053 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6054 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6055 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6056
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6057 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6058 ins_reg()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6059 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6060 int need_redraw = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6061 int regname;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6062 int literally = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6063
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6064 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6065 * If we are going to wait for a character, show a '"'.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6066 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6067 pc_status = PC_STATUS_UNSET;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6068 if (redrawing() && !char_avail())
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6069 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6070 /* may need to redraw when no more chars available now */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6071 ins_redraw();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6072
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6073 edit_putchar('"', TRUE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6074 #ifdef FEAT_CMDL_INFO
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6075 add_to_showcmd_c(Ctrl_R);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6076 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6077 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6078
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6079 #ifdef USE_ON_FLY_SCROLL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6080 dont_scroll = TRUE; /* disallow scrolling here */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6081 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6082
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6083 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6084 * Don't map the register name. This also prevents the mode message to be
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6085 * deleted when ESC is hit.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6086 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6087 ++no_mapping;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6088 regname = safe_vgetc();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6089 #ifdef FEAT_LANGMAP
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6090 LANGMAP_ADJUST(regname, TRUE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6091 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6092 if (regname == Ctrl_R || regname == Ctrl_O || regname == Ctrl_P)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6093 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6094 /* Get a third key for literal register insertion */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6095 literally = regname;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6096 #ifdef FEAT_CMDL_INFO
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6097 add_to_showcmd_c(literally);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6098 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6099 regname = safe_vgetc();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6100 #ifdef FEAT_LANGMAP
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6101 LANGMAP_ADJUST(regname, TRUE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6102 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6103 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6104 --no_mapping;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6105
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6106 #ifdef FEAT_EVAL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6107 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6108 * Don't call u_sync() while getting the expression,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6109 * evaluating it or giving an error message for it!
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6110 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6111 ++no_u_sync;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6112 if (regname == '=')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6113 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6114 #ifdef USE_IM_CONTROL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6115 int im_on = im_get_status();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6116 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6117 regname = get_expr_register();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6118 #ifdef USE_IM_CONTROL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6119 /* Restore the Input Method. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6120 if (im_on)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6121 im_set_active(TRUE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6122 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6123 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6124 if (regname == NUL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6125 need_redraw = TRUE; /* remove the '"' */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6126 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6127 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6128 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6129 if (literally == Ctrl_O || literally == Ctrl_P)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6130 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6131 /* Append the command to the redo buffer. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6132 AppendCharToRedobuff(Ctrl_R);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6133 AppendCharToRedobuff(literally);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6134 AppendCharToRedobuff(regname);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6135
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6136 do_put(regname, BACKWARD, 1L,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6137 (literally == Ctrl_P ? PUT_FIXINDENT : 0) | PUT_CURSEND);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6138 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6139 else if (insert_reg(regname, literally) == FAIL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6140 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6141 vim_beep();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6142 need_redraw = TRUE; /* remove the '"' */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6143 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6144 #ifdef FEAT_EVAL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6145 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6146 --no_u_sync;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6147 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6148 #ifdef FEAT_CMDL_INFO
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6149 clear_showcmd();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6150 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6151
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6152 /* If the inserted register is empty, we need to remove the '"' */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6153 if (need_redraw || stuff_empty())
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6154 edit_unputchar();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6155 }
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 * CTRL-G commands in Insert mode.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6159 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6160 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6161 ins_ctrl_g()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6162 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6163 int c;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6164
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6165 #ifdef FEAT_INS_EXPAND
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6166 /* Right after CTRL-X the cursor will be after the ruler. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6167 setcursor();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6168 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6169
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6170 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6171 * Don't map the second key. This also prevents the mode message to be
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6172 * deleted when ESC is hit.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6173 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6174 ++no_mapping;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6175 c = safe_vgetc();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6176 --no_mapping;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6177 switch (c)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6178 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6179 /* CTRL-G k and CTRL-G <Up>: cursor up to Insstart.col */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6180 case K_UP:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6181 case Ctrl_K:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6182 case 'k': ins_up(TRUE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6183 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6184
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6185 /* CTRL-G j and CTRL-G <Down>: cursor down to Insstart.col */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6186 case K_DOWN:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6187 case Ctrl_J:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6188 case 'j': ins_down(TRUE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6189 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6190
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6191 /* CTRL-G u: start new undoable edit */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6192 case 'u': u_sync();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6193 ins_need_undo = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6194 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6195
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6196 /* Unknown CTRL-G command, reserved for future expansion. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6197 default: vim_beep();
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
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6201 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6202 * Handle ESC in insert mode.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6203 * Returns TRUE when leaving insert mode, FALSE when going to repeat the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6204 * insert.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6205 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6206 static int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6207 ins_esc(count, cmdchar)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6208 long *count;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6209 int cmdchar;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6210 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6211 int temp;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6212 static int disabled_redraw = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6213
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6214 #if defined(FEAT_HANGULIN)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6215 # if defined(ESC_CHG_TO_ENG_MODE)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6216 hangul_input_state_set(0);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6217 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6218 if (composing_hangul)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6219 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6220 push_raw_key(composing_hangul_buffer, 2);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6221 composing_hangul = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6222 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6223 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6224 #if defined(FEAT_MBYTE) && defined(MACOS_CLASSIC)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6225 previous_script = GetScriptManagerVariable(smKeyScript);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6226 KeyScript(smKeyRoman); /* or smKeySysScript */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6227 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6228
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6229 temp = curwin->w_cursor.col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6230 if (disabled_redraw)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6231 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6232 --RedrawingDisabled;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6233 disabled_redraw = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6234 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6235 if (!arrow_used)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6236 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6237 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6238 * Don't append the ESC for "r<CR>" and "grx".
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6239 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6240 if (cmdchar != 'r' && cmdchar != 'v')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6241 AppendToRedobuff(ESC_STR);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6242
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6243 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6244 * Repeating insert may take a long time. Check for
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6245 * interrupt now and then.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6246 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6247 if (*count > 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6248 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6249 line_breakcheck();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6250 if (got_int)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6251 *count = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6252 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6253
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6254 if (--*count > 0) /* repeat what was typed */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6255 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6256 (void)start_redo_ins();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6257 if (cmdchar == 'r' || cmdchar == 'v')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6258 stuffReadbuff(ESC_STR); /* no ESC in redo buffer */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6259 ++RedrawingDisabled;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6260 disabled_redraw = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6261 return FALSE; /* repeat the insert */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6262 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6263 stop_insert(&curwin->w_cursor, TRUE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6264 undisplay_dollar();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6265 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6266
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6267 /* When an autoindent was removed, curswant stays after the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6268 * indent */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6269 if (restart_edit == NUL && (colnr_T)temp == curwin->w_cursor.col)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6270 curwin->w_set_curswant = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6271
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6272 /* Remember the last Insert position in the '^ mark. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6273 if (!cmdmod.keepjumps)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6274 curbuf->b_last_insert = curwin->w_cursor;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6275
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6276 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6277 * The cursor should end up on the last inserted character.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6278 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6279 if ((curwin->w_cursor.col != 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6280 #ifdef FEAT_VIRTUALEDIT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6281 || curwin->w_cursor.coladd > 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6282 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6283 ) && (restart_edit == NUL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6284 || (gchar_cursor() == NUL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6285 #ifdef FEAT_VISUAL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6286 && !VIsual_active
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6287 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6288 ))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6289 #ifdef FEAT_RIGHTLEFT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6290 && !revins_on
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6291 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6292 )
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6293 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6294 #ifdef FEAT_VIRTUALEDIT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6295 if (curwin->w_cursor.coladd > 0 || ve_flags == VE_ALL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6296 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6297 oneleft();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6298 if (restart_edit != NUL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6299 ++curwin->w_cursor.coladd;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6300 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6301 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6302 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6303 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6304 --curwin->w_cursor.col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6305 #ifdef FEAT_MBYTE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6306 /* Correct cursor for multi-byte character. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6307 if (has_mbyte)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6308 mb_adjust_cursor();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6309 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6310 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6311 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6312
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6313 #ifdef USE_IM_CONTROL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6314 /* Disable IM to allow typing English directly for Normal mode commands.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6315 * When ":lmap" is enabled don't change 'iminsert' (IM can be enabled as
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6316 * well). */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6317 if (!(State & LANGMAP))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6318 im_save_status(&curbuf->b_p_iminsert);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6319 im_set_active(FALSE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6320 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6321
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6322 State = NORMAL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6323 /* need to position cursor again (e.g. when on a TAB ) */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6324 changed_cline_bef_curs();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6325
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6326 #ifdef FEAT_MOUSE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6327 setmouse();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6328 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6329 #ifdef CURSOR_SHAPE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6330 ui_cursor_shape(); /* may show different cursor shape */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6331 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6332
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6333 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6334 * When recording or for CTRL-O, need to display the new mode.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6335 * Otherwise remove the mode message.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6336 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6337 if (Recording || restart_edit != NUL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6338 showmode();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6339 else if (p_smd)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6340 MSG("");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6341
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6342 return TRUE; /* exit Insert mode */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6343 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6344
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6345 #ifdef FEAT_RIGHTLEFT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6346 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6347 * Toggle language: hkmap and revins_on.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6348 * Move to end of reverse inserted text.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6349 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6350 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6351 ins_ctrl_()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6352 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6353 if (revins_on && revins_chars && revins_scol >= 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6354 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6355 while (gchar_cursor() != NUL && revins_chars--)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6356 ++curwin->w_cursor.col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6357 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6358 p_ri = !p_ri;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6359 revins_on = (State == INSERT && p_ri);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6360 if (revins_on)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6361 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6362 revins_scol = curwin->w_cursor.col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6363 revins_legal++;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6364 revins_chars = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6365 undisplay_dollar();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6366 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6367 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6368 revins_scol = -1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6369 #ifdef FEAT_FKMAP
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6370 if (p_altkeymap)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6371 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6372 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6373 * to be consistent also for redo command, using '.'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6374 * set arrow_used to true and stop it - causing to redo
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6375 * characters entered in one mode (normal/reverse insert).
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6376 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6377 arrow_used = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6378 (void)stop_arrow();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6379 p_fkmap = curwin->w_p_rl ^ p_ri;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6380 if (p_fkmap && p_ri)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6381 State = INSERT;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6382 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6383 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6384 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6385 p_hkmap = curwin->w_p_rl ^ p_ri; /* be consistent! */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6386 showmode();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6387 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6388 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6389
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6390 #ifdef FEAT_VISUAL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6391 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6392 * If 'keymodel' contains "startsel", may start selection.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6393 * Returns TRUE when a CTRL-O and other keys stuffed.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6394 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6395 static int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6396 ins_start_select(c)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6397 int c;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6398 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6399 if (km_startsel)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6400 switch (c)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6401 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6402 case K_KHOME:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6403 case K_XHOME:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6404 case K_KEND:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6405 case K_XEND:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6406 case K_PAGEUP:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6407 case K_KPAGEUP:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6408 case K_PAGEDOWN:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6409 case K_KPAGEDOWN:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6410 # ifdef MACOS
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6411 case K_LEFT:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6412 case K_RIGHT:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6413 case K_UP:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6414 case K_DOWN:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6415 case K_END:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6416 case K_HOME:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6417 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6418 if (!(mod_mask & MOD_MASK_SHIFT))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6419 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6420 /* FALLTHROUGH */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6421 case K_S_LEFT:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6422 case K_S_RIGHT:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6423 case K_S_UP:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6424 case K_S_DOWN:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6425 case K_S_END:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6426 case K_S_HOME:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6427 /* Start selection right away, the cursor can move with
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6428 * CTRL-O when beyond the end of the line. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6429 start_selection();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6430
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6431 /* Execute the key in (insert) Select mode. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6432 stuffcharReadbuff(Ctrl_O);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6433 if (mod_mask)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6434 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6435 char_u buf[4];
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6436
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6437 buf[0] = K_SPECIAL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6438 buf[1] = KS_MODIFIER;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6439 buf[2] = mod_mask;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6440 buf[3] = NUL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6441 stuffReadbuff(buf);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6442 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6443 stuffcharReadbuff(c);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6444 return TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6445 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6446 return FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6447 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6448 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6449
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6450 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6451 * If the cursor is on an indent, ^T/^D insert/delete one
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6452 * shiftwidth. Otherwise ^T/^D behave like a "<<" or ">>".
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6453 * Always round the indent to 'shiftwith', this is compatible
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6454 * with vi. But vi only supports ^T and ^D after an
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6455 * autoindent, we support it everywhere.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6456 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6457 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6458 ins_shift(c, lastc)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6459 int c;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6460 int lastc;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6461 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6462 if (stop_arrow() == FAIL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6463 return;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6464 AppendCharToRedobuff(c);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6465
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6466 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6467 * 0^D and ^^D: remove all indent.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6468 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6469 if ((lastc == '0' || lastc == '^') && curwin->w_cursor.col)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6470 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6471 --curwin->w_cursor.col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6472 (void)del_char(FALSE); /* delete the '^' or '0' */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6473 /* In Replace mode, restore the characters that '^' or '0' replaced. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6474 if (State & REPLACE_FLAG)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6475 replace_pop_ins();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6476 if (lastc == '^')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6477 old_indent = get_indent(); /* remember curr. indent */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6478 change_indent(INDENT_SET, 0, TRUE, 0);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6479 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6480 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6481 change_indent(c == Ctrl_D ? INDENT_DEC : INDENT_INC, 0, TRUE, 0);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6482
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6483 if (did_ai && *skipwhite(ml_get_curline()) != NUL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6484 did_ai = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6485 #ifdef FEAT_SMARTINDENT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6486 did_si = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6487 can_si = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6488 can_si_back = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6489 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6490 #ifdef FEAT_CINDENT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6491 can_cindent = FALSE; /* no cindenting after ^D or ^T */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6492 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6493 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6494
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6495 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6496 ins_del()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6497 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6498 int temp;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6499
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6500 if (stop_arrow() == FAIL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6501 return;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6502 if (gchar_cursor() == NUL) /* delete newline */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6503 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6504 temp = curwin->w_cursor.col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6505 if (!can_bs(BS_EOL) /* only if "eol" included */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6506 || u_save((linenr_T)(curwin->w_cursor.lnum - 1),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6507 (linenr_T)(curwin->w_cursor.lnum + 2)) == FAIL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6508 || do_join(FALSE) == FAIL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6509 vim_beep();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6510 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6511 curwin->w_cursor.col = temp;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6512 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6513 else if (del_char(FALSE) == FAIL) /* delete char under cursor */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6514 vim_beep();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6515 did_ai = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6516 #ifdef FEAT_SMARTINDENT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6517 did_si = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6518 can_si = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6519 can_si_back = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6520 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6521 AppendCharToRedobuff(K_DEL);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6522 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6523
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6524 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6525 * Handle Backspace, delete-word and delete-line in Insert mode.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6526 * Return TRUE when backspace was actually used.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6527 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6528 static int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6529 ins_bs(c, mode, inserted_space_p)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6530 int c;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6531 int mode;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6532 int *inserted_space_p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6533 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6534 linenr_T lnum;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6535 int cc;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6536 int temp = 0; /* init for GCC */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6537 colnr_T mincol;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6538 int did_backspace = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6539 int in_indent;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6540 int oldState;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6541 #ifdef FEAT_MBYTE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6542 int p1, p2;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6543 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6544
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6545 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6546 * can't delete anything in an empty file
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6547 * can't backup past first character in buffer
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6548 * can't backup past starting point unless 'backspace' > 1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6549 * can backup to a previous line if 'backspace' == 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6550 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6551 if ( bufempty()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6552 || (
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6553 #ifdef FEAT_RIGHTLEFT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6554 !revins_on &&
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6555 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6556 ((curwin->w_cursor.lnum == 1 && curwin->w_cursor.col == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6557 || (!can_bs(BS_START)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6558 && (arrow_used
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6559 || (curwin->w_cursor.lnum == Insstart.lnum
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6560 && curwin->w_cursor.col <= Insstart.col)))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6561 || (!can_bs(BS_INDENT) && !arrow_used && ai_col > 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6562 && curwin->w_cursor.col <= ai_col)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6563 || (!can_bs(BS_EOL) && curwin->w_cursor.col == 0))))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6564 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6565 vim_beep();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6566 return FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6567 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6568
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6569 if (stop_arrow() == FAIL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6570 return FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6571 in_indent = inindent(0);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6572 #ifdef FEAT_CINDENT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6573 if (in_indent)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6574 can_cindent = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6575 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6576 #ifdef FEAT_COMMENTS
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6577 end_comment_pending = NUL; /* After BS, don't auto-end comment */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6578 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6579 #ifdef FEAT_RIGHTLEFT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6580 if (revins_on) /* put cursor after last inserted char */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6581 inc_cursor();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6582 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6583
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6584 #ifdef FEAT_VIRTUALEDIT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6585 /* Virtualedit:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6586 * BACKSPACE_CHAR eats a virtual space
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6587 * BACKSPACE_WORD eats all coladd
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6588 * BACKSPACE_LINE eats all coladd and keeps going
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6589 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6590 if (curwin->w_cursor.coladd > 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6591 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6592 if (mode == BACKSPACE_CHAR)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6593 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6594 --curwin->w_cursor.coladd;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6595 return TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6596 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6597 if (mode == BACKSPACE_WORD)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6598 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6599 curwin->w_cursor.coladd = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6600 return TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6601 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6602 curwin->w_cursor.coladd = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6603 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6604 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6605
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6606 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6607 * delete newline!
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6608 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6609 if (curwin->w_cursor.col == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6610 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6611 lnum = Insstart.lnum;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6612 if (curwin->w_cursor.lnum == Insstart.lnum
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6613 #ifdef FEAT_RIGHTLEFT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6614 || revins_on
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6615 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6616 )
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6617 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6618 if (u_save((linenr_T)(curwin->w_cursor.lnum - 2),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6619 (linenr_T)(curwin->w_cursor.lnum + 1)) == FAIL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6620 return FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6621 --Insstart.lnum;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6622 Insstart.col = MAXCOL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6623 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6624 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6625 * In replace mode:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6626 * cc < 0: NL was inserted, delete it
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6627 * cc >= 0: NL was replaced, put original characters back
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6628 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6629 cc = -1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6630 if (State & REPLACE_FLAG)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6631 cc = replace_pop(); /* returns -1 if NL was inserted */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6632 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6633 * In replace mode, in the line we started replacing, we only move the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6634 * cursor.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6635 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6636 if ((State & REPLACE_FLAG) && curwin->w_cursor.lnum <= lnum)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6637 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6638 dec_cursor();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6639 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6640 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6641 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6642 #ifdef FEAT_VREPLACE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6643 if (!(State & VREPLACE_FLAG)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6644 || curwin->w_cursor.lnum > orig_line_count)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6645 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6646 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6647 temp = gchar_cursor(); /* remember current char */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6648 --curwin->w_cursor.lnum;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6649 (void)do_join(FALSE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6650 if (temp == NUL && gchar_cursor() != NUL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6651 inc_cursor();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6652 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6653 #ifdef FEAT_VREPLACE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6654 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6655 dec_cursor();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6656 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6657
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6658 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6659 * In REPLACE mode we have to put back the text that was replaced
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6660 * by the NL. On the replace stack is first a NUL-terminated
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6661 * sequence of characters that were deleted and then the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6662 * characters that NL replaced.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6663 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6664 if (State & REPLACE_FLAG)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6665 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6666 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6667 * Do the next ins_char() in NORMAL state, to
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6668 * prevent ins_char() from replacing characters and
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6669 * avoiding showmatch().
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6670 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6671 oldState = State;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6672 State = NORMAL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6673 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6674 * restore characters (blanks) deleted after cursor
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6675 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6676 while (cc > 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6677 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6678 temp = curwin->w_cursor.col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6679 #ifdef FEAT_MBYTE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6680 mb_replace_pop_ins(cc);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6681 #else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6682 ins_char(cc);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6683 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6684 curwin->w_cursor.col = temp;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6685 cc = replace_pop();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6686 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6687 /* restore the characters that NL replaced */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6688 replace_pop_ins();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6689 State = oldState;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6690 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6691 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6692 did_ai = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6693 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6694 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6695 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6696 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6697 * Delete character(s) before the cursor.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6698 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6699 #ifdef FEAT_RIGHTLEFT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6700 if (revins_on) /* put cursor on last inserted char */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6701 dec_cursor();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6702 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6703 mincol = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6704 /* keep indent */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6705 if (mode == BACKSPACE_LINE && curbuf->b_p_ai
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6706 #ifdef FEAT_RIGHTLEFT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6707 && !revins_on
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6708 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6709 )
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6710 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6711 temp = curwin->w_cursor.col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6712 beginline(BL_WHITE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6713 if (curwin->w_cursor.col < (colnr_T)temp)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6714 mincol = curwin->w_cursor.col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6715 curwin->w_cursor.col = temp;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6716 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6717
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6718 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6719 * Handle deleting one 'shiftwidth' or 'softtabstop'.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6720 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6721 if ( mode == BACKSPACE_CHAR
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6722 && ((p_sta && in_indent)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6723 || (curbuf->b_p_sts
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6724 && (*(ml_get_cursor() - 1) == TAB
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6725 || (*(ml_get_cursor() - 1) == ' '
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6726 && (!*inserted_space_p
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6727 || arrow_used))))))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6728 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6729 int ts;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6730 colnr_T vcol;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6731 colnr_T want_vcol;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6732 int extra = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6733
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6734 *inserted_space_p = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6735 if (p_sta)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6736 ts = curbuf->b_p_sw;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6737 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6738 ts = curbuf->b_p_sts;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6739 /* Compute the virtual column where we want to be. Since
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6740 * 'showbreak' may get in the way, need to get the last column of
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6741 * the previous character. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6742 getvcol(curwin, &curwin->w_cursor, &vcol, NULL, NULL);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6743 dec_cursor();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6744 getvcol(curwin, &curwin->w_cursor, NULL, NULL, &want_vcol);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6745 inc_cursor();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6746 want_vcol = (want_vcol / ts) * ts;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6747
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6748 /* delete characters until we are at or before want_vcol */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6749 while (vcol > want_vcol
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6750 && (cc = *(ml_get_cursor() - 1), vim_iswhite(cc)))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6751 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6752 dec_cursor();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6753 getvcol(curwin, &curwin->w_cursor, &vcol, NULL, NULL);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6754 if (State & REPLACE_FLAG)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6755 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6756 /* Don't delete characters before the insert point when in
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6757 * Replace mode */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6758 if (curwin->w_cursor.lnum != Insstart.lnum
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6759 || curwin->w_cursor.col >= Insstart.col)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6760 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6761 #if 0 /* what was this for? It causes problems when sw != ts. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6762 if (State == REPLACE && (int)vcol < want_vcol)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6763 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6764 (void)del_char(FALSE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6765 extra = 2; /* don't pop too much */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6766 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6767 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6768 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6769 replace_do_bs();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6770 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6771 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6772 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6773 (void)del_char(FALSE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6774 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6775
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6776 /* insert extra spaces until we are at want_vcol */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6777 while (vcol < want_vcol)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6778 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6779 /* Remember the first char we inserted */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6780 if (curwin->w_cursor.lnum == Insstart.lnum
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6781 && curwin->w_cursor.col < Insstart.col)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6782 Insstart.col = curwin->w_cursor.col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6783
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6784 #ifdef FEAT_VREPLACE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6785 if (State & VREPLACE_FLAG)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6786 ins_char(' ');
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6787 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6788 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6789 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6790 ins_str((char_u *)" ");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6791 if ((State & REPLACE_FLAG) && extra <= 1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6792 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6793 if (extra)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6794 replace_push_off(NUL);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6795 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6796 replace_push(NUL);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6797 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6798 if (extra == 2)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6799 extra = 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6800 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6801 getvcol(curwin, &curwin->w_cursor, &vcol, NULL, NULL);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6802 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6803 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6804
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6805 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6806 * Delete upto starting point, start of line or previous word.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6807 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6808 else do
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6809 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6810 #ifdef FEAT_RIGHTLEFT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6811 if (!revins_on) /* put cursor on char to be deleted */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6812 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6813 dec_cursor();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6814
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6815 /* start of word? */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6816 if (mode == BACKSPACE_WORD && !vim_isspace(gchar_cursor()))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6817 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6818 mode = BACKSPACE_WORD_NOT_SPACE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6819 temp = vim_iswordc(gchar_cursor());
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6820 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6821 /* end of word? */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6822 else if (mode == BACKSPACE_WORD_NOT_SPACE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6823 && (vim_isspace(cc = gchar_cursor())
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6824 || vim_iswordc(cc) != temp))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6825 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6826 #ifdef FEAT_RIGHTLEFT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6827 if (!revins_on)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6828 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6829 inc_cursor();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6830 #ifdef FEAT_RIGHTLEFT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6831 else if (State & REPLACE_FLAG)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6832 dec_cursor();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6833 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6834 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6835 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6836 if (State & REPLACE_FLAG)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6837 replace_do_bs();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6838 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6839 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6840 #ifdef FEAT_MBYTE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6841 if (enc_utf8 && p_deco)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6842 (void)utfc_ptr2char(ml_get_cursor(), &p1, &p2);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6843 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6844 (void)del_char(FALSE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6845 #ifdef FEAT_MBYTE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6846 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6847 * If p1 or p2 is non-zero, there are combining characters we
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6848 * need to take account of. Don't back up before the base
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6849 * character.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6850 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6851 if (enc_utf8 && p_deco && (p1 != NUL || p2 != NUL))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6852 inc_cursor();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6853 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6854 #ifdef FEAT_RIGHTLEFT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6855 if (revins_chars)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6856 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6857 revins_chars--;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6858 revins_legal++;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6859 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6860 if (revins_on && gchar_cursor() == NUL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6861 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6862 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6863 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6864 /* Just a single backspace?: */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6865 if (mode == BACKSPACE_CHAR)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6866 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6867 } while (
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6868 #ifdef FEAT_RIGHTLEFT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6869 revins_on ||
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6870 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6871 (curwin->w_cursor.col > mincol
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6872 && (curwin->w_cursor.lnum != Insstart.lnum
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6873 || curwin->w_cursor.col != Insstart.col)));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6874 did_backspace = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6875 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6876 #ifdef FEAT_SMARTINDENT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6877 did_si = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6878 can_si = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6879 can_si_back = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6880 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6881 if (curwin->w_cursor.col <= 1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6882 did_ai = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6883 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6884 * It's a little strange to put backspaces into the redo
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6885 * buffer, but it makes auto-indent a lot easier to deal
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6886 * with.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6887 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6888 AppendCharToRedobuff(c);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6889
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6890 /* If deleted before the insertion point, adjust it */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6891 if (curwin->w_cursor.lnum == Insstart.lnum
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6892 && curwin->w_cursor.col < Insstart.col)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6893 Insstart.col = curwin->w_cursor.col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6894
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6895 /* vi behaviour: the cursor moves backward but the character that
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6896 * was there remains visible
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6897 * Vim behaviour: the cursor moves backward and the character that
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6898 * was there is erased from the screen.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6899 * We can emulate the vi behaviour by pretending there is a dollar
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6900 * displayed even when there isn't.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6901 * --pkv Sun Jan 19 01:56:40 EST 2003 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6902 if (vim_strchr(p_cpo, CPO_BACKSPACE) != NULL && dollar_vcol == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6903 dollar_vcol = curwin->w_virtcol;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6904
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6905 return did_backspace;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6906 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6907
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6908 #ifdef FEAT_MOUSE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6909 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6910 ins_mouse(c)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6911 int c;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6912 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6913 pos_T tpos;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6914
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6915 # ifdef FEAT_GUI
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6916 /* When GUI is active, also move/paste when 'mouse' is empty */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6917 if (!gui.in_use)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6918 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6919 if (!mouse_has(MOUSE_INSERT))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6920 return;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6921
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6922 undisplay_dollar();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6923 tpos = curwin->w_cursor;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6924 if (do_mouse(NULL, c, BACKWARD, 1L, 0))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6925 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6926 start_arrow(&tpos);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6927 # ifdef FEAT_CINDENT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6928 can_cindent = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6929 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6930 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6931
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6932 #ifdef FEAT_WINDOWS
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6933 /* redraw status lines (in case another window became active) */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6934 redraw_statuslines();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6935 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6936 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6937
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6938 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6939 ins_mousescroll(up)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6940 int up;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6941 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6942 pos_T tpos;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6943 # if defined(FEAT_GUI) && defined(FEAT_WINDOWS)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6944 win_T *old_curwin;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6945 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6946
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6947 tpos = curwin->w_cursor;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6948
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6949 # if defined(FEAT_GUI) && defined(FEAT_WINDOWS)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6950 old_curwin = curwin;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6951
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6952 /* Currently the mouse coordinates are only known in the GUI. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6953 if (gui.in_use && mouse_row >= 0 && mouse_col >= 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6954 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6955 int row, col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6956
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6957 row = mouse_row;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6958 col = mouse_col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6959
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6960 /* find the window at the pointer coordinates */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6961 curwin = mouse_find_win(&row, &col);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6962 curbuf = curwin->w_buffer;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6963 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6964 if (curwin == old_curwin)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6965 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6966 undisplay_dollar();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6967
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6968 if (mod_mask & (MOD_MASK_SHIFT | MOD_MASK_CTRL))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6969 scroll_redraw(up, (long)(curwin->w_botline - curwin->w_topline));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6970 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6971 scroll_redraw(up, 3L);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6972
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6973 # if defined(FEAT_GUI) && defined(FEAT_WINDOWS)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6974 curwin->w_redr_status = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6975
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6976 curwin = old_curwin;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6977 curbuf = curwin->w_buffer;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6978 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6979
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6980 if (!equalpos(curwin->w_cursor, tpos))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6981 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6982 start_arrow(&tpos);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6983 # ifdef FEAT_CINDENT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6984 can_cindent = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6985 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6986 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6987 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6988 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6989
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6990 #ifdef FEAT_GUI
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6991 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6992 ins_scroll()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6993 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6994 pos_T tpos;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6995
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6996 undisplay_dollar();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6997 tpos = curwin->w_cursor;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6998 if (gui_do_scroll())
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6999 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7000 start_arrow(&tpos);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7001 # ifdef FEAT_CINDENT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7002 can_cindent = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7003 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7004 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7005 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7006
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7007 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7008 ins_horscroll()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7009 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7010 pos_T tpos;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7011
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7012 undisplay_dollar();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7013 tpos = curwin->w_cursor;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7014 if (gui_do_horiz_scroll())
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7015 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7016 start_arrow(&tpos);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7017 # ifdef FEAT_CINDENT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7018 can_cindent = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7019 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7020 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7021 }
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 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7025 ins_left()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7026 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7027 pos_T tpos;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7028
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7029 #ifdef FEAT_FOLDING
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7030 if ((fdo_flags & FDO_HOR) && KeyTyped)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7031 foldOpenCursor();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7032 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7033 undisplay_dollar();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7034 tpos = curwin->w_cursor;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7035 if (oneleft() == OK)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7036 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7037 start_arrow(&tpos);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7038 #ifdef FEAT_RIGHTLEFT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7039 /* If exit reversed string, position is fixed */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7040 if (revins_scol != -1 && (int)curwin->w_cursor.col >= revins_scol)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7041 revins_legal++;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7042 revins_chars++;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7043 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7044 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7045
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7046 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7047 * if 'whichwrap' set for cursor in insert mode may go to
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7048 * previous line
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7049 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7050 else if (vim_strchr(p_ww, '[') != NULL && curwin->w_cursor.lnum > 1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7051 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7052 start_arrow(&tpos);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7053 --(curwin->w_cursor.lnum);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7054 coladvance((colnr_T)MAXCOL);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7055 curwin->w_set_curswant = TRUE; /* so we stay at the end */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7056 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7057 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7058 vim_beep();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7059 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7060
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7061 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7062 ins_home(c)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7063 int c;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7064 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7065 pos_T tpos;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7066
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7067 #ifdef FEAT_FOLDING
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7068 if ((fdo_flags & FDO_HOR) && KeyTyped)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7069 foldOpenCursor();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7070 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7071 undisplay_dollar();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7072 tpos = curwin->w_cursor;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7073 if (c == K_C_HOME)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7074 curwin->w_cursor.lnum = 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7075 curwin->w_cursor.col = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7076 #ifdef FEAT_VIRTUALEDIT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7077 curwin->w_cursor.coladd = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7078 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7079 curwin->w_curswant = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7080 start_arrow(&tpos);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7081 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7082
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7083 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7084 ins_end(c)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7085 int c;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7086 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7087 pos_T tpos;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7088
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7089 #ifdef FEAT_FOLDING
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7090 if ((fdo_flags & FDO_HOR) && KeyTyped)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7091 foldOpenCursor();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7092 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7093 undisplay_dollar();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7094 tpos = curwin->w_cursor;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7095 if (c == K_C_END)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7096 curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7097 coladvance((colnr_T)MAXCOL);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7098 curwin->w_curswant = MAXCOL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7099
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7100 start_arrow(&tpos);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7101 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7102
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7103 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7104 ins_s_left()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7105 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7106 #ifdef FEAT_FOLDING
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7107 if ((fdo_flags & FDO_HOR) && KeyTyped)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7108 foldOpenCursor();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7109 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7110 undisplay_dollar();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7111 if (curwin->w_cursor.lnum > 1 || curwin->w_cursor.col > 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7112 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7113 start_arrow(&curwin->w_cursor);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7114 (void)bck_word(1L, FALSE, FALSE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7115 curwin->w_set_curswant = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7116 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7117 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7118 vim_beep();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7119 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7120
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7121 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7122 ins_right()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7123 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7124 #ifdef FEAT_FOLDING
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7125 if ((fdo_flags & FDO_HOR) && KeyTyped)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7126 foldOpenCursor();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7127 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7128 undisplay_dollar();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7129 if (gchar_cursor() != NUL || virtual_active()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7130 )
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7131 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7132 start_arrow(&curwin->w_cursor);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7133 curwin->w_set_curswant = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7134 #ifdef FEAT_VIRTUALEDIT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7135 if (virtual_active())
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7136 oneright();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7137 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7138 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7139 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7140 #ifdef FEAT_MBYTE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7141 if (has_mbyte)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7142 curwin->w_cursor.col += (*mb_ptr2len_check)(ml_get_cursor());
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7143 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7144 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7145 ++curwin->w_cursor.col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7146 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7147
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7148 #ifdef FEAT_RIGHTLEFT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7149 revins_legal++;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7150 if (revins_chars)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7151 revins_chars--;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7152 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7153 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7154 /* if 'whichwrap' set for cursor in insert mode, may move the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7155 * cursor to the next line */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7156 else if (vim_strchr(p_ww, ']') != NULL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7157 && curwin->w_cursor.lnum < curbuf->b_ml.ml_line_count)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7158 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7159 start_arrow(&curwin->w_cursor);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7160 curwin->w_set_curswant = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7161 ++curwin->w_cursor.lnum;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7162 curwin->w_cursor.col = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7163 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7164 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7165 vim_beep();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7166 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7167
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7168 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7169 ins_s_right()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7170 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7171 #ifdef FEAT_FOLDING
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7172 if ((fdo_flags & FDO_HOR) && KeyTyped)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7173 foldOpenCursor();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7174 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7175 undisplay_dollar();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7176 if (curwin->w_cursor.lnum < curbuf->b_ml.ml_line_count
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7177 || gchar_cursor() != NUL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7178 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7179 start_arrow(&curwin->w_cursor);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7180 (void)fwd_word(1L, FALSE, 0);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7181 curwin->w_set_curswant = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7182 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7183 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7184 vim_beep();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7185 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7186
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7187 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7188 ins_up(startcol)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7189 int startcol; /* when TRUE move to Insstart.col */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7190 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7191 pos_T tpos;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7192 linenr_T old_topline = curwin->w_topline;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7193 #ifdef FEAT_DIFF
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7194 int old_topfill = curwin->w_topfill;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7195 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7196
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7197 undisplay_dollar();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7198 tpos = curwin->w_cursor;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7199 if (cursor_up(1L, TRUE) == OK)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7200 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7201 if (startcol)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7202 coladvance(getvcol_nolist(&Insstart));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7203 if (old_topline != curwin->w_topline
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7204 #ifdef FEAT_DIFF
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7205 || old_topfill != curwin->w_topfill
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7206 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7207 )
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7208 redraw_later(VALID);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7209 start_arrow(&tpos);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7210 #ifdef FEAT_CINDENT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7211 can_cindent = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7212 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7213 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7214 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7215 vim_beep();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7216 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7217
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7218 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7219 ins_pageup()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7220 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7221 pos_T tpos;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7222
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7223 undisplay_dollar();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7224 tpos = curwin->w_cursor;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7225 if (onepage(BACKWARD, 1L) == OK)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7226 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7227 start_arrow(&tpos);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7228 #ifdef FEAT_CINDENT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7229 can_cindent = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7230 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7231 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7232 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7233 vim_beep();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7234 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7235
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7236 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7237 ins_down(startcol)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7238 int startcol; /* when TRUE move to Insstart.col */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7239 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7240 pos_T tpos;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7241 linenr_T old_topline = curwin->w_topline;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7242 #ifdef FEAT_DIFF
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7243 int old_topfill = curwin->w_topfill;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7244 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7245
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7246 undisplay_dollar();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7247 tpos = curwin->w_cursor;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7248 if (cursor_down(1L, TRUE) == OK)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7249 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7250 if (startcol)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7251 coladvance(getvcol_nolist(&Insstart));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7252 if (old_topline != curwin->w_topline
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7253 #ifdef FEAT_DIFF
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7254 || old_topfill != curwin->w_topfill
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 redraw_later(VALID);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7258 start_arrow(&tpos);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7259 #ifdef FEAT_CINDENT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7260 can_cindent = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7261 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7262 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7263 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7264 vim_beep();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7265 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7266
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7267 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7268 ins_pagedown()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7269 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7270 pos_T tpos;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7271
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7272 undisplay_dollar();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7273 tpos = curwin->w_cursor;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7274 if (onepage(FORWARD, 1L) == OK)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7275 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7276 start_arrow(&tpos);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7277 #ifdef FEAT_CINDENT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7278 can_cindent = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7279 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7280 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7281 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7282 vim_beep();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7283 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7284
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7285 #ifdef FEAT_DND
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7286 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7287 ins_drop()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7288 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7289 do_put('~', BACKWARD, 1L, PUT_CURSEND);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7290 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7291 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7292
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7293 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7294 * Handle TAB in Insert or Replace mode.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7295 * Return TRUE when the TAB needs to be inserted like a normal character.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7296 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7297 static int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7298 ins_tab()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7299 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7300 int ind;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7301 int i;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7302 int temp;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7303
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7304 if (Insstart_blank_vcol == MAXCOL && curwin->w_cursor.lnum == Insstart.lnum)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7305 Insstart_blank_vcol = get_nolist_virtcol();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7306 if (echeck_abbr(TAB + ABBR_OFF))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7307 return FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7308
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7309 ind = inindent(0);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7310 #ifdef FEAT_CINDENT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7311 if (ind)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7312 can_cindent = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7313 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7314
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7315 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7316 * When nothing special, insert TAB like a normal character
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7317 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7318 if (!curbuf->b_p_et
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7319 && !(p_sta && ind && curbuf->b_p_ts != curbuf->b_p_sw)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7320 && curbuf->b_p_sts == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7321 return TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7322
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7323 if (stop_arrow() == FAIL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7324 return TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7325
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7326 did_ai = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7327 #ifdef FEAT_SMARTINDENT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7328 did_si = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7329 can_si = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7330 can_si_back = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7331 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7332 AppendToRedobuff((char_u *)"\t");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7333
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7334 if (p_sta && ind) /* insert tab in indent, use 'shiftwidth' */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7335 temp = (int)curbuf->b_p_sw;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7336 else if (curbuf->b_p_sts > 0) /* use 'softtabstop' when set */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7337 temp = (int)curbuf->b_p_sts;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7338 else /* otherwise use 'tabstop' */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7339 temp = (int)curbuf->b_p_ts;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7340 temp -= get_nolist_virtcol() % temp;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7341
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7342 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7343 * Insert the first space with ins_char(). It will delete one char in
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7344 * replace mode. Insert the rest with ins_str(); it will not delete any
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7345 * chars. For VREPLACE mode, we use ins_char() for all characters.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7346 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7347 ins_char(' ');
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7348 while (--temp > 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7349 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7350 #ifdef FEAT_VREPLACE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7351 if (State & VREPLACE_FLAG)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7352 ins_char(' ');
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7353 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7354 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7355 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7356 ins_str((char_u *)" ");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7357 if (State & REPLACE_FLAG) /* no char replaced */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7358 replace_push(NUL);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7359 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7360 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7361
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7362 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7363 * When 'expandtab' not set: Replace spaces by TABs where possible.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7364 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7365 if (!curbuf->b_p_et && (curbuf->b_p_sts || (p_sta && ind)))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7366 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7367 char_u *ptr;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7368 #ifdef FEAT_VREPLACE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7369 char_u *saved_line = NULL; /* init for GCC */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7370 pos_T pos;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7371 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7372 pos_T fpos;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7373 pos_T *cursor;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7374 colnr_T want_vcol, vcol;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7375 int change_col = -1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7376 int save_list = curwin->w_p_list;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7377
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7378 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7379 * Get the current line. For VREPLACE mode, don't make real changes
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7380 * yet, just work on a copy of the line.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7381 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7382 #ifdef FEAT_VREPLACE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7383 if (State & VREPLACE_FLAG)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7384 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7385 pos = curwin->w_cursor;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7386 cursor = &pos;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7387 saved_line = vim_strsave(ml_get_curline());
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7388 if (saved_line == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7389 return FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7390 ptr = saved_line + pos.col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7391 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7392 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7393 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7394 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7395 ptr = ml_get_cursor();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7396 cursor = &curwin->w_cursor;
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 /* When 'L' is not in 'cpoptions' a tab always takes up 'ts' spaces. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7400 if (vim_strchr(p_cpo, CPO_LISTWM) == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7401 curwin->w_p_list = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7402
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7403 /* Find first white before the cursor */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7404 fpos = curwin->w_cursor;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7405 while (fpos.col > 0 && vim_iswhite(ptr[-1]))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7406 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7407 --fpos.col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7408 --ptr;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7409 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7410
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7411 /* In Replace mode, don't change characters before the insert point. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7412 if ((State & REPLACE_FLAG)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7413 && fpos.lnum == Insstart.lnum
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7414 && fpos.col < Insstart.col)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7415 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7416 ptr += Insstart.col - fpos.col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7417 fpos.col = Insstart.col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7418 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7419
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7420 /* compute virtual column numbers of first white and cursor */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7421 getvcol(curwin, &fpos, &vcol, NULL, NULL);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7422 getvcol(curwin, cursor, &want_vcol, NULL, NULL);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7423
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7424 /* Use as many TABs as possible. Beware of 'showbreak' and
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7425 * 'linebreak' adding extra virtual columns. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7426 while (vim_iswhite(*ptr))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7427 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7428 i = lbr_chartabsize((char_u *)"\t", vcol);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7429 if (vcol + i > want_vcol)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7430 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7431 if (*ptr != TAB)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7432 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7433 *ptr = TAB;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7434 if (change_col < 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7435 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7436 change_col = fpos.col; /* Column of first change */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7437 /* May have to adjust Insstart */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7438 if (fpos.lnum == Insstart.lnum && fpos.col < Insstart.col)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7439 Insstart.col = fpos.col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7440 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7441 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7442 ++fpos.col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7443 ++ptr;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7444 vcol += i;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7445 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7446
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7447 if (change_col >= 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7448 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7449 int repl_off = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7450
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7451 /* Skip over the spaces we need. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7452 while (vcol < want_vcol && *ptr == ' ')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7453 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7454 vcol += lbr_chartabsize(ptr, vcol);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7455 ++ptr;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7456 ++repl_off;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7457 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7458 if (vcol > want_vcol)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7459 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7460 /* Must have a char with 'showbreak' just before it. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7461 --ptr;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7462 --repl_off;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7463 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7464 fpos.col += repl_off;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7465
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7466 /* Delete following spaces. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7467 i = cursor->col - fpos.col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7468 if (i > 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7469 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7470 mch_memmove(ptr, ptr + i, STRLEN(ptr + i) + 1);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7471 /* correct replace stack. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7472 if ((State & REPLACE_FLAG)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7473 #ifdef FEAT_VREPLACE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7474 && !(State & VREPLACE_FLAG)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7475 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7476 )
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7477 for (temp = i; --temp >= 0; )
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7478 replace_join(repl_off);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7479 }
33
f6033dcbaf31 updated for version 7.0020
vimboss
parents: 20
diff changeset
7480 #ifdef FEAT_NETBEANS_INTG
f6033dcbaf31 updated for version 7.0020
vimboss
parents: 20
diff changeset
7481 if (usingNetbeans)
f6033dcbaf31 updated for version 7.0020
vimboss
parents: 20
diff changeset
7482 {
f6033dcbaf31 updated for version 7.0020
vimboss
parents: 20
diff changeset
7483 netbeans_removed(curbuf, fpos.lnum, cursor->col,
f6033dcbaf31 updated for version 7.0020
vimboss
parents: 20
diff changeset
7484 (long)(i + 1));
f6033dcbaf31 updated for version 7.0020
vimboss
parents: 20
diff changeset
7485 netbeans_inserted(curbuf, fpos.lnum, cursor->col,
f6033dcbaf31 updated for version 7.0020
vimboss
parents: 20
diff changeset
7486 (char_u *)"\t", 1);
f6033dcbaf31 updated for version 7.0020
vimboss
parents: 20
diff changeset
7487 }
f6033dcbaf31 updated for version 7.0020
vimboss
parents: 20
diff changeset
7488 #endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7489 cursor->col -= i;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7490
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7491 #ifdef FEAT_VREPLACE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7492 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7493 * In VREPLACE mode, we haven't changed anything yet. Do it now by
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7494 * backspacing over the changed spacing and then inserting the new
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7495 * spacing.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7496 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7497 if (State & VREPLACE_FLAG)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7498 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7499 /* Backspace from real cursor to change_col */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7500 backspace_until_column(change_col);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7501
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7502 /* Insert each char in saved_line from changed_col to
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7503 * ptr-cursor */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7504 ins_bytes_len(saved_line + change_col,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7505 cursor->col - change_col);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7506 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7507 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7508 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7509
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7510 #ifdef FEAT_VREPLACE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7511 if (State & VREPLACE_FLAG)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7512 vim_free(saved_line);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7513 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7514 curwin->w_p_list = save_list;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7515 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7516
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7517 return FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7518 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7519
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7520 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7521 * Handle CR or NL in insert mode.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7522 * Return TRUE when out of memory or can't undo.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7523 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7524 static int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7525 ins_eol(c)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7526 int c;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7527 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7528 int i;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7529
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7530 if (echeck_abbr(c + ABBR_OFF))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7531 return FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7532 if (stop_arrow() == FAIL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7533 return TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7534 undisplay_dollar();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7535
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7536 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7537 * Strange Vi behaviour: In Replace mode, typing a NL will not delete the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7538 * character under the cursor. Only push a NUL on the replace stack,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7539 * nothing to put back when the NL is deleted.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7540 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7541 if ((State & REPLACE_FLAG)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7542 #ifdef FEAT_VREPLACE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7543 && !(State & VREPLACE_FLAG)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7544 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7545 )
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7546 replace_push(NUL);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7547
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7548 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7549 * In VREPLACE mode, a NL replaces the rest of the line, and starts
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7550 * replacing the next line, so we push all of the characters left on the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7551 * line onto the replace stack. This is not done here though, it is done
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7552 * in open_line().
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7553 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7554
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7555 #ifdef FEAT_RIGHTLEFT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7556 # ifdef FEAT_FKMAP
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7557 if (p_altkeymap && p_fkmap)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7558 fkmap(NL);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7559 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7560 /* NL in reverse insert will always start in the end of
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7561 * current line. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7562 if (revins_on)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7563 curwin->w_cursor.col += (colnr_T)STRLEN(ml_get_cursor());
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7564 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7565
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7566 AppendToRedobuff(NL_STR);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7567 i = open_line(FORWARD,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7568 #ifdef FEAT_COMMENTS
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7569 has_format_option(FO_RET_COMS) ? OPENLINE_DO_COM :
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7570 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7571 0, old_indent);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7572 old_indent = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7573 #ifdef FEAT_CINDENT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7574 can_cindent = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7575 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7576
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7577 return (!i);
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 #ifdef FEAT_DIGRAPHS
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7581 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7582 * Handle digraph in insert mode.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7583 * Returns character still to be inserted, or NUL when nothing remaining to be
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7584 * done.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7585 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7586 static int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7587 ins_digraph()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7588 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7589 int c;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7590 int cc;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7591
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7592 pc_status = PC_STATUS_UNSET;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7593 if (redrawing() && !char_avail())
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7594 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7595 /* may need to redraw when no more chars available now */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7596 ins_redraw();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7597
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7598 edit_putchar('?', TRUE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7599 #ifdef FEAT_CMDL_INFO
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7600 add_to_showcmd_c(Ctrl_K);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7601 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7602 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7603
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7604 #ifdef USE_ON_FLY_SCROLL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7605 dont_scroll = TRUE; /* disallow scrolling here */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7606 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7607
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7608 /* don't map the digraph chars. This also prevents the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7609 * mode message to be deleted when ESC is hit */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7610 ++no_mapping;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7611 ++allow_keys;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7612 c = safe_vgetc();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7613 --no_mapping;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7614 --allow_keys;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7615 if (IS_SPECIAL(c) || mod_mask) /* special key */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7616 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7617 #ifdef FEAT_CMDL_INFO
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7618 clear_showcmd();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7619 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7620 insert_special(c, TRUE, FALSE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7621 return NUL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7622 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7623 if (c != ESC)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7624 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7625 if (redrawing() && !char_avail())
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7626 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7627 /* may need to redraw when no more chars available now */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7628 ins_redraw();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7629
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7630 if (char2cells(c) == 1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7631 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7632 /* first remove the '?', otherwise it's restored when typing
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7633 * an ESC next */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7634 edit_unputchar();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7635 ins_redraw();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7636 edit_putchar(c, TRUE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7637 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7638 #ifdef FEAT_CMDL_INFO
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7639 add_to_showcmd_c(c);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7640 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7641 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7642 ++no_mapping;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7643 ++allow_keys;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7644 cc = safe_vgetc();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7645 --no_mapping;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7646 --allow_keys;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7647 if (cc != ESC)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7648 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7649 AppendToRedobuff((char_u *)CTRL_V_STR);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7650 c = getdigraph(c, cc, TRUE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7651 #ifdef FEAT_CMDL_INFO
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7652 clear_showcmd();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7653 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7654 return c;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7655 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7656 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7657 edit_unputchar();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7658 #ifdef FEAT_CMDL_INFO
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7659 clear_showcmd();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7660 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7661 return NUL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7662 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7663 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7664
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7665 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7666 * Handle CTRL-E and CTRL-Y in Insert mode: copy char from other line.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7667 * Returns the char to be inserted, or NUL if none found.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7668 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7669 static int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7670 ins_copychar(lnum)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7671 linenr_T lnum;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7672 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7673 int c;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7674 int temp;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7675 char_u *ptr, *prev_ptr;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7676
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7677 if (lnum < 1 || lnum > curbuf->b_ml.ml_line_count)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7678 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7679 vim_beep();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7680 return NUL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7681 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7682
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7683 /* try to advance to the cursor column */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7684 temp = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7685 ptr = ml_get(lnum);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7686 prev_ptr = ptr;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7687 validate_virtcol();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7688 while ((colnr_T)temp < curwin->w_virtcol && *ptr != NUL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7689 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7690 prev_ptr = ptr;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7691 temp += lbr_chartabsize_adv(&ptr, (colnr_T)temp);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7692 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7693 if ((colnr_T)temp > curwin->w_virtcol)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7694 ptr = prev_ptr;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7695
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7696 #ifdef FEAT_MBYTE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7697 c = (*mb_ptr2char)(ptr);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7698 #else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7699 c = *ptr;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7700 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7701 if (c == NUL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7702 vim_beep();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7703 return c;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7704 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7705
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7706 #ifdef FEAT_SMARTINDENT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7707 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7708 * Try to do some very smart auto-indenting.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7709 * Used when inserting 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 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7712 ins_try_si(c)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7713 int c;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7714 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7715 pos_T *pos, old_pos;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7716 char_u *ptr;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7717 int i;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7718 int temp;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7719
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7720 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7721 * do some very smart indenting when entering '{' or '}'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7722 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7723 if (((did_si || can_si_back) && c == '{') || (can_si && c == '}'))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7724 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7725 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7726 * for '}' set indent equal to indent of line containing matching '{'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7727 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7728 if (c == '}' && (pos = findmatch(NULL, '{')) != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7729 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7730 old_pos = curwin->w_cursor;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7731 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7732 * If the matching '{' has a ')' immediately before it (ignoring
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7733 * white-space), then line up with the start of the line
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7734 * containing the matching '(' if there is one. This handles the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7735 * case where an "if (..\n..) {" statement continues over multiple
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7736 * lines -- webb
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7737 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7738 ptr = ml_get(pos->lnum);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7739 i = pos->col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7740 if (i > 0) /* skip blanks before '{' */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7741 while (--i > 0 && vim_iswhite(ptr[i]))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7742 ;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7743 curwin->w_cursor.lnum = pos->lnum;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7744 curwin->w_cursor.col = i;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7745 if (ptr[i] == ')' && (pos = findmatch(NULL, '(')) != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7746 curwin->w_cursor = *pos;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7747 i = get_indent();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7748 curwin->w_cursor = old_pos;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7749 #ifdef FEAT_VREPLACE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7750 if (State & VREPLACE_FLAG)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7751 change_indent(INDENT_SET, i, FALSE, NUL);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7752 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7753 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7754 (void)set_indent(i, SIN_CHANGED);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7755 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7756 else if (curwin->w_cursor.col > 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7757 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7758 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7759 * when inserting '{' after "O" reduce indent, but not
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7760 * more than indent of previous line
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7761 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7762 temp = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7763 if (c == '{' && can_si_back && curwin->w_cursor.lnum > 1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7764 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7765 old_pos = curwin->w_cursor;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7766 i = get_indent();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7767 while (curwin->w_cursor.lnum > 1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7768 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7769 ptr = skipwhite(ml_get(--(curwin->w_cursor.lnum)));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7770
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7771 /* ignore empty lines and lines starting with '#'. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7772 if (*ptr != '#' && *ptr != NUL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7773 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7774 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7775 if (get_indent() >= i)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7776 temp = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7777 curwin->w_cursor = old_pos;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7778 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7779 if (temp)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7780 shift_line(TRUE, FALSE, 1);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7781 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7782 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7783
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7784 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7785 * set indent of '#' always to 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7786 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7787 if (curwin->w_cursor.col > 0 && can_si && c == '#')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7788 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7789 /* remember current indent for next line */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7790 old_indent = get_indent();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7791 (void)set_indent(0, SIN_CHANGED);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7792 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7793
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7794 /* Adjust ai_col, the char at this position can be deleted. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7795 if (ai_col > curwin->w_cursor.col)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7796 ai_col = curwin->w_cursor.col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7797 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7798 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7799
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7800 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7801 * Get the value that w_virtcol would have when 'list' is off.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7802 * Unless 'cpo' contains the 'L' flag.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7803 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7804 static colnr_T
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7805 get_nolist_virtcol()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7806 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7807 if (curwin->w_p_list && vim_strchr(p_cpo, CPO_LISTWM) == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7808 return getvcol_nolist(&curwin->w_cursor);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7809 validate_virtcol();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7810 return curwin->w_virtcol;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7811 }