7
|
1 /* vi:set ts=8 sts=4 sw=4:
|
|
2 *
|
|
3 * VIM - Vi IMproved by Bram Moolenaar
|
|
4 *
|
|
5 * Do ":help uganda" in Vim to read copying and usage conditions.
|
|
6 * Do ":help credits" in Vim to see a list of people who contributed.
|
|
7 * See README.txt for an overview of the Vim source code.
|
|
8 */
|
|
9 /*
|
|
10 * normal.c: Contains the main routine for processing characters in command
|
|
11 * mode. Communicates closely with the code in ops.c to handle
|
|
12 * the operators.
|
|
13 */
|
|
14
|
|
15 #include "vim.h"
|
|
16
|
|
17 #ifdef FEAT_VISUAL
|
|
18 /*
|
|
19 * The Visual area is remembered for reselection.
|
|
20 */
|
|
21 static int resel_VIsual_mode = NUL; /* 'v', 'V', or Ctrl-V */
|
|
22 static linenr_T resel_VIsual_line_count; /* number of lines */
|
|
23 static colnr_T resel_VIsual_col; /* nr of cols or end col */
|
|
24
|
|
25 static int restart_VIsual_select = 0;
|
|
26 #endif
|
|
27
|
|
28 static int
|
|
29 # ifdef __BORLANDC__
|
|
30 _RTLENTRYF
|
|
31 # endif
|
|
32 nv_compare __ARGS((const void *s1, const void *s2));
|
|
33 static int find_command __ARGS((int cmdchar));
|
|
34 static void op_colon __ARGS((oparg_T *oap));
|
|
35 #if defined(FEAT_MOUSE) && defined(FEAT_VISUAL)
|
|
36 static void find_start_of_word __ARGS((pos_T *));
|
|
37 static void find_end_of_word __ARGS((pos_T *));
|
|
38 static int get_mouse_class __ARGS((char_u *p));
|
|
39 #endif
|
|
40 static void prep_redo_cmd __ARGS((cmdarg_T *cap));
|
|
41 static void prep_redo __ARGS((int regname, long, int, int, int, int, int));
|
|
42 static int checkclearop __ARGS((oparg_T *oap));
|
|
43 static int checkclearopq __ARGS((oparg_T *oap));
|
|
44 static void clearop __ARGS((oparg_T *oap));
|
|
45 static void clearopbeep __ARGS((oparg_T *oap));
|
|
46 #ifdef FEAT_VISUAL
|
|
47 static void unshift_special __ARGS((cmdarg_T *cap));
|
|
48 #endif
|
|
49 #ifdef FEAT_CMDL_INFO
|
|
50 static void del_from_showcmd __ARGS((int));
|
|
51 #endif
|
|
52
|
|
53 /*
|
|
54 * nv_*(): functions called to handle Normal and Visual mode commands.
|
|
55 * n_*(): functions called to handle Normal mode commands.
|
|
56 * v_*(): functions called to handle Visual mode commands.
|
|
57 */
|
|
58 static void nv_ignore __ARGS((cmdarg_T *cap));
|
|
59 static void nv_error __ARGS((cmdarg_T *cap));
|
|
60 static void nv_help __ARGS((cmdarg_T *cap));
|
|
61 static void nv_addsub __ARGS((cmdarg_T *cap));
|
|
62 static void nv_page __ARGS((cmdarg_T *cap));
|
|
63 static void nv_gd __ARGS((oparg_T *oap, int nchar));
|
|
64 static int nv_screengo __ARGS((oparg_T *oap, int dir, long dist));
|
|
65 #ifdef FEAT_MOUSE
|
|
66 static void nv_mousescroll __ARGS((cmdarg_T *cap));
|
|
67 static void nv_mouse __ARGS((cmdarg_T *cap));
|
|
68 #endif
|
|
69 static void nv_scroll_line __ARGS((cmdarg_T *cap));
|
|
70 static void nv_zet __ARGS((cmdarg_T *cap));
|
|
71 #ifdef FEAT_GUI
|
|
72 static void nv_ver_scrollbar __ARGS((cmdarg_T *cap));
|
|
73 static void nv_hor_scrollbar __ARGS((cmdarg_T *cap));
|
|
74 #endif
|
|
75 static void nv_exmode __ARGS((cmdarg_T *cap));
|
|
76 static void nv_colon __ARGS((cmdarg_T *cap));
|
|
77 static void nv_ctrlg __ARGS((cmdarg_T *cap));
|
|
78 static void nv_ctrlh __ARGS((cmdarg_T *cap));
|
|
79 static void nv_clear __ARGS((cmdarg_T *cap));
|
|
80 static void nv_ctrlo __ARGS((cmdarg_T *cap));
|
|
81 static void nv_hat __ARGS((cmdarg_T *cap));
|
|
82 static void nv_Zet __ARGS((cmdarg_T *cap));
|
|
83 static void nv_ident __ARGS((cmdarg_T *cap));
|
|
84 #ifdef FEAT_VISUAL
|
|
85 static int get_visual_text __ARGS((cmdarg_T *cap, char_u **pp, int *lenp));
|
|
86 #endif
|
|
87 static void nv_tagpop __ARGS((cmdarg_T *cap));
|
|
88 static void nv_scroll __ARGS((cmdarg_T *cap));
|
|
89 static void nv_right __ARGS((cmdarg_T *cap));
|
|
90 static void nv_left __ARGS((cmdarg_T *cap));
|
|
91 static void nv_up __ARGS((cmdarg_T *cap));
|
|
92 static void nv_down __ARGS((cmdarg_T *cap));
|
|
93 #ifdef FEAT_SEARCHPATH
|
|
94 static void nv_gotofile __ARGS((cmdarg_T *cap));
|
|
95 #endif
|
|
96 static void nv_end __ARGS((cmdarg_T *cap));
|
|
97 static void nv_dollar __ARGS((cmdarg_T *cap));
|
|
98 static void nv_search __ARGS((cmdarg_T *cap));
|
|
99 static void nv_next __ARGS((cmdarg_T *cap));
|
|
100 static void normal_search __ARGS((cmdarg_T *cap, int dir, char_u *pat, int opt));
|
|
101 static void nv_csearch __ARGS((cmdarg_T *cap));
|
|
102 static void nv_brackets __ARGS((cmdarg_T *cap));
|
|
103 static void nv_percent __ARGS((cmdarg_T *cap));
|
|
104 static void nv_brace __ARGS((cmdarg_T *cap));
|
|
105 static void nv_mark __ARGS((cmdarg_T *cap));
|
|
106 static void nv_findpar __ARGS((cmdarg_T *cap));
|
|
107 static void nv_undo __ARGS((cmdarg_T *cap));
|
|
108 static void nv_kundo __ARGS((cmdarg_T *cap));
|
|
109 static void nv_Replace __ARGS((cmdarg_T *cap));
|
|
110 #ifdef FEAT_VREPLACE
|
|
111 static void nv_vreplace __ARGS((cmdarg_T *cap));
|
|
112 #endif
|
|
113 #ifdef FEAT_VISUAL
|
|
114 static void v_swap_corners __ARGS((int cmdchar));
|
|
115 #endif
|
|
116 static void nv_replace __ARGS((cmdarg_T *cap));
|
|
117 static void n_swapchar __ARGS((cmdarg_T *cap));
|
|
118 static void nv_cursormark __ARGS((cmdarg_T *cap, int flag, pos_T *pos));
|
|
119 #ifdef FEAT_VISUAL
|
|
120 static void v_visop __ARGS((cmdarg_T *cap));
|
|
121 #endif
|
|
122 static void nv_subst __ARGS((cmdarg_T *cap));
|
|
123 static void nv_abbrev __ARGS((cmdarg_T *cap));
|
|
124 static void nv_optrans __ARGS((cmdarg_T *cap));
|
|
125 static void nv_gomark __ARGS((cmdarg_T *cap));
|
|
126 static void nv_pcmark __ARGS((cmdarg_T *cap));
|
|
127 static void nv_regname __ARGS((cmdarg_T *cap));
|
|
128 #ifdef FEAT_VISUAL
|
|
129 static void nv_visual __ARGS((cmdarg_T *cap));
|
|
130 static void n_start_visual_mode __ARGS((int c));
|
|
131 #endif
|
|
132 static void nv_window __ARGS((cmdarg_T *cap));
|
|
133 static void nv_suspend __ARGS((cmdarg_T *cap));
|
|
134 static void nv_g_cmd __ARGS((cmdarg_T *cap));
|
|
135 static void n_opencmd __ARGS((cmdarg_T *cap));
|
|
136 static void nv_dot __ARGS((cmdarg_T *cap));
|
|
137 static void nv_redo __ARGS((cmdarg_T *cap));
|
|
138 static void nv_Undo __ARGS((cmdarg_T *cap));
|
|
139 static void nv_tilde __ARGS((cmdarg_T *cap));
|
|
140 static void nv_operator __ARGS((cmdarg_T *cap));
|
|
141 static void nv_lineop __ARGS((cmdarg_T *cap));
|
|
142 static void nv_home __ARGS((cmdarg_T *cap));
|
|
143 static void nv_pipe __ARGS((cmdarg_T *cap));
|
|
144 static void nv_bck_word __ARGS((cmdarg_T *cap));
|
|
145 static void nv_wordcmd __ARGS((cmdarg_T *cap));
|
|
146 static void nv_beginline __ARGS((cmdarg_T *cap));
|
|
147 #ifdef FEAT_VISUAL
|
|
148 static void adjust_for_sel __ARGS((cmdarg_T *cap));
|
|
149 static int unadjust_for_sel __ARGS((void));
|
|
150 static void nv_select __ARGS((cmdarg_T *cap));
|
|
151 #endif
|
|
152 static void nv_goto __ARGS((cmdarg_T *cap));
|
|
153 static void nv_normal __ARGS((cmdarg_T *cap));
|
|
154 static void nv_esc __ARGS((cmdarg_T *oap));
|
|
155 static void nv_edit __ARGS((cmdarg_T *cap));
|
|
156 static void invoke_edit __ARGS((cmdarg_T *cap, int repl, int cmd, int startln));
|
|
157 #ifdef FEAT_TEXTOBJ
|
|
158 static void nv_object __ARGS((cmdarg_T *cap));
|
|
159 #endif
|
|
160 static void nv_record __ARGS((cmdarg_T *cap));
|
|
161 static void nv_at __ARGS((cmdarg_T *cap));
|
|
162 static void nv_halfpage __ARGS((cmdarg_T *cap));
|
|
163 static void nv_join __ARGS((cmdarg_T *cap));
|
|
164 static void nv_put __ARGS((cmdarg_T *cap));
|
|
165 static void nv_open __ARGS((cmdarg_T *cap));
|
|
166 #ifdef FEAT_SNIFF
|
|
167 static void nv_sniff __ARGS((cmdarg_T *cap));
|
|
168 #endif
|
|
169 #ifdef FEAT_NETBEANS_INTG
|
|
170 static void nv_nbcmd __ARGS((cmdarg_T *cap));
|
|
171 #endif
|
|
172 #ifdef FEAT_DND
|
|
173 static void nv_drop __ARGS((cmdarg_T *cap));
|
|
174 #endif
|
203
|
175 #ifdef FEAT_AUTOCMD
|
|
176 static void nv_cursorhold __ARGS((cmdarg_T *cap));
|
|
177 #endif
|
7
|
178
|
|
179 /*
|
|
180 * Function to be called for a Normal or Visual mode command.
|
|
181 * The argument is a cmdarg_T.
|
|
182 */
|
|
183 typedef void (*nv_func_T) __ARGS((cmdarg_T *cap));
|
|
184
|
|
185 /* Values for cmd_flags. */
|
|
186 #define NV_NCH 0x01 /* may need to get a second char */
|
|
187 #define NV_NCH_NOP (0x02|NV_NCH) /* get second char when no operator pending */
|
|
188 #define NV_NCH_ALW (0x04|NV_NCH) /* always get a second char */
|
|
189 #define NV_LANG 0x08 /* second char needs language adjustment */
|
|
190
|
|
191 #define NV_SS 0x10 /* may start selection */
|
|
192 #define NV_SSS 0x20 /* may start selection with shift modifier */
|
|
193 #define NV_STS 0x40 /* may stop selection without shift modif. */
|
|
194 #define NV_RL 0x80 /* 'rightleft' modifies command */
|
|
195 #define NV_KEEPREG 0x100 /* don't clear regname */
|
|
196 #define NV_NCW 0x200 /* not allowed in command-line window */
|
|
197
|
|
198 /*
|
|
199 * Generally speaking, every Normal mode command should either clear any
|
|
200 * pending operator (with *clearop*()), or set the motion type variable
|
|
201 * oap->motion_type.
|
|
202 *
|
|
203 * When a cursor motion command is made, it is marked as being a character or
|
|
204 * line oriented motion. Then, if an operator is in effect, the operation
|
|
205 * becomes character or line oriented accordingly.
|
|
206 */
|
|
207
|
|
208 /*
|
|
209 * This table contains one entry for every Normal or Visual mode command.
|
|
210 * The order doesn't matter, init_normal_cmds() will create a sorted index.
|
|
211 * It is faster when all keys from zero to '~' are present.
|
|
212 */
|
|
213 static const struct nv_cmd
|
|
214 {
|
|
215 int cmd_char; /* (first) command character */
|
|
216 nv_func_T cmd_func; /* function for this command */
|
|
217 short_u cmd_flags; /* NV_ flags */
|
|
218 short cmd_arg; /* value for ca.arg */
|
|
219 } nv_cmds[] =
|
|
220 {
|
|
221 {NUL, nv_error, 0, 0},
|
|
222 {Ctrl_A, nv_addsub, 0, 0},
|
|
223 {Ctrl_B, nv_page, NV_STS, BACKWARD},
|
|
224 {Ctrl_C, nv_esc, 0, TRUE},
|
|
225 {Ctrl_D, nv_halfpage, 0, 0},
|
|
226 {Ctrl_E, nv_scroll_line, 0, TRUE},
|
|
227 {Ctrl_F, nv_page, NV_STS, FORWARD},
|
|
228 {Ctrl_G, nv_ctrlg, 0, 0},
|
|
229 {Ctrl_H, nv_ctrlh, 0, 0},
|
|
230 {Ctrl_I, nv_pcmark, 0, 0},
|
|
231 {NL, nv_down, 0, FALSE},
|
|
232 {Ctrl_K, nv_error, 0, 0},
|
|
233 {Ctrl_L, nv_clear, 0, 0},
|
|
234 {CAR, nv_down, 0, TRUE},
|
|
235 {Ctrl_N, nv_down, NV_STS, FALSE},
|
|
236 {Ctrl_O, nv_ctrlo, 0, 0},
|
|
237 {Ctrl_P, nv_up, NV_STS, FALSE},
|
167
|
238 #ifdef FEAT_VISUAL
|
|
239 {Ctrl_Q, nv_visual, 0, FALSE},
|
|
240 #else
|
7
|
241 {Ctrl_Q, nv_ignore, 0, 0},
|
167
|
242 #endif
|
7
|
243 {Ctrl_R, nv_redo, 0, 0},
|
|
244 {Ctrl_S, nv_ignore, 0, 0},
|
|
245 {Ctrl_T, nv_tagpop, NV_NCW, 0},
|
|
246 {Ctrl_U, nv_halfpage, 0, 0},
|
|
247 #ifdef FEAT_VISUAL
|
|
248 {Ctrl_V, nv_visual, 0, FALSE},
|
|
249 {'V', nv_visual, 0, FALSE},
|
|
250 {'v', nv_visual, 0, FALSE},
|
|
251 #else
|
|
252 {Ctrl_V, nv_error, 0, 0},
|
|
253 {'V', nv_error, 0, 0},
|
|
254 {'v', nv_error, 0, 0},
|
|
255 #endif
|
|
256 {Ctrl_W, nv_window, 0, 0},
|
|
257 {Ctrl_X, nv_addsub, 0, 0},
|
|
258 {Ctrl_Y, nv_scroll_line, 0, FALSE},
|
|
259 {Ctrl_Z, nv_suspend, 0, 0},
|
|
260 {ESC, nv_esc, 0, FALSE},
|
|
261 {Ctrl_BSL, nv_normal, NV_NCH_ALW, 0},
|
|
262 {Ctrl_RSB, nv_ident, NV_NCW, 0},
|
|
263 {Ctrl_HAT, nv_hat, NV_NCW, 0},
|
|
264 {Ctrl__, nv_error, 0, 0},
|
|
265 {' ', nv_right, 0, 0},
|
|
266 {'!', nv_operator, 0, 0},
|
|
267 {'"', nv_regname, NV_NCH_NOP|NV_KEEPREG, 0},
|
|
268 {'#', nv_ident, 0, 0},
|
|
269 {'$', nv_dollar, 0, 0},
|
|
270 {'%', nv_percent, 0, 0},
|
|
271 {'&', nv_optrans, 0, 0},
|
|
272 {'\'', nv_gomark, NV_NCH_ALW, TRUE},
|
|
273 {'(', nv_brace, 0, BACKWARD},
|
|
274 {')', nv_brace, 0, FORWARD},
|
|
275 {'*', nv_ident, 0, 0},
|
|
276 {'+', nv_down, 0, TRUE},
|
|
277 {',', nv_csearch, 0, TRUE},
|
|
278 {'-', nv_up, 0, TRUE},
|
|
279 {'.', nv_dot, NV_KEEPREG, 0},
|
|
280 {'/', nv_search, 0, FALSE},
|
|
281 {'0', nv_beginline, 0, 0},
|
|
282 {'1', nv_ignore, 0, 0},
|
|
283 {'2', nv_ignore, 0, 0},
|
|
284 {'3', nv_ignore, 0, 0},
|
|
285 {'4', nv_ignore, 0, 0},
|
|
286 {'5', nv_ignore, 0, 0},
|
|
287 {'6', nv_ignore, 0, 0},
|
|
288 {'7', nv_ignore, 0, 0},
|
|
289 {'8', nv_ignore, 0, 0},
|
|
290 {'9', nv_ignore, 0, 0},
|
|
291 {':', nv_colon, 0, 0},
|
|
292 {';', nv_csearch, 0, FALSE},
|
|
293 {'<', nv_operator, NV_RL, 0},
|
|
294 {'=', nv_operator, 0, 0},
|
|
295 {'>', nv_operator, NV_RL, 0},
|
|
296 {'?', nv_search, 0, FALSE},
|
|
297 {'@', nv_at, NV_NCH_NOP, FALSE},
|
|
298 {'A', nv_edit, 0, 0},
|
|
299 {'B', nv_bck_word, 0, 1},
|
|
300 {'C', nv_abbrev, NV_KEEPREG, 0},
|
|
301 {'D', nv_abbrev, NV_KEEPREG, 0},
|
|
302 {'E', nv_wordcmd, 0, TRUE},
|
|
303 {'F', nv_csearch, NV_NCH_ALW|NV_LANG, BACKWARD},
|
|
304 {'G', nv_goto, 0, TRUE},
|
|
305 {'H', nv_scroll, 0, 0},
|
|
306 {'I', nv_edit, 0, 0},
|
|
307 {'J', nv_join, 0, 0},
|
|
308 {'K', nv_ident, 0, 0},
|
|
309 {'L', nv_scroll, 0, 0},
|
|
310 {'M', nv_scroll, 0, 0},
|
|
311 {'N', nv_next, 0, SEARCH_REV},
|
|
312 {'O', nv_open, 0, 0},
|
|
313 {'P', nv_put, 0, 0},
|
|
314 {'Q', nv_exmode, NV_NCW, 0},
|
|
315 {'R', nv_Replace, 0, FALSE},
|
|
316 {'S', nv_subst, NV_KEEPREG, 0},
|
|
317 {'T', nv_csearch, NV_NCH_ALW|NV_LANG, BACKWARD},
|
|
318 {'U', nv_Undo, 0, 0},
|
|
319 {'W', nv_wordcmd, 0, TRUE},
|
|
320 {'X', nv_abbrev, NV_KEEPREG, 0},
|
|
321 {'Y', nv_abbrev, NV_KEEPREG, 0},
|
|
322 {'Z', nv_Zet, NV_NCH_NOP|NV_NCW, 0},
|
|
323 {'[', nv_brackets, NV_NCH_ALW, BACKWARD},
|
|
324 {'\\', nv_error, 0, 0},
|
|
325 {']', nv_brackets, NV_NCH_ALW, FORWARD},
|
|
326 {'^', nv_beginline, 0, BL_WHITE | BL_FIX},
|
|
327 {'_', nv_lineop, 0, 0},
|
|
328 {'`', nv_gomark, NV_NCH_ALW, FALSE},
|
|
329 {'a', nv_edit, NV_NCH, 0},
|
|
330 {'b', nv_bck_word, 0, 0},
|
|
331 {'c', nv_operator, 0, 0},
|
|
332 {'d', nv_operator, 0, 0},
|
|
333 {'e', nv_wordcmd, 0, FALSE},
|
|
334 {'f', nv_csearch, NV_NCH_ALW|NV_LANG, FORWARD},
|
|
335 {'g', nv_g_cmd, NV_NCH_ALW, FALSE},
|
|
336 {'h', nv_left, NV_RL, 0},
|
|
337 {'i', nv_edit, NV_NCH, 0},
|
|
338 {'j', nv_down, 0, FALSE},
|
|
339 {'k', nv_up, 0, FALSE},
|
|
340 {'l', nv_right, NV_RL, 0},
|
|
341 {'m', nv_mark, NV_NCH_NOP, 0},
|
|
342 {'n', nv_next, 0, 0},
|
|
343 {'o', nv_open, 0, 0},
|
|
344 {'p', nv_put, 0, 0},
|
|
345 {'q', nv_record, NV_NCH, 0},
|
|
346 {'r', nv_replace, NV_NCH_NOP|NV_LANG, 0},
|
|
347 {'s', nv_subst, NV_KEEPREG, 0},
|
|
348 {'t', nv_csearch, NV_NCH_ALW|NV_LANG, FORWARD},
|
|
349 {'u', nv_undo, 0, 0},
|
|
350 {'w', nv_wordcmd, 0, FALSE},
|
|
351 {'x', nv_abbrev, NV_KEEPREG, 0},
|
|
352 {'y', nv_operator, 0, 0},
|
|
353 {'z', nv_zet, NV_NCH_ALW, 0},
|
|
354 {'{', nv_findpar, 0, BACKWARD},
|
|
355 {'|', nv_pipe, 0, 0},
|
|
356 {'}', nv_findpar, 0, FORWARD},
|
|
357 {'~', nv_tilde, 0, 0},
|
|
358
|
|
359 /* pound sign */
|
|
360 {POUND, nv_ident, 0, 0},
|
|
361 #ifdef FEAT_MOUSE
|
|
362 {K_MOUSEUP, nv_mousescroll, 0, TRUE},
|
|
363 {K_MOUSEDOWN, nv_mousescroll, 0, FALSE},
|
|
364 {K_LEFTMOUSE, nv_mouse, 0, 0},
|
|
365 {K_LEFTMOUSE_NM, nv_mouse, 0, 0},
|
|
366 {K_LEFTDRAG, nv_mouse, 0, 0},
|
|
367 {K_LEFTRELEASE, nv_mouse, 0, 0},
|
|
368 {K_LEFTRELEASE_NM, nv_mouse, 0, 0},
|
|
369 {K_MIDDLEMOUSE, nv_mouse, 0, 0},
|
|
370 {K_MIDDLEDRAG, nv_mouse, 0, 0},
|
|
371 {K_MIDDLERELEASE, nv_mouse, 0, 0},
|
|
372 {K_RIGHTMOUSE, nv_mouse, 0, 0},
|
|
373 {K_RIGHTDRAG, nv_mouse, 0, 0},
|
|
374 {K_RIGHTRELEASE, nv_mouse, 0, 0},
|
|
375 {K_X1MOUSE, nv_mouse, 0, 0},
|
|
376 {K_X1DRAG, nv_mouse, 0, 0},
|
|
377 {K_X1RELEASE, nv_mouse, 0, 0},
|
|
378 {K_X2MOUSE, nv_mouse, 0, 0},
|
|
379 {K_X2DRAG, nv_mouse, 0, 0},
|
|
380 {K_X2RELEASE, nv_mouse, 0, 0},
|
|
381 #endif
|
|
382 {K_IGNORE, nv_ignore, 0, 0},
|
|
383 {K_INS, nv_edit, 0, 0},
|
|
384 {K_KINS, nv_edit, 0, 0},
|
|
385 {K_BS, nv_ctrlh, 0, 0},
|
|
386 {K_UP, nv_up, NV_SSS|NV_STS, FALSE},
|
|
387 {K_S_UP, nv_page, NV_SS, BACKWARD},
|
|
388 {K_DOWN, nv_down, NV_SSS|NV_STS, FALSE},
|
|
389 {K_S_DOWN, nv_page, NV_SS, FORWARD},
|
|
390 {K_LEFT, nv_left, NV_SSS|NV_STS|NV_RL, 0},
|
|
391 {K_S_LEFT, nv_bck_word, NV_SS|NV_RL, 0},
|
|
392 {K_C_LEFT, nv_bck_word, NV_SSS|NV_RL|NV_STS, 1},
|
|
393 {K_RIGHT, nv_right, NV_SSS|NV_STS|NV_RL, 0},
|
|
394 {K_S_RIGHT, nv_wordcmd, NV_SS|NV_RL, FALSE},
|
|
395 {K_C_RIGHT, nv_wordcmd, NV_SSS|NV_RL|NV_STS, TRUE},
|
|
396 {K_PAGEUP, nv_page, NV_SSS|NV_STS, BACKWARD},
|
|
397 {K_KPAGEUP, nv_page, NV_SSS|NV_STS, BACKWARD},
|
|
398 {K_PAGEDOWN, nv_page, NV_SSS|NV_STS, FORWARD},
|
|
399 {K_KPAGEDOWN, nv_page, NV_SSS|NV_STS, FORWARD},
|
|
400 {K_END, nv_end, NV_SSS|NV_STS, FALSE},
|
|
401 {K_KEND, nv_end, NV_SSS|NV_STS, FALSE},
|
|
402 {K_S_END, nv_end, NV_SS, FALSE},
|
|
403 {K_C_END, nv_end, NV_SSS|NV_STS, TRUE},
|
|
404 {K_HOME, nv_home, NV_SSS|NV_STS, 0},
|
|
405 {K_KHOME, nv_home, NV_SSS|NV_STS, 0},
|
|
406 {K_S_HOME, nv_home, NV_SS, 0},
|
|
407 {K_C_HOME, nv_goto, NV_SSS|NV_STS, FALSE},
|
|
408 {K_DEL, nv_abbrev, 0, 0},
|
|
409 {K_KDEL, nv_abbrev, 0, 0},
|
|
410 {K_UNDO, nv_kundo, 0, 0},
|
|
411 {K_HELP, nv_help, NV_NCW, 0},
|
|
412 {K_F1, nv_help, NV_NCW, 0},
|
|
413 {K_XF1, nv_help, NV_NCW, 0},
|
|
414 #ifdef FEAT_VISUAL
|
|
415 {K_SELECT, nv_select, 0, 0},
|
|
416 #endif
|
|
417 #ifdef FEAT_GUI
|
|
418 {K_VER_SCROLLBAR, nv_ver_scrollbar, 0, 0},
|
|
419 {K_HOR_SCROLLBAR, nv_hor_scrollbar, 0, 0},
|
|
420 #endif
|
|
421 #ifdef FEAT_FKMAP
|
|
422 {K_F8, farsi_fkey, 0, 0},
|
|
423 {K_F9, farsi_fkey, 0, 0},
|
|
424 #endif
|
|
425 #ifdef FEAT_SNIFF
|
|
426 {K_SNIFF, nv_sniff, 0, 0},
|
|
427 #endif
|
|
428 #ifdef FEAT_NETBEANS_INTG
|
|
429 {K_F21, nv_nbcmd, NV_NCH_ALW, 0},
|
|
430 #endif
|
|
431 #ifdef FEAT_DND
|
|
432 {K_DROP, nv_drop, NV_STS, 0},
|
|
433 #endif
|
203
|
434 #ifdef FEAT_AUTOCMD
|
|
435 {K_CURSORHOLD, nv_cursorhold, 0, 0},
|
|
436 #endif
|
7
|
437 };
|
|
438
|
|
439 /* Number of commands in nv_cmds[]. */
|
|
440 #define NV_CMDS_SIZE (sizeof(nv_cmds) / sizeof(struct nv_cmd))
|
|
441
|
|
442 /* Sorted index of commands in nv_cmds[]. */
|
|
443 static short nv_cmd_idx[NV_CMDS_SIZE];
|
|
444
|
|
445 /* The highest index for which
|
|
446 * nv_cmds[idx].cmd_char == nv_cmd_idx[nv_cmds[idx].cmd_char] */
|
|
447 static int nv_max_linear;
|
|
448
|
|
449 /*
|
|
450 * Compare functions for qsort() below, that checks the command character
|
|
451 * through the index in nv_cmd_idx[].
|
|
452 */
|
|
453 static int
|
|
454 #ifdef __BORLANDC__
|
|
455 _RTLENTRYF
|
|
456 #endif
|
|
457 nv_compare(s1, s2)
|
|
458 const void *s1;
|
|
459 const void *s2;
|
|
460 {
|
|
461 int c1, c2;
|
|
462
|
|
463 /* The commands are sorted on absolute value. */
|
|
464 c1 = nv_cmds[*(const short *)s1].cmd_char;
|
|
465 c2 = nv_cmds[*(const short *)s2].cmd_char;
|
|
466 if (c1 < 0)
|
|
467 c1 = -c1;
|
|
468 if (c2 < 0)
|
|
469 c2 = -c2;
|
|
470 return c1 - c2;
|
|
471 }
|
|
472
|
|
473 /*
|
|
474 * Initialize the nv_cmd_idx[] table.
|
|
475 */
|
|
476 void
|
|
477 init_normal_cmds()
|
|
478 {
|
|
479 int i;
|
|
480
|
|
481 /* Fill the index table with a one to one relation. */
|
|
482 for (i = 0; i < NV_CMDS_SIZE; ++i)
|
|
483 nv_cmd_idx[i] = i;
|
|
484
|
|
485 /* Sort the commands by the command character. */
|
|
486 qsort((void *)&nv_cmd_idx, (size_t)NV_CMDS_SIZE, sizeof(short), nv_compare);
|
|
487
|
|
488 /* Find the first entry that can't be indexed by the command character. */
|
|
489 for (i = 0; i < NV_CMDS_SIZE; ++i)
|
|
490 if (i != nv_cmds[nv_cmd_idx[i]].cmd_char)
|
|
491 break;
|
|
492 nv_max_linear = i - 1;
|
|
493 }
|
|
494
|
|
495 /*
|
|
496 * Search for a command in the commands table.
|
|
497 * Returns -1 for invalid command.
|
|
498 */
|
|
499 static int
|
|
500 find_command(cmdchar)
|
|
501 int cmdchar;
|
|
502 {
|
|
503 int i;
|
|
504 int idx;
|
|
505 int top, bot;
|
|
506 int c;
|
|
507
|
|
508 #ifdef FEAT_MBYTE
|
|
509 /* A multi-byte character is never a command. */
|
|
510 if (cmdchar >= 0x100)
|
|
511 return -1;
|
|
512 #endif
|
|
513
|
|
514 /* We use the absolute value of the character. Special keys have a
|
|
515 * negative value, but are sorted on their absolute value. */
|
|
516 if (cmdchar < 0)
|
|
517 cmdchar = -cmdchar;
|
|
518
|
|
519 /* If the character is in the first part: The character is the index into
|
|
520 * nv_cmd_idx[]. */
|
|
521 if (cmdchar <= nv_max_linear)
|
|
522 return nv_cmd_idx[cmdchar];
|
|
523
|
|
524 /* Perform a binary search. */
|
|
525 bot = nv_max_linear + 1;
|
|
526 top = NV_CMDS_SIZE - 1;
|
|
527 idx = -1;
|
|
528 while (bot <= top)
|
|
529 {
|
|
530 i = (top + bot) / 2;
|
|
531 c = nv_cmds[nv_cmd_idx[i]].cmd_char;
|
|
532 if (c < 0)
|
|
533 c = -c;
|
|
534 if (cmdchar == c)
|
|
535 {
|
|
536 idx = nv_cmd_idx[i];
|
|
537 break;
|
|
538 }
|
|
539 if (cmdchar > c)
|
|
540 bot = i + 1;
|
|
541 else
|
|
542 top = i - 1;
|
|
543 }
|
|
544 return idx;
|
|
545 }
|
|
546
|
|
547 /*
|
|
548 * Execute a command in Normal mode.
|
|
549 */
|
|
550 /*ARGSUSED*/
|
|
551 void
|
|
552 normal_cmd(oap, toplevel)
|
|
553 oparg_T *oap;
|
|
554 int toplevel; /* TRUE when called from main() */
|
|
555 {
|
|
556 static long opcount = 0; /* ca.opcount saved here */
|
|
557 cmdarg_T ca; /* command arguments */
|
|
558 int c;
|
|
559 int ctrl_w = FALSE; /* got CTRL-W command */
|
|
560 int old_col = curwin->w_curswant;
|
|
561 #ifdef FEAT_CMDL_INFO
|
|
562 int need_flushbuf; /* need to call out_flush() */
|
|
563 #endif
|
|
564 #ifdef FEAT_VISUAL
|
|
565 pos_T old_pos; /* cursor position before command */
|
|
566 int mapped_len;
|
|
567 #endif
|
|
568 static int old_mapped_len = 0;
|
|
569 int idx;
|
|
570
|
|
571 vim_memset(&ca, 0, sizeof(ca)); /* also resets ca.retval */
|
|
572 ca.oap = oap;
|
|
573 ca.opcount = opcount;
|
|
574
|
|
575 #ifdef FEAT_SNIFF
|
|
576 want_sniff_request = sniff_connected;
|
|
577 #endif
|
|
578
|
|
579 /*
|
|
580 * If there is an operator pending, then the command we take this time
|
|
581 * will terminate it. Finish_op tells us to finish the operation before
|
|
582 * returning this time (unless the operation was cancelled).
|
|
583 */
|
|
584 #ifdef CURSOR_SHAPE
|
|
585 c = finish_op;
|
|
586 #endif
|
|
587 finish_op = (oap->op_type != OP_NOP);
|
|
588 #ifdef CURSOR_SHAPE
|
|
589 if (finish_op != c)
|
|
590 {
|
|
591 ui_cursor_shape(); /* may show different cursor shape */
|
|
592 # ifdef FEAT_MOUSESHAPE
|
|
593 update_mouseshape(-1);
|
|
594 # endif
|
|
595 }
|
|
596 #endif
|
|
597
|
|
598 if (!finish_op && !oap->regname)
|
|
599 ca.opcount = 0;
|
|
600
|
|
601 #ifdef FEAT_VISUAL
|
|
602 mapped_len = typebuf_maplen();
|
|
603 #endif
|
|
604
|
|
605 State = NORMAL_BUSY;
|
|
606 #ifdef USE_ON_FLY_SCROLL
|
|
607 dont_scroll = FALSE; /* allow scrolling here */
|
|
608 #endif
|
|
609
|
|
610 /*
|
|
611 * Get the command character from the user.
|
|
612 */
|
|
613 c = safe_vgetc();
|
|
614
|
|
615 #ifdef FEAT_LANGMAP
|
|
616 LANGMAP_ADJUST(c, TRUE);
|
|
617 #endif
|
|
618
|
|
619 /*
|
|
620 * If a mapping was started in Visual or Select mode, remember the length
|
|
621 * of the mapping. This is used below to not return to Insert mode for as
|
|
622 * long as the mapping is being executed.
|
|
623 */
|
|
624 if (restart_edit == 0)
|
|
625 old_mapped_len = 0;
|
|
626 else if (old_mapped_len
|
|
627 #ifdef FEAT_VISUAL
|
|
628 || (VIsual_active && mapped_len == 0 && typebuf_maplen() > 0)
|
|
629 #endif
|
|
630 )
|
|
631 old_mapped_len = typebuf_maplen();
|
|
632
|
|
633 if (c == NUL)
|
|
634 c = K_ZERO;
|
|
635
|
|
636 #ifdef FEAT_VISUAL
|
|
637 /*
|
|
638 * In Select mode, typed text replaces the selection.
|
|
639 */
|
|
640 if (VIsual_active
|
|
641 && VIsual_select
|
|
642 && (vim_isprintc(c) || c == NL || c == CAR || c == K_KENTER))
|
|
643 {
|
|
644 # ifdef FEAT_MBYTE
|
|
645 char_u buf[MB_MAXBYTES + 1];
|
|
646
|
|
647 buf[(*mb_char2bytes)(c, buf)] = NUL;
|
|
648 # else
|
|
649 char_u buf[2];
|
|
650
|
|
651 buf[0] = c;
|
|
652 buf[1] = NUL;
|
|
653 # endif
|
|
654 /* Fake a "c"hange command.
|
|
655 * Insert the typed character in the typeahead buffer, so that it will
|
|
656 * be mapped in Insert mode. Required for ":lmap" to work. May cause
|
|
657 * mapping a character from ":vnoremap"... */
|
|
658 (void)ins_typebuf(buf, REMAP_YES, 0, !KeyTyped, FALSE);
|
|
659 c = 'c';
|
|
660 }
|
|
661 #endif
|
|
662
|
|
663 #ifdef FEAT_CMDL_INFO
|
|
664 need_flushbuf = add_to_showcmd(c);
|
|
665 #endif
|
|
666
|
|
667 getcount:
|
|
668 #ifdef FEAT_VISUAL
|
|
669 if (!(VIsual_active && VIsual_select))
|
|
670 #endif
|
|
671 {
|
|
672 /*
|
|
673 * Handle a count before a command and compute ca.count0.
|
|
674 * Note that '0' is a command and not the start of a count, but it's
|
|
675 * part of a count after other digits.
|
|
676 */
|
|
677 while ( (c >= '1' && c <= '9')
|
|
678 || (ca.count0 != 0 && (c == K_DEL || c == K_KDEL || c == '0')))
|
|
679 {
|
|
680 if (c == K_DEL || c == K_KDEL)
|
|
681 {
|
|
682 ca.count0 /= 10;
|
|
683 #ifdef FEAT_CMDL_INFO
|
|
684 del_from_showcmd(4); /* delete the digit and ~@% */
|
|
685 #endif
|
|
686 }
|
|
687 else
|
|
688 ca.count0 = ca.count0 * 10 + (c - '0');
|
|
689 if (ca.count0 < 0) /* got too large! */
|
|
690 ca.count0 = 999999999L;
|
|
691 if (ctrl_w)
|
|
692 {
|
|
693 ++no_mapping;
|
|
694 ++allow_keys; /* no mapping for nchar, but keys */
|
|
695 }
|
|
696 ++no_zero_mapping; /* don't map zero here */
|
|
697 c = safe_vgetc();
|
|
698 #ifdef FEAT_LANGMAP
|
|
699 LANGMAP_ADJUST(c, TRUE);
|
|
700 #endif
|
|
701 --no_zero_mapping;
|
|
702 if (ctrl_w)
|
|
703 {
|
|
704 --no_mapping;
|
|
705 --allow_keys;
|
|
706 }
|
|
707 #ifdef FEAT_CMDL_INFO
|
|
708 need_flushbuf |= add_to_showcmd(c);
|
|
709 #endif
|
|
710 }
|
|
711
|
|
712 /*
|
|
713 * If we got CTRL-W there may be a/another count
|
|
714 */
|
|
715 if (c == Ctrl_W && !ctrl_w && oap->op_type == OP_NOP)
|
|
716 {
|
|
717 ctrl_w = TRUE;
|
|
718 ca.opcount = ca.count0; /* remember first count */
|
|
719 ca.count0 = 0;
|
|
720 ++no_mapping;
|
|
721 ++allow_keys; /* no mapping for nchar, but keys */
|
|
722 c = safe_vgetc(); /* get next character */
|
|
723 #ifdef FEAT_LANGMAP
|
|
724 LANGMAP_ADJUST(c, TRUE);
|
|
725 #endif
|
|
726 --no_mapping;
|
|
727 --allow_keys;
|
|
728 #ifdef FEAT_CMDL_INFO
|
|
729 need_flushbuf |= add_to_showcmd(c);
|
|
730 #endif
|
|
731 goto getcount; /* jump back */
|
|
732 }
|
|
733 }
|
|
734
|
|
735 /*
|
|
736 * If we're in the middle of an operator (including after entering a yank
|
|
737 * buffer with '"') AND we had a count before the operator, then that
|
|
738 * count overrides the current value of ca.count0.
|
|
739 * What this means effectively, is that commands like "3dw" get turned
|
|
740 * into "d3w" which makes things fall into place pretty neatly.
|
|
741 * If you give a count before AND after the operator, they are multiplied.
|
|
742 */
|
|
743 if (ca.opcount != 0)
|
|
744 {
|
|
745 if (ca.count0)
|
|
746 ca.count0 *= ca.opcount;
|
|
747 else
|
|
748 ca.count0 = ca.opcount;
|
|
749 }
|
|
750
|
|
751 /*
|
|
752 * Always remember the count. It will be set to zero (on the next call,
|
|
753 * above) when there is no pending operator.
|
|
754 * When called from main(), save the count for use by the "count" built-in
|
|
755 * variable.
|
|
756 */
|
|
757 ca.opcount = ca.count0;
|
|
758 ca.count1 = (ca.count0 == 0 ? 1 : ca.count0);
|
|
759
|
|
760 #ifdef FEAT_EVAL
|
|
761 /*
|
|
762 * Only set v:count when called from main() and not a stuffed command.
|
|
763 */
|
|
764 if (toplevel && stuff_empty())
|
|
765 set_vcount(ca.count0, ca.count1);
|
|
766 #endif
|
|
767
|
|
768 /*
|
|
769 * Find the command character in the table of commands.
|
|
770 * For CTRL-W we already got nchar when looking for a count.
|
|
771 */
|
|
772 if (ctrl_w)
|
|
773 {
|
|
774 ca.nchar = c;
|
|
775 ca.cmdchar = Ctrl_W;
|
|
776 }
|
|
777 else
|
|
778 ca.cmdchar = c;
|
|
779 idx = find_command(ca.cmdchar);
|
|
780 if (idx < 0)
|
|
781 {
|
|
782 /* Not a known command: beep. */
|
|
783 clearopbeep(oap);
|
|
784 goto normal_end;
|
|
785 }
|
|
786 #ifdef FEAT_CMDWIN
|
|
787 if (cmdwin_type != 0 && (nv_cmds[idx].cmd_flags & NV_NCW))
|
|
788 {
|
|
789 /* This command is not allowed in the cmdline window: beep. */
|
|
790 clearopbeep(oap);
|
|
791 EMSG(_(e_cmdwin));
|
|
792 goto normal_end;
|
|
793 }
|
|
794 #endif
|
|
795
|
|
796 #ifdef FEAT_VISUAL
|
|
797 /*
|
|
798 * In Visual/Select mode, a few keys are handled in a special way.
|
|
799 */
|
|
800 if (VIsual_active)
|
|
801 {
|
|
802 /* when 'keymodel' contains "stopsel" may stop Select/Visual mode */
|
|
803 if (km_stopsel
|
|
804 && (nv_cmds[idx].cmd_flags & NV_STS)
|
|
805 && !(mod_mask & MOD_MASK_SHIFT))
|
|
806 {
|
|
807 end_visual_mode();
|
|
808 redraw_curbuf_later(INVERTED);
|
|
809 }
|
|
810
|
|
811 /* Keys that work different when 'keymodel' contains "startsel" */
|
|
812 if (km_startsel)
|
|
813 {
|
|
814 if (nv_cmds[idx].cmd_flags & NV_SS)
|
|
815 {
|
|
816 unshift_special(&ca);
|
|
817 idx = find_command(ca.cmdchar);
|
|
818 }
|
|
819 else if ((nv_cmds[idx].cmd_flags & NV_SSS)
|
|
820 && (mod_mask & MOD_MASK_SHIFT))
|
|
821 {
|
|
822 mod_mask &= ~MOD_MASK_SHIFT;
|
|
823 }
|
|
824 }
|
|
825 }
|
|
826 #endif
|
|
827
|
|
828 #ifdef FEAT_RIGHTLEFT
|
|
829 if (curwin->w_p_rl && KeyTyped && !KeyStuffed
|
|
830 && (nv_cmds[idx].cmd_flags & NV_RL))
|
|
831 {
|
|
832 /* Invert horizontal movements and operations. Only when typed by the
|
|
833 * user directly, not when the result of a mapping or "x" translated
|
|
834 * to "dl". */
|
|
835 switch (ca.cmdchar)
|
|
836 {
|
|
837 case 'l': ca.cmdchar = 'h'; break;
|
|
838 case K_RIGHT: ca.cmdchar = K_LEFT; break;
|
|
839 case K_S_RIGHT: ca.cmdchar = K_S_LEFT; break;
|
|
840 case K_C_RIGHT: ca.cmdchar = K_C_LEFT; break;
|
|
841 case 'h': ca.cmdchar = 'l'; break;
|
|
842 case K_LEFT: ca.cmdchar = K_RIGHT; break;
|
|
843 case K_S_LEFT: ca.cmdchar = K_S_RIGHT; break;
|
|
844 case K_C_LEFT: ca.cmdchar = K_C_RIGHT; break;
|
|
845 case '>': ca.cmdchar = '<'; break;
|
|
846 case '<': ca.cmdchar = '>'; break;
|
|
847 }
|
|
848 idx = find_command(ca.cmdchar);
|
|
849 }
|
|
850 #endif
|
|
851
|
|
852 /*
|
|
853 * Get an additional character if we need one.
|
|
854 */
|
|
855 if ((nv_cmds[idx].cmd_flags & NV_NCH)
|
|
856 && (((nv_cmds[idx].cmd_flags & NV_NCH_NOP) == NV_NCH_NOP
|
|
857 && oap->op_type == OP_NOP)
|
|
858 || (nv_cmds[idx].cmd_flags & NV_NCH_ALW) == NV_NCH_ALW
|
|
859 || (ca.cmdchar == 'q'
|
|
860 && oap->op_type == OP_NOP
|
|
861 && !Recording
|
|
862 && !Exec_reg)
|
|
863 || ((ca.cmdchar == 'a' || ca.cmdchar == 'i')
|
|
864 && (oap->op_type != OP_NOP
|
|
865 #ifdef FEAT_VISUAL
|
|
866 || VIsual_active
|
|
867 #endif
|
|
868 ))))
|
|
869 {
|
|
870 int *cp;
|
|
871 int repl = FALSE; /* get character for replace mode */
|
|
872 int lit = FALSE; /* get extra character literally */
|
|
873 int langmap_active = FALSE; /* using :lmap mappings */
|
|
874 int lang; /* getting a text character */
|
|
875 #ifdef USE_IM_CONTROL
|
|
876 int save_smd; /* saved value of p_smd */
|
|
877 #endif
|
|
878
|
|
879 ++no_mapping;
|
|
880 ++allow_keys; /* no mapping for nchar, but allow key codes */
|
|
881 if (ca.cmdchar == 'g')
|
|
882 {
|
|
883 /*
|
|
884 * For 'g' get the next character now, so that we can check for
|
|
885 * "gr", "g'" and "g`".
|
|
886 */
|
|
887 ca.nchar = safe_vgetc();
|
|
888 #ifdef FEAT_LANGMAP
|
|
889 LANGMAP_ADJUST(ca.nchar, TRUE);
|
|
890 #endif
|
|
891 #ifdef FEAT_CMDL_INFO
|
|
892 need_flushbuf |= add_to_showcmd(ca.nchar);
|
|
893 #endif
|
|
894 if (ca.nchar == 'r' || ca.nchar == '\'' || ca.nchar == '`'
|
|
895 || ca.nchar == Ctrl_BSL)
|
|
896 {
|
|
897 cp = &ca.extra_char; /* need to get a third character */
|
|
898 if (ca.nchar != 'r')
|
|
899 lit = TRUE; /* get it literally */
|
|
900 else
|
|
901 repl = TRUE; /* get it in replace mode */
|
|
902 }
|
|
903 else
|
|
904 cp = NULL; /* no third character needed */
|
|
905 }
|
|
906 else
|
|
907 {
|
|
908 if (ca.cmdchar == 'r') /* get it in replace mode */
|
|
909 repl = TRUE;
|
|
910 cp = &ca.nchar;
|
|
911 }
|
|
912 lang = (repl || (nv_cmds[idx].cmd_flags & NV_LANG));
|
|
913
|
|
914 /*
|
|
915 * Get a second or third character.
|
|
916 */
|
|
917 if (cp != NULL)
|
|
918 {
|
|
919 #ifdef CURSOR_SHAPE
|
|
920 if (repl)
|
|
921 {
|
|
922 State = REPLACE; /* pretend Replace mode */
|
|
923 ui_cursor_shape(); /* show different cursor shape */
|
|
924 }
|
|
925 #endif
|
|
926 if (lang && curbuf->b_p_iminsert == B_IMODE_LMAP)
|
|
927 {
|
|
928 /* Allow mappings defined with ":lmap". */
|
|
929 --no_mapping;
|
|
930 --allow_keys;
|
|
931 if (repl)
|
|
932 State = LREPLACE;
|
|
933 else
|
|
934 State = LANGMAP;
|
|
935 langmap_active = TRUE;
|
|
936 }
|
|
937 #ifdef USE_IM_CONTROL
|
|
938 save_smd = p_smd;
|
|
939 p_smd = FALSE; /* Don't let the IM code show the mode here */
|
|
940 if (lang && curbuf->b_p_iminsert == B_IMODE_IM)
|
|
941 im_set_active(TRUE);
|
|
942 #endif
|
|
943
|
|
944 *cp = safe_vgetc();
|
|
945
|
|
946 if (langmap_active)
|
|
947 {
|
|
948 /* Undo the decrement done above */
|
|
949 ++no_mapping;
|
|
950 ++allow_keys;
|
|
951 State = NORMAL_BUSY;
|
|
952 }
|
|
953 #ifdef USE_IM_CONTROL
|
|
954 if (lang)
|
|
955 {
|
|
956 if (curbuf->b_p_iminsert != B_IMODE_LMAP)
|
|
957 im_save_status(&curbuf->b_p_iminsert);
|
|
958 im_set_active(FALSE);
|
|
959 }
|
|
960 p_smd = save_smd;
|
|
961 #endif
|
|
962 #ifdef CURSOR_SHAPE
|
|
963 State = NORMAL_BUSY;
|
|
964 #endif
|
|
965 #ifdef FEAT_CMDL_INFO
|
|
966 need_flushbuf |= add_to_showcmd(*cp);
|
|
967 #endif
|
|
968
|
|
969 if (!lit)
|
|
970 {
|
|
971 #ifdef FEAT_DIGRAPHS
|
|
972 /* Typing CTRL-K gets a digraph. */
|
|
973 if (*cp == Ctrl_K
|
|
974 && ((nv_cmds[idx].cmd_flags & NV_LANG)
|
|
975 || cp == &ca.extra_char)
|
|
976 && vim_strchr(p_cpo, CPO_DIGRAPH) == NULL)
|
|
977 {
|
|
978 c = get_digraph(FALSE);
|
|
979 if (c > 0)
|
|
980 {
|
|
981 *cp = c;
|
|
982 # ifdef FEAT_CMDL_INFO
|
|
983 /* Guessing how to update showcmd here... */
|
|
984 del_from_showcmd(3);
|
|
985 need_flushbuf |= add_to_showcmd(*cp);
|
|
986 # endif
|
|
987 }
|
|
988 }
|
|
989 #endif
|
|
990
|
|
991 #ifdef FEAT_LANGMAP
|
|
992 /* adjust chars > 127, except after "tTfFr" commands */
|
|
993 LANGMAP_ADJUST(*cp, !lang);
|
|
994 #endif
|
|
995 #ifdef FEAT_RIGHTLEFT
|
|
996 /* adjust Hebrew mapped char */
|
|
997 if (p_hkmap && lang && KeyTyped)
|
|
998 *cp = hkmap(*cp);
|
|
999 # ifdef FEAT_FKMAP
|
|
1000 /* adjust Farsi mapped char */
|
|
1001 if (p_fkmap && lang && KeyTyped)
|
|
1002 *cp = fkmap(*cp);
|
|
1003 # endif
|
|
1004 #endif
|
|
1005 }
|
|
1006
|
|
1007 /*
|
|
1008 * When the next character is CTRL-\ a following CTRL-N means the
|
|
1009 * command is aborted and we go to Normal mode.
|
|
1010 */
|
|
1011 if (cp == &ca.extra_char
|
|
1012 && ca.nchar == Ctrl_BSL
|
|
1013 && (ca.extra_char == Ctrl_N || ca.extra_char == Ctrl_G))
|
|
1014 {
|
|
1015 ca.cmdchar = Ctrl_BSL;
|
|
1016 ca.nchar = ca.extra_char;
|
|
1017 idx = find_command(ca.cmdchar);
|
|
1018 }
|
|
1019 else if (*cp == Ctrl_BSL)
|
|
1020 {
|
|
1021 long towait = (p_ttm >= 0 ? p_ttm : p_tm);
|
|
1022
|
|
1023 /* There is a busy wait here when typing "f<C-\>" and then
|
|
1024 * something different from CTRL-N. Can't be avoided. */
|
|
1025 while ((c = vpeekc()) <= 0 && towait > 0L)
|
|
1026 {
|
|
1027 do_sleep(towait > 50L ? 50L : towait);
|
|
1028 towait -= 50L;
|
|
1029 }
|
|
1030 if (c > 0)
|
|
1031 {
|
|
1032 c = safe_vgetc();
|
|
1033 if (c != Ctrl_N && c != Ctrl_G)
|
|
1034 vungetc(c);
|
|
1035 else
|
|
1036 {
|
|
1037 ca.cmdchar = Ctrl_BSL;
|
|
1038 ca.nchar = c;
|
|
1039 idx = find_command(ca.cmdchar);
|
|
1040 }
|
|
1041 }
|
|
1042 }
|
|
1043
|
|
1044 #ifdef FEAT_MBYTE
|
|
1045 /* When getting a text character and the next character is a
|
|
1046 * multi-byte character, it could be a composing character.
|
|
1047 * However, don't wait for it to arrive. */
|
|
1048 while (enc_utf8 && lang && (c = vpeekc()) > 0
|
|
1049 && (c >= 0x100 || MB_BYTE2LEN(vpeekc()) > 1))
|
|
1050 {
|
|
1051 c = safe_vgetc();
|
|
1052 if (!utf_iscomposing(c))
|
|
1053 {
|
|
1054 vungetc(c); /* it wasn't, put it back */
|
|
1055 break;
|
|
1056 }
|
|
1057 else if (ca.ncharC1 == 0)
|
|
1058 ca.ncharC1 = c;
|
|
1059 else
|
|
1060 ca.ncharC2 = c;
|
|
1061 }
|
|
1062 #endif
|
|
1063 }
|
|
1064 --no_mapping;
|
|
1065 --allow_keys;
|
|
1066 }
|
|
1067
|
|
1068 #ifdef FEAT_CMDL_INFO
|
|
1069 /*
|
|
1070 * Flush the showcmd characters onto the screen so we can see them while
|
|
1071 * the command is being executed. Only do this when the shown command was
|
|
1072 * actually displayed, otherwise this will slow down a lot when executing
|
|
1073 * mappings.
|
|
1074 */
|
|
1075 if (need_flushbuf)
|
|
1076 out_flush();
|
|
1077 #endif
|
203
|
1078 #ifdef FEAT_AUTOCMD
|
|
1079 did_cursorhold = FALSE;
|
|
1080 #endif
|
7
|
1081
|
|
1082 State = NORMAL;
|
|
1083
|
|
1084 if (ca.nchar == ESC)
|
|
1085 {
|
|
1086 clearop(oap);
|
|
1087 if (restart_edit == 0 && goto_im())
|
|
1088 restart_edit = 'a';
|
|
1089 goto normal_end;
|
|
1090 }
|
|
1091
|
24
|
1092 if (ca.cmdchar != K_IGNORE)
|
|
1093 {
|
|
1094 msg_didout = FALSE; /* don't scroll screen up for normal command */
|
|
1095 msg_col = 0;
|
|
1096 }
|
7
|
1097
|
|
1098 #ifdef FEAT_VISUAL
|
|
1099 old_pos = curwin->w_cursor; /* remember where cursor was */
|
|
1100
|
|
1101 /* When 'keymodel' contains "startsel" some keys start Select/Visual
|
|
1102 * mode. */
|
|
1103 if (!VIsual_active && km_startsel)
|
|
1104 {
|
|
1105 if (nv_cmds[idx].cmd_flags & NV_SS)
|
|
1106 {
|
|
1107 start_selection();
|
|
1108 unshift_special(&ca);
|
|
1109 idx = find_command(ca.cmdchar);
|
|
1110 }
|
|
1111 else if ((nv_cmds[idx].cmd_flags & NV_SSS)
|
|
1112 && (mod_mask & MOD_MASK_SHIFT))
|
|
1113 {
|
|
1114 start_selection();
|
|
1115 mod_mask &= ~MOD_MASK_SHIFT;
|
|
1116 }
|
|
1117 }
|
|
1118 #endif
|
|
1119
|
|
1120 /*
|
|
1121 * Execute the command!
|
|
1122 * Call the command function found in the commands table.
|
|
1123 */
|
|
1124 ca.arg = nv_cmds[idx].cmd_arg;
|
|
1125 (nv_cmds[idx].cmd_func)(&ca);
|
|
1126
|
|
1127 /*
|
|
1128 * If we didn't start or finish an operator, reset oap->regname, unless we
|
|
1129 * need it later.
|
|
1130 */
|
|
1131 if (!finish_op
|
|
1132 && !oap->op_type
|
|
1133 && (idx < 0 || !(nv_cmds[idx].cmd_flags & NV_KEEPREG)))
|
|
1134 {
|
|
1135 clearop(oap);
|
|
1136 #ifdef FEAT_EVAL
|
|
1137 set_reg_var('"');
|
|
1138 #endif
|
|
1139 }
|
|
1140
|
36
|
1141 /* get the length of mapped chars again after typing a count, second
|
|
1142 * character or "z333<cr>". */
|
|
1143 if (old_mapped_len > 0)
|
|
1144 old_mapped_len = typebuf_maplen();
|
|
1145
|
7
|
1146 /*
|
|
1147 * If an operation is pending, handle it...
|
|
1148 */
|
|
1149 do_pending_operator(&ca, old_col, FALSE);
|
|
1150
|
|
1151 /*
|
|
1152 * Wait for a moment when a message is displayed that will be overwritten
|
|
1153 * by the mode message.
|
|
1154 * In Visual mode and with "^O" in Insert mode, a short message will be
|
|
1155 * overwritten by the mode message. Wait a bit, until a key is hit.
|
|
1156 * In Visual mode, it's more important to keep the Visual area updated
|
|
1157 * than keeping a message (e.g. from a /pat search).
|
|
1158 * Only do this if the command was typed, not from a mapping.
|
|
1159 * Don't wait when emsg_silent is non-zero.
|
|
1160 * Also wait a bit after an error message, e.g. for "^O:".
|
|
1161 * Don't redraw the screen, it would remove the message.
|
|
1162 */
|
|
1163 if ( ((p_smd
|
|
1164 && (restart_edit != 0
|
|
1165 #ifdef FEAT_VISUAL
|
|
1166 || (VIsual_active
|
|
1167 && old_pos.lnum == curwin->w_cursor.lnum
|
|
1168 && old_pos.col == curwin->w_cursor.col)
|
|
1169 #endif
|
|
1170 )
|
|
1171 && (clear_cmdline
|
|
1172 || redraw_cmdline)
|
|
1173 && (msg_didout || (msg_didany && msg_scroll))
|
|
1174 && !msg_nowait
|
|
1175 && KeyTyped)
|
|
1176 || (restart_edit != 0
|
|
1177 #ifdef FEAT_VISUAL
|
|
1178 && !VIsual_active
|
|
1179 #endif
|
|
1180 && (msg_scroll
|
|
1181 || emsg_on_display)))
|
|
1182 && oap->regname == 0
|
|
1183 && !(ca.retval & CA_COMMAND_BUSY)
|
|
1184 && stuff_empty()
|
|
1185 && typebuf_typed()
|
|
1186 && emsg_silent == 0
|
|
1187 && !did_wait_return
|
|
1188 && oap->op_type == OP_NOP)
|
|
1189 {
|
|
1190 int save_State = State;
|
|
1191
|
|
1192 /* Draw the cursor with the right shape here */
|
|
1193 if (restart_edit != 0)
|
|
1194 State = INSERT;
|
|
1195
|
|
1196 /* If need to redraw, and there is a "keep_msg", redraw before the
|
|
1197 * delay */
|
|
1198 if (must_redraw && keep_msg != NULL && !emsg_on_display)
|
|
1199 {
|
|
1200 char_u *kmsg;
|
|
1201
|
|
1202 kmsg = keep_msg;
|
|
1203 keep_msg = NULL;
|
|
1204 /* showmode() will clear keep_msg, but we want to use it anyway */
|
|
1205 update_screen(0);
|
|
1206 /* now reset it, otherwise it's put in the history again */
|
|
1207 keep_msg = kmsg;
|
|
1208 msg_attr(kmsg, keep_msg_attr);
|
|
1209 vim_free(kmsg);
|
|
1210 }
|
|
1211 setcursor();
|
|
1212 cursor_on();
|
|
1213 out_flush();
|
|
1214 if (msg_scroll || emsg_on_display)
|
|
1215 ui_delay(1000L, TRUE); /* wait at least one second */
|
|
1216 ui_delay(3000L, FALSE); /* wait up to three seconds */
|
|
1217 State = save_State;
|
|
1218
|
|
1219 msg_scroll = FALSE;
|
|
1220 emsg_on_display = FALSE;
|
|
1221 }
|
|
1222
|
|
1223 /*
|
|
1224 * Finish up after executing a Normal mode command.
|
|
1225 */
|
|
1226 normal_end:
|
|
1227
|
|
1228 msg_nowait = FALSE;
|
|
1229
|
|
1230 /* Reset finish_op, in case it was set */
|
|
1231 #ifdef CURSOR_SHAPE
|
|
1232 c = finish_op;
|
|
1233 #endif
|
|
1234 finish_op = FALSE;
|
|
1235 #ifdef CURSOR_SHAPE
|
|
1236 /* Redraw the cursor with another shape, if we were in Operator-pending
|
|
1237 * mode or did a replace command. */
|
|
1238 if (c || ca.cmdchar == 'r')
|
|
1239 {
|
|
1240 ui_cursor_shape(); /* may show different cursor shape */
|
|
1241 # ifdef FEAT_MOUSESHAPE
|
|
1242 update_mouseshape(-1);
|
|
1243 # endif
|
|
1244 }
|
|
1245 #endif
|
|
1246
|
|
1247 #ifdef FEAT_CMDL_INFO
|
|
1248 if (oap->op_type == OP_NOP && oap->regname == 0)
|
|
1249 clear_showcmd();
|
|
1250 #endif
|
|
1251
|
|
1252 checkpcmark(); /* check if we moved since setting pcmark */
|
|
1253 vim_free(ca.searchbuf);
|
|
1254
|
|
1255 #ifdef FEAT_MBYTE
|
|
1256 if (has_mbyte)
|
|
1257 mb_adjust_cursor();
|
|
1258 #endif
|
|
1259
|
|
1260 #ifdef FEAT_SCROLLBIND
|
|
1261 if (curwin->w_p_scb && toplevel)
|
|
1262 {
|
|
1263 validate_cursor(); /* may need to update w_leftcol */
|
|
1264 do_check_scrollbind(TRUE);
|
|
1265 }
|
|
1266 #endif
|
|
1267
|
|
1268 /*
|
|
1269 * May restart edit(), if we got here with CTRL-O in Insert mode (but not
|
|
1270 * if still inside a mapping that started in Visual mode).
|
|
1271 * May switch from Visual to Select mode after CTRL-O command.
|
|
1272 */
|
|
1273 if ( oap->op_type == OP_NOP
|
|
1274 #ifdef FEAT_VISUAL
|
|
1275 && ((restart_edit != 0 && !VIsual_active && old_mapped_len == 0)
|
|
1276 || restart_VIsual_select == 1)
|
|
1277 #endif
|
|
1278 && !(ca.retval & CA_COMMAND_BUSY)
|
|
1279 && stuff_empty()
|
|
1280 && oap->regname == 0)
|
|
1281 {
|
|
1282 #ifdef FEAT_VISUAL
|
|
1283 if (restart_VIsual_select == 1)
|
|
1284 {
|
|
1285 VIsual_select = TRUE;
|
|
1286 showmode();
|
|
1287 restart_VIsual_select = 0;
|
|
1288 }
|
|
1289 #endif
|
|
1290 if (restart_edit != 0
|
|
1291 #ifdef FEAT_VISUAL
|
|
1292 && !VIsual_active
|
|
1293 #endif
|
|
1294 && old_mapped_len == 0)
|
|
1295 (void)edit(restart_edit, FALSE, 1L);
|
|
1296 }
|
|
1297
|
|
1298 #ifdef FEAT_VISUAL
|
|
1299 if (restart_VIsual_select == 2)
|
|
1300 restart_VIsual_select = 1;
|
|
1301 #endif
|
|
1302
|
|
1303 /* Save count before an operator for next time. */
|
|
1304 opcount = ca.opcount;
|
|
1305 }
|
|
1306
|
|
1307 /*
|
|
1308 * Handle an operator after visual mode or when the movement is finished
|
|
1309 */
|
|
1310 void
|
|
1311 do_pending_operator(cap, old_col, gui_yank)
|
|
1312 cmdarg_T *cap;
|
|
1313 int old_col;
|
|
1314 int gui_yank;
|
|
1315 {
|
|
1316 oparg_T *oap = cap->oap;
|
|
1317 pos_T old_cursor;
|
|
1318 int empty_region_error;
|
|
1319 int restart_edit_save;
|
|
1320
|
|
1321 #ifdef FEAT_VISUAL
|
|
1322 /* The visual area is remembered for redo */
|
|
1323 static int redo_VIsual_mode = NUL; /* 'v', 'V', or Ctrl-V */
|
|
1324 static linenr_T redo_VIsual_line_count; /* number of lines */
|
|
1325 static colnr_T redo_VIsual_col; /* number of cols or end column */
|
|
1326 static long redo_VIsual_count; /* count for Visual operator */
|
|
1327 # ifdef FEAT_VIRTUALEDIT
|
|
1328 int include_line_break = FALSE;
|
|
1329 # endif
|
|
1330 #endif
|
|
1331
|
|
1332 #if defined(FEAT_CLIPBOARD)
|
|
1333 /*
|
|
1334 * Yank the visual area into the GUI selection register before we operate
|
|
1335 * on it and lose it forever.
|
|
1336 * Don't do it if a specific register was specified, so that ""x"*P works.
|
|
1337 * This could call do_pending_operator() recursively, but that's OK
|
|
1338 * because gui_yank will be TRUE for the nested call.
|
|
1339 */
|
|
1340 if (clip_star.available
|
|
1341 && oap->op_type != OP_NOP
|
|
1342 && !gui_yank
|
|
1343 # ifdef FEAT_VISUAL
|
|
1344 && VIsual_active
|
|
1345 && !redo_VIsual_busy
|
|
1346 # endif
|
|
1347 && oap->regname == 0)
|
|
1348 clip_auto_select();
|
|
1349 #endif
|
|
1350 old_cursor = curwin->w_cursor;
|
|
1351
|
|
1352 /*
|
|
1353 * If an operation is pending, handle it...
|
|
1354 */
|
|
1355 if ((finish_op
|
|
1356 #ifdef FEAT_VISUAL
|
|
1357 || VIsual_active
|
|
1358 #endif
|
|
1359 ) && oap->op_type != OP_NOP)
|
|
1360 {
|
|
1361 #ifdef FEAT_VISUAL
|
|
1362 oap->is_VIsual = VIsual_active;
|
|
1363 if (oap->motion_force == 'V')
|
|
1364 oap->motion_type = MLINE;
|
|
1365 else if (oap->motion_force == 'v')
|
|
1366 {
|
|
1367 /* If the motion was linewise, "inclusive" will not have been set.
|
|
1368 * Use "exclusive" to be consistent. Makes "dvj" work nice. */
|
|
1369 if (oap->motion_type == MLINE)
|
|
1370 oap->inclusive = FALSE;
|
|
1371 /* If the motion already was characterwise, toggle "inclusive" */
|
|
1372 else if (oap->motion_type == MCHAR)
|
|
1373 oap->inclusive = !oap->inclusive;
|
|
1374 oap->motion_type = MCHAR;
|
|
1375 }
|
|
1376 else if (oap->motion_force == Ctrl_V)
|
|
1377 {
|
|
1378 /* Change line- or characterwise motion into Visual block mode. */
|
|
1379 VIsual_active = TRUE;
|
|
1380 VIsual = oap->start;
|
|
1381 VIsual_mode = Ctrl_V;
|
|
1382 VIsual_select = FALSE;
|
|
1383 VIsual_reselect = FALSE;
|
|
1384 }
|
|
1385 #endif
|
|
1386
|
|
1387 /* only redo yank when 'y' flag is in 'cpoptions' */
|
|
1388 /* never redo "zf" (define fold) */
|
|
1389 if ((vim_strchr(p_cpo, CPO_YANK) != NULL || oap->op_type != OP_YANK)
|
|
1390 #ifdef FEAT_VISUAL
|
|
1391 && (!VIsual_active || oap->motion_force)
|
|
1392 #endif
|
164
|
1393 && cap->cmdchar != 'D'
|
7
|
1394 #ifdef FEAT_FOLDING
|
|
1395 && oap->op_type != OP_FOLD
|
|
1396 && oap->op_type != OP_FOLDOPEN
|
|
1397 && oap->op_type != OP_FOLDOPENREC
|
|
1398 && oap->op_type != OP_FOLDCLOSE
|
|
1399 && oap->op_type != OP_FOLDCLOSEREC
|
|
1400 && oap->op_type != OP_FOLDDEL
|
|
1401 && oap->op_type != OP_FOLDDELREC
|
|
1402 #endif
|
|
1403 )
|
|
1404 {
|
|
1405 prep_redo(oap->regname, cap->count0,
|
|
1406 get_op_char(oap->op_type), get_extra_op_char(oap->op_type),
|
|
1407 oap->motion_force, cap->cmdchar, cap->nchar);
|
|
1408 if (cap->cmdchar == '/' || cap->cmdchar == '?') /* was a search */
|
|
1409 {
|
|
1410 /*
|
|
1411 * If 'cpoptions' does not contain 'r', insert the search
|
|
1412 * pattern to really repeat the same command.
|
|
1413 */
|
|
1414 if (vim_strchr(p_cpo, CPO_REDO) == NULL)
|
|
1415 AppendToRedobuffLit(cap->searchbuf);
|
|
1416 AppendToRedobuff(NL_STR);
|
|
1417 }
|
|
1418 else if (cap->cmdchar == ':')
|
|
1419 {
|
|
1420 /* do_cmdline() has stored the first typed line in
|
|
1421 * "repeat_cmdline". When several lines are typed repeating
|
|
1422 * won't be possible. */
|
|
1423 if (repeat_cmdline == NULL)
|
|
1424 ResetRedobuff();
|
|
1425 else
|
|
1426 {
|
|
1427 AppendToRedobuffLit(repeat_cmdline);
|
|
1428 AppendToRedobuff(NL_STR);
|
|
1429 vim_free(repeat_cmdline);
|
|
1430 repeat_cmdline = NULL;
|
|
1431 }
|
|
1432 }
|
|
1433 }
|
|
1434
|
|
1435 #ifdef FEAT_VISUAL
|
|
1436 if (redo_VIsual_busy)
|
|
1437 {
|
|
1438 oap->start = curwin->w_cursor;
|
|
1439 curwin->w_cursor.lnum += redo_VIsual_line_count - 1;
|
|
1440 if (curwin->w_cursor.lnum > curbuf->b_ml.ml_line_count)
|
|
1441 curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count;
|
|
1442 VIsual_mode = redo_VIsual_mode;
|
|
1443 if (VIsual_mode == 'v')
|
|
1444 {
|
|
1445 if (redo_VIsual_line_count <= 1)
|
|
1446 curwin->w_cursor.col += redo_VIsual_col - 1;
|
|
1447 else
|
|
1448 curwin->w_cursor.col = redo_VIsual_col;
|
|
1449 }
|
|
1450 if (redo_VIsual_col == MAXCOL)
|
|
1451 {
|
|
1452 curwin->w_curswant = MAXCOL;
|
|
1453 coladvance((colnr_T)MAXCOL);
|
|
1454 }
|
|
1455 cap->count0 = redo_VIsual_count;
|
|
1456 if (redo_VIsual_count != 0)
|
|
1457 cap->count1 = redo_VIsual_count;
|
|
1458 else
|
|
1459 cap->count1 = 1;
|
|
1460 }
|
|
1461 else if (VIsual_active)
|
|
1462 {
|
|
1463 /* Save the current VIsual area for '< and '> marks, and "gv" */
|
|
1464 curbuf->b_visual_start = VIsual;
|
|
1465 curbuf->b_visual_end = curwin->w_cursor;
|
|
1466 curbuf->b_visual_mode = VIsual_mode;
|
|
1467 # ifdef FEAT_EVAL
|
|
1468 curbuf->b_visual_mode_eval = VIsual_mode;
|
|
1469 # endif
|
|
1470 curbuf->b_visual_curswant = curwin->w_curswant;
|
|
1471
|
|
1472 /* In Select mode, a linewise selection is operated upon like a
|
|
1473 * characterwise selection. */
|
|
1474 if (VIsual_select && VIsual_mode == 'V')
|
|
1475 {
|
|
1476 if (lt(VIsual, curwin->w_cursor))
|
|
1477 {
|
|
1478 VIsual.col = 0;
|
|
1479 curwin->w_cursor.col =
|
|
1480 (colnr_T)STRLEN(ml_get(curwin->w_cursor.lnum));
|
|
1481 }
|
|
1482 else
|
|
1483 {
|
|
1484 curwin->w_cursor.col = 0;
|
|
1485 VIsual.col = (colnr_T)STRLEN(ml_get(VIsual.lnum));
|
|
1486 }
|
|
1487 VIsual_mode = 'v';
|
|
1488 }
|
|
1489 /* If 'selection' is "exclusive", backup one character for
|
|
1490 * charwise selections. */
|
|
1491 else if (VIsual_mode == 'v')
|
|
1492 {
|
|
1493 # ifdef FEAT_VIRTUALEDIT
|
|
1494 include_line_break =
|
|
1495 # endif
|
|
1496 unadjust_for_sel();
|
|
1497 }
|
|
1498
|
|
1499 oap->start = VIsual;
|
|
1500 if (VIsual_mode == 'V')
|
|
1501 oap->start.col = 0;
|
|
1502 }
|
|
1503 #endif /* FEAT_VISUAL */
|
|
1504
|
|
1505 /*
|
|
1506 * Set oap->start to the first position of the operated text, oap->end
|
|
1507 * to the end of the operated text. w_cursor is equal to oap->start.
|
|
1508 */
|
|
1509 if (lt(oap->start, curwin->w_cursor))
|
|
1510 {
|
|
1511 #ifdef FEAT_FOLDING
|
|
1512 /* Include folded lines completely. */
|
|
1513 if (!VIsual_active)
|
|
1514 {
|
|
1515 if (hasFolding(oap->start.lnum, &oap->start.lnum, NULL))
|
|
1516 oap->start.col = 0;
|
|
1517 if (hasFolding(curwin->w_cursor.lnum, NULL,
|
|
1518 &curwin->w_cursor.lnum))
|
|
1519 curwin->w_cursor.col = (colnr_T)STRLEN(ml_get_curline());
|
|
1520 }
|
|
1521 #endif
|
|
1522 oap->end = curwin->w_cursor;
|
|
1523 curwin->w_cursor = oap->start;
|
|
1524
|
|
1525 /* w_virtcol may have been updated; if the cursor goes back to its
|
|
1526 * previous position w_virtcol becomes invalid and isn't updated
|
|
1527 * automatically. */
|
|
1528 curwin->w_valid &= ~VALID_VIRTCOL;
|
|
1529 }
|
|
1530 else
|
|
1531 {
|
|
1532 #ifdef FEAT_FOLDING
|
|
1533 /* Include folded lines completely. */
|
|
1534 if (!VIsual_active && oap->motion_type == MLINE)
|
|
1535 {
|
|
1536 if (hasFolding(curwin->w_cursor.lnum, &curwin->w_cursor.lnum,
|
|
1537 NULL))
|
|
1538 curwin->w_cursor.col = 0;
|
|
1539 if (hasFolding(oap->start.lnum, NULL, &oap->start.lnum))
|
|
1540 oap->start.col = (colnr_T)STRLEN(ml_get(oap->start.lnum));
|
|
1541 }
|
|
1542 #endif
|
|
1543 oap->end = oap->start;
|
|
1544 oap->start = curwin->w_cursor;
|
|
1545 }
|
|
1546
|
|
1547 oap->line_count = oap->end.lnum - oap->start.lnum + 1;
|
|
1548
|
|
1549 #ifdef FEAT_VIRTUALEDIT
|
|
1550 /* Set "virtual_op" before resetting VIsual_active. */
|
|
1551 virtual_op = virtual_active();
|
|
1552 #endif
|
|
1553
|
|
1554 #ifdef FEAT_VISUAL
|
|
1555 if (VIsual_active || redo_VIsual_busy)
|
|
1556 {
|
|
1557 if (VIsual_mode == Ctrl_V) /* block mode */
|
|
1558 {
|
|
1559 colnr_T start, end;
|
|
1560
|
|
1561 oap->block_mode = TRUE;
|
|
1562
|
|
1563 getvvcol(curwin, &(oap->start),
|
|
1564 &oap->start_vcol, NULL, &oap->end_vcol);
|
|
1565 if (!redo_VIsual_busy)
|
|
1566 {
|
|
1567 getvvcol(curwin, &(oap->end), &start, NULL, &end);
|
|
1568
|
|
1569 if (start < oap->start_vcol)
|
|
1570 oap->start_vcol = start;
|
|
1571 if (end > oap->end_vcol)
|
|
1572 {
|
|
1573 if (*p_sel == 'e' && start >= 1
|
|
1574 && start - 1 >= oap->end_vcol)
|
|
1575 oap->end_vcol = start - 1;
|
|
1576 else
|
|
1577 oap->end_vcol = end;
|
|
1578 }
|
|
1579 }
|
|
1580
|
|
1581 /* if '$' was used, get oap->end_vcol from longest line */
|
|
1582 if (curwin->w_curswant == MAXCOL)
|
|
1583 {
|
|
1584 curwin->w_cursor.col = MAXCOL;
|
|
1585 oap->end_vcol = 0;
|
|
1586 for (curwin->w_cursor.lnum = oap->start.lnum;
|
|
1587 curwin->w_cursor.lnum <= oap->end.lnum;
|
|
1588 ++curwin->w_cursor.lnum)
|
|
1589 {
|
|
1590 getvvcol(curwin, &curwin->w_cursor, NULL, NULL, &end);
|
|
1591 if (end > oap->end_vcol)
|
|
1592 oap->end_vcol = end;
|
|
1593 }
|
|
1594 }
|
|
1595 else if (redo_VIsual_busy)
|
|
1596 oap->end_vcol = oap->start_vcol + redo_VIsual_col - 1;
|
|
1597 /*
|
|
1598 * Correct oap->end.col and oap->start.col to be the
|
|
1599 * upper-left and lower-right corner of the block area.
|
|
1600 *
|
|
1601 * (Actually, this does convert column positions into character
|
|
1602 * positions)
|
|
1603 */
|
|
1604 curwin->w_cursor.lnum = oap->end.lnum;
|
|
1605 coladvance(oap->end_vcol);
|
|
1606 oap->end = curwin->w_cursor;
|
|
1607
|
|
1608 curwin->w_cursor = oap->start;
|
|
1609 coladvance(oap->start_vcol);
|
|
1610 oap->start = curwin->w_cursor;
|
|
1611 }
|
|
1612
|
|
1613 if (!redo_VIsual_busy && !gui_yank)
|
|
1614 {
|
|
1615 /*
|
|
1616 * Prepare to reselect and redo Visual: this is based on the
|
|
1617 * size of the Visual text
|
|
1618 */
|
|
1619 resel_VIsual_mode = VIsual_mode;
|
|
1620 if (curwin->w_curswant == MAXCOL)
|
|
1621 resel_VIsual_col = MAXCOL;
|
|
1622 else if (VIsual_mode == Ctrl_V)
|
|
1623 resel_VIsual_col = oap->end_vcol - oap->start_vcol + 1;
|
|
1624 else if (oap->line_count > 1)
|
|
1625 resel_VIsual_col = oap->end.col;
|
|
1626 else
|
|
1627 resel_VIsual_col = oap->end.col - oap->start.col + 1;
|
|
1628 resel_VIsual_line_count = oap->line_count;
|
|
1629 }
|
|
1630
|
|
1631 /* can't redo yank (unless 'y' is in 'cpoptions') and ":" */
|
|
1632 if ((vim_strchr(p_cpo, CPO_YANK) != NULL || oap->op_type != OP_YANK)
|
|
1633 && oap->op_type != OP_COLON
|
|
1634 #ifdef FEAT_FOLDING
|
|
1635 && oap->op_type != OP_FOLD
|
|
1636 && oap->op_type != OP_FOLDOPEN
|
|
1637 && oap->op_type != OP_FOLDOPENREC
|
|
1638 && oap->op_type != OP_FOLDCLOSE
|
|
1639 && oap->op_type != OP_FOLDCLOSEREC
|
|
1640 && oap->op_type != OP_FOLDDEL
|
|
1641 && oap->op_type != OP_FOLDDELREC
|
|
1642 #endif
|
|
1643 && oap->motion_force == NUL
|
|
1644 )
|
|
1645 {
|
|
1646 /* Prepare for redoing. Only use the nchar field for "r",
|
|
1647 * otherwise it might be the second char of the operator. */
|
|
1648 prep_redo(oap->regname, 0L, NUL, 'v',
|
|
1649 get_op_char(oap->op_type),
|
|
1650 get_extra_op_char(oap->op_type),
|
|
1651 oap->op_type == OP_REPLACE ? cap->nchar : NUL);
|
|
1652 if (!redo_VIsual_busy)
|
|
1653 {
|
|
1654 redo_VIsual_mode = resel_VIsual_mode;
|
|
1655 redo_VIsual_col = resel_VIsual_col;
|
|
1656 redo_VIsual_line_count = resel_VIsual_line_count;
|
|
1657 redo_VIsual_count = cap->count0;
|
|
1658 }
|
|
1659 }
|
|
1660
|
|
1661 /*
|
|
1662 * oap->inclusive defaults to TRUE.
|
|
1663 * If oap->end is on a NUL (empty line) oap->inclusive becomes
|
|
1664 * FALSE. This makes "d}P" and "v}dP" work the same.
|
|
1665 */
|
|
1666 if (oap->motion_force == NUL || oap->motion_type == MLINE)
|
|
1667 oap->inclusive = TRUE;
|
|
1668 if (VIsual_mode == 'V')
|
|
1669 oap->motion_type = MLINE;
|
|
1670 else
|
|
1671 {
|
|
1672 oap->motion_type = MCHAR;
|
|
1673 if (VIsual_mode != Ctrl_V && *ml_get_pos(&(oap->end)) == NUL
|
|
1674 # ifdef FEAT_VIRTUALEDIT
|
|
1675 && (include_line_break || !virtual_op)
|
|
1676 # endif
|
|
1677 )
|
|
1678 {
|
|
1679 oap->inclusive = FALSE;
|
|
1680 /* Try to include the newline, unless it's an operator
|
|
1681 * that works on lines only */
|
|
1682 if (*p_sel != 'o'
|
|
1683 && !op_on_lines(oap->op_type)
|
|
1684 && oap->end.lnum < curbuf->b_ml.ml_line_count)
|
|
1685 {
|
|
1686 ++oap->end.lnum;
|
|
1687 oap->end.col = 0;
|
|
1688 # ifdef FEAT_VIRTUALEDIT
|
|
1689 oap->end.coladd = 0;
|
|
1690 # endif
|
|
1691 ++oap->line_count;
|
|
1692 }
|
|
1693 }
|
|
1694 }
|
|
1695
|
|
1696 redo_VIsual_busy = FALSE;
|
|
1697 /*
|
|
1698 * Switch Visual off now, so screen updating does
|
|
1699 * not show inverted text when the screen is redrawn.
|
|
1700 * With OP_YANK and sometimes with OP_COLON and OP_FILTER there is
|
|
1701 * no screen redraw, so it is done here to remove the inverted
|
|
1702 * part.
|
|
1703 */
|
|
1704 if (!gui_yank)
|
|
1705 {
|
|
1706 VIsual_active = FALSE;
|
|
1707 # ifdef FEAT_MOUSE
|
|
1708 setmouse();
|
|
1709 mouse_dragging = 0;
|
|
1710 # endif
|
|
1711 if (p_smd)
|
|
1712 clear_cmdline = TRUE; /* unshow visual mode later */
|
|
1713 #ifdef FEAT_CMDL_INFO
|
|
1714 else
|
|
1715 clear_showcmd();
|
|
1716 #endif
|
|
1717 if ((oap->op_type == OP_YANK
|
|
1718 || oap->op_type == OP_COLON
|
|
1719 || oap->op_type == OP_FILTER)
|
|
1720 && oap->motion_force == NUL)
|
|
1721 redraw_curbuf_later(INVERTED);
|
|
1722 }
|
|
1723 }
|
|
1724 #endif
|
|
1725
|
|
1726 #ifdef FEAT_MBYTE
|
|
1727 /* Include the trailing byte of a multi-byte char. */
|
|
1728 if (has_mbyte && oap->inclusive)
|
|
1729 {
|
|
1730 int l;
|
|
1731
|
|
1732 l = (*mb_ptr2len_check)(ml_get_pos(&oap->end));
|
|
1733 if (l > 1)
|
|
1734 oap->end.col += l - 1;
|
|
1735 }
|
|
1736 #endif
|
|
1737 curwin->w_set_curswant = TRUE;
|
|
1738
|
|
1739 /*
|
|
1740 * oap->empty is set when start and end are the same. The inclusive
|
|
1741 * flag affects this too, unless yanking and the end is on a NUL.
|
|
1742 */
|
|
1743 oap->empty = (oap->motion_type == MCHAR
|
|
1744 && (!oap->inclusive
|
|
1745 || (oap->op_type == OP_YANK
|
|
1746 && gchar_pos(&oap->end) == NUL))
|
|
1747 && equalpos(oap->start, oap->end)
|
|
1748 #ifdef FEAT_VIRTUALEDIT
|
|
1749 && !(virtual_op && oap->start.coladd != oap->end.coladd)
|
|
1750 #endif
|
|
1751 );
|
|
1752 /*
|
|
1753 * For delete, change and yank, it's an error to operate on an
|
|
1754 * empty region, when 'E' included in 'cpoptions' (Vi compatible).
|
|
1755 */
|
|
1756 empty_region_error = (oap->empty
|
|
1757 && vim_strchr(p_cpo, CPO_EMPTYREGION) != NULL);
|
|
1758
|
|
1759 #ifdef FEAT_VISUAL
|
|
1760 /* Force a redraw when operating on an empty Visual region, when
|
|
1761 * 'modifiable is off or creating a fold. */
|
|
1762 if (oap->is_VIsual && (oap->empty || !curbuf->b_p_ma
|
|
1763 # ifdef FEAT_FOLDING
|
|
1764 || oap->op_type == OP_FOLD
|
|
1765 # endif
|
|
1766 ))
|
|
1767 redraw_curbuf_later(INVERTED);
|
|
1768 #endif
|
|
1769
|
|
1770 /*
|
|
1771 * If the end of an operator is in column one while oap->motion_type
|
|
1772 * is MCHAR and oap->inclusive is FALSE, we put op_end after the last
|
|
1773 * character in the previous line. If op_start is on or before the
|
|
1774 * first non-blank in the line, the operator becomes linewise
|
|
1775 * (strange, but that's the way vi does it).
|
|
1776 */
|
|
1777 if ( oap->motion_type == MCHAR
|
|
1778 && oap->inclusive == FALSE
|
|
1779 && !(cap->retval & CA_NO_ADJ_OP_END)
|
|
1780 && oap->end.col == 0
|
|
1781 #ifdef FEAT_VISUAL
|
|
1782 && (!oap->is_VIsual || *p_sel == 'o')
|
47
|
1783 && !oap->block_mode
|
7
|
1784 #endif
|
|
1785 && oap->line_count > 1)
|
|
1786 {
|
|
1787 oap->end_adjusted = TRUE; /* remember that we did this */
|
|
1788 --oap->line_count;
|
|
1789 --oap->end.lnum;
|
|
1790 if (inindent(0))
|
|
1791 oap->motion_type = MLINE;
|
|
1792 else
|
|
1793 {
|
|
1794 oap->end.col = (colnr_T)STRLEN(ml_get(oap->end.lnum));
|
|
1795 if (oap->end.col)
|
|
1796 {
|
|
1797 --oap->end.col;
|
|
1798 oap->inclusive = TRUE;
|
|
1799 }
|
|
1800 }
|
|
1801 }
|
|
1802 else
|
|
1803 oap->end_adjusted = FALSE;
|
|
1804
|
|
1805 switch (oap->op_type)
|
|
1806 {
|
|
1807 case OP_LSHIFT:
|
|
1808 case OP_RSHIFT:
|
|
1809 op_shift(oap, TRUE,
|
|
1810 #ifdef FEAT_VISUAL
|
|
1811 oap->is_VIsual ? (int)cap->count1 :
|
|
1812 #endif
|
|
1813 1);
|
|
1814 auto_format(FALSE, TRUE);
|
|
1815 break;
|
|
1816
|
|
1817 case OP_JOIN_NS:
|
|
1818 case OP_JOIN:
|
|
1819 if (oap->line_count < 2)
|
|
1820 oap->line_count = 2;
|
|
1821 if (curwin->w_cursor.lnum + oap->line_count - 1 >
|
|
1822 curbuf->b_ml.ml_line_count)
|
|
1823 beep_flush();
|
|
1824 else
|
|
1825 {
|
|
1826 do_do_join(oap->line_count, oap->op_type == OP_JOIN);
|
|
1827 auto_format(FALSE, TRUE);
|
|
1828 }
|
|
1829 break;
|
|
1830
|
|
1831 case OP_DELETE:
|
|
1832 #ifdef FEAT_VISUAL
|
|
1833 VIsual_reselect = FALSE; /* don't reselect now */
|
|
1834 #endif
|
|
1835 if (empty_region_error)
|
|
1836 vim_beep();
|
|
1837 else
|
|
1838 {
|
|
1839 (void)op_delete(oap);
|
|
1840 if (oap->motion_type == MLINE && has_format_option(FO_AUTO))
|
|
1841 u_save_cursor(); /* cursor line wasn't saved yet */
|
|
1842 auto_format(FALSE, TRUE);
|
|
1843 }
|
|
1844 break;
|
|
1845
|
|
1846 case OP_YANK:
|
|
1847 if (empty_region_error)
|
|
1848 {
|
|
1849 if (!gui_yank)
|
|
1850 vim_beep();
|
|
1851 }
|
|
1852 else
|
|
1853 (void)op_yank(oap, FALSE, !gui_yank);
|
|
1854 check_cursor_col();
|
|
1855 break;
|
|
1856
|
|
1857 case OP_CHANGE:
|
|
1858 #ifdef FEAT_VISUAL
|
|
1859 VIsual_reselect = FALSE; /* don't reselect now */
|
|
1860 #endif
|
|
1861 if (empty_region_error)
|
|
1862 vim_beep();
|
|
1863 else
|
|
1864 {
|
|
1865 /* This is a new edit command, not a restart. Need to
|
|
1866 * remember it to make 'insertmode' work with mappings for
|
|
1867 * Visual mode. But do this only once and not when typed and
|
|
1868 * 'insertmode' isn't set. */
|
|
1869 if (p_im || !KeyTyped)
|
|
1870 restart_edit_save = restart_edit;
|
|
1871 else
|
|
1872 restart_edit_save = 0;
|
|
1873 restart_edit = 0;
|
|
1874 /* Reset finish_op now, don't want it set inside edit(). */
|
|
1875 finish_op = FALSE;
|
|
1876 if (op_change(oap)) /* will call edit() */
|
|
1877 cap->retval |= CA_COMMAND_BUSY;
|
|
1878 if (restart_edit == 0)
|
|
1879 restart_edit = restart_edit_save;
|
|
1880 }
|
|
1881 break;
|
|
1882
|
|
1883 case OP_FILTER:
|
|
1884 if (vim_strchr(p_cpo, CPO_FILTER) != NULL)
|
|
1885 AppendToRedobuff((char_u *)"!\r"); /* use any last used !cmd */
|
|
1886 else
|
|
1887 bangredo = TRUE; /* do_bang() will put cmd in redo buffer */
|
|
1888
|
|
1889 case OP_INDENT:
|
|
1890 case OP_COLON:
|
|
1891
|
|
1892 #if defined(FEAT_LISP) || defined(FEAT_CINDENT)
|
|
1893 /*
|
|
1894 * If 'equalprg' is empty, do the indenting internally.
|
|
1895 */
|
|
1896 if (oap->op_type == OP_INDENT && *get_equalprg() == NUL)
|
|
1897 {
|
|
1898 # ifdef FEAT_LISP
|
|
1899 if (curbuf->b_p_lisp)
|
|
1900 {
|
|
1901 op_reindent(oap, get_lisp_indent);
|
|
1902 break;
|
|
1903 }
|
|
1904 # endif
|
|
1905 # ifdef FEAT_CINDENT
|
|
1906 op_reindent(oap,
|
|
1907 # ifdef FEAT_EVAL
|
|
1908 *curbuf->b_p_inde != NUL ? get_expr_indent :
|
|
1909 # endif
|
|
1910 get_c_indent);
|
|
1911 break;
|
|
1912 # endif
|
|
1913 }
|
|
1914 #endif
|
|
1915
|
|
1916 op_colon(oap);
|
|
1917 break;
|
|
1918
|
|
1919 case OP_TILDE:
|
|
1920 case OP_UPPER:
|
|
1921 case OP_LOWER:
|
|
1922 case OP_ROT13:
|
|
1923 if (empty_region_error)
|
|
1924 vim_beep();
|
|
1925 else
|
|
1926 op_tilde(oap);
|
|
1927 check_cursor_col();
|
|
1928 break;
|
|
1929
|
|
1930 case OP_FORMAT:
|
|
1931 if (*p_fp != NUL)
|
|
1932 op_colon(oap); /* use external command */
|
|
1933 else
|
|
1934 op_format(oap, FALSE); /* use internal function */
|
|
1935 break;
|
|
1936
|
|
1937 case OP_FORMAT2:
|
|
1938 op_format(oap, TRUE); /* use internal function */
|
|
1939 break;
|
|
1940
|
|
1941 case OP_INSERT:
|
|
1942 case OP_APPEND:
|
|
1943 #ifdef FEAT_VISUAL
|
|
1944 VIsual_reselect = FALSE; /* don't reselect now */
|
|
1945 #endif
|
|
1946 #ifdef FEAT_VISUALEXTRA
|
|
1947 if (empty_region_error)
|
|
1948 vim_beep();
|
|
1949 else
|
|
1950 {
|
|
1951 /* This is a new edit command, not a restart. Need to
|
|
1952 * remember it to make 'insertmode' work with mappings for
|
|
1953 * Visual mode. But do this only once. */
|
|
1954 restart_edit_save = restart_edit;
|
|
1955 restart_edit = 0;
|
|
1956
|
|
1957 op_insert(oap, cap->count1);
|
|
1958
|
|
1959 /* TODO: when inserting in several lines, should format all
|
|
1960 * the lines. */
|
|
1961 auto_format(FALSE, TRUE);
|
|
1962
|
|
1963 if (restart_edit == 0)
|
|
1964 restart_edit = restart_edit_save;
|
|
1965 }
|
|
1966 #else
|
|
1967 vim_beep();
|
|
1968 #endif
|
|
1969 break;
|
|
1970
|
|
1971 case OP_REPLACE:
|
|
1972 #ifdef FEAT_VISUAL
|
|
1973 VIsual_reselect = FALSE; /* don't reselect now */
|
|
1974 #endif
|
|
1975 #ifdef FEAT_VISUALEXTRA
|
|
1976 if (empty_region_error)
|
|
1977 #endif
|
|
1978 vim_beep();
|
|
1979 #ifdef FEAT_VISUALEXTRA
|
|
1980 else
|
|
1981 op_replace(oap, cap->nchar);
|
|
1982 #endif
|
|
1983 break;
|
|
1984
|
|
1985 #ifdef FEAT_FOLDING
|
|
1986 case OP_FOLD:
|
|
1987 VIsual_reselect = FALSE; /* don't reselect now */
|
|
1988 foldCreate(oap->start.lnum, oap->end.lnum);
|
|
1989 break;
|
|
1990
|
|
1991 case OP_FOLDOPEN:
|
|
1992 case OP_FOLDOPENREC:
|
|
1993 case OP_FOLDCLOSE:
|
|
1994 case OP_FOLDCLOSEREC:
|
|
1995 VIsual_reselect = FALSE; /* don't reselect now */
|
|
1996 opFoldRange(oap->start.lnum, oap->end.lnum,
|
|
1997 oap->op_type == OP_FOLDOPEN
|
|
1998 || oap->op_type == OP_FOLDOPENREC,
|
|
1999 oap->op_type == OP_FOLDOPENREC
|
|
2000 || oap->op_type == OP_FOLDCLOSEREC,
|
|
2001 oap->is_VIsual);
|
|
2002 break;
|
|
2003
|
|
2004 case OP_FOLDDEL:
|
|
2005 case OP_FOLDDELREC:
|
|
2006 VIsual_reselect = FALSE; /* don't reselect now */
|
|
2007 deleteFold(oap->start.lnum, oap->end.lnum,
|
|
2008 oap->op_type == OP_FOLDDELREC, oap->is_VIsual);
|
|
2009 break;
|
|
2010 #endif
|
|
2011 default:
|
|
2012 clearopbeep(oap);
|
|
2013 }
|
|
2014 #ifdef FEAT_VIRTUALEDIT
|
|
2015 virtual_op = MAYBE;
|
|
2016 #endif
|
|
2017 if (!gui_yank)
|
|
2018 {
|
|
2019 /*
|
|
2020 * if 'sol' not set, go back to old column for some commands
|
|
2021 */
|
|
2022 if (!p_sol && oap->motion_type == MLINE && !oap->end_adjusted
|
|
2023 && (oap->op_type == OP_LSHIFT || oap->op_type == OP_RSHIFT
|
|
2024 || oap->op_type == OP_DELETE))
|
|
2025 coladvance(curwin->w_curswant = old_col);
|
|
2026 }
|
|
2027 else
|
|
2028 {
|
|
2029 curwin->w_cursor = old_cursor;
|
|
2030 }
|
|
2031 #ifdef FEAT_VISUAL
|
|
2032 oap->block_mode = FALSE;
|
|
2033 #endif
|
|
2034 clearop(oap);
|
|
2035 }
|
|
2036 }
|
|
2037
|
|
2038 /*
|
|
2039 * Handle indent and format operators and visual mode ":".
|
|
2040 */
|
|
2041 static void
|
|
2042 op_colon(oap)
|
|
2043 oparg_T *oap;
|
|
2044 {
|
|
2045 stuffcharReadbuff(':');
|
|
2046 #ifdef FEAT_VISUAL
|
|
2047 if (oap->is_VIsual)
|
|
2048 stuffReadbuff((char_u *)"'<,'>");
|
|
2049 else
|
|
2050 #endif
|
|
2051 {
|
|
2052 /*
|
|
2053 * Make the range look nice, so it can be repeated.
|
|
2054 */
|
|
2055 if (oap->start.lnum == curwin->w_cursor.lnum)
|
|
2056 stuffcharReadbuff('.');
|
|
2057 else
|
|
2058 stuffnumReadbuff((long)oap->start.lnum);
|
|
2059 if (oap->end.lnum != oap->start.lnum)
|
|
2060 {
|
|
2061 stuffcharReadbuff(',');
|
|
2062 if (oap->end.lnum == curwin->w_cursor.lnum)
|
|
2063 stuffcharReadbuff('.');
|
|
2064 else if (oap->end.lnum == curbuf->b_ml.ml_line_count)
|
|
2065 stuffcharReadbuff('$');
|
|
2066 else if (oap->start.lnum == curwin->w_cursor.lnum)
|
|
2067 {
|
|
2068 stuffReadbuff((char_u *)".+");
|
|
2069 stuffnumReadbuff((long)oap->line_count - 1);
|
|
2070 }
|
|
2071 else
|
|
2072 stuffnumReadbuff((long)oap->end.lnum);
|
|
2073 }
|
|
2074 }
|
|
2075 if (oap->op_type != OP_COLON)
|
|
2076 stuffReadbuff((char_u *)"!");
|
|
2077 if (oap->op_type == OP_INDENT)
|
|
2078 {
|
|
2079 #ifndef FEAT_CINDENT
|
|
2080 if (*get_equalprg() == NUL)
|
|
2081 stuffReadbuff((char_u *)"indent");
|
|
2082 else
|
|
2083 #endif
|
|
2084 stuffReadbuff(get_equalprg());
|
|
2085 stuffReadbuff((char_u *)"\n");
|
|
2086 }
|
|
2087 else if (oap->op_type == OP_FORMAT)
|
|
2088 {
|
|
2089 if (*p_fp == NUL)
|
|
2090 stuffReadbuff((char_u *)"fmt");
|
|
2091 else
|
|
2092 stuffReadbuff(p_fp);
|
216
|
2093 stuffReadbuff((char_u *)"\n']");
|
7
|
2094 }
|
|
2095
|
|
2096 /*
|
|
2097 * do_cmdline() does the rest
|
|
2098 */
|
|
2099 }
|
|
2100
|
|
2101 #if defined(FEAT_MOUSE) || defined(PROTO)
|
|
2102 /*
|
|
2103 * Do the appropriate action for the current mouse click in the current mode.
|
|
2104 * Not used for Command-line mode.
|
|
2105 *
|
|
2106 * Normal Mode:
|
|
2107 * event modi- position visual change action
|
|
2108 * fier cursor window
|
|
2109 * left press - yes end yes
|
|
2110 * left press C yes end yes "^]" (2)
|
|
2111 * left press S yes end yes "*" (2)
|
|
2112 * left drag - yes start if moved no
|
|
2113 * left relse - yes start if moved no
|
|
2114 * middle press - yes if not active no put register
|
|
2115 * middle press - yes if active no yank and put
|
|
2116 * right press - yes start or extend yes
|
|
2117 * right press S yes no change yes "#" (2)
|
|
2118 * right drag - yes extend no
|
|
2119 * right relse - yes extend no
|
|
2120 *
|
|
2121 * Insert or Replace Mode:
|
|
2122 * event modi- position visual change action
|
|
2123 * fier cursor window
|
|
2124 * left press - yes (cannot be active) yes
|
|
2125 * left press C yes (cannot be active) yes "CTRL-O^]" (2)
|
|
2126 * left press S yes (cannot be active) yes "CTRL-O*" (2)
|
|
2127 * left drag - yes start or extend (1) no CTRL-O (1)
|
|
2128 * left relse - yes start or extend (1) no CTRL-O (1)
|
|
2129 * middle press - no (cannot be active) no put register
|
|
2130 * right press - yes start or extend yes CTRL-O
|
|
2131 * right press S yes (cannot be active) yes "CTRL-O#" (2)
|
|
2132 *
|
|
2133 * (1) only if mouse pointer moved since press
|
|
2134 * (2) only if click is in same buffer
|
|
2135 *
|
|
2136 * Return TRUE if start_arrow() should be called for edit mode.
|
|
2137 */
|
|
2138 int
|
|
2139 do_mouse(oap, c, dir, count, fixindent)
|
|
2140 oparg_T *oap; /* operator argument, can be NULL */
|
|
2141 int c; /* K_LEFTMOUSE, etc */
|
|
2142 int dir; /* Direction to 'put' if necessary */
|
|
2143 long count;
|
|
2144 int fixindent; /* PUT_FIXINDENT if fixing indent necessary */
|
|
2145 {
|
|
2146 static int do_always = FALSE; /* ignore 'mouse' setting next time */
|
|
2147 static int got_click = FALSE; /* got a click some time back */
|
|
2148
|
|
2149 int which_button; /* MOUSE_LEFT, _MIDDLE or _RIGHT */
|
|
2150 int is_click; /* If FALSE it's a drag or release event */
|
|
2151 int is_drag; /* If TRUE it's a drag event */
|
|
2152 int jump_flags = 0; /* flags for jump_to_mouse() */
|
|
2153 pos_T start_visual;
|
|
2154 int moved; /* Has cursor moved? */
|
|
2155 int in_status_line; /* mouse in status line */
|
|
2156 #ifdef FEAT_VERTSPLIT
|
|
2157 int in_sep_line; /* mouse in vertical separator line */
|
|
2158 #endif
|
|
2159 int c1, c2;
|
|
2160 #if defined(FEAT_FOLDING)
|
|
2161 pos_T save_cursor;
|
|
2162 #endif
|
|
2163 win_T *old_curwin = curwin;
|
|
2164 #ifdef FEAT_VISUAL
|
|
2165 static pos_T orig_cursor;
|
|
2166 colnr_T leftcol, rightcol;
|
|
2167 pos_T end_visual;
|
|
2168 int diff;
|
|
2169 int old_active = VIsual_active;
|
|
2170 int old_mode = VIsual_mode;
|
|
2171 #endif
|
|
2172 int regname;
|
|
2173
|
|
2174 #if defined(FEAT_FOLDING)
|
|
2175 save_cursor = curwin->w_cursor;
|
|
2176 #endif
|
|
2177
|
|
2178 /*
|
|
2179 * When GUI is active, always recognize mouse events, otherwise:
|
|
2180 * - Ignore mouse event in normal mode if 'mouse' doesn't include 'n'.
|
|
2181 * - Ignore mouse event in visual mode if 'mouse' doesn't include 'v'.
|
|
2182 * - For command line and insert mode 'mouse' is checked before calling
|
|
2183 * do_mouse().
|
|
2184 */
|
|
2185 if (do_always)
|
|
2186 do_always = FALSE;
|
|
2187 else
|
|
2188 #ifdef FEAT_GUI
|
|
2189 if (!gui.in_use)
|
|
2190 #endif
|
|
2191 {
|
|
2192 #ifdef FEAT_VISUAL
|
|
2193 if (VIsual_active)
|
|
2194 {
|
|
2195 if (!mouse_has(MOUSE_VISUAL))
|
|
2196 return FALSE;
|
|
2197 }
|
|
2198 else
|
|
2199 #endif
|
|
2200 if (State == NORMAL && !mouse_has(MOUSE_NORMAL))
|
|
2201 return FALSE;
|
|
2202 }
|
|
2203
|
|
2204 which_button = get_mouse_button(KEY2TERMCAP1(c), &is_click, &is_drag);
|
|
2205
|
|
2206 #ifdef FEAT_MOUSESHAPE
|
|
2207 /* May have stopped dragging the status or separator line. The pointer is
|
|
2208 * most likely still on the status or separator line. */
|
|
2209 if (!is_drag && drag_status_line)
|
|
2210 {
|
|
2211 drag_status_line = FALSE;
|
|
2212 update_mouseshape(SHAPE_IDX_STATUS);
|
|
2213 }
|
|
2214 # ifdef FEAT_VERTSPLIT
|
|
2215 if (!is_drag && drag_sep_line)
|
|
2216 {
|
|
2217 drag_sep_line = FALSE;
|
|
2218 update_mouseshape(SHAPE_IDX_VSEP);
|
|
2219 }
|
|
2220 # endif
|
|
2221 #endif
|
|
2222
|
|
2223 /*
|
|
2224 * Ignore drag and release events if we didn't get a click.
|
|
2225 */
|
|
2226 if (is_click)
|
|
2227 got_click = TRUE;
|
|
2228 else
|
|
2229 {
|
|
2230 if (!got_click) /* didn't get click, ignore */
|
|
2231 return FALSE;
|
|
2232 if (!is_drag) /* release, reset got_click */
|
|
2233 got_click = FALSE;
|
|
2234 }
|
|
2235
|
|
2236 /*
|
|
2237 * ALT is currently ignored
|
|
2238 */
|
|
2239 if ((mod_mask & MOD_MASK_ALT))
|
|
2240 return FALSE;
|
|
2241
|
|
2242 /*
|
|
2243 * CTRL right mouse button does CTRL-T
|
|
2244 */
|
|
2245 if (is_click && (mod_mask & MOD_MASK_CTRL) && which_button == MOUSE_RIGHT)
|
|
2246 {
|
|
2247 if (State & INSERT)
|
|
2248 stuffcharReadbuff(Ctrl_O);
|
|
2249 if (count > 1)
|
|
2250 stuffnumReadbuff(count);
|
|
2251 stuffcharReadbuff(Ctrl_T);
|
|
2252 got_click = FALSE; /* ignore drag&release now */
|
|
2253 return FALSE;
|
|
2254 }
|
|
2255
|
|
2256 /*
|
|
2257 * CTRL only works with left mouse button
|
|
2258 */
|
|
2259 if ((mod_mask & MOD_MASK_CTRL) && which_button != MOUSE_LEFT)
|
|
2260 return FALSE;
|
|
2261
|
|
2262 /*
|
|
2263 * When a modifier is down, ignore drag and release events, as well as
|
|
2264 * multiple clicks and the middle mouse button.
|
|
2265 * Accept shift-leftmouse drags when 'mousemodel' is "popup.*".
|
|
2266 */
|
179
|
2267 if ((mod_mask & (MOD_MASK_SHIFT | MOD_MASK_CTRL | MOD_MASK_ALT
|
|
2268 | MOD_MASK_META))
|
7
|
2269 && (!is_click
|
|
2270 || (mod_mask & MOD_MASK_MULTI_CLICK)
|
|
2271 || which_button == MOUSE_MIDDLE)
|
|
2272 && !((mod_mask & MOD_MASK_SHIFT)
|
|
2273 && mouse_model_popup()
|
|
2274 && which_button == MOUSE_LEFT)
|
|
2275 )
|
|
2276 return FALSE;
|
|
2277
|
|
2278 /*
|
|
2279 * If the button press was used as the movement command for an operator
|
|
2280 * (eg "d<MOUSE>"), or it is the middle button that is held down, ignore
|
|
2281 * drag/release events.
|
|
2282 */
|
|
2283 if (!is_click && which_button == MOUSE_MIDDLE)
|
|
2284 return FALSE;
|
|
2285
|
|
2286 if (oap != NULL)
|
|
2287 regname = oap->regname;
|
|
2288 else
|
|
2289 regname = 0;
|
|
2290
|
|
2291 /*
|
|
2292 * Middle mouse button does a 'put' of the selected text
|
|
2293 */
|
|
2294 if (which_button == MOUSE_MIDDLE)
|
|
2295 {
|
|
2296 if (State == NORMAL)
|
|
2297 {
|
|
2298 /*
|
|
2299 * If an operator was pending, we don't know what the user wanted
|
|
2300 * to do. Go back to normal mode: Clear the operator and beep().
|
|
2301 */
|
|
2302 if (oap != NULL && oap->op_type != OP_NOP)
|
|
2303 {
|
|
2304 clearopbeep(oap);
|
|
2305 return FALSE;
|
|
2306 }
|
|
2307
|
|
2308 #ifdef FEAT_VISUAL
|
|
2309 /*
|
|
2310 * If visual was active, yank the highlighted text and put it
|
|
2311 * before the mouse pointer position.
|
|
2312 */
|
|
2313 if (VIsual_active)
|
|
2314 {
|
|
2315 stuffcharReadbuff('y');
|
|
2316 stuffcharReadbuff(K_MIDDLEMOUSE);
|
|
2317 do_always = TRUE; /* ignore 'mouse' setting next time */
|
|
2318 return FALSE;
|
|
2319 }
|
|
2320 #endif
|
|
2321 /*
|
|
2322 * The rest is below jump_to_mouse()
|
|
2323 */
|
|
2324 }
|
|
2325
|
|
2326 else if ((State & INSERT) == 0)
|
|
2327 return FALSE;
|
|
2328
|
|
2329 /*
|
|
2330 * Middle click in insert mode doesn't move the mouse, just insert the
|
|
2331 * contents of a register. '.' register is special, can't insert that
|
|
2332 * with do_put().
|
|
2333 * Also paste at the cursor if the current mode isn't in 'mouse' (only
|
|
2334 * happens for the GUI).
|
|
2335 */
|
|
2336 if ((State & INSERT) || !mouse_has(MOUSE_NORMAL))
|
|
2337 {
|
|
2338 if (regname == '.')
|
|
2339 insert_reg(regname, TRUE);
|
|
2340 else
|
|
2341 {
|
|
2342 #ifdef FEAT_CLIPBOARD
|
|
2343 if (clip_star.available && regname == 0)
|
|
2344 regname = '*';
|
|
2345 #endif
|
|
2346 if ((State & REPLACE_FLAG) && !yank_register_mline(regname))
|
|
2347 insert_reg(regname, TRUE);
|
|
2348 else
|
|
2349 {
|
|
2350 do_put(regname, BACKWARD, 1L, fixindent | PUT_CURSEND);
|
|
2351
|
|
2352 /* Repeat it with CTRL-R CTRL-O r or CTRL-R CTRL-P r */
|
|
2353 AppendCharToRedobuff(Ctrl_R);
|
|
2354 AppendCharToRedobuff(fixindent ? Ctrl_P : Ctrl_O);
|
|
2355 AppendCharToRedobuff(regname == 0 ? '"' : regname);
|
|
2356 }
|
|
2357 }
|
|
2358 return FALSE;
|
|
2359 }
|
|
2360 }
|
|
2361
|
|
2362 /* When dragging or button-up stay in the same window. */
|
|
2363 if (!is_click)
|
|
2364 jump_flags |= MOUSE_FOCUS | MOUSE_DID_MOVE;
|
|
2365
|
|
2366 start_visual.lnum = 0;
|
|
2367
|
|
2368 /*
|
|
2369 * When 'mousemodel' is "popup" or "popup_setpos", translate mouse events:
|
|
2370 * right button up -> pop-up menu
|
|
2371 * shift-left button -> right button
|
|
2372 */
|
|
2373 if (mouse_model_popup())
|
|
2374 {
|
|
2375 if (which_button == MOUSE_RIGHT
|
|
2376 && !(mod_mask & (MOD_MASK_SHIFT | MOD_MASK_CTRL)))
|
|
2377 {
|
|
2378 /*
|
|
2379 * NOTE: Ignore right button down and drag mouse events.
|
|
2380 * Windows only shows the popup menu on the button up event.
|
|
2381 */
|
11
|
2382 #if defined(FEAT_GUI_MOTIF) || defined(FEAT_GUI_GTK) || defined(FEAT_GUI_PHOTON) || defined(FEAT_GUI_KDE)
|
7
|
2383 if (!is_click)
|
|
2384 return FALSE;
|
|
2385 #endif
|
|
2386 #if defined(FEAT_GUI_ATHENA) || defined(FEAT_GUI_MSWIN)
|
|
2387 if (is_click || is_drag)
|
|
2388 return FALSE;
|
|
2389 #endif
|
11
|
2390 #if defined(FEAT_GUI_MOTIF) || defined(FEAT_GUI_GTK) || defined(FEAT_GUI_KDE) \
|
7
|
2391 || defined(FEAT_GUI_ATHENA) || defined(FEAT_GUI_MSWIN) \
|
|
2392 || defined(FEAT_GUI_MAC) || defined(FEAT_GUI_PHOTON)
|
|
2393 if (gui.in_use)
|
|
2394 {
|
|
2395 jump_flags = 0;
|
|
2396 if (STRCMP(p_mousem, "popup_setpos") == 0)
|
|
2397 {
|
|
2398 /* First set the cursor position before showing the popup
|
|
2399 * menu. */
|
|
2400 #ifdef FEAT_VISUAL
|
|
2401 if (VIsual_active)
|
|
2402 {
|
|
2403 pos_T m_pos;
|
|
2404
|
|
2405 /*
|
|
2406 * set MOUSE_MAY_STOP_VIS if we are outside the
|
|
2407 * selection or the current window (might have false
|
|
2408 * negative here)
|
|
2409 */
|
|
2410 if (mouse_row < W_WINROW(curwin)
|
|
2411 || mouse_row
|
|
2412 > (W_WINROW(curwin) + curwin->w_height))
|
|
2413 jump_flags = MOUSE_MAY_STOP_VIS;
|
|
2414 else if (get_fpos_of_mouse(&m_pos) != IN_BUFFER)
|
|
2415 jump_flags = MOUSE_MAY_STOP_VIS;
|
|
2416 else
|
|
2417 {
|
|
2418 if ((lt(curwin->w_cursor, VIsual)
|
|
2419 && (lt(m_pos, curwin->w_cursor)
|
|
2420 || lt(VIsual, m_pos)))
|
|
2421 || (lt(VIsual, curwin->w_cursor)
|
|
2422 && (lt(m_pos, VIsual)
|
|
2423 || lt(curwin->w_cursor, m_pos))))
|
|
2424 {
|
|
2425 jump_flags = MOUSE_MAY_STOP_VIS;
|
|
2426 }
|
|
2427 else if (VIsual_mode == Ctrl_V)
|
|
2428 {
|
|
2429 getvcols(curwin, &curwin->w_cursor, &VIsual,
|
|
2430 &leftcol, &rightcol);
|
|
2431 getvcol(curwin, &m_pos, NULL, &m_pos.col, NULL);
|
|
2432 if (m_pos.col < leftcol || m_pos.col > rightcol)
|
|
2433 jump_flags = MOUSE_MAY_STOP_VIS;
|
|
2434 }
|
|
2435 }
|
|
2436 }
|
|
2437 else
|
|
2438 jump_flags = MOUSE_MAY_STOP_VIS;
|
|
2439 #endif
|
|
2440 }
|
|
2441 if (jump_flags)
|
|
2442 {
|
|
2443 jump_flags = jump_to_mouse(jump_flags, NULL, which_button);
|
|
2444 update_curbuf(
|
|
2445 #ifdef FEAT_VISUAL
|
|
2446 VIsual_active ? INVERTED :
|
|
2447 #endif
|
|
2448 VALID);
|
|
2449 setcursor();
|
|
2450 out_flush(); /* Update before showing popup menu */
|
|
2451 }
|
|
2452 # ifdef FEAT_MENU
|
|
2453 gui_show_popupmenu();
|
|
2454 # endif
|
|
2455 return (jump_flags & CURSOR_MOVED) != 0;
|
|
2456 }
|
|
2457 else
|
|
2458 return FALSE;
|
|
2459 #else
|
|
2460 return FALSE;
|
|
2461 #endif
|
|
2462 }
|
|
2463 if (which_button == MOUSE_LEFT && (mod_mask & MOD_MASK_SHIFT))
|
|
2464 {
|
|
2465 which_button = MOUSE_RIGHT;
|
|
2466 mod_mask &= ~MOD_MASK_SHIFT;
|
|
2467 }
|
|
2468 }
|
|
2469
|
|
2470 #ifdef FEAT_VISUAL
|
|
2471 if ((State & (NORMAL | INSERT))
|
|
2472 && !(mod_mask & (MOD_MASK_SHIFT | MOD_MASK_CTRL)))
|
|
2473 {
|
|
2474 if (which_button == MOUSE_LEFT)
|
|
2475 {
|
|
2476 if (is_click)
|
|
2477 {
|
|
2478 /* stop Visual mode for a left click in a window, but not when
|
|
2479 * on a status line */
|
|
2480 if (VIsual_active)
|
|
2481 jump_flags |= MOUSE_MAY_STOP_VIS;
|
|
2482 }
|
|
2483 else if (mouse_has(MOUSE_VISUAL))
|
|
2484 jump_flags |= MOUSE_MAY_VIS;
|
|
2485 }
|
|
2486 else if (which_button == MOUSE_RIGHT)
|
|
2487 {
|
|
2488 if (is_click && VIsual_active)
|
|
2489 {
|
|
2490 /*
|
|
2491 * Remember the start and end of visual before moving the
|
|
2492 * cursor.
|
|
2493 */
|
|
2494 if (lt(curwin->w_cursor, VIsual))
|
|
2495 {
|
|
2496 start_visual = curwin->w_cursor;
|
|
2497 end_visual = VIsual;
|
|
2498 }
|
|
2499 else
|
|
2500 {
|
|
2501 start_visual = VIsual;
|
|
2502 end_visual = curwin->w_cursor;
|
|
2503 }
|
|
2504 }
|
|
2505 jump_flags |= MOUSE_FOCUS;
|
|
2506 if (mouse_has(MOUSE_VISUAL))
|
|
2507 jump_flags |= MOUSE_MAY_VIS;
|
|
2508 }
|
|
2509 }
|
|
2510 #endif
|
|
2511
|
|
2512 /*
|
|
2513 * If an operator is pending, ignore all drags and releases until the
|
|
2514 * next mouse click.
|
|
2515 */
|
|
2516 if (!is_drag && oap != NULL && oap->op_type != OP_NOP)
|
|
2517 {
|
|
2518 got_click = FALSE;
|
|
2519 oap->motion_type = MCHAR;
|
|
2520 }
|
|
2521
|
|
2522 /* When releasing the button let jump_to_mouse() know. */
|
|
2523 if (!is_click && !is_drag)
|
|
2524 jump_flags |= MOUSE_RELEASED;
|
|
2525
|
|
2526 /*
|
|
2527 * JUMP!
|
|
2528 */
|
|
2529 jump_flags = jump_to_mouse(jump_flags,
|
|
2530 oap == NULL ? NULL : &(oap->inclusive), which_button);
|
|
2531 moved = (jump_flags & CURSOR_MOVED);
|
|
2532 in_status_line = (jump_flags & IN_STATUS_LINE);
|
|
2533 #ifdef FEAT_VERTSPLIT
|
|
2534 in_sep_line = (jump_flags & IN_SEP_LINE);
|
|
2535 #endif
|
|
2536
|
|
2537 #ifdef FEAT_NETBEANS_INTG
|
|
2538 if (usingNetbeans && isNetbeansBuffer(curbuf)
|
|
2539 && !(jump_flags & (IN_STATUS_LINE | IN_SEP_LINE)))
|
|
2540 {
|
|
2541 int key = KEY2TERMCAP1(c);
|
|
2542
|
|
2543 if (key == (int)KE_LEFTRELEASE || key == (int)KE_MIDDLERELEASE
|
|
2544 || key == (int)KE_RIGHTRELEASE)
|
|
2545 netbeans_button_release(which_button);
|
|
2546 }
|
|
2547 #endif
|
|
2548
|
|
2549 /* When jumping to another window, clear a pending operator. That's a bit
|
|
2550 * friendlier than beeping and not jumping to that window. */
|
|
2551 if (curwin != old_curwin && oap != NULL && oap->op_type != OP_NOP)
|
|
2552 clearop(oap);
|
|
2553
|
|
2554 #ifdef FEAT_FOLDING
|
|
2555 if (mod_mask == 0
|
|
2556 && !is_drag
|
|
2557 && (jump_flags & (MOUSE_FOLD_CLOSE | MOUSE_FOLD_OPEN))
|
|
2558 && which_button == MOUSE_LEFT)
|
|
2559 {
|
|
2560 /* open or close a fold at this line */
|
|
2561 if (jump_flags & MOUSE_FOLD_OPEN)
|
|
2562 openFold(curwin->w_cursor.lnum, 1L);
|
|
2563 else
|
|
2564 closeFold(curwin->w_cursor.lnum, 1L);
|
|
2565 /* don't move the cursor if still in the same window */
|
|
2566 if (curwin == old_curwin)
|
|
2567 curwin->w_cursor = save_cursor;
|
|
2568 }
|
|
2569 #endif
|
|
2570
|
|
2571 #if defined(FEAT_CLIPBOARD) && defined(FEAT_CMDWIN)
|
|
2572 if ((jump_flags & IN_OTHER_WIN) && !VIsual_active && clip_star.available)
|
|
2573 {
|
|
2574 clip_modeless(which_button, is_click, is_drag);
|
|
2575 return FALSE;
|
|
2576 }
|
|
2577 #endif
|
|
2578
|
|
2579 #ifdef FEAT_VISUAL
|
|
2580 /* Set global flag that we are extending the Visual area with mouse
|
|
2581 * dragging; temporarily mimimize 'scrolloff'. */
|
|
2582 if (VIsual_active && is_drag && p_so)
|
|
2583 {
|
|
2584 /* In the very first line, allow scrolling one line */
|
|
2585 if (mouse_row == 0)
|
|
2586 mouse_dragging = 2;
|
|
2587 else
|
|
2588 mouse_dragging = 1;
|
|
2589 }
|
|
2590
|
|
2591 /* When dragging the mouse above the window, scroll down. */
|
|
2592 if (is_drag && mouse_row < 0 && !in_status_line)
|
|
2593 {
|
|
2594 scroll_redraw(FALSE, 1L);
|
|
2595 mouse_row = 0;
|
|
2596 }
|
|
2597
|
|
2598 if (start_visual.lnum) /* right click in visual mode */
|
|
2599 {
|
|
2600 /*
|
|
2601 * In Visual-block mode, divide the area in four, pick up the corner
|
|
2602 * that is in the quarter that the cursor is in.
|
|
2603 */
|
|
2604 if (VIsual_mode == Ctrl_V)
|
|
2605 {
|
|
2606 getvcols(curwin, &start_visual, &end_visual, &leftcol, &rightcol);
|
|
2607 if (curwin->w_curswant > (leftcol + rightcol) / 2)
|
|
2608 end_visual.col = leftcol;
|
|
2609 else
|
|
2610 end_visual.col = rightcol;
|
|
2611 if (curwin->w_cursor.lnum <
|
|
2612 (start_visual.lnum + end_visual.lnum) / 2)
|
|
2613 end_visual.lnum = end_visual.lnum;
|
|
2614 else
|
|
2615 end_visual.lnum = start_visual.lnum;
|
|
2616
|
|
2617 /* move VIsual to the right column */
|
|
2618 start_visual = curwin->w_cursor; /* save the cursor pos */
|
|
2619 curwin->w_cursor = end_visual;
|
|
2620 coladvance(end_visual.col);
|
|
2621 VIsual = curwin->w_cursor;
|
|
2622 curwin->w_cursor = start_visual; /* restore the cursor */
|
|
2623 }
|
|
2624 else
|
|
2625 {
|
|
2626 /*
|
|
2627 * If the click is before the start of visual, change the start.
|
|
2628 * If the click is after the end of visual, change the end. If
|
|
2629 * the click is inside the visual, change the closest side.
|
|
2630 */
|
|
2631 if (lt(curwin->w_cursor, start_visual))
|
|
2632 VIsual = end_visual;
|
|
2633 else if (lt(end_visual, curwin->w_cursor))
|
|
2634 VIsual = start_visual;
|
|
2635 else
|
|
2636 {
|
|
2637 /* In the same line, compare column number */
|
|
2638 if (end_visual.lnum == start_visual.lnum)
|
|
2639 {
|
|
2640 if (curwin->w_cursor.col - start_visual.col >
|
|
2641 end_visual.col - curwin->w_cursor.col)
|
|
2642 VIsual = start_visual;
|
|
2643 else
|
|
2644 VIsual = end_visual;
|
|
2645 }
|
|
2646
|
|
2647 /* In different lines, compare line number */
|
|
2648 else
|
|
2649 {
|
|
2650 diff = (curwin->w_cursor.lnum - start_visual.lnum) -
|
|
2651 (end_visual.lnum - curwin->w_cursor.lnum);
|
|
2652
|
|
2653 if (diff > 0) /* closest to end */
|
|
2654 VIsual = start_visual;
|
|
2655 else if (diff < 0) /* closest to start */
|
|
2656 VIsual = end_visual;
|
|
2657 else /* in the middle line */
|
|
2658 {
|
|
2659 if (curwin->w_cursor.col <
|
|
2660 (start_visual.col + end_visual.col) / 2)
|
|
2661 VIsual = end_visual;
|
|
2662 else
|
|
2663 VIsual = start_visual;
|
|
2664 }
|
|
2665 }
|
|
2666 }
|
|
2667 }
|
|
2668 }
|
|
2669 /*
|
|
2670 * If Visual mode started in insert mode, execute "CTRL-O"
|
|
2671 */
|
|
2672 else if ((State & INSERT) && VIsual_active)
|
|
2673 stuffcharReadbuff(Ctrl_O);
|
|
2674 #endif
|
|
2675
|
|
2676 /*
|
|
2677 * Middle mouse click: Put text before cursor.
|
|
2678 */
|
|
2679 if (which_button == MOUSE_MIDDLE)
|
|
2680 {
|
|
2681 #ifdef FEAT_CLIPBOARD
|
|
2682 if (clip_star.available && regname == 0)
|
|
2683 regname = '*';
|
|
2684 #endif
|
|
2685 if (yank_register_mline(regname))
|
|
2686 {
|
|
2687 if (mouse_past_bottom)
|
|
2688 dir = FORWARD;
|
|
2689 }
|
|
2690 else if (mouse_past_eol)
|
|
2691 dir = FORWARD;
|
|
2692
|
|
2693 if (fixindent)
|
|
2694 {
|
|
2695 c1 = (dir == BACKWARD) ? '[' : ']';
|
|
2696 c2 = 'p';
|
|
2697 }
|
|
2698 else
|
|
2699 {
|
|
2700 c1 = (dir == FORWARD) ? 'p' : 'P';
|
|
2701 c2 = NUL;
|
|
2702 }
|
|
2703 prep_redo(regname, count, NUL, c1, NUL, c2, NUL);
|
|
2704
|
|
2705 /*
|
|
2706 * Remember where the paste started, so in edit() Insstart can be set
|
|
2707 * to this position
|
|
2708 */
|
|
2709 if (restart_edit != 0)
|
|
2710 where_paste_started = curwin->w_cursor;
|
|
2711 do_put(regname, dir, count, fixindent | PUT_CURSEND);
|
|
2712 }
|
|
2713
|
|
2714 #if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
|
|
2715 /*
|
|
2716 * Ctrl-Mouse click or double click in a quickfix window jumps to the
|
|
2717 * error under the mouse pointer.
|
|
2718 */
|
|
2719 else if (((mod_mask & MOD_MASK_CTRL)
|
|
2720 || (mod_mask & MOD_MASK_MULTI_CLICK) == MOD_MASK_2CLICK)
|
|
2721 && bt_quickfix(curbuf))
|
|
2722 {
|
|
2723 if (State & INSERT)
|
|
2724 stuffcharReadbuff(Ctrl_O);
|
|
2725 stuffReadbuff((char_u *)":.cc\n");
|
|
2726 got_click = FALSE; /* ignore drag&release now */
|
|
2727 }
|
|
2728 #endif
|
|
2729
|
|
2730 /*
|
|
2731 * Ctrl-Mouse click (or double click in a help window) jumps to the tag
|
|
2732 * under the mouse pointer.
|
|
2733 */
|
|
2734 else if ((mod_mask & MOD_MASK_CTRL) || (curbuf->b_help
|
|
2735 && (mod_mask & MOD_MASK_MULTI_CLICK) == MOD_MASK_2CLICK))
|
|
2736 {
|
|
2737 if (State & INSERT)
|
|
2738 stuffcharReadbuff(Ctrl_O);
|
|
2739 stuffcharReadbuff(Ctrl_RSB);
|
|
2740 got_click = FALSE; /* ignore drag&release now */
|
|
2741 }
|
|
2742
|
|
2743 /*
|
|
2744 * Shift-Mouse click searches for the next occurrence of the word under
|
|
2745 * the mouse pointer
|
|
2746 */
|
|
2747 else if ((mod_mask & MOD_MASK_SHIFT))
|
|
2748 {
|
|
2749 if (State & INSERT
|
|
2750 #ifdef FEAT_VISUAL
|
|
2751 || (VIsual_active && VIsual_select)
|
|
2752 #endif
|
|
2753 )
|
|
2754 stuffcharReadbuff(Ctrl_O);
|
|
2755 if (which_button == MOUSE_LEFT)
|
|
2756 stuffcharReadbuff('*');
|
|
2757 else /* MOUSE_RIGHT */
|
|
2758 stuffcharReadbuff('#');
|
|
2759 }
|
|
2760
|
|
2761 /* Handle double clicks, unless on status line */
|
|
2762 else if (in_status_line)
|
|
2763 {
|
|
2764 #ifdef FEAT_MOUSESHAPE
|
|
2765 if ((is_drag || is_click) && !drag_status_line)
|
|
2766 {
|
|
2767 drag_status_line = TRUE;
|
|
2768 update_mouseshape(-1);
|
|
2769 }
|
|
2770 #endif
|
|
2771 }
|
|
2772 #ifdef FEAT_VERTSPLIT
|
|
2773 else if (in_sep_line)
|
|
2774 {
|
|
2775 # ifdef FEAT_MOUSESHAPE
|
|
2776 if ((is_drag || is_click) && !drag_sep_line)
|
|
2777 {
|
|
2778 drag_sep_line = TRUE;
|
|
2779 update_mouseshape(-1);
|
|
2780 }
|
|
2781 # endif
|
|
2782 }
|
|
2783 #endif
|
|
2784 #ifdef FEAT_VISUAL
|
|
2785 else if ((mod_mask & MOD_MASK_MULTI_CLICK) && (State & (NORMAL | INSERT))
|
|
2786 && mouse_has(MOUSE_VISUAL))
|
|
2787 {
|
|
2788 if (is_click || !VIsual_active)
|
|
2789 {
|
|
2790 if (VIsual_active)
|
|
2791 orig_cursor = VIsual;
|
|
2792 else
|
|
2793 {
|
|
2794 check_visual_highlight();
|
|
2795 VIsual = curwin->w_cursor;
|
|
2796 orig_cursor = VIsual;
|
|
2797 VIsual_active = TRUE;
|
|
2798 VIsual_reselect = TRUE;
|
|
2799 /* start Select mode if 'selectmode' contains "mouse" */
|
|
2800 may_start_select('o');
|
|
2801 setmouse();
|
|
2802 }
|
|
2803 if ((mod_mask & MOD_MASK_MULTI_CLICK) == MOD_MASK_2CLICK)
|
|
2804 VIsual_mode = 'v';
|
|
2805 else if ((mod_mask & MOD_MASK_MULTI_CLICK) == MOD_MASK_3CLICK)
|
|
2806 VIsual_mode = 'V';
|
|
2807 else if ((mod_mask & MOD_MASK_MULTI_CLICK) == MOD_MASK_4CLICK)
|
|
2808 VIsual_mode = Ctrl_V;
|
|
2809 #ifdef FEAT_CLIPBOARD
|
|
2810 /* Make sure the clipboard gets updated. Needed because start and
|
|
2811 * end may still be the same, and the selection needs to be owned */
|
|
2812 clip_star.vmode = NUL;
|
|
2813 #endif
|
|
2814 }
|
|
2815 /*
|
|
2816 * A double click selects a word or a block.
|
|
2817 */
|
|
2818 if ((mod_mask & MOD_MASK_MULTI_CLICK) == MOD_MASK_2CLICK)
|
|
2819 {
|
|
2820 pos_T *pos = NULL;
|
|
2821
|
|
2822 if (is_click)
|
|
2823 {
|
|
2824 /* If the character under the cursor (skipping white space) is
|
|
2825 * not a word character, try finding a match and select a (),
|
|
2826 * {}, [], #if/#endif, etc. block. */
|
|
2827 end_visual = curwin->w_cursor;
|
|
2828 while (vim_iswhite(gchar_pos(&end_visual)))
|
|
2829 inc(&end_visual);
|
|
2830 if (oap != NULL)
|
|
2831 oap->motion_type = MCHAR;
|
|
2832 if (oap != NULL
|
|
2833 && VIsual_mode == 'v'
|
|
2834 && !vim_iswordc(gchar_pos(&end_visual))
|
|
2835 && equalpos(curwin->w_cursor, VIsual)
|
|
2836 && (pos = findmatch(oap, NUL)) != NULL)
|
|
2837 {
|
|
2838 curwin->w_cursor = *pos;
|
|
2839 if (oap->motion_type == MLINE)
|
|
2840 VIsual_mode = 'V';
|
|
2841 else if (*p_sel == 'e')
|
|
2842 {
|
|
2843 if (lt(curwin->w_cursor, VIsual))
|
|
2844 ++VIsual.col;
|
|
2845 else
|
|
2846 ++curwin->w_cursor.col;
|
|
2847 }
|
|
2848 }
|
|
2849 }
|
|
2850
|
|
2851 if (pos == NULL && (is_click || is_drag))
|
|
2852 {
|
|
2853 /* When not found a match or when dragging: extend to include
|
|
2854 * a word. */
|
|
2855 if (lt(curwin->w_cursor, orig_cursor))
|
|
2856 {
|
|
2857 find_start_of_word(&curwin->w_cursor);
|
|
2858 find_end_of_word(&VIsual);
|
|
2859 }
|
|
2860 else
|
|
2861 {
|
|
2862 find_start_of_word(&VIsual);
|
|
2863 if (*p_sel == 'e' && *ml_get_cursor() != NUL)
|
|
2864 #ifdef FEAT_MBYTE
|
|
2865 curwin->w_cursor.col +=
|
|
2866 (*mb_ptr2len_check)(ml_get_cursor());
|
|
2867 #else
|
|
2868 ++curwin->w_cursor.col;
|
|
2869 #endif
|
|
2870 find_end_of_word(&curwin->w_cursor);
|
|
2871 }
|
|
2872 }
|
|
2873 curwin->w_set_curswant = TRUE;
|
|
2874 }
|
|
2875 if (is_click)
|
|
2876 redraw_curbuf_later(INVERTED); /* update the inversion */
|
|
2877 }
|
|
2878 else if (VIsual_active && !old_active)
|
|
2879 VIsual_mode = 'v';
|
|
2880
|
|
2881 /* If Visual mode changed show it later. */
|
|
2882 if (p_smd && (VIsual_active != old_active || VIsual_mode != old_mode))
|
|
2883 redraw_cmdline = TRUE;
|
|
2884 #endif
|
|
2885
|
|
2886 return moved;
|
|
2887 }
|
|
2888
|
|
2889 #ifdef FEAT_VISUAL
|
|
2890 /*
|
|
2891 * Move "pos" back to the start of the word it's in.
|
|
2892 */
|
|
2893 static void
|
|
2894 find_start_of_word(pos)
|
|
2895 pos_T *pos;
|
|
2896 {
|
|
2897 char_u *line;
|
|
2898 int cclass;
|
|
2899 int col;
|
|
2900
|
|
2901 line = ml_get(pos->lnum);
|
|
2902 cclass = get_mouse_class(line + pos->col);
|
|
2903
|
|
2904 while (pos->col > 0)
|
|
2905 {
|
|
2906 col = pos->col - 1;
|
|
2907 #ifdef FEAT_MBYTE
|
|
2908 col -= (*mb_head_off)(line, line + col);
|
|
2909 #endif
|
|
2910 if (get_mouse_class(line + col) != cclass)
|
|
2911 break;
|
|
2912 pos->col = col;
|
|
2913 }
|
|
2914 }
|
|
2915
|
|
2916 /*
|
|
2917 * Move "pos" forward to the end of the word it's in.
|
|
2918 * When 'selection' is "exclusive", the position is just after the word.
|
|
2919 */
|
|
2920 static void
|
|
2921 find_end_of_word(pos)
|
|
2922 pos_T *pos;
|
|
2923 {
|
|
2924 char_u *line;
|
|
2925 int cclass;
|
|
2926 int col;
|
|
2927
|
|
2928 line = ml_get(pos->lnum);
|
|
2929 if (*p_sel == 'e' && pos->col > 0)
|
|
2930 {
|
|
2931 --pos->col;
|
|
2932 #ifdef FEAT_MBYTE
|
|
2933 pos->col -= (*mb_head_off)(line, line + pos->col);
|
|
2934 #endif
|
|
2935 }
|
|
2936 cclass = get_mouse_class(line + pos->col);
|
|
2937 while (line[pos->col] != NUL)
|
|
2938 {
|
|
2939 #ifdef FEAT_MBYTE
|
|
2940 col = pos->col + (*mb_ptr2len_check)(line + pos->col);
|
|
2941 #else
|
|
2942 col = pos->col + 1;
|
|
2943 #endif
|
|
2944 if (get_mouse_class(line + col) != cclass)
|
|
2945 {
|
|
2946 if (*p_sel == 'e')
|
|
2947 pos->col = col;
|
|
2948 break;
|
|
2949 }
|
|
2950 pos->col = col;
|
|
2951 }
|
|
2952 }
|
|
2953
|
|
2954 /*
|
|
2955 * Get class of a character for selection: same class means same word.
|
|
2956 * 0: blank
|
|
2957 * 1: punctuation groups
|
|
2958 * 2: normal word character
|
|
2959 * >2: multi-byte word character.
|
|
2960 */
|
|
2961 static int
|
|
2962 get_mouse_class(p)
|
|
2963 char_u *p;
|
|
2964 {
|
|
2965 int c;
|
|
2966
|
|
2967 #ifdef FEAT_MBYTE
|
|
2968 if (has_mbyte && MB_BYTE2LEN(p[0]) > 1)
|
|
2969 return mb_get_class(p);
|
|
2970 #endif
|
|
2971
|
|
2972 c = *p;
|
|
2973 if (c == ' ' || c == '\t')
|
|
2974 return 0;
|
|
2975
|
|
2976 if (vim_iswordc(c))
|
|
2977 return 2;
|
|
2978
|
|
2979 /*
|
|
2980 * There are a few special cases where we want certain combinations of
|
|
2981 * characters to be considered as a single word. These are things like
|
|
2982 * "->", "/ *", "*=", "+=", "&=", "<=", ">=", "!=" etc. Otherwise, each
|
|
2983 * character is in it's own class.
|
|
2984 */
|
|
2985 if (c != NUL && vim_strchr((char_u *)"-+*/%<>&|^!=", c) != NULL)
|
|
2986 return 1;
|
|
2987 return c;
|
|
2988 }
|
|
2989 #endif /* FEAT_VISUAL */
|
|
2990 #endif /* FEAT_MOUSE */
|
|
2991
|
|
2992 #if defined(FEAT_VISUAL) || defined(PROTO)
|
|
2993 /*
|
|
2994 * Check if highlighting for visual mode is possible, give a warning message
|
|
2995 * if not.
|
|
2996 */
|
|
2997 void
|
|
2998 check_visual_highlight()
|
|
2999 {
|
|
3000 static int did_check = FALSE;
|
|
3001
|
|
3002 if (full_screen)
|
|
3003 {
|
|
3004 if (!did_check && hl_attr(HLF_V) == 0)
|
|
3005 MSG(_("Warning: terminal cannot highlight"));
|
|
3006 did_check = TRUE;
|
|
3007 }
|
|
3008 }
|
|
3009
|
|
3010 /*
|
|
3011 * End visual mode.
|
|
3012 * This function should ALWAYS be called to end Visual mode, except from
|
|
3013 * do_pending_operator().
|
|
3014 */
|
|
3015 void
|
|
3016 end_visual_mode()
|
|
3017 {
|
|
3018 #ifdef FEAT_CLIPBOARD
|
|
3019 /*
|
|
3020 * If we are using the clipboard, then remember what was selected in case
|
|
3021 * we need to paste it somewhere while we still own the selection.
|
|
3022 * Only do this when the clipboard is already owned. Don't want to grab
|
|
3023 * the selection when hitting ESC.
|
|
3024 */
|
|
3025 if (clip_star.available && clip_star.owned)
|
|
3026 clip_auto_select();
|
|
3027 #endif
|
|
3028
|
|
3029 VIsual_active = FALSE;
|
|
3030 #ifdef FEAT_MOUSE
|
|
3031 setmouse();
|
|
3032 mouse_dragging = 0;
|
|
3033 #endif
|
|
3034
|
|
3035 /* Save the current VIsual area for '< and '> marks, and "gv" */
|
|
3036 curbuf->b_visual_mode = VIsual_mode;
|
|
3037 #ifdef FEAT_EVAL
|
|
3038 curbuf->b_visual_mode_eval = VIsual_mode;
|
|
3039 #endif
|
|
3040 curbuf->b_visual_start = VIsual;
|
|
3041 curbuf->b_visual_end = curwin->w_cursor;
|
|
3042 curbuf->b_visual_curswant = curwin->w_curswant;
|
|
3043 #ifdef FEAT_VIRTUALEDIT
|
|
3044 if (!virtual_active())
|
|
3045 curwin->w_cursor.coladd = 0;
|
|
3046 #endif
|
|
3047
|
|
3048 if (p_smd)
|
|
3049 clear_cmdline = TRUE; /* unshow visual mode later */
|
|
3050 #ifdef FEAT_CMDL_INFO
|
|
3051 else
|
|
3052 clear_showcmd();
|
|
3053 #endif
|
|
3054
|
|
3055 /* Don't leave the cursor past the end of the line */
|
|
3056 if (curwin->w_cursor.col > 0 && *ml_get_cursor() == NUL)
|
|
3057 --curwin->w_cursor.col;
|
|
3058 }
|
|
3059
|
|
3060 /*
|
|
3061 * Reset VIsual_active and VIsual_reselect.
|
|
3062 */
|
|
3063 void
|
|
3064 reset_VIsual_and_resel()
|
|
3065 {
|
|
3066 if (VIsual_active)
|
|
3067 {
|
|
3068 end_visual_mode();
|
|
3069 redraw_curbuf_later(INVERTED); /* delete the inversion later */
|
|
3070 }
|
|
3071 VIsual_reselect = FALSE;
|
|
3072 }
|
|
3073
|
|
3074 /*
|
|
3075 * Reset VIsual_active and VIsual_reselect if it's set.
|
|
3076 */
|
|
3077 void
|
|
3078 reset_VIsual()
|
|
3079 {
|
|
3080 if (VIsual_active)
|
|
3081 {
|
|
3082 end_visual_mode();
|
|
3083 redraw_curbuf_later(INVERTED); /* delete the inversion later */
|
|
3084 VIsual_reselect = FALSE;
|
|
3085 }
|
|
3086 }
|
|
3087 #endif /* FEAT_VISUAL */
|
|
3088
|
184
|
3089 #if defined(FEAT_BEVAL)
|
7
|
3090 static int find_is_eval_item __ARGS((char_u *ptr, int *colp, int *nbp, int dir));
|
|
3091
|
|
3092 /*
|
|
3093 * Check for a balloon-eval special item to include when searching for an
|
|
3094 * identifier. When "dir" is BACKWARD "ptr[-1]" must be valid!
|
|
3095 * Returns TRUE if the character at "*ptr" should be included.
|
|
3096 * "dir" is FORWARD or BACKWARD, the direction of searching.
|
|
3097 * "*colp" is in/decremented if "ptr[-dir]" should also be included.
|
|
3098 * "bnp" points to a counter for square brackets.
|
|
3099 */
|
|
3100 static int
|
|
3101 find_is_eval_item(ptr, colp, bnp, dir)
|
|
3102 char_u *ptr;
|
|
3103 int *colp;
|
|
3104 int *bnp;
|
|
3105 int dir;
|
|
3106 {
|
|
3107 /* Accept everything inside []. */
|
|
3108 if ((*ptr == ']' && dir == BACKWARD) || (*ptr == '[' && dir == FORWARD))
|
|
3109 ++*bnp;
|
|
3110 if (*bnp > 0)
|
|
3111 {
|
|
3112 if ((*ptr == '[' && dir == BACKWARD) || (*ptr == ']' && dir == FORWARD))
|
|
3113 --*bnp;
|
|
3114 return TRUE;
|
|
3115 }
|
|
3116
|
|
3117 /* skip over "s.var" */
|
|
3118 if (*ptr == '.')
|
|
3119 return TRUE;
|
|
3120
|
|
3121 /* two-character item: s->var */
|
|
3122 if (ptr[dir == BACKWARD ? 0 : 1] == '>'
|
|
3123 && ptr[dir == BACKWARD ? -1 : 0] == '-')
|
|
3124 {
|
|
3125 *colp += dir;
|
|
3126 return TRUE;
|
|
3127 }
|
|
3128 return FALSE;
|
|
3129 }
|
|
3130 #endif
|
|
3131
|
|
3132 /*
|
|
3133 * Find the identifier under or to the right of the cursor.
|
|
3134 * "find_type" can have one of three values:
|
|
3135 * FIND_IDENT: find an identifier (keyword)
|
|
3136 * FIND_STRING: find any non-white string
|
|
3137 * FIND_IDENT + FIND_STRING: find any non-white string, identifier preferred.
|
184
|
3138 * FIND_EVAL: find text useful for C program debugging
|
7
|
3139 *
|
|
3140 * There are three steps:
|
|
3141 * 1. Search forward for the start of an identifier/string. Doesn't move if
|
|
3142 * already on one.
|
|
3143 * 2. Search backward for the start of this identifier/string.
|
|
3144 * This doesn't match the real Vi but I like it a little better and it
|
|
3145 * shouldn't bother anyone.
|
|
3146 * 3. Search forward to the end of this identifier/string.
|
|
3147 * When FIND_IDENT isn't defined, we backup until a blank.
|
|
3148 *
|
|
3149 * Returns the length of the string, or zero if no string is found.
|
|
3150 * If a string is found, a pointer to the string is put in "*string". This
|
|
3151 * string is not always NUL terminated.
|
|
3152 */
|
|
3153 int
|
|
3154 find_ident_under_cursor(string, find_type)
|
|
3155 char_u **string;
|
|
3156 int find_type;
|
|
3157 {
|
|
3158 return find_ident_at_pos(curwin, curwin->w_cursor.lnum,
|
|
3159 curwin->w_cursor.col, string, find_type);
|
|
3160 }
|
|
3161
|
|
3162 /*
|
|
3163 * Like find_ident_under_cursor(), but for any window and any position.
|
|
3164 * However: Uses 'iskeyword' from the current window!.
|
|
3165 */
|
|
3166 int
|
|
3167 find_ident_at_pos(wp, lnum, startcol, string, find_type)
|
|
3168 win_T *wp;
|
|
3169 linenr_T lnum;
|
|
3170 colnr_T startcol;
|
|
3171 char_u **string;
|
|
3172 int find_type;
|
|
3173 {
|
|
3174 char_u *ptr;
|
|
3175 int col = 0; /* init to shut up GCC */
|
|
3176 int i;
|
|
3177 #ifdef FEAT_MBYTE
|
|
3178 int this_class = 0;
|
|
3179 int prev_class;
|
|
3180 int prevcol;
|
|
3181 #endif
|
184
|
3182 #if defined(FEAT_BEVAL)
|
7
|
3183 int bn = 0; /* bracket nesting */
|
|
3184 #endif
|
|
3185
|
|
3186 /*
|
|
3187 * if i == 0: try to find an identifier
|
|
3188 * if i == 1: try to find any non-white string
|
|
3189 */
|
|
3190 ptr = ml_get_buf(wp->w_buffer, lnum, FALSE);
|
|
3191 for (i = (find_type & FIND_IDENT) ? 0 : 1; i < 2; ++i)
|
|
3192 {
|
|
3193 /*
|
|
3194 * 1. skip to start of identifier/string
|
|
3195 */
|
|
3196 col = startcol;
|
|
3197 #ifdef FEAT_MBYTE
|
|
3198 if (has_mbyte)
|
|
3199 {
|
|
3200 while (ptr[col] != NUL)
|
|
3201 {
|
184
|
3202 # if defined(FEAT_BEVAL)
|
7
|
3203 /* Stop at a ']' to evaluate "a[x]". */
|
|
3204 if ((find_type & FIND_EVAL) && ptr[col] == ']')
|
|
3205 break;
|
|
3206 # endif
|
|
3207 this_class = mb_get_class(ptr + col);
|
|
3208 if (this_class != 0 && (i == 1 || this_class != 1))
|
|
3209 break;
|
|
3210 col += (*mb_ptr2len_check)(ptr + col);
|
|
3211 }
|
|
3212 }
|
|
3213 else
|
|
3214 #endif
|
|
3215 while (ptr[col] != NUL
|
|
3216 && (i == 0 ? !vim_iswordc(ptr[col]) : vim_iswhite(ptr[col]))
|
184
|
3217 # if defined(FEAT_BEVAL)
|
7
|
3218 && (!(find_type & FIND_EVAL) || ptr[col] != ']')
|
|
3219 # endif
|
|
3220 )
|
|
3221 ++col;
|
|
3222
|
184
|
3223 #if defined(FEAT_BEVAL)
|
7
|
3224 /* When starting on a ']' count it, so that we include the '['. */
|
|
3225 bn = ptr[col] == ']';
|
|
3226 #endif
|
|
3227
|
|
3228 /*
|
|
3229 * 2. Back up to start of identifier/string.
|
|
3230 */
|
|
3231 #ifdef FEAT_MBYTE
|
|
3232 if (has_mbyte)
|
|
3233 {
|
|
3234 /* Remember class of character under cursor. */
|
184
|
3235 # if defined(FEAT_BEVAL)
|
7
|
3236 if ((find_type & FIND_EVAL) && ptr[col] == ']')
|
|
3237 this_class = mb_get_class((char_u *)"a");
|
|
3238 else
|
|
3239 # endif
|
|
3240 this_class = mb_get_class(ptr + col);
|
|
3241 while (col > 0)
|
|
3242 {
|
|
3243 prevcol = col - 1 - (*mb_head_off)(ptr, ptr + col - 1);
|
|
3244 prev_class = mb_get_class(ptr + prevcol);
|
|
3245 if (this_class != prev_class
|
|
3246 && (i == 0
|
|
3247 || prev_class == 0
|
|
3248 || (find_type & FIND_IDENT))
|
184
|
3249 # if defined(FEAT_BEVAL)
|
7
|
3250 && (!(find_type & FIND_EVAL)
|
|
3251 || prevcol == 0
|
|
3252 || !find_is_eval_item(ptr + prevcol, &prevcol,
|
|
3253 &bn, BACKWARD))
|
|
3254 # endif
|
|
3255 )
|
|
3256 break;
|
|
3257 col = prevcol;
|
|
3258 }
|
|
3259
|
|
3260 /* If we don't want just any old string, or we've found an
|
|
3261 * identifier, stop searching. */
|
|
3262 if (this_class > 2)
|
|
3263 this_class = 2;
|
|
3264 if (!(find_type & FIND_STRING) || this_class == 2)
|
|
3265 break;
|
|
3266 }
|
|
3267 else
|
|
3268 #endif
|
|
3269 {
|
|
3270 while (col > 0
|
|
3271 && ((i == 0
|
|
3272 ? vim_iswordc(ptr[col - 1])
|
|
3273 : (!vim_iswhite(ptr[col - 1])
|
|
3274 && (!(find_type & FIND_IDENT)
|
|
3275 || !vim_iswordc(ptr[col - 1]))))
|
184
|
3276 #if defined(FEAT_BEVAL)
|
7
|
3277 || ((find_type & FIND_EVAL)
|
|
3278 && col > 1
|
|
3279 && find_is_eval_item(ptr + col - 1, &col,
|
|
3280 &bn, BACKWARD))
|
|
3281 #endif
|
|
3282 ))
|
|
3283 --col;
|
|
3284
|
|
3285 /* If we don't want just any old string, or we've found an
|
|
3286 * identifier, stop searching. */
|
|
3287 if (!(find_type & FIND_STRING) || vim_iswordc(ptr[col]))
|
|
3288 break;
|
|
3289 }
|
|
3290 }
|
|
3291
|
|
3292 if (ptr[col] == NUL || (i == 0 && (
|
|
3293 #ifdef FEAT_MBYTE
|
|
3294 has_mbyte ? this_class != 2 :
|
|
3295 #endif
|
|
3296 !vim_iswordc(ptr[col]))))
|
|
3297 {
|
|
3298 /*
|
|
3299 * didn't find an identifier or string
|
|
3300 */
|
|
3301 if (find_type & FIND_STRING)
|
|
3302 EMSG(_("E348: No string under cursor"));
|
|
3303 else
|
|
3304 EMSG(_("E349: No identifier under cursor"));
|
|
3305 return 0;
|
|
3306 }
|
|
3307 ptr += col;
|
|
3308 *string = ptr;
|
|
3309
|
|
3310 /*
|
|
3311 * 3. Find the end if the identifier/string.
|
|
3312 */
|
184
|
3313 #if defined(FEAT_BEVAL)
|
7
|
3314 bn = 0;
|
|
3315 startcol -= col;
|
|
3316 #endif
|
|
3317 col = 0;
|
|
3318 #ifdef FEAT_MBYTE
|
|
3319 if (has_mbyte)
|
|
3320 {
|
|
3321 /* Search for point of changing multibyte character class. */
|
|
3322 this_class = mb_get_class(ptr);
|
|
3323 while (ptr[col] != NUL
|
|
3324 && ((i == 0 ? mb_get_class(ptr + col) == this_class
|
|
3325 : mb_get_class(ptr + col) != 0)
|
184
|
3326 # if defined(FEAT_BEVAL)
|
7
|
3327 || ((find_type & FIND_EVAL)
|
|
3328 && col <= (int)startcol
|
|
3329 && find_is_eval_item(ptr + col, &col, &bn, FORWARD))
|
|
3330 # endif
|
|
3331 ))
|
|
3332 col += (*mb_ptr2len_check)(ptr + col);
|
|
3333 }
|
|
3334 else
|
|
3335 #endif
|
|
3336 while ((i == 0 ? vim_iswordc(ptr[col])
|
|
3337 : (ptr[col] != NUL && !vim_iswhite(ptr[col])))
|
184
|
3338 # if defined(FEAT_BEVAL)
|
7
|
3339 || ((find_type & FIND_EVAL)
|
|
3340 && col <= (int)startcol
|
|
3341 && find_is_eval_item(ptr + col, &col, &bn, FORWARD))
|
|
3342 # endif
|
|
3343 )
|
|
3344 {
|
|
3345 ++col;
|
|
3346 }
|
|
3347
|
|
3348 return col;
|
|
3349 }
|
|
3350
|
|
3351 /*
|
|
3352 * Prepare for redo of a normal command.
|
|
3353 */
|
|
3354 static void
|
|
3355 prep_redo_cmd(cap)
|
|
3356 cmdarg_T *cap;
|
|
3357 {
|
|
3358 prep_redo(cap->oap->regname, cap->count0,
|
|
3359 NUL, cap->cmdchar, NUL, NUL, cap->nchar);
|
|
3360 }
|
|
3361
|
|
3362 /*
|
|
3363 * Prepare for redo of any command.
|
|
3364 * Note that only the last argument can be a multi-byte char.
|
|
3365 */
|
|
3366 static void
|
|
3367 prep_redo(regname, num, cmd1, cmd2, cmd3, cmd4, cmd5)
|
|
3368 int regname;
|
|
3369 long num;
|
|
3370 int cmd1;
|
|
3371 int cmd2;
|
|
3372 int cmd3;
|
|
3373 int cmd4;
|
|
3374 int cmd5;
|
|
3375 {
|
|
3376 ResetRedobuff();
|
|
3377 if (regname != 0) /* yank from specified buffer */
|
|
3378 {
|
|
3379 AppendCharToRedobuff('"');
|
|
3380 AppendCharToRedobuff(regname);
|
|
3381 }
|
|
3382 if (num)
|
|
3383 AppendNumberToRedobuff(num);
|
|
3384
|
|
3385 if (cmd1 != NUL)
|
|
3386 AppendCharToRedobuff(cmd1);
|
|
3387 if (cmd2 != NUL)
|
|
3388 AppendCharToRedobuff(cmd2);
|
|
3389 if (cmd3 != NUL)
|
|
3390 AppendCharToRedobuff(cmd3);
|
|
3391 if (cmd4 != NUL)
|
|
3392 AppendCharToRedobuff(cmd4);
|
|
3393 if (cmd5 != NUL)
|
|
3394 AppendCharToRedobuff(cmd5);
|
|
3395 }
|
|
3396
|
|
3397 /*
|
|
3398 * check for operator active and clear it
|
|
3399 *
|
|
3400 * return TRUE if operator was active
|
|
3401 */
|
|
3402 static int
|
|
3403 checkclearop(oap)
|
|
3404 oparg_T *oap;
|
|
3405 {
|
|
3406 if (oap->op_type == OP_NOP)
|
|
3407 return FALSE;
|
|
3408 clearopbeep(oap);
|
|
3409 return TRUE;
|
|
3410 }
|
|
3411
|
|
3412 /*
|
|
3413 * check for operator or Visual active and clear it
|
|
3414 *
|
|
3415 * return TRUE if operator was active
|
|
3416 */
|
|
3417 static int
|
|
3418 checkclearopq(oap)
|
|
3419 oparg_T *oap;
|
|
3420 {
|
|
3421 if (oap->op_type == OP_NOP
|
|
3422 #ifdef FEAT_VISUAL
|
|
3423 && !VIsual_active
|
|
3424 #endif
|
|
3425 )
|
|
3426 return FALSE;
|
|
3427 clearopbeep(oap);
|
|
3428 return TRUE;
|
|
3429 }
|
|
3430
|
|
3431 static void
|
|
3432 clearop(oap)
|
|
3433 oparg_T *oap;
|
|
3434 {
|
|
3435 oap->op_type = OP_NOP;
|
|
3436 oap->regname = 0;
|
|
3437 oap->motion_force = NUL;
|
|
3438 oap->use_reg_one = FALSE;
|
|
3439 }
|
|
3440
|
|
3441 static void
|
|
3442 clearopbeep(oap)
|
|
3443 oparg_T *oap;
|
|
3444 {
|
|
3445 clearop(oap);
|
|
3446 beep_flush();
|
|
3447 }
|
|
3448
|
|
3449 #ifdef FEAT_VISUAL
|
|
3450 /*
|
|
3451 * Remove the shift modifier from a special key.
|
|
3452 */
|
|
3453 static void
|
|
3454 unshift_special(cap)
|
|
3455 cmdarg_T *cap;
|
|
3456 {
|
|
3457 switch (cap->cmdchar)
|
|
3458 {
|
|
3459 case K_S_RIGHT: cap->cmdchar = K_RIGHT; break;
|
|
3460 case K_S_LEFT: cap->cmdchar = K_LEFT; break;
|
|
3461 case K_S_UP: cap->cmdchar = K_UP; break;
|
|
3462 case K_S_DOWN: cap->cmdchar = K_DOWN; break;
|
|
3463 case K_S_HOME: cap->cmdchar = K_HOME; break;
|
|
3464 case K_S_END: cap->cmdchar = K_END; break;
|
|
3465 }
|
|
3466 cap->cmdchar = simplify_key(cap->cmdchar, &mod_mask);
|
|
3467 }
|
|
3468 #endif
|
|
3469
|
|
3470 #if defined(FEAT_CMDL_INFO) || defined(PROTO)
|
|
3471 /*
|
|
3472 * Routines for displaying a partly typed command
|
|
3473 */
|
|
3474
|
|
3475 #ifdef FEAT_VISUAL /* need room for size of Visual area */
|
|
3476 # define SHOWCMD_BUFLEN SHOWCMD_COLS + 1 + 30
|
|
3477 #else
|
|
3478 # define SHOWCMD_BUFLEN SHOWCMD_COLS + 1
|
|
3479 #endif
|
|
3480 static char_u showcmd_buf[SHOWCMD_BUFLEN];
|
|
3481 static char_u old_showcmd_buf[SHOWCMD_BUFLEN]; /* For push_showcmd() */
|
|
3482 static int showcmd_is_clear = TRUE;
|
|
3483 static int showcmd_visual = FALSE;
|
|
3484
|
|
3485 static void display_showcmd __ARGS((void));
|
|
3486
|
|
3487 void
|
|
3488 clear_showcmd()
|
|
3489 {
|
|
3490 if (!p_sc)
|
|
3491 return;
|
|
3492
|
|
3493 #ifdef FEAT_VISUAL
|
|
3494 if (VIsual_active && !char_avail())
|
|
3495 {
|
|
3496 int i = lt(VIsual, curwin->w_cursor);
|
|
3497 long lines;
|
|
3498 colnr_T leftcol, rightcol;
|
|
3499 linenr_T top, bot;
|
|
3500
|
|
3501 /* Show the size of the Visual area. */
|
|
3502 if (i)
|
|
3503 {
|
|
3504 top = VIsual.lnum;
|
|
3505 bot = curwin->w_cursor.lnum;
|
|
3506 }
|
|
3507 else
|
|
3508 {
|
|
3509 top = curwin->w_cursor.lnum;
|
|
3510 bot = VIsual.lnum;
|
|
3511 }
|
|
3512 # ifdef FEAT_FOLDING
|
|
3513 /* Include closed folds as a whole. */
|
|
3514 hasFolding(top, &top, NULL);
|
|
3515 hasFolding(bot, NULL, &bot);
|
|
3516 # endif
|
|
3517 lines = bot - top + 1;
|
|
3518
|
|
3519 if (VIsual_mode == Ctrl_V)
|
|
3520 {
|
|
3521 getvcols(curwin, &curwin->w_cursor, &VIsual, &leftcol, &rightcol);
|
|
3522 sprintf((char *)showcmd_buf, "%ldx%ld", lines,
|
|
3523 (long)(rightcol - leftcol + 1));
|
|
3524 }
|
|
3525 else if (VIsual_mode == 'V' || VIsual.lnum != curwin->w_cursor.lnum)
|
|
3526 sprintf((char *)showcmd_buf, "%ld", lines);
|
|
3527 else
|
|
3528 sprintf((char *)showcmd_buf, "%ld", (long)(i
|
|
3529 ? curwin->w_cursor.col - VIsual.col
|
|
3530 : VIsual.col - curwin->w_cursor.col) + (*p_sel != 'e'));
|
|
3531 showcmd_buf[SHOWCMD_COLS] = NUL; /* truncate */
|
|
3532 showcmd_visual = TRUE;
|
|
3533 }
|
|
3534 else
|
|
3535 #endif
|
|
3536 {
|
|
3537 showcmd_buf[0] = NUL;
|
|
3538 showcmd_visual = FALSE;
|
|
3539
|
|
3540 /* Don't actually display something if there is nothing to clear. */
|
|
3541 if (showcmd_is_clear)
|
|
3542 return;
|
|
3543 }
|
|
3544
|
|
3545 display_showcmd();
|
|
3546 }
|
|
3547
|
|
3548 /*
|
|
3549 * Add 'c' to string of shown command chars.
|
|
3550 * Return TRUE if output has been written (and setcursor() has been called).
|
|
3551 */
|
|
3552 int
|
|
3553 add_to_showcmd(c)
|
|
3554 int c;
|
|
3555 {
|
|
3556 char_u *p;
|
|
3557 int old_len;
|
|
3558 int extra_len;
|
|
3559 int overflow;
|
|
3560 #if defined(FEAT_MOUSE)
|
|
3561 int i;
|
|
3562 static int ignore[] =
|
|
3563 {
|
|
3564 #ifdef FEAT_GUI
|
|
3565 K_VER_SCROLLBAR, K_HOR_SCROLLBAR,
|
|
3566 K_LEFTMOUSE_NM, K_LEFTRELEASE_NM,
|
|
3567 #endif
|
|
3568 K_IGNORE,
|
|
3569 K_LEFTMOUSE, K_LEFTDRAG, K_LEFTRELEASE,
|
|
3570 K_MIDDLEMOUSE, K_MIDDLEDRAG, K_MIDDLERELEASE,
|
|
3571 K_RIGHTMOUSE, K_RIGHTDRAG, K_RIGHTRELEASE,
|
|
3572 K_MOUSEDOWN, K_MOUSEUP,
|
|
3573 K_X1MOUSE, K_X1DRAG, K_X1RELEASE, K_X2MOUSE, K_X2DRAG, K_X2RELEASE,
|
|
3574 0
|
|
3575 };
|
|
3576 #endif
|
|
3577
|
|
3578 if (!p_sc)
|
|
3579 return FALSE;
|
|
3580
|
|
3581 if (showcmd_visual)
|
|
3582 {
|
|
3583 showcmd_buf[0] = NUL;
|
|
3584 showcmd_visual = FALSE;
|
|
3585 }
|
|
3586
|
|
3587 #if defined(FEAT_MOUSE)
|
|
3588 /* Ignore keys that are scrollbar updates and mouse clicks */
|
|
3589 if (IS_SPECIAL(c))
|
|
3590 for (i = 0; ignore[i] != 0; ++i)
|
|
3591 if (ignore[i] == c)
|
|
3592 return FALSE;
|
|
3593 #endif
|
|
3594
|
|
3595 p = transchar(c);
|
|
3596 old_len = (int)STRLEN(showcmd_buf);
|
|
3597 extra_len = (int)STRLEN(p);
|
|
3598 overflow = old_len + extra_len - SHOWCMD_COLS;
|
|
3599 if (overflow > 0)
|
|
3600 STRCPY(showcmd_buf, showcmd_buf + overflow);
|
|
3601 STRCAT(showcmd_buf, p);
|
|
3602
|
|
3603 if (char_avail())
|
|
3604 return FALSE;
|
|
3605
|
|
3606 display_showcmd();
|
|
3607
|
|
3608 return TRUE;
|
|
3609 }
|
|
3610
|
|
3611 void
|
|
3612 add_to_showcmd_c(c)
|
|
3613 int c;
|
|
3614 {
|
|
3615 if (!add_to_showcmd(c))
|
|
3616 setcursor();
|
|
3617 }
|
|
3618
|
|
3619 /*
|
|
3620 * Delete 'len' characters from the end of the shown command.
|
|
3621 */
|
|
3622 static void
|
|
3623 del_from_showcmd(len)
|
|
3624 int len;
|
|
3625 {
|
|
3626 int old_len;
|
|
3627
|
|
3628 if (!p_sc)
|
|
3629 return;
|
|
3630
|
|
3631 old_len = (int)STRLEN(showcmd_buf);
|
|
3632 if (len > old_len)
|
|
3633 len = old_len;
|
|
3634 showcmd_buf[old_len - len] = NUL;
|
|
3635
|
|
3636 if (!char_avail())
|
|
3637 display_showcmd();
|
|
3638 }
|
|
3639
|
|
3640 /*
|
|
3641 * push_showcmd() and pop_showcmd() are used when waiting for the user to type
|
|
3642 * something and there is a partial mapping.
|
|
3643 */
|
|
3644 void
|
|
3645 push_showcmd()
|
|
3646 {
|
|
3647 if (p_sc)
|
|
3648 STRCPY(old_showcmd_buf, showcmd_buf);
|
|
3649 }
|
|
3650
|
|
3651 void
|
|
3652 pop_showcmd()
|
|
3653 {
|
|
3654 if (!p_sc)
|
|
3655 return;
|
|
3656
|
|
3657 STRCPY(showcmd_buf, old_showcmd_buf);
|
|
3658
|
|
3659 display_showcmd();
|
|
3660 }
|
|
3661
|
|
3662 static void
|
|
3663 display_showcmd()
|
|
3664 {
|
|
3665 int len;
|
|
3666
|
|
3667 cursor_off();
|
|
3668
|
|
3669 len = (int)STRLEN(showcmd_buf);
|
|
3670 if (len == 0)
|
|
3671 showcmd_is_clear = TRUE;
|
|
3672 else
|
|
3673 {
|
|
3674 screen_puts(showcmd_buf, (int)Rows - 1, sc_col, 0);
|
|
3675 showcmd_is_clear = FALSE;
|
|
3676 }
|
|
3677
|
|
3678 /*
|
|
3679 * clear the rest of an old message by outputing up to SHOWCMD_COLS spaces
|
|
3680 */
|
|
3681 screen_puts((char_u *)" " + len, (int)Rows - 1, sc_col + len, 0);
|
|
3682
|
|
3683 setcursor(); /* put cursor back where it belongs */
|
|
3684 }
|
|
3685 #endif
|
|
3686
|
|
3687 #ifdef FEAT_SCROLLBIND
|
|
3688 /*
|
|
3689 * When "check" is FALSE, prepare for commands that scroll the window.
|
|
3690 * When "check" is TRUE, take care of scroll-binding after the window has
|
|
3691 * scrolled. Called from normal_cmd() and edit().
|
|
3692 */
|
|
3693 void
|
|
3694 do_check_scrollbind(check)
|
|
3695 int check;
|
|
3696 {
|
|
3697 static win_T *old_curwin = NULL;
|
|
3698 static linenr_T old_topline = 0;
|
|
3699 #ifdef FEAT_DIFF
|
|
3700 static int old_topfill = 0;
|
|
3701 #endif
|
|
3702 static buf_T *old_buf = NULL;
|
|
3703 static colnr_T old_leftcol = 0;
|
|
3704
|
|
3705 if (check && curwin->w_p_scb)
|
|
3706 {
|
|
3707 /* If a ":syncbind" command was just used, don't scroll, only reset
|
|
3708 * the values. */
|
|
3709 if (did_syncbind)
|
|
3710 did_syncbind = FALSE;
|
|
3711 else if (curwin == old_curwin)
|
|
3712 {
|
|
3713 /*
|
|
3714 * Synchronize other windows, as necessary according to
|
|
3715 * 'scrollbind'. Don't do this after an ":edit" command, except
|
|
3716 * when 'diff' is set.
|
|
3717 */
|
|
3718 if ((curwin->w_buffer == old_buf
|
|
3719 #ifdef FEAT_DIFF
|
|
3720 || curwin->w_p_diff
|
|
3721 #endif
|
|
3722 )
|
|
3723 && (curwin->w_topline != old_topline
|
|
3724 #ifdef FEAT_DIFF
|
|
3725 || curwin->w_topfill != old_topfill
|
|
3726 #endif
|
|
3727 || curwin->w_leftcol != old_leftcol))
|
|
3728 {
|
|
3729 check_scrollbind(curwin->w_topline - old_topline,
|
|
3730 (long)(curwin->w_leftcol - old_leftcol));
|
|
3731 }
|
|
3732 }
|
|
3733 else if (vim_strchr(p_sbo, 'j')) /* jump flag set in 'scrollopt' */
|
|
3734 {
|
|
3735 /*
|
|
3736 * When switching between windows, make sure that the relative
|
|
3737 * vertical offset is valid for the new window. The relative
|
|
3738 * offset is invalid whenever another 'scrollbind' window has
|
|
3739 * scrolled to a point that would force the current window to
|
|
3740 * scroll past the beginning or end of its buffer. When the
|
|
3741 * resync is performed, some of the other 'scrollbind' windows may
|
|
3742 * need to jump so that the current window's relative position is
|
|
3743 * visible on-screen.
|
|
3744 */
|
|
3745 check_scrollbind(curwin->w_topline - curwin->w_scbind_pos, 0L);
|
|
3746 }
|
|
3747 curwin->w_scbind_pos = curwin->w_topline;
|
|
3748 }
|
|
3749
|
|
3750 old_curwin = curwin;
|
|
3751 old_topline = curwin->w_topline;
|
|
3752 #ifdef FEAT_DIFF
|
|
3753 old_topfill = curwin->w_topfill;
|
|
3754 #endif
|
|
3755 old_buf = curwin->w_buffer;
|
|
3756 old_leftcol = curwin->w_leftcol;
|
|
3757 }
|
|
3758
|
|
3759 /*
|
|
3760 * Synchronize any windows that have "scrollbind" set, based on the
|
|
3761 * number of rows by which the current window has changed
|
|
3762 * (1998-11-02 16:21:01 R. Edward Ralston <eralston@computer.org>)
|
|
3763 */
|
|
3764 void
|
|
3765 check_scrollbind(topline_diff, leftcol_diff)
|
|
3766 linenr_T topline_diff;
|
|
3767 long leftcol_diff;
|
|
3768 {
|
|
3769 int want_ver;
|
|
3770 int want_hor;
|
|
3771 win_T *old_curwin = curwin;
|
|
3772 buf_T *old_curbuf = curbuf;
|
|
3773 #ifdef FEAT_VISUAL
|
|
3774 int old_VIsual_select = VIsual_select;
|
|
3775 int old_VIsual_active = VIsual_active;
|
|
3776 #endif
|
|
3777 colnr_T tgt_leftcol = curwin->w_leftcol;
|
|
3778 long topline;
|
|
3779 long y;
|
|
3780
|
|
3781 /*
|
|
3782 * check 'scrollopt' string for vertical and horizontal scroll options
|
|
3783 */
|
|
3784 want_ver = (vim_strchr(p_sbo, 'v') && topline_diff != 0);
|
|
3785 #ifdef FEAT_DIFF
|
|
3786 want_ver |= old_curwin->w_p_diff;
|
|
3787 #endif
|
|
3788 want_hor = (vim_strchr(p_sbo, 'h') && (leftcol_diff || topline_diff != 0));
|
|
3789
|
|
3790 /*
|
|
3791 * loop through the scrollbound windows and scroll accordingly
|
|
3792 */
|
|
3793 #ifdef FEAT_VISUAL
|
|
3794 VIsual_select = VIsual_active = 0;
|
|
3795 #endif
|
|
3796 for (curwin = firstwin; curwin; curwin = curwin->w_next)
|
|
3797 {
|
|
3798 curbuf = curwin->w_buffer;
|
|
3799 /* skip original window and windows with 'noscrollbind' */
|
|
3800 if (curwin != old_curwin && curwin->w_p_scb)
|
|
3801 {
|
|
3802 /*
|
|
3803 * do the vertical scroll
|
|
3804 */
|
|
3805 if (want_ver)
|
|
3806 {
|
|
3807 #ifdef FEAT_DIFF
|
|
3808 if (old_curwin->w_p_diff && curwin->w_p_diff)
|
|
3809 {
|
|
3810 diff_set_topline(old_curwin, curwin);
|
|
3811 }
|
|
3812 else
|
|
3813 #endif
|
|
3814 {
|
|
3815 curwin->w_scbind_pos += topline_diff;
|
|
3816 topline = curwin->w_scbind_pos;
|
|
3817 if (topline > curbuf->b_ml.ml_line_count)
|
|
3818 topline = curbuf->b_ml.ml_line_count;
|
|
3819 if (topline < 1)
|
|
3820 topline = 1;
|
|
3821
|
|
3822 y = topline - curwin->w_topline;
|
|
3823 if (y > 0)
|
|
3824 scrollup(y, FALSE);
|
|
3825 else
|
|
3826 scrolldown(-y, FALSE);
|
|
3827 }
|
|
3828
|
|
3829 redraw_later(VALID);
|
|
3830 cursor_correct();
|
|
3831 #ifdef FEAT_WINDOWS
|
|
3832 curwin->w_redr_status = TRUE;
|
|
3833 #endif
|
|
3834 }
|
|
3835
|
|
3836 /*
|
|
3837 * do the horizontal scroll
|
|
3838 */
|
|
3839 if (want_hor && curwin->w_leftcol != tgt_leftcol)
|
|
3840 {
|
|
3841 curwin->w_leftcol = tgt_leftcol;
|
|
3842 leftcol_changed();
|
|
3843 }
|
|
3844 }
|
|
3845 }
|
|
3846
|
|
3847 /*
|
|
3848 * reset current-window
|
|
3849 */
|
|
3850 #ifdef FEAT_VISUAL
|
|
3851 VIsual_select = old_VIsual_select;
|
|
3852 VIsual_active = old_VIsual_active;
|
|
3853 #endif
|
|
3854 curwin = old_curwin;
|
|
3855 curbuf = old_curbuf;
|
|
3856 }
|
|
3857 #endif /* #ifdef FEAT_SCROLLBIND */
|
|
3858
|
|
3859 /*
|
|
3860 * Command character that's ignored.
|
|
3861 * Used for CTRL-Q and CTRL-S to avoid problems with terminals that use
|
|
3862 * xon/xoff
|
|
3863 */
|
|
3864 /*ARGSUSED */
|
|
3865 static void
|
|
3866 nv_ignore(cap)
|
|
3867 cmdarg_T *cap;
|
|
3868 {
|
226
|
3869 cap->retval |= CA_COMMAND_BUSY; /* don't call edit() now */
|
7
|
3870 }
|
|
3871
|
|
3872 /*
|
|
3873 * Command character doesn't exist.
|
|
3874 */
|
|
3875 static void
|
|
3876 nv_error(cap)
|
|
3877 cmdarg_T *cap;
|
|
3878 {
|
|
3879 clearopbeep(cap->oap);
|
|
3880 }
|
|
3881
|
|
3882 /*
|
|
3883 * <Help> and <F1> commands.
|
|
3884 */
|
|
3885 static void
|
|
3886 nv_help(cap)
|
|
3887 cmdarg_T *cap;
|
|
3888 {
|
|
3889 if (!checkclearopq(cap->oap))
|
|
3890 ex_help(NULL);
|
|
3891 }
|
|
3892
|
|
3893 /*
|
|
3894 * CTRL-A and CTRL-X: Add or subtract from letter or number under cursor.
|
|
3895 */
|
|
3896 static void
|
|
3897 nv_addsub(cap)
|
|
3898 cmdarg_T *cap;
|
|
3899 {
|
|
3900 if (!checkclearopq(cap->oap)
|
|
3901 && do_addsub((int)cap->cmdchar, cap->count1) == OK)
|
|
3902 prep_redo_cmd(cap);
|
|
3903 }
|
|
3904
|
|
3905 /*
|
|
3906 * CTRL-F, CTRL-B, etc: Scroll page up or down.
|
|
3907 */
|
|
3908 static void
|
|
3909 nv_page(cap)
|
|
3910 cmdarg_T *cap;
|
|
3911 {
|
|
3912 if (!checkclearop(cap->oap))
|
|
3913 (void)onepage(cap->arg, cap->count1);
|
|
3914 }
|
|
3915
|
|
3916 /*
|
|
3917 * Implementation of "gd" and "gD" command.
|
|
3918 */
|
|
3919 static void
|
|
3920 nv_gd(oap, nchar)
|
|
3921 oparg_T *oap;
|
|
3922 int nchar;
|
|
3923 {
|
|
3924 int len;
|
|
3925 char_u *pat;
|
|
3926 pos_T old_pos;
|
|
3927 int t;
|
|
3928 int save_p_ws;
|
|
3929 int save_p_scs;
|
|
3930 char_u *ptr;
|
|
3931
|
|
3932 if ((len = find_ident_under_cursor(&ptr, FIND_IDENT)) == 0 ||
|
|
3933 (pat = alloc(len + 5)) == NULL)
|
|
3934 {
|
|
3935 clearopbeep(oap);
|
|
3936 return;
|
|
3937 }
|
|
3938 sprintf((char *)pat, vim_iswordp(ptr) ? "\\<%.*s\\>" : "%.*s", len, ptr);
|
|
3939 old_pos = curwin->w_cursor;
|
|
3940 save_p_ws = p_ws;
|
|
3941 save_p_scs = p_scs;
|
|
3942 p_ws = FALSE; /* don't wrap around end of file now */
|
|
3943 p_scs = FALSE; /* don't switch ignorecase off now */
|
|
3944
|
|
3945 /*
|
|
3946 * With "gD" go to line 1.
|
|
3947 * With "gd" Search back for the start of the current function, then go
|
|
3948 * back until a blank line. If this fails go to line 1.
|
|
3949 */
|
|
3950 if (nchar == 'D' || !findpar(oap, BACKWARD, 1L, '{', FALSE))
|
|
3951 {
|
|
3952 setpcmark(); /* Set in findpar() otherwise */
|
|
3953 curwin->w_cursor.lnum = 1;
|
|
3954 }
|
|
3955 else
|
|
3956 {
|
|
3957 while (curwin->w_cursor.lnum > 1 && *skipwhite(ml_get_curline()) != NUL)
|
|
3958 --curwin->w_cursor.lnum;
|
|
3959 }
|
|
3960 curwin->w_cursor.col = 0;
|
|
3961
|
|
3962 /* Search forward for the identifier, ignore comment lines. */
|
|
3963 while ((t = searchit(curwin, curbuf, &curwin->w_cursor, FORWARD, pat, 1L, 0,
|
|
3964 RE_LAST)) != FAIL
|
|
3965 #ifdef FEAT_COMMENTS
|
|
3966 && get_leader_len(ml_get_curline(), NULL, FALSE) > 0
|
|
3967 #endif
|
|
3968 && old_pos.lnum > curwin->w_cursor.lnum)
|
|
3969 {
|
|
3970 /* Ignore this line, continue at start of next line. */
|
|
3971 ++curwin->w_cursor.lnum;
|
|
3972 curwin->w_cursor.col = 0;
|
|
3973 }
|
|
3974 if (t == FAIL || old_pos.lnum <= curwin->w_cursor.lnum)
|
|
3975 {
|
|
3976 clearopbeep(oap);
|
|
3977 curwin->w_cursor = old_pos;
|
|
3978 }
|
|
3979 else
|
|
3980 {
|
|
3981 curwin->w_set_curswant = TRUE;
|
|
3982 #ifdef FEAT_FOLDING
|
|
3983 if ((fdo_flags & FDO_SEARCH) && KeyTyped && oap->op_type == OP_NOP)
|
|
3984 foldOpenCursor();
|
|
3985 #endif
|
|
3986 /* "n" searches forward now */
|
|
3987 reset_search_dir();
|
|
3988 }
|
|
3989
|
|
3990 vim_free(pat);
|
|
3991 p_ws = save_p_ws;
|
|
3992 p_scs = save_p_scs;
|
|
3993 }
|
|
3994
|
|
3995 /*
|
|
3996 * Move 'dist' lines in direction 'dir', counting lines by *screen*
|
|
3997 * lines rather than lines in the file.
|
|
3998 * 'dist' must be positive.
|
|
3999 *
|
|
4000 * Return OK if able to move cursor, FAIL otherwise.
|
|
4001 */
|
|
4002 static int
|
|
4003 nv_screengo(oap, dir, dist)
|
|
4004 oparg_T *oap;
|
|
4005 int dir;
|
|
4006 long dist;
|
|
4007 {
|
|
4008 int linelen = linetabsize(ml_get_curline());
|
|
4009 int retval = OK;
|
|
4010 int atend = FALSE;
|
|
4011 int n;
|
|
4012 int col_off1; /* margin offset for first screen line */
|
|
4013 int col_off2; /* margin offset for wrapped screen line */
|
|
4014 int width1; /* text width for first screen line */
|
|
4015 int width2; /* test width for wrapped screen line */
|
|
4016
|
|
4017 oap->motion_type = MCHAR;
|
|
4018 oap->inclusive = FALSE;
|
|
4019
|
|
4020 col_off1 = curwin_col_off();
|
|
4021 col_off2 = col_off1 - curwin_col_off2();
|
|
4022 width1 = W_WIDTH(curwin) - col_off1;
|
|
4023 width2 = W_WIDTH(curwin) - col_off2;
|
|
4024
|
|
4025 #ifdef FEAT_VERTSPLIT
|
|
4026 if (curwin->w_width != 0)
|
|
4027 {
|
|
4028 #endif
|
|
4029 /*
|
|
4030 * Instead of sticking at the last character of the buffer line we
|
|
4031 * try to stick in the last column of the screen.
|
|
4032 */
|
|
4033 if (curwin->w_curswant == MAXCOL)
|
|
4034 {
|
|
4035 atend = TRUE;
|
|
4036 validate_virtcol();
|
|
4037 if (width1 <= 0)
|
|
4038 curwin->w_curswant = 0;
|
|
4039 else
|
|
4040 {
|
|
4041 curwin->w_curswant = width1 - 1;
|
|
4042 if (curwin->w_virtcol > curwin->w_curswant)
|
|
4043 curwin->w_curswant += ((curwin->w_virtcol
|
|
4044 - curwin->w_curswant - 1) / width2 + 1) * width2;
|
|
4045 }
|
|
4046 }
|
|
4047 else
|
|
4048 {
|
|
4049 if (linelen > width1)
|
|
4050 n = ((linelen - width1 - 1) / width2 + 1) * width2 + width1;
|
|
4051 else
|
|
4052 n = width1;
|
|
4053 if (curwin->w_curswant > (colnr_T)n + 1)
|
|
4054 curwin->w_curswant -= ((curwin->w_curswant - n) / width2 + 1)
|
|
4055 * width2;
|
|
4056 }
|
|
4057
|
|
4058 while (dist--)
|
|
4059 {
|
|
4060 if (dir == BACKWARD)
|
|
4061 {
|
|
4062 if ((long)curwin->w_curswant >= width2)
|
|
4063 /* move back within line */
|
|
4064 curwin->w_curswant -= width2;
|
|
4065 else
|
|
4066 {
|
|
4067 /* to previous line */
|
|
4068 if (curwin->w_cursor.lnum == 1)
|
|
4069 {
|
|
4070 retval = FAIL;
|
|
4071 break;
|
|
4072 }
|
|
4073 --curwin->w_cursor.lnum;
|
|
4074 #ifdef FEAT_FOLDING
|
|
4075 /* Move to the start of a closed fold. Don't do that when
|
|
4076 * 'foldopen' contains "all": it will open in a moment. */
|
|
4077 if (!(fdo_flags & FDO_ALL))
|
|
4078 (void)hasFolding(curwin->w_cursor.lnum,
|
|
4079 &curwin->w_cursor.lnum, NULL);
|
|
4080 #endif
|
|
4081 linelen = linetabsize(ml_get_curline());
|
|
4082 if (linelen > width1)
|
|
4083 curwin->w_curswant += (((linelen - width1 - 1) / width2)
|
|
4084 + 1) * width2;
|
|
4085 }
|
|
4086 }
|
|
4087 else /* dir == FORWARD */
|
|
4088 {
|
|
4089 if (linelen > width1)
|
|
4090 n = ((linelen - width1 - 1) / width2 + 1) * width2 + width1;
|
|
4091 else
|
|
4092 n = width1;
|
|
4093 if (curwin->w_curswant + width2 < (colnr_T)n)
|
|
4094 /* move forward within line */
|
|
4095 curwin->w_curswant += width2;
|
|
4096 else
|
|
4097 {
|
|
4098 /* to next line */
|
|
4099 #ifdef FEAT_FOLDING
|
|
4100 /* Move to the end of a closed fold. */
|
|
4101 (void)hasFolding(curwin->w_cursor.lnum, NULL,
|
|
4102 &curwin->w_cursor.lnum);
|
|
4103 #endif
|
|
4104 if (curwin->w_cursor.lnum == curbuf->b_ml.ml_line_count)
|
|
4105 {
|
|
4106 retval = FAIL;
|
|
4107 break;
|
|
4108 }
|
|
4109 curwin->w_cursor.lnum++;
|
|
4110 curwin->w_curswant %= width2;
|
|
4111 }
|
|
4112 }
|
|
4113 }
|
|
4114 #ifdef FEAT_VERTSPLIT
|
|
4115 }
|
|
4116 #endif
|
|
4117
|
|
4118 coladvance(curwin->w_curswant);
|
|
4119
|
|
4120 #if defined(FEAT_LINEBREAK) || defined(FEAT_MBYTE)
|
|
4121 if (curwin->w_cursor.col > 0 && curwin->w_p_wrap)
|
|
4122 {
|
|
4123 /*
|
|
4124 * Check for landing on a character that got split at the end of the
|
|
4125 * last line. We want to advance a screenline, not end up in the same
|
|
4126 * screenline or move two screenlines.
|
|
4127 */
|
|
4128 validate_virtcol();
|
|
4129 if (curwin->w_virtcol > curwin->w_curswant
|
|
4130 && (curwin->w_curswant < (colnr_T)width1
|
|
4131 ? (curwin->w_curswant > (colnr_T)width1 / 2)
|
|
4132 : ((curwin->w_curswant - width1) % width2
|
|
4133 > (colnr_T)width2 / 2)))
|
|
4134 --curwin->w_cursor.col;
|
|
4135 }
|
|
4136 #endif
|
|
4137
|
|
4138 if (atend)
|
|
4139 curwin->w_curswant = MAXCOL; /* stick in the last column */
|
|
4140
|
|
4141 return retval;
|
|
4142 }
|
|
4143
|
|
4144 #ifdef FEAT_MOUSE
|
|
4145 /*
|
|
4146 * Mouse scroll wheel: Default action is to scroll three lines, or one page
|
|
4147 * when Shift or Ctrl is used.
|
|
4148 * K_MOUSEUP (cap->arg == TRUE) or K_MOUSEDOWN (cap->arg == FALSE)
|
|
4149 */
|
|
4150 static void
|
|
4151 nv_mousescroll(cap)
|
|
4152 cmdarg_T *cap;
|
|
4153 {
|
|
4154 # if defined(FEAT_GUI) && defined(FEAT_WINDOWS)
|
|
4155 win_T *old_curwin;
|
|
4156
|
|
4157 old_curwin = curwin;
|
|
4158
|
|
4159 /* Currently we only get the mouse coordinates in the GUI. */
|
|
4160 if (gui.in_use && mouse_row >= 0 && mouse_col >= 0)
|
|
4161 {
|
|
4162 int row, col;
|
|
4163
|
|
4164 row = mouse_row;
|
|
4165 col = mouse_col;
|
|
4166
|
|
4167 /* find the window at the pointer coordinates */
|
|
4168 curwin = mouse_find_win(&row, &col);
|
|
4169 curbuf = curwin->w_buffer;
|
|
4170 }
|
|
4171 # endif
|
|
4172
|
|
4173 if (mod_mask & (MOD_MASK_SHIFT | MOD_MASK_CTRL))
|
|
4174 {
|
|
4175 (void)onepage(cap->arg ? FORWARD : BACKWARD, 1L);
|
|
4176 }
|
|
4177 else
|
|
4178 {
|
|
4179 cap->count1 = 3;
|
|
4180 cap->count0 = 3;
|
|
4181 nv_scroll_line(cap);
|
|
4182 }
|
|
4183
|
|
4184 # if defined(FEAT_GUI) && defined(FEAT_WINDOWS)
|
|
4185 curwin->w_redr_status = TRUE;
|
|
4186
|
|
4187 curwin = old_curwin;
|
|
4188 curbuf = curwin->w_buffer;
|
|
4189 # endif
|
|
4190 }
|
|
4191
|
|
4192 /*
|
|
4193 * Mouse clicks and drags.
|
|
4194 */
|
|
4195 static void
|
|
4196 nv_mouse(cap)
|
|
4197 cmdarg_T *cap;
|
|
4198 {
|
|
4199 (void)do_mouse(cap->oap, cap->cmdchar, BACKWARD, cap->count1, 0);
|
|
4200 }
|
|
4201 #endif
|
|
4202
|
|
4203 /*
|
|
4204 * Handle CTRL-E and CTRL-Y commands: scroll a line up or down.
|
|
4205 * cap->arg must be TRUE for CTRL-E.
|
|
4206 */
|
|
4207 static void
|
|
4208 nv_scroll_line(cap)
|
|
4209 cmdarg_T *cap;
|
|
4210 {
|
|
4211 if (!checkclearop(cap->oap))
|
|
4212 scroll_redraw(cap->arg, cap->count1);
|
|
4213 }
|
|
4214
|
|
4215 /*
|
|
4216 * Scroll "count" lines up or down, and redraw.
|
|
4217 */
|
|
4218 void
|
|
4219 scroll_redraw(up, count)
|
|
4220 int up;
|
|
4221 long count;
|
|
4222 {
|
|
4223 linenr_T prev_topline = curwin->w_topline;
|
|
4224 #ifdef FEAT_DIFF
|
|
4225 int prev_topfill = curwin->w_topfill;
|
|
4226 #endif
|
|
4227 linenr_T prev_lnum = curwin->w_cursor.lnum;
|
|
4228
|
|
4229 if (up)
|
|
4230 scrollup(count, TRUE);
|
|
4231 else
|
|
4232 scrolldown(count, TRUE);
|
|
4233 if (p_so)
|
|
4234 {
|
|
4235 /* Adjust the cursor position for 'scrolloff'. Mark w_topline as
|
|
4236 * valid, otherwise the screen jumps back at the end of the file. */
|
|
4237 cursor_correct();
|
|
4238 check_cursor_moved(curwin);
|
|
4239 curwin->w_valid |= VALID_TOPLINE;
|
|
4240
|
|
4241 /* If moved back to where we were, at least move the cursor, otherwise
|
|
4242 * we get stuck at one position. Don't move the cursor up if the
|
|
4243 * first line of the buffer is already on the screen */
|
|
4244 while (curwin->w_topline == prev_topline
|
|
4245 #ifdef FEAT_DIFF
|
|
4246 && curwin->w_topfill == prev_topfill
|
|
4247 #endif
|
|
4248 )
|
|
4249 {
|
|
4250 if (up)
|
|
4251 {
|
|
4252 if (curwin->w_cursor.lnum > prev_lnum
|
|
4253 || cursor_down(1L, FALSE) == FAIL)
|
|
4254 break;
|
|
4255 }
|
|
4256 else
|
|
4257 {
|
|
4258 if (curwin->w_cursor.lnum < prev_lnum
|
|
4259 || prev_topline == 1L
|
|
4260 || cursor_up(1L, FALSE) == FAIL)
|
|
4261 break;
|
|
4262 }
|
|
4263 /* Mark w_topline as valid, otherwise the screen jumps back at the
|
|
4264 * end of the file. */
|
|
4265 check_cursor_moved(curwin);
|
|
4266 curwin->w_valid |= VALID_TOPLINE;
|
|
4267 }
|
|
4268 }
|
|
4269 if (curwin->w_cursor.lnum != prev_lnum)
|
|
4270 coladvance(curwin->w_curswant);
|
|
4271 redraw_later(VALID);
|
|
4272 }
|
|
4273
|
|
4274 /*
|
|
4275 * Commands that start with "z".
|
|
4276 */
|
|
4277 static void
|
|
4278 nv_zet(cap)
|
|
4279 cmdarg_T *cap;
|
|
4280 {
|
|
4281 long n;
|
|
4282 colnr_T col;
|
|
4283 int nchar = cap->nchar;
|
|
4284 #ifdef FEAT_FOLDING
|
|
4285 long old_fdl = curwin->w_p_fdl;
|
|
4286 int old_fen = curwin->w_p_fen;
|
|
4287 #endif
|
|
4288
|
|
4289 if (VIM_ISDIGIT(nchar))
|
|
4290 {
|
|
4291 /*
|
|
4292 * "z123{nchar}": edit the count before obtaining {nchar}
|
|
4293 */
|
|
4294 if (checkclearop(cap->oap))
|
|
4295 return;
|
|
4296 n = nchar - '0';
|
|
4297 for (;;)
|
|
4298 {
|
|
4299 #ifdef USE_ON_FLY_SCROLL
|
|
4300 dont_scroll = TRUE; /* disallow scrolling here */
|
|
4301 #endif
|
|
4302 ++no_mapping;
|
|
4303 ++allow_keys; /* no mapping for nchar, but allow key codes */
|
|
4304 nchar = safe_vgetc();
|
|
4305 #ifdef FEAT_LANGMAP
|
|
4306 LANGMAP_ADJUST(nchar, TRUE);
|
|
4307 #endif
|
|
4308 --no_mapping;
|
|
4309 --allow_keys;
|
|
4310 #ifdef FEAT_CMDL_INFO
|
|
4311 (void)add_to_showcmd(nchar);
|
|
4312 #endif
|
|
4313 if (nchar == K_DEL || nchar == K_KDEL)
|
|
4314 n /= 10;
|
|
4315 else if (VIM_ISDIGIT(nchar))
|
|
4316 n = n * 10 + (nchar - '0');
|
|
4317 else if (nchar == CAR)
|
|
4318 {
|
|
4319 #ifdef FEAT_GUI
|
|
4320 need_mouse_correct = TRUE;
|
|
4321 #endif
|
|
4322 win_setheight((int)n);
|
|
4323 break;
|
|
4324 }
|
|
4325 else if (nchar == 'l'
|
|
4326 || nchar == 'h'
|
|
4327 || nchar == K_LEFT
|
229
|
4328 || nchar == K_RIGHT)
|
7
|
4329 {
|
|
4330 cap->count1 = n ? n * cap->count1 : cap->count1;
|
|
4331 goto dozet;
|
|
4332 }
|
|
4333 else
|
|
4334 {
|
|
4335 clearopbeep(cap->oap);
|
|
4336 break;
|
|
4337 }
|
|
4338 }
|
|
4339 cap->oap->op_type = OP_NOP;
|
|
4340 return;
|
|
4341 }
|
|
4342
|
|
4343 dozet:
|
|
4344 if (
|
|
4345 #ifdef FEAT_FOLDING
|
|
4346 /* "zf" and "zF" are always an operator, "zd", "zo", "zO", "zc"
|
|
4347 * and "zC" only in Visual mode. "zj" and "zk" are motion
|
|
4348 * commands. */
|
|
4349 cap->nchar != 'f' && cap->nchar != 'F'
|
|
4350 && !(VIsual_active && vim_strchr((char_u *)"dcCoO", cap->nchar))
|
|
4351 && cap->nchar != 'j' && cap->nchar != 'k'
|
|
4352 &&
|
|
4353 #endif
|
|
4354 checkclearop(cap->oap))
|
|
4355 return;
|
|
4356
|
|
4357 /*
|
|
4358 * For "z+", "z<CR>", "zt", "z.", "zz", "z^", "z-", "zb":
|
|
4359 * If line number given, set cursor.
|
|
4360 */
|
|
4361 if ((vim_strchr((char_u *)"+\r\nt.z^-b", nchar) != NULL)
|
|
4362 && cap->count0
|
|
4363 && cap->count0 != curwin->w_cursor.lnum)
|
|
4364 {
|
|
4365 setpcmark();
|
|
4366 if (cap->count0 > curbuf->b_ml.ml_line_count)
|
|
4367 curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count;
|
|
4368 else
|
|
4369 curwin->w_cursor.lnum = cap->count0;
|
22
|
4370 check_cursor_col();
|
7
|
4371 }
|
|
4372
|
|
4373 switch (nchar)
|
|
4374 {
|
|
4375 /* "z+", "z<CR>" and "zt": put cursor at top of screen */
|
|
4376 case '+':
|
|
4377 if (cap->count0 == 0)
|
|
4378 {
|
|
4379 /* No count given: put cursor at the line below screen */
|
|
4380 validate_botline(); /* make sure w_botline is valid */
|
|
4381 if (curwin->w_botline > curbuf->b_ml.ml_line_count)
|
|
4382 curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count;
|
|
4383 else
|
|
4384 curwin->w_cursor.lnum = curwin->w_botline;
|
|
4385 }
|
|
4386 /* FALLTHROUGH */
|
|
4387 case NL:
|
|
4388 case CAR:
|
|
4389 case K_KENTER:
|
|
4390 beginline(BL_WHITE | BL_FIX);
|
|
4391 /* FALLTHROUGH */
|
|
4392
|
|
4393 case 't': scroll_cursor_top(0, TRUE);
|
|
4394 redraw_later(VALID);
|
|
4395 break;
|
|
4396
|
|
4397 /* "z." and "zz": put cursor in middle of screen */
|
|
4398 case '.': beginline(BL_WHITE | BL_FIX);
|
|
4399 /* FALLTHROUGH */
|
|
4400
|
|
4401 case 'z': scroll_cursor_halfway(TRUE);
|
|
4402 redraw_later(VALID);
|
|
4403 break;
|
|
4404
|
|
4405 /* "z^", "z-" and "zb": put cursor at bottom of screen */
|
|
4406 case '^': /* Strange Vi behavior: <count>z^ finds line at top of window
|
|
4407 * when <count> is at bottom of window, and puts that one at
|
|
4408 * bottom of window. */
|
|
4409 if (cap->count0 != 0)
|
|
4410 {
|
|
4411 scroll_cursor_bot(0, TRUE);
|
|
4412 curwin->w_cursor.lnum = curwin->w_topline;
|
|
4413 }
|
|
4414 else if (curwin->w_topline == 1)
|
|
4415 curwin->w_cursor.lnum = 1;
|
|
4416 else
|
|
4417 curwin->w_cursor.lnum = curwin->w_topline - 1;
|
|
4418 /* FALLTHROUGH */
|
|
4419 case '-':
|
|
4420 beginline(BL_WHITE | BL_FIX);
|
|
4421 /* FALLTHROUGH */
|
|
4422
|
|
4423 case 'b': scroll_cursor_bot(0, TRUE);
|
|
4424 redraw_later(VALID);
|
|
4425 break;
|
|
4426
|
|
4427 /* "zH" - scroll screen right half-page */
|
|
4428 case 'H':
|
|
4429 cap->count1 *= W_WIDTH(curwin) / 2;
|
|
4430 /* FALLTHROUGH */
|
|
4431
|
|
4432 /* "zh" - scroll screen to the right */
|
|
4433 case 'h':
|
|
4434 case K_LEFT:
|
|
4435 if (!curwin->w_p_wrap)
|
|
4436 {
|
|
4437 if ((colnr_T)cap->count1 > curwin->w_leftcol)
|
|
4438 curwin->w_leftcol = 0;
|
|
4439 else
|
|
4440 curwin->w_leftcol -= (colnr_T)cap->count1;
|
|
4441 leftcol_changed();
|
|
4442 }
|
|
4443 break;
|
|
4444
|
|
4445 /* "zL" - scroll screen left half-page */
|
|
4446 case 'L': cap->count1 *= W_WIDTH(curwin) / 2;
|
|
4447 /* FALLTHROUGH */
|
|
4448
|
|
4449 /* "zl" - scroll screen to the left */
|
|
4450 case 'l':
|
|
4451 case K_RIGHT:
|
|
4452 if (!curwin->w_p_wrap)
|
|
4453 {
|
|
4454 /* scroll the window left */
|
|
4455 curwin->w_leftcol += (colnr_T)cap->count1;
|
|
4456 leftcol_changed();
|
|
4457 }
|
|
4458 break;
|
|
4459
|
|
4460 /* "zs" - scroll screen, cursor at the start */
|
|
4461 case 's': if (!curwin->w_p_wrap)
|
|
4462 {
|
|
4463 #ifdef FEAT_FOLDING
|
|
4464 if (hasFolding(curwin->w_cursor.lnum, NULL, NULL))
|
|
4465 col = 0; /* like the cursor is in col 0 */
|
|
4466 else
|
|
4467 #endif
|
|
4468 getvcol(curwin, &curwin->w_cursor, &col, NULL, NULL);
|
|
4469 if ((long)col > p_siso)
|
|
4470 col -= p_siso;
|
|
4471 else
|
|
4472 col = 0;
|
|
4473 if (curwin->w_leftcol != col)
|
|
4474 {
|
|
4475 curwin->w_leftcol = col;
|
|
4476 redraw_later(NOT_VALID);
|
|
4477 }
|
|
4478 }
|
|
4479 break;
|
|
4480
|
|
4481 /* "ze" - scroll screen, cursor at the end */
|
|
4482 case 'e': if (!curwin->w_p_wrap)
|
|
4483 {
|
|
4484 #ifdef FEAT_FOLDING
|
|
4485 if (hasFolding(curwin->w_cursor.lnum, NULL, NULL))
|
|
4486 col = 0; /* like the cursor is in col 0 */
|
|
4487 else
|
|
4488 #endif
|
|
4489 getvcol(curwin, &curwin->w_cursor, NULL, NULL, &col);
|
|
4490 n = W_WIDTH(curwin) - curwin_col_off();
|
|
4491 if ((long)col + p_siso < n)
|
|
4492 col = 0;
|
|
4493 else
|
|
4494 col = col + p_siso - n + 1;
|
|
4495 if (curwin->w_leftcol != col)
|
|
4496 {
|
|
4497 curwin->w_leftcol = col;
|
|
4498 redraw_later(NOT_VALID);
|
|
4499 }
|
|
4500 }
|
|
4501 break;
|
|
4502
|
|
4503 #ifdef FEAT_FOLDING
|
|
4504 /* "zF": create fold command */
|
|
4505 /* "zf": create fold operator */
|
|
4506 case 'F':
|
|
4507 case 'f': if (foldManualAllowed(TRUE))
|
|
4508 {
|
|
4509 cap->nchar = 'f';
|
|
4510 nv_operator(cap);
|
|
4511 curwin->w_p_fen = TRUE;
|
|
4512
|
|
4513 /* "zF" is like "zfzf" */
|
|
4514 if (nchar == 'F' && cap->oap->op_type == OP_FOLD)
|
|
4515 {
|
|
4516 nv_operator(cap);
|
|
4517 finish_op = TRUE;
|
|
4518 }
|
|
4519 }
|
|
4520 else
|
|
4521 clearopbeep(cap->oap);
|
|
4522 break;
|
|
4523
|
|
4524 /* "zd": delete fold at cursor */
|
|
4525 /* "zD": delete fold at cursor recursively */
|
|
4526 case 'd':
|
|
4527 case 'D': if (foldManualAllowed(FALSE))
|
|
4528 {
|
|
4529 if (VIsual_active)
|
|
4530 nv_operator(cap);
|
|
4531 else
|
|
4532 deleteFold(curwin->w_cursor.lnum,
|
|
4533 curwin->w_cursor.lnum, nchar == 'D', FALSE);
|
|
4534 }
|
|
4535 break;
|
|
4536
|
|
4537 /* "zE": erease all folds */
|
|
4538 case 'E': if (foldmethodIsManual(curwin))
|
|
4539 {
|
|
4540 clearFolding(curwin);
|
|
4541 changed_window_setting();
|
|
4542 }
|
|
4543 else if (foldmethodIsMarker(curwin))
|
|
4544 deleteFold((linenr_T)1, curbuf->b_ml.ml_line_count,
|
|
4545 TRUE, FALSE);
|
|
4546 else
|
|
4547 EMSG(_("E352: Cannot erase folds with current 'foldmethod'"));
|
|
4548 break;
|
|
4549
|
|
4550 /* "zn": fold none: reset 'foldenable' */
|
|
4551 case 'n': curwin->w_p_fen = FALSE;
|
|
4552 break;
|
|
4553
|
|
4554 /* "zN": fold Normal: set 'foldenable' */
|
|
4555 case 'N': curwin->w_p_fen = TRUE;
|
|
4556 break;
|
|
4557
|
|
4558 /* "zi": invert folding: toggle 'foldenable' */
|
|
4559 case 'i': curwin->w_p_fen = !curwin->w_p_fen;
|
|
4560 break;
|
|
4561
|
|
4562 /* "za": open closed fold or close open fold at cursor */
|
|
4563 case 'a': if (hasFolding(curwin->w_cursor.lnum, NULL, NULL))
|
|
4564 openFold(curwin->w_cursor.lnum, cap->count1);
|
|
4565 else
|
|
4566 {
|
|
4567 closeFold(curwin->w_cursor.lnum, cap->count1);
|
|
4568 curwin->w_p_fen = TRUE;
|
|
4569 }
|
|
4570 break;
|
|
4571
|
|
4572 /* "zA": open fold at cursor recursively */
|
|
4573 case 'A': if (hasFolding(curwin->w_cursor.lnum, NULL, NULL))
|
|
4574 openFoldRecurse(curwin->w_cursor.lnum);
|
|
4575 else
|
|
4576 {
|
|
4577 closeFoldRecurse(curwin->w_cursor.lnum);
|
|
4578 curwin->w_p_fen = TRUE;
|
|
4579 }
|
|
4580 break;
|
|
4581
|
|
4582 /* "zo": open fold at cursor or Visual area */
|
|
4583 case 'o': if (VIsual_active)
|
|
4584 nv_operator(cap);
|
|
4585 else
|
|
4586 openFold(curwin->w_cursor.lnum, cap->count1);
|
|
4587 break;
|
|
4588
|
|
4589 /* "zO": open fold recursively */
|
|
4590 case 'O': if (VIsual_active)
|
|
4591 nv_operator(cap);
|
|
4592 else
|
|
4593 openFoldRecurse(curwin->w_cursor.lnum);
|
|
4594 break;
|
|
4595
|
|
4596 /* "zc": close fold at cursor or Visual area */
|
|
4597 case 'c': if (VIsual_active)
|
|
4598 nv_operator(cap);
|
|
4599 else
|
|
4600 closeFold(curwin->w_cursor.lnum, cap->count1);
|
|
4601 curwin->w_p_fen = TRUE;
|
|
4602 break;
|
|
4603
|
|
4604 /* "zC": close fold recursively */
|
|
4605 case 'C': if (VIsual_active)
|
|
4606 nv_operator(cap);
|
|
4607 else
|
|
4608 closeFoldRecurse(curwin->w_cursor.lnum);
|
|
4609 curwin->w_p_fen = TRUE;
|
|
4610 break;
|
|
4611
|
|
4612 /* "zv": open folds at the cursor */
|
|
4613 case 'v': foldOpenCursor();
|
|
4614 break;
|
|
4615
|
|
4616 /* "zx": re-apply 'foldlevel' and open folds at the cursor */
|
|
4617 case 'x': curwin->w_p_fen = TRUE;
|
|
4618 newFoldLevel(); /* update right now */
|
|
4619 foldOpenCursor();
|
|
4620 break;
|
|
4621
|
|
4622 /* "zX": undo manual opens/closes, re-apply 'foldlevel' */
|
|
4623 case 'X': curwin->w_p_fen = TRUE;
|
|
4624 old_fdl = -1; /* force an update */
|
|
4625 break;
|
|
4626
|
|
4627 /* "zm": fold more */
|
|
4628 case 'm': if (curwin->w_p_fdl > 0)
|
|
4629 --curwin->w_p_fdl;
|
|
4630 old_fdl = -1; /* force an update */
|
|
4631 curwin->w_p_fen = TRUE;
|
|
4632 break;
|
|
4633
|
|
4634 /* "zM": close all folds */
|
|
4635 case 'M': curwin->w_p_fdl = 0;
|
|
4636 old_fdl = -1; /* force an update */
|
|
4637 curwin->w_p_fen = TRUE;
|
|
4638 break;
|
|
4639
|
|
4640 /* "zr": reduce folding */
|
|
4641 case 'r': ++curwin->w_p_fdl;
|
|
4642 break;
|
|
4643
|
|
4644 /* "zR": open all folds */
|
|
4645 case 'R': curwin->w_p_fdl = getDeepestNesting();
|
|
4646 old_fdl = -1; /* force an update */
|
|
4647 break;
|
|
4648
|
|
4649 case 'j': /* "zj" move to next fold downwards */
|
|
4650 case 'k': /* "zk" move to next fold upwards */
|
|
4651 if (foldMoveTo(TRUE, nchar == 'j' ? FORWARD : BACKWARD,
|
|
4652 cap->count1) == FAIL)
|
|
4653 clearopbeep(cap->oap);
|
|
4654 break;
|
|
4655
|
|
4656 #endif /* FEAT_FOLDING */
|
|
4657
|
|
4658 default: clearopbeep(cap->oap);
|
|
4659 }
|
|
4660
|
|
4661 #ifdef FEAT_FOLDING
|
|
4662 /* Redraw when 'foldenable' changed */
|
|
4663 if (old_fen != curwin->w_p_fen)
|
|
4664 {
|
|
4665 # ifdef FEAT_DIFF
|
|
4666 win_T *wp;
|
|
4667
|
|
4668 if (foldmethodIsDiff(curwin) && curwin->w_p_scb)
|
|
4669 {
|
|
4670 /* Adjust 'foldenable' in diff-synced windows. */
|
|
4671 FOR_ALL_WINDOWS(wp)
|
|
4672 {
|
|
4673 if (wp != curwin && foldmethodIsDiff(wp) && wp->w_p_scb)
|
|
4674 {
|
|
4675 wp->w_p_fen = curwin->w_p_fen;
|
|
4676 changed_window_setting_win(wp);
|
|
4677 }
|
|
4678 }
|
|
4679 }
|
|
4680 # endif
|
|
4681 changed_window_setting();
|
|
4682 }
|
|
4683
|
|
4684 /* Redraw when 'foldlevel' changed. */
|
|
4685 if (old_fdl != curwin->w_p_fdl)
|
|
4686 newFoldLevel();
|
|
4687 #endif
|
|
4688 }
|
|
4689
|
|
4690 #ifdef FEAT_GUI
|
|
4691 /*
|
|
4692 * Vertical scrollbar movement.
|
|
4693 */
|
|
4694 static void
|
|
4695 nv_ver_scrollbar(cap)
|
|
4696 cmdarg_T *cap;
|
|
4697 {
|
|
4698 if (cap->oap->op_type != OP_NOP)
|
|
4699 clearopbeep(cap->oap);
|
|
4700
|
|
4701 /* Even if an operator was pending, we still want to scroll */
|
|
4702 gui_do_scroll();
|
|
4703 }
|
|
4704
|
|
4705 /*
|
|
4706 * Horizontal scrollbar movement.
|
|
4707 */
|
|
4708 static void
|
|
4709 nv_hor_scrollbar(cap)
|
|
4710 cmdarg_T *cap;
|
|
4711 {
|
|
4712 if (cap->oap->op_type != OP_NOP)
|
|
4713 clearopbeep(cap->oap);
|
|
4714
|
|
4715 /* Even if an operator was pending, we still want to scroll */
|
|
4716 gui_do_horiz_scroll();
|
|
4717 }
|
|
4718 #endif
|
|
4719
|
|
4720 /*
|
|
4721 * "Q" command.
|
|
4722 */
|
|
4723 static void
|
|
4724 nv_exmode(cap)
|
|
4725 cmdarg_T *cap;
|
|
4726 {
|
|
4727 /*
|
|
4728 * Ignore 'Q' in Visual mode, just give a beep.
|
|
4729 */
|
|
4730 #ifdef FEAT_VISUAL
|
|
4731 if (VIsual_active)
|
|
4732 vim_beep();
|
|
4733 else
|
|
4734 #endif
|
|
4735 if (!checkclearop(cap->oap))
|
|
4736 do_exmode(FALSE);
|
|
4737 }
|
|
4738
|
|
4739 /*
|
|
4740 * Handle a ":" command.
|
|
4741 */
|
|
4742 static void
|
|
4743 nv_colon(cap)
|
|
4744 cmdarg_T *cap;
|
|
4745 {
|
|
4746 int old_p_im;
|
|
4747
|
|
4748 #ifdef FEAT_VISUAL
|
|
4749 if (VIsual_active)
|
|
4750 nv_operator(cap);
|
|
4751 else
|
|
4752 #endif
|
|
4753 {
|
|
4754 if (cap->oap->op_type != OP_NOP)
|
|
4755 {
|
|
4756 /* Using ":" as a movement is characterwise exclusive. */
|
|
4757 cap->oap->motion_type = MCHAR;
|
|
4758 cap->oap->inclusive = FALSE;
|
|
4759 }
|
|
4760 else if (cap->count0)
|
|
4761 {
|
|
4762 /* translate "count:" into ":.,.+(count - 1)" */
|
|
4763 stuffcharReadbuff('.');
|
|
4764 if (cap->count0 > 1)
|
|
4765 {
|
|
4766 stuffReadbuff((char_u *)",.+");
|
|
4767 stuffnumReadbuff((long)cap->count0 - 1L);
|
|
4768 }
|
|
4769 }
|
|
4770
|
|
4771 /* When typing, don't type below an old message */
|
|
4772 if (KeyTyped)
|
|
4773 compute_cmdrow();
|
|
4774
|
|
4775 old_p_im = p_im;
|
|
4776
|
|
4777 /* get a command line and execute it */
|
|
4778 do_cmdline(NULL, getexline, NULL,
|
|
4779 cap->oap->op_type != OP_NOP ? DOCMD_KEEPLINE : 0);
|
|
4780
|
|
4781 /* If 'insertmode' changed, enter or exit Insert mode */
|
|
4782 if (p_im != old_p_im)
|
|
4783 {
|
|
4784 if (p_im)
|
|
4785 restart_edit = 'i';
|
|
4786 else
|
|
4787 restart_edit = 0;
|
|
4788 }
|
|
4789
|
|
4790 /* The start of the operator may have become invalid by the Ex
|
|
4791 * command. */
|
|
4792 if (cap->oap->op_type != OP_NOP
|
|
4793 && (cap->oap->start.lnum > curbuf->b_ml.ml_line_count
|
|
4794 || cap->oap->start.col >
|
|
4795 STRLEN(ml_get(cap->oap->start.lnum))))
|
|
4796 clearopbeep(cap->oap);
|
|
4797 }
|
|
4798 }
|
|
4799
|
|
4800 /*
|
|
4801 * Handle CTRL-G command.
|
|
4802 */
|
|
4803 static void
|
|
4804 nv_ctrlg(cap)
|
|
4805 cmdarg_T *cap;
|
|
4806 {
|
|
4807 #ifdef FEAT_VISUAL
|
|
4808 if (VIsual_active) /* toggle Selection/Visual mode */
|
|
4809 {
|
|
4810 VIsual_select = !VIsual_select;
|
|
4811 showmode();
|
|
4812 }
|
|
4813 else
|
|
4814 #endif
|
|
4815 if (!checkclearop(cap->oap))
|
|
4816 /* print full name if count given or :cd used */
|
|
4817 fileinfo((int)cap->count0, FALSE, TRUE);
|
|
4818 }
|
|
4819
|
|
4820 /*
|
|
4821 * Handle CTRL-H <Backspace> command.
|
|
4822 */
|
|
4823 static void
|
|
4824 nv_ctrlh(cap)
|
|
4825 cmdarg_T *cap;
|
|
4826 {
|
|
4827 #ifdef FEAT_VISUAL
|
|
4828 if (VIsual_active && VIsual_select)
|
|
4829 {
|
|
4830 cap->cmdchar = 'x'; /* BS key behaves like 'x' in Select mode */
|
|
4831 v_visop(cap);
|
|
4832 }
|
|
4833 else
|
|
4834 #endif
|
|
4835 nv_left(cap);
|
|
4836 }
|
|
4837
|
|
4838 /*
|
|
4839 * CTRL-L: clear screen and redraw.
|
|
4840 */
|
|
4841 static void
|
|
4842 nv_clear(cap)
|
|
4843 cmdarg_T *cap;
|
|
4844 {
|
|
4845 if (!checkclearop(cap->oap))
|
|
4846 {
|
|
4847 #if defined(__BEOS__) && !USE_THREAD_FOR_INPUT_WITH_TIMEOUT
|
|
4848 /*
|
|
4849 * Right now, the BeBox doesn't seem to have an easy way to detect
|
|
4850 * window resizing, so we cheat and make the user detect it
|
|
4851 * manually with CTRL-L instead
|
|
4852 */
|
|
4853 ui_get_shellsize();
|
|
4854 #endif
|
|
4855 #ifdef FEAT_SYN_HL
|
|
4856 /* Clear all syntax states to force resyncing. */
|
|
4857 syn_stack_free_all(curbuf);
|
|
4858 #endif
|
|
4859 redraw_later(CLEAR);
|
|
4860 }
|
|
4861 }
|
|
4862
|
|
4863 /*
|
|
4864 * CTRL-O: In Select mode: switch to Visual mode for one command.
|
|
4865 * Otherwise: Go to older pcmark.
|
|
4866 */
|
|
4867 static void
|
|
4868 nv_ctrlo(cap)
|
|
4869 cmdarg_T *cap;
|
|
4870 {
|
|
4871 #ifdef FEAT_VISUAL
|
|
4872 if (VIsual_active && VIsual_select)
|
|
4873 {
|
|
4874 VIsual_select = FALSE;
|
|
4875 showmode();
|
|
4876 restart_VIsual_select = 2; /* restart Select mode later */
|
|
4877 }
|
|
4878 else
|
|
4879 #endif
|
|
4880 {
|
|
4881 cap->count1 = -cap->count1;
|
|
4882 nv_pcmark(cap);
|
|
4883 }
|
|
4884 }
|
|
4885
|
|
4886 /*
|
|
4887 * CTRL-^ command, short for ":e #"
|
|
4888 */
|
|
4889 static void
|
|
4890 nv_hat(cap)
|
|
4891 cmdarg_T *cap;
|
|
4892 {
|
|
4893 if (!checkclearopq(cap->oap))
|
|
4894 (void)buflist_getfile((int)cap->count0, (linenr_T)0,
|
|
4895 GETF_SETMARK|GETF_ALT, FALSE);
|
|
4896 }
|
|
4897
|
|
4898 /*
|
|
4899 * "Z" commands.
|
|
4900 */
|
|
4901 static void
|
|
4902 nv_Zet(cap)
|
|
4903 cmdarg_T *cap;
|
|
4904 {
|
|
4905 if (!checkclearopq(cap->oap))
|
|
4906 {
|
|
4907 switch (cap->nchar)
|
|
4908 {
|
|
4909 /* "ZZ": equivalent to ":x". */
|
|
4910 case 'Z': do_cmdline_cmd((char_u *)"x");
|
|
4911 break;
|
|
4912
|
|
4913 /* "ZQ": equivalent to ":q!" (Elvis compatible). */
|
|
4914 case 'Q': do_cmdline_cmd((char_u *)"q!");
|
|
4915 break;
|
|
4916
|
|
4917 default: clearopbeep(cap->oap);
|
|
4918 }
|
|
4919 }
|
|
4920 }
|
|
4921
|
|
4922 #if defined(FEAT_WINDOWS) || defined(PROTO)
|
|
4923 /*
|
|
4924 * Call nv_ident() as if "c1" was used, with "c2" as next character.
|
|
4925 */
|
|
4926 void
|
|
4927 do_nv_ident(c1, c2)
|
|
4928 int c1;
|
|
4929 int c2;
|
|
4930 {
|
|
4931 oparg_T oa;
|
|
4932 cmdarg_T ca;
|
|
4933
|
|
4934 clear_oparg(&oa);
|
|
4935 vim_memset(&ca, 0, sizeof(ca));
|
|
4936 ca.oap = &oa;
|
|
4937 ca.cmdchar = c1;
|
|
4938 ca.nchar = c2;
|
|
4939 nv_ident(&ca);
|
|
4940 }
|
|
4941 #endif
|
|
4942
|
|
4943 /*
|
|
4944 * Handle the commands that use the word under the cursor.
|
|
4945 * [g] CTRL-] :ta to current identifier
|
|
4946 * [g] 'K' run program for current identifier
|
|
4947 * [g] '*' / to current identifier or string
|
|
4948 * [g] '#' ? to current identifier or string
|
|
4949 * g ']' :tselect for current identifier
|
|
4950 */
|
|
4951 static void
|
|
4952 nv_ident(cap)
|
|
4953 cmdarg_T *cap;
|
|
4954 {
|
|
4955 char_u *ptr = NULL;
|
|
4956 char_u *buf;
|
|
4957 char_u *p;
|
|
4958 char_u *kp; /* value of 'keywordprg' */
|
|
4959 int kp_help; /* 'keywordprg' is ":help" */
|
|
4960 int n = 0; /* init for GCC */
|
|
4961 int cmdchar;
|
|
4962 int g_cmd; /* "g" command */
|
|
4963 char_u *aux_ptr;
|
|
4964 int isman;
|
|
4965 int isman_s;
|
|
4966
|
|
4967 if (cap->cmdchar == 'g') /* "g*", "g#", "g]" and "gCTRL-]" */
|
|
4968 {
|
|
4969 cmdchar = cap->nchar;
|
|
4970 g_cmd = TRUE;
|
|
4971 }
|
|
4972 else
|
|
4973 {
|
|
4974 cmdchar = cap->cmdchar;
|
|
4975 g_cmd = FALSE;
|
|
4976 }
|
|
4977
|
|
4978 if (cmdchar == POUND) /* the pound sign, '#' for English keyboards */
|
|
4979 cmdchar = '#';
|
|
4980
|
|
4981 /*
|
|
4982 * The "]", "CTRL-]" and "K" commands accept an argument in Visual mode.
|
|
4983 */
|
|
4984 if (cmdchar == ']' || cmdchar == Ctrl_RSB || cmdchar == 'K')
|
|
4985 {
|
|
4986 #ifdef FEAT_VISUAL
|
|
4987 if (VIsual_active && get_visual_text(cap, &ptr, &n) == FAIL)
|
|
4988 return;
|
|
4989 #endif
|
|
4990 if (checkclearopq(cap->oap))
|
|
4991 return;
|
|
4992 }
|
|
4993
|
|
4994 if (ptr == NULL && (n = find_ident_under_cursor(&ptr,
|
|
4995 (cmdchar == '*' || cmdchar == '#')
|
|
4996 ? FIND_IDENT|FIND_STRING : FIND_IDENT)) == 0)
|
|
4997 {
|
|
4998 clearop(cap->oap);
|
|
4999 return;
|
|
5000 }
|
|
5001
|
|
5002 /* Allocate buffer to put the command in. Inserting backslashes can
|
|
5003 * double the length of the word. p_kp / curbuf->b_p_kp could be added
|
|
5004 * and some numbers. */
|
|
5005 kp = (*curbuf->b_p_kp == NUL ? p_kp : curbuf->b_p_kp);
|
|
5006 kp_help = (*kp == NUL || STRCMP(kp, ":he") == 0
|
|
5007 || STRCMP(kp, ":help") == 0);
|
|
5008 buf = alloc((unsigned)(n * 2 + 30 + STRLEN(kp)));
|
|
5009 if (buf == NULL)
|
|
5010 return;
|
|
5011 buf[0] = NUL;
|
|
5012
|
|
5013 switch (cmdchar)
|
|
5014 {
|
|
5015 case '*':
|
|
5016 case '#':
|
|
5017 /*
|
|
5018 * Put cursor at start of word, makes search skip the word
|
|
5019 * under the cursor.
|
|
5020 * Call setpcmark() first, so "*``" puts the cursor back where
|
|
5021 * it was.
|
|
5022 */
|
|
5023 setpcmark();
|
|
5024 curwin->w_cursor.col = (colnr_T) (ptr - ml_get_curline());
|
|
5025
|
|
5026 if (!g_cmd && vim_iswordp(ptr))
|
|
5027 STRCPY(buf, "\\<");
|
|
5028 no_smartcase = TRUE; /* don't use 'smartcase' now */
|
|
5029 break;
|
|
5030
|
|
5031 case 'K':
|
|
5032 if (kp_help)
|
|
5033 STRCPY(buf, "he! ");
|
|
5034 else
|
|
5035 {
|
|
5036 /* When a count is given, turn it into a range. Is this
|
|
5037 * really what we want? */
|
|
5038 isman = (STRCMP(kp, "man") == 0);
|
|
5039 isman_s = (STRCMP(kp, "man -s") == 0);
|
|
5040 if (cap->count0 != 0 && !(isman || isman_s))
|
|
5041 sprintf((char *)buf, ".,.+%ld", cap->count0 - 1);
|
|
5042
|
|
5043 STRCAT(buf, "! ");
|
|
5044 if (cap->count0 == 0 && isman_s)
|
|
5045 STRCAT(buf, "man");
|
|
5046 else
|
|
5047 STRCAT(buf, kp);
|
|
5048 STRCAT(buf, " ");
|
|
5049 if (cap->count0 != 0 && (isman || isman_s))
|
|
5050 {
|
|
5051 sprintf((char *)buf + STRLEN(buf), "%ld", cap->count0);
|
|
5052 STRCAT(buf, " ");
|
|
5053 }
|
|
5054 }
|
|
5055 break;
|
|
5056
|
|
5057 case ']':
|
|
5058 #ifdef FEAT_CSCOPE
|
|
5059 if (p_cst)
|
|
5060 STRCPY(buf, "cstag ");
|
|
5061 else
|
|
5062 #endif
|
|
5063 STRCPY(buf, "ts ");
|
|
5064 break;
|
|
5065
|
|
5066 default:
|
|
5067 if (curbuf->b_help)
|
|
5068 STRCPY(buf, "he! ");
|
|
5069 else if (g_cmd)
|
|
5070 STRCPY(buf, "tj ");
|
|
5071 else
|
|
5072 STRCPY(buf, "ta ");
|
|
5073 }
|
|
5074
|
|
5075 /*
|
|
5076 * Now grab the chars in the identifier
|
|
5077 */
|
|
5078 if (cmdchar == '*')
|
|
5079 aux_ptr = (char_u *)(p_magic ? "/.*~[^$\\" : "/^$\\");
|
|
5080 else if (cmdchar == '#')
|
|
5081 aux_ptr = (char_u *)(p_magic ? "/?.*~[^$\\" : "/?^$\\");
|
|
5082 else if (cmdchar == 'K' && !kp_help)
|
|
5083 aux_ptr = (char_u *)" \t\\\"|!";
|
|
5084 else
|
|
5085 /* Don't escape spaces and Tabs in a tag with a backslash */
|
|
5086 aux_ptr = (char_u *)"\\|\"";
|
|
5087
|
|
5088 p = buf + STRLEN(buf);
|
|
5089 while (n-- > 0)
|
|
5090 {
|
|
5091 /* put a backslash before \ and some others */
|
|
5092 if (vim_strchr(aux_ptr, *ptr) != NULL)
|
|
5093 *p++ = '\\';
|
|
5094 #ifdef FEAT_MBYTE
|
|
5095 /* When current byte is a part of multibyte character, copy all bytes
|
|
5096 * of that character. */
|
|
5097 if (has_mbyte)
|
|
5098 {
|
|
5099 int i;
|
|
5100 int len = (*mb_ptr2len_check)(ptr) - 1;
|
|
5101
|
|
5102 for (i = 0; i < len && n >= 1; ++i, --n)
|
|
5103 *p++ = *ptr++;
|
|
5104 }
|
|
5105 #endif
|
|
5106 *p++ = *ptr++;
|
|
5107 }
|
|
5108 *p = NUL;
|
|
5109
|
|
5110 /*
|
|
5111 * Execute the command.
|
|
5112 */
|
|
5113 if (cmdchar == '*' || cmdchar == '#')
|
|
5114 {
|
|
5115 if (!g_cmd && (
|
|
5116 #ifdef FEAT_MBYTE
|
|
5117 has_mbyte ? vim_iswordp(mb_prevptr(ml_get_curline(), ptr)) :
|
|
5118 #endif
|
|
5119 vim_iswordc(ptr[-1])))
|
|
5120 STRCAT(buf, "\\>");
|
|
5121 #ifdef FEAT_CMDHIST
|
|
5122 /* put pattern in search history */
|
|
5123 add_to_history(HIST_SEARCH, buf, TRUE, NUL);
|
|
5124 #endif
|
|
5125 normal_search(cap, cmdchar == '*' ? '/' : '?', buf, 0);
|
|
5126 }
|
|
5127 else
|
|
5128 do_cmdline_cmd(buf);
|
|
5129
|
|
5130 vim_free(buf);
|
|
5131 }
|
|
5132
|
|
5133 #ifdef FEAT_VISUAL
|
|
5134 /*
|
|
5135 * Get visually selected text, within one line only.
|
|
5136 * Returns FAIL if more than one line selected.
|
|
5137 */
|
|
5138 static int
|
|
5139 get_visual_text(cap, pp, lenp)
|
|
5140 cmdarg_T *cap;
|
|
5141 char_u **pp; /* return: start of selected text */
|
|
5142 int *lenp; /* return: length of selected text */
|
|
5143 {
|
|
5144 if (VIsual_mode != 'V')
|
|
5145 unadjust_for_sel();
|
|
5146 if (VIsual.lnum != curwin->w_cursor.lnum)
|
|
5147 {
|
|
5148 clearopbeep(cap->oap);
|
|
5149 return FAIL;
|
|
5150 }
|
|
5151 if (VIsual_mode == 'V')
|
|
5152 {
|
|
5153 *pp = ml_get_curline();
|
|
5154 *lenp = (int)STRLEN(*pp);
|
|
5155 }
|
|
5156 else
|
|
5157 {
|
|
5158 if (lt(curwin->w_cursor, VIsual))
|
|
5159 {
|
|
5160 *pp = ml_get_pos(&curwin->w_cursor);
|
|
5161 *lenp = VIsual.col - curwin->w_cursor.col + 1;
|
|
5162 }
|
|
5163 else
|
|
5164 {
|
|
5165 *pp = ml_get_pos(&VIsual);
|
|
5166 *lenp = curwin->w_cursor.col - VIsual.col + 1;
|
|
5167 }
|
|
5168 #ifdef FEAT_MBYTE
|
|
5169 if (has_mbyte)
|
|
5170 /* Correct the length to include the whole last character. */
|
|
5171 *lenp += (*mb_ptr2len_check)(*pp + (*lenp - 1)) - 1;
|
|
5172 #endif
|
|
5173 }
|
|
5174 reset_VIsual_and_resel();
|
|
5175 return OK;
|
|
5176 }
|
|
5177 #endif
|
|
5178
|
|
5179 /*
|
|
5180 * CTRL-T: backwards in tag stack
|
|
5181 */
|
|
5182 static void
|
|
5183 nv_tagpop(cap)
|
|
5184 cmdarg_T *cap;
|
|
5185 {
|
|
5186 if (!checkclearopq(cap->oap))
|
|
5187 do_tag((char_u *)"", DT_POP, (int)cap->count1, FALSE, TRUE);
|
|
5188 }
|
|
5189
|
|
5190 /*
|
|
5191 * Handle scrolling command 'H', 'L' and 'M'.
|
|
5192 */
|
|
5193 static void
|
|
5194 nv_scroll(cap)
|
|
5195 cmdarg_T *cap;
|
|
5196 {
|
|
5197 int used = 0;
|
|
5198 long n;
|
|
5199 #ifdef FEAT_FOLDING
|
|
5200 linenr_T lnum;
|
|
5201 #endif
|
|
5202 int half;
|
|
5203
|
|
5204 cap->oap->motion_type = MLINE;
|
|
5205 setpcmark();
|
|
5206
|
|
5207 if (cap->cmdchar == 'L')
|
|
5208 {
|
|
5209 validate_botline(); /* make sure curwin->w_botline is valid */
|
|
5210 curwin->w_cursor.lnum = curwin->w_botline - 1;
|
|
5211 if (cap->count1 - 1 >= curwin->w_cursor.lnum)
|
|
5212 curwin->w_cursor.lnum = 1;
|
|
5213 else
|
9
|
5214 {
|
|
5215 #ifdef FEAT_FOLDING
|
|
5216 if (hasAnyFolding(curwin))
|
|
5217 {
|
|
5218 /* Count a fold for one screen line. */
|
|
5219 for (n = cap->count1 - 1; n > 0
|
|
5220 && curwin->w_cursor.lnum > curwin->w_topline; --n)
|
|
5221 {
|
|
5222 (void)hasFolding(curwin->w_cursor.lnum,
|
|
5223 &curwin->w_cursor.lnum, NULL);
|
|
5224 --curwin->w_cursor.lnum;
|
|
5225 }
|
|
5226 }
|
|
5227 else
|
|
5228 #endif
|
|
5229 curwin->w_cursor.lnum -= cap->count1 - 1;
|
|
5230 }
|
7
|
5231 }
|
|
5232 else
|
|
5233 {
|
|
5234 if (cap->cmdchar == 'M')
|
|
5235 {
|
|
5236 #ifdef FEAT_DIFF
|
|
5237 /* Don't count filler lines above the window. */
|
|
5238 used -= diff_check_fill(curwin, curwin->w_topline)
|
|
5239 - curwin->w_topfill;
|
|
5240 #endif
|
|
5241 validate_botline(); /* make sure w_empty_rows is valid */
|
|
5242 half = (curwin->w_height - curwin->w_empty_rows + 1) / 2;
|
|
5243 for (n = 0; curwin->w_topline + n < curbuf->b_ml.ml_line_count; ++n)
|
|
5244 {
|
|
5245 #ifdef FEAT_DIFF
|
|
5246 /* Count half he number of filler lines to be "below this
|
|
5247 * line" and half to be "above the next line". */
|
|
5248 if (n > 0 && used + diff_check_fill(curwin, curwin->w_topline
|
|
5249 + n) / 2 >= half)
|
|
5250 {
|
|
5251 --n;
|
|
5252 break;
|
|
5253 }
|
|
5254 #endif
|
|
5255 used += plines(curwin->w_topline + n);
|
|
5256 if (used >= half)
|
|
5257 break;
|
|
5258 #ifdef FEAT_FOLDING
|
|
5259 if (hasFolding(curwin->w_topline + n, NULL, &lnum))
|
|
5260 n = lnum - curwin->w_topline;
|
|
5261 #endif
|
|
5262 }
|
|
5263 if (n > 0 && used > curwin->w_height)
|
|
5264 --n;
|
|
5265 }
|
9
|
5266 else /* (cap->cmdchar == 'H') */
|
|
5267 {
|
7
|
5268 n = cap->count1 - 1;
|
9
|
5269 #ifdef FEAT_FOLDING
|
|
5270 if (hasAnyFolding(curwin))
|
|
5271 {
|
|
5272 /* Count a fold for one screen line. */
|
|
5273 lnum = curwin->w_topline;
|
|
5274 while (n-- > 0 && lnum < curwin->w_botline - 1)
|
|
5275 {
|
|
5276 hasFolding(lnum, NULL, &lnum);
|
|
5277 ++lnum;
|
|
5278 }
|
|
5279 n = lnum - curwin->w_topline;
|
|
5280 }
|
|
5281 #endif
|
|
5282 }
|
7
|
5283 curwin->w_cursor.lnum = curwin->w_topline + n;
|
|
5284 if (curwin->w_cursor.lnum > curbuf->b_ml.ml_line_count)
|
|
5285 curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count;
|
|
5286 }
|
|
5287
|
|
5288 cursor_correct(); /* correct for 'so' */
|
|
5289 beginline(BL_SOL | BL_FIX);
|
|
5290 }
|
|
5291
|
|
5292 /*
|
|
5293 * Cursor right commands.
|
|
5294 */
|
|
5295 static void
|
|
5296 nv_right(cap)
|
|
5297 cmdarg_T *cap;
|
|
5298 {
|
|
5299 long n;
|
|
5300 #ifdef FEAT_VISUAL
|
|
5301 int PAST_LINE;
|
|
5302 #else
|
|
5303 # define PAST_LINE 0
|
|
5304 #endif
|
|
5305
|
180
|
5306 if (mod_mask & (MOD_MASK_SHIFT | MOD_MASK_CTRL))
|
|
5307 {
|
|
5308 /* <C-Right> and <S-Right> move a word or WORD right */
|
|
5309 if (mod_mask & MOD_MASK_CTRL)
|
|
5310 cap->arg = TRUE;
|
|
5311 nv_wordcmd(cap);
|
|
5312 return;
|
|
5313 }
|
|
5314
|
7
|
5315 cap->oap->motion_type = MCHAR;
|
|
5316 cap->oap->inclusive = FALSE;
|
|
5317 #ifdef FEAT_VISUAL
|
|
5318 PAST_LINE = (VIsual_active && *p_sel != 'o');
|
|
5319
|
|
5320 # ifdef FEAT_VIRTUALEDIT
|
|
5321 /*
|
|
5322 * In virtual mode, there's no such thing as "PAST_LINE", as lines are
|
|
5323 * (theoretically) infinitly long.
|
|
5324 */
|
|
5325 if (virtual_active())
|
|
5326 PAST_LINE = 0;
|
|
5327 # endif
|
|
5328 #endif
|
|
5329
|
|
5330 for (n = cap->count1; n > 0; --n)
|
|
5331 {
|
|
5332 if ((!PAST_LINE && oneright() == FAIL)
|
|
5333 || (PAST_LINE && *ml_get_cursor() == NUL))
|
|
5334 {
|
|
5335 /*
|
|
5336 * <Space> wraps to next line if 'whichwrap' bit 1 set.
|
|
5337 * 'l' wraps to next line if 'whichwrap' bit 2 set.
|
|
5338 * CURS_RIGHT wraps to next line if 'whichwrap' bit 3 set
|
|
5339 */
|
|
5340 if ( ((cap->cmdchar == ' '
|
|
5341 && vim_strchr(p_ww, 's') != NULL)
|
|
5342 || (cap->cmdchar == 'l'
|
|
5343 && vim_strchr(p_ww, 'l') != NULL)
|
229
|
5344 || (cap->cmdchar == K_RIGHT
|
7
|
5345 && vim_strchr(p_ww, '>') != NULL))
|
|
5346 && curwin->w_cursor.lnum < curbuf->b_ml.ml_line_count)
|
|
5347 {
|
|
5348 /* When deleting we also count the NL as a character.
|
|
5349 * Set cap->oap->inclusive when last char in the line is
|
|
5350 * included, move to next line after that */
|
|
5351 if ( (cap->oap->op_type == OP_DELETE
|
|
5352 || cap->oap->op_type == OP_CHANGE)
|
|
5353 && !cap->oap->inclusive
|
|
5354 && !lineempty(curwin->w_cursor.lnum))
|
|
5355 cap->oap->inclusive = TRUE;
|
|
5356 else
|
|
5357 {
|
|
5358 ++curwin->w_cursor.lnum;
|
|
5359 curwin->w_cursor.col = 0;
|
|
5360 #ifdef FEAT_VIRTUALEDIT
|
|
5361 curwin->w_cursor.coladd = 0;
|
|
5362 #endif
|
|
5363 curwin->w_set_curswant = TRUE;
|
|
5364 cap->oap->inclusive = FALSE;
|
|
5365 }
|
|
5366 continue;
|
|
5367 }
|
|
5368 if (cap->oap->op_type == OP_NOP)
|
|
5369 {
|
|
5370 /* Only beep and flush if not moved at all */
|
|
5371 if (n == cap->count1)
|
|
5372 beep_flush();
|
|
5373 }
|
|
5374 else
|
|
5375 {
|
|
5376 if (!lineempty(curwin->w_cursor.lnum))
|
|
5377 cap->oap->inclusive = TRUE;
|
|
5378 }
|
|
5379 break;
|
|
5380 }
|
|
5381 #ifdef FEAT_VISUAL
|
|
5382 else if (PAST_LINE)
|
|
5383 {
|
|
5384 curwin->w_set_curswant = TRUE;
|
|
5385 # ifdef FEAT_VIRTUALEDIT
|
|
5386 if (virtual_active())
|
|
5387 oneright();
|
|
5388 else
|
|
5389 # endif
|
|
5390 {
|
|
5391 # ifdef FEAT_MBYTE
|
|
5392 if (has_mbyte)
|
|
5393 curwin->w_cursor.col +=
|
|
5394 (*mb_ptr2len_check)(ml_get_cursor());
|
|
5395 else
|
|
5396 # endif
|
|
5397 ++curwin->w_cursor.col;
|
|
5398 }
|
|
5399 }
|
|
5400 #endif
|
|
5401 }
|
|
5402 #ifdef FEAT_FOLDING
|
|
5403 if (n != cap->count1 && (fdo_flags & FDO_HOR) && KeyTyped
|
|
5404 && cap->oap->op_type == OP_NOP)
|
|
5405 foldOpenCursor();
|
|
5406 #endif
|
|
5407 }
|
|
5408
|
|
5409 /*
|
|
5410 * Cursor left commands.
|
|
5411 *
|
|
5412 * Returns TRUE when operator end should not be adjusted.
|
|
5413 */
|
|
5414 static void
|
|
5415 nv_left(cap)
|
|
5416 cmdarg_T *cap;
|
|
5417 {
|
|
5418 long n;
|
|
5419
|
180
|
5420 if (mod_mask & (MOD_MASK_SHIFT | MOD_MASK_CTRL))
|
|
5421 {
|
|
5422 /* <C-Left> and <S-Left> move a word or WORD left */
|
|
5423 if (mod_mask & MOD_MASK_CTRL)
|
|
5424 cap->arg = 1;
|
|
5425 nv_bck_word(cap);
|
|
5426 return;
|
|
5427 }
|
|
5428
|
7
|
5429 cap->oap->motion_type = MCHAR;
|
|
5430 cap->oap->inclusive = FALSE;
|
|
5431 for (n = cap->count1; n > 0; --n)
|
|
5432 {
|
|
5433 if (oneleft() == FAIL)
|
|
5434 {
|
|
5435 /* <BS> and <Del> wrap to previous line if 'whichwrap' has 'b'.
|
|
5436 * 'h' wraps to previous line if 'whichwrap' has 'h'.
|
|
5437 * CURS_LEFT wraps to previous line if 'whichwrap' has '<'.
|
|
5438 */
|
|
5439 if ( (((cap->cmdchar == K_BS
|
|
5440 || cap->cmdchar == Ctrl_H)
|
|
5441 && vim_strchr(p_ww, 'b') != NULL)
|
|
5442 || (cap->cmdchar == 'h'
|
|
5443 && vim_strchr(p_ww, 'h') != NULL)
|
229
|
5444 || (cap->cmdchar == K_LEFT
|
7
|
5445 && vim_strchr(p_ww, '<') != NULL))
|
|
5446 && curwin->w_cursor.lnum > 1)
|
|
5447 {
|
|
5448 --(curwin->w_cursor.lnum);
|
|
5449 coladvance((colnr_T)MAXCOL);
|
|
5450 curwin->w_set_curswant = TRUE;
|
|
5451
|
|
5452 /* When the NL before the first char has to be deleted we
|
|
5453 * put the cursor on the NUL after the previous line.
|
|
5454 * This is a very special case, be careful!
|
|
5455 * don't adjust op_end now, otherwise it won't work */
|
|
5456 if ( (cap->oap->op_type == OP_DELETE
|
|
5457 || cap->oap->op_type == OP_CHANGE)
|
|
5458 && !lineempty(curwin->w_cursor.lnum))
|
|
5459 {
|
|
5460 ++curwin->w_cursor.col;
|
|
5461 cap->retval |= CA_NO_ADJ_OP_END;
|
|
5462 }
|
|
5463 continue;
|
|
5464 }
|
|
5465 /* Only beep and flush if not moved at all */
|
|
5466 else if (cap->oap->op_type == OP_NOP && n == cap->count1)
|
|
5467 beep_flush();
|
|
5468 break;
|
|
5469 }
|
|
5470 }
|
|
5471 #ifdef FEAT_FOLDING
|
|
5472 if (n != cap->count1 && (fdo_flags & FDO_HOR) && KeyTyped
|
|
5473 && cap->oap->op_type == OP_NOP)
|
|
5474 foldOpenCursor();
|
|
5475 #endif
|
|
5476 }
|
|
5477
|
|
5478 /*
|
|
5479 * Cursor up commands.
|
|
5480 * cap->arg is TRUE for "-": Move cursor to first non-blank.
|
|
5481 */
|
|
5482 static void
|
|
5483 nv_up(cap)
|
|
5484 cmdarg_T *cap;
|
|
5485 {
|
180
|
5486 if (mod_mask & MOD_MASK_SHIFT)
|
|
5487 {
|
|
5488 /* <S-Up> is page up */
|
|
5489 cap->arg = BACKWARD;
|
|
5490 nv_page(cap);
|
|
5491 }
|
|
5492 else
|
|
5493 {
|
|
5494 cap->oap->motion_type = MLINE;
|
|
5495 if (cursor_up(cap->count1, cap->oap->op_type == OP_NOP) == FAIL)
|
|
5496 clearopbeep(cap->oap);
|
|
5497 else if (cap->arg)
|
|
5498 beginline(BL_WHITE | BL_FIX);
|
|
5499 }
|
7
|
5500 }
|
|
5501
|
|
5502 /*
|
|
5503 * Cursor down commands.
|
|
5504 * cap->arg is TRUE for CR and "+": Move cursor to first non-blank.
|
|
5505 */
|
|
5506 static void
|
|
5507 nv_down(cap)
|
|
5508 cmdarg_T *cap;
|
|
5509 {
|
180
|
5510 if (mod_mask & MOD_MASK_SHIFT)
|
|
5511 {
|
|
5512 /* <S-Down> is page down */
|
|
5513 cap->arg = FORWARD;
|
|
5514 nv_page(cap);
|
|
5515 }
|
|
5516 else
|
7
|
5517 #if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
|
|
5518 /* In a quickfix window a <CR> jumps to the error under the cursor. */
|
170
|
5519 if (bt_quickfix(curbuf) && cap->cmdchar == CAR)
|
7
|
5520 do_cmdline_cmd((char_u *)".cc");
|
|
5521 else
|
|
5522 #endif
|
|
5523 {
|
|
5524 #ifdef FEAT_CMDWIN
|
|
5525 /* In the cmdline window a <CR> executes the command. */
|
170
|
5526 if (cmdwin_type != 0 && cap->cmdchar == CAR)
|
7
|
5527 cmdwin_result = CAR;
|
|
5528 else
|
|
5529 #endif
|
|
5530 {
|
|
5531 cap->oap->motion_type = MLINE;
|
|
5532 if (cursor_down(cap->count1, cap->oap->op_type == OP_NOP) == FAIL)
|
|
5533 clearopbeep(cap->oap);
|
|
5534 else if (cap->arg)
|
|
5535 beginline(BL_WHITE | BL_FIX);
|
|
5536 }
|
|
5537 }
|
|
5538 }
|
|
5539
|
|
5540 #ifdef FEAT_SEARCHPATH
|
|
5541 /*
|
|
5542 * Grab the file name under the cursor and edit it.
|
|
5543 */
|
|
5544 static void
|
|
5545 nv_gotofile(cap)
|
|
5546 cmdarg_T *cap;
|
|
5547 {
|
|
5548 char_u *ptr;
|
|
5549
|
|
5550 #ifdef FEAT_CMDWIN
|
|
5551 if (cmdwin_type != 0)
|
|
5552 {
|
|
5553 clearopbeep(cap->oap);
|
|
5554 return;
|
|
5555 }
|
|
5556 #endif
|
|
5557
|
|
5558 # ifdef FEAT_VISUAL
|
|
5559 /*
|
|
5560 * In Visual mode, use the selected text as a file name.
|
|
5561 * Don't allow selection across multiple lines.
|
|
5562 */
|
|
5563 if (VIsual_active)
|
|
5564 {
|
|
5565 int len;
|
|
5566
|
|
5567 if (get_visual_text(cap, &ptr, &len) == FAIL)
|
|
5568 return;
|
|
5569 ptr = find_file_name_in_path(ptr, len,
|
|
5570 FNAME_MESS|FNAME_EXP|FNAME_REL, cap->count1, curbuf->b_ffname);
|
|
5571 }
|
|
5572 else
|
|
5573 # endif
|
|
5574 ptr = file_name_at_cursor(FNAME_MESS|FNAME_HYP|FNAME_EXP|FNAME_REL,
|
|
5575 cap->count1);
|
|
5576
|
|
5577 if (ptr != NULL)
|
|
5578 {
|
|
5579 /* do autowrite if necessary */
|
|
5580 if (curbufIsChanged() && curbuf->b_nwindows <= 1 && !P_HID(curbuf))
|
|
5581 autowrite(curbuf, FALSE);
|
|
5582 setpcmark();
|
|
5583 (void)do_ecmd(0, ptr, NULL, NULL, ECMD_LAST,
|
|
5584 P_HID(curbuf) ? ECMD_HIDE : 0);
|
|
5585 vim_free(ptr);
|
|
5586 }
|
|
5587 else
|
|
5588 clearop(cap->oap);
|
|
5589 }
|
|
5590 #endif
|
|
5591
|
|
5592 /*
|
|
5593 * <End> command: to end of current line or last line.
|
|
5594 */
|
|
5595 static void
|
|
5596 nv_end(cap)
|
|
5597 cmdarg_T *cap;
|
|
5598 {
|
180
|
5599 if (cap->arg || (mod_mask & MOD_MASK_CTRL)) /* CTRL-END = goto last line */
|
|
5600 {
|
|
5601 cap->arg = TRUE;
|
7
|
5602 nv_goto(cap);
|
|
5603 cap->count1 = 1; /* to end of current line */
|
|
5604 }
|
|
5605 nv_dollar(cap);
|
|
5606 }
|
|
5607
|
|
5608 /*
|
|
5609 * Handle the "$" command.
|
|
5610 */
|
|
5611 static void
|
|
5612 nv_dollar(cap)
|
|
5613 cmdarg_T *cap;
|
|
5614 {
|
|
5615 cap->oap->motion_type = MCHAR;
|
|
5616 cap->oap->inclusive = TRUE;
|
|
5617 #ifdef FEAT_VIRTUALEDIT
|
|
5618 /* In virtual mode when off the edge of a line and an operator
|
|
5619 * is pending (whew!) keep the cursor where it is.
|
|
5620 * Otherwise, send it to the end of the line. */
|
|
5621 if (!virtual_active() || gchar_cursor() != NUL
|
|
5622 || cap->oap->op_type == OP_NOP)
|
|
5623 #endif
|
|
5624 curwin->w_curswant = MAXCOL; /* so we stay at the end */
|
|
5625 if (cursor_down((long)(cap->count1 - 1),
|
|
5626 cap->oap->op_type == OP_NOP) == FAIL)
|
|
5627 clearopbeep(cap->oap);
|
|
5628 #ifdef FEAT_FOLDING
|
|
5629 else if ((fdo_flags & FDO_HOR) && KeyTyped && cap->oap->op_type == OP_NOP)
|
|
5630 foldOpenCursor();
|
|
5631 #endif
|
|
5632 }
|
|
5633
|
|
5634 /*
|
|
5635 * Implementation of '?' and '/' commands.
|
|
5636 * If cap->arg is TRUE don't set PC mark.
|
|
5637 */
|
|
5638 static void
|
|
5639 nv_search(cap)
|
|
5640 cmdarg_T *cap;
|
|
5641 {
|
|
5642 oparg_T *oap = cap->oap;
|
|
5643
|
|
5644 if (cap->cmdchar == '?' && cap->oap->op_type == OP_ROT13)
|
|
5645 {
|
|
5646 /* Translate "g??" to "g?g?" */
|
|
5647 cap->cmdchar = 'g';
|
|
5648 cap->nchar = '?';
|
|
5649 nv_operator(cap);
|
|
5650 return;
|
|
5651 }
|
|
5652
|
|
5653 cap->searchbuf = getcmdline(cap->cmdchar, cap->count1, 0);
|
|
5654
|
|
5655 if (cap->searchbuf == NULL)
|
|
5656 {
|
|
5657 clearop(oap);
|
|
5658 return;
|
|
5659 }
|
|
5660
|
|
5661 normal_search(cap, cap->cmdchar, cap->searchbuf,
|
|
5662 (cap->arg ? 0 : SEARCH_MARK));
|
|
5663 }
|
|
5664
|
|
5665 /*
|
|
5666 * Handle "N" and "n" commands.
|
|
5667 * cap->arg is SEARCH_REV for "N", 0 for "n".
|
|
5668 */
|
|
5669 static void
|
|
5670 nv_next(cap)
|
|
5671 cmdarg_T *cap;
|
|
5672 {
|
|
5673 normal_search(cap, 0, NULL, SEARCH_MARK | cap->arg);
|
|
5674 }
|
|
5675
|
|
5676 /*
|
|
5677 * Search for "pat" in direction "dir" ('/' or '?', 0 for repeat).
|
|
5678 * Uses only cap->count1 and cap->oap from "cap".
|
|
5679 */
|
|
5680 static void
|
|
5681 normal_search(cap, dir, pat, opt)
|
|
5682 cmdarg_T *cap;
|
|
5683 int dir;
|
|
5684 char_u *pat;
|
|
5685 int opt; /* extra flags for do_search() */
|
|
5686 {
|
|
5687 int i;
|
|
5688
|
|
5689 cap->oap->motion_type = MCHAR;
|
|
5690 cap->oap->inclusive = FALSE;
|
|
5691 cap->oap->use_reg_one = TRUE;
|
|
5692 curwin->w_set_curswant = TRUE;
|
|
5693
|
|
5694 i = do_search(cap->oap, dir, pat, cap->count1,
|
|
5695 opt | SEARCH_OPT | SEARCH_ECHO | SEARCH_MSG);
|
|
5696 if (i == 0)
|
|
5697 clearop(cap->oap);
|
|
5698 else
|
|
5699 {
|
|
5700 if (i == 2)
|
|
5701 cap->oap->motion_type = MLINE;
|
|
5702 #ifdef FEAT_VIRTUALEDIT
|
|
5703 curwin->w_cursor.coladd = 0;
|
|
5704 #endif
|
|
5705 #ifdef FEAT_FOLDING
|
|
5706 if (cap->oap->op_type == OP_NOP && (fdo_flags & FDO_SEARCH) && KeyTyped)
|
|
5707 foldOpenCursor();
|
|
5708 #endif
|
|
5709 }
|
|
5710
|
|
5711 /* "/$" will put the cursor after the end of the line, may need to
|
|
5712 * correct that here */
|
|
5713 check_cursor();
|
|
5714 }
|
|
5715
|
|
5716 /*
|
|
5717 * Character search commands.
|
|
5718 * cap->arg is BACKWARD for 'F' and 'T', FORWARD for 'f' and 't', TRUE for
|
|
5719 * ',' and FALSE for ';'.
|
|
5720 * cap->nchar is NUL for ',' and ';' (repeat the search)
|
|
5721 */
|
|
5722 static void
|
|
5723 nv_csearch(cap)
|
|
5724 cmdarg_T *cap;
|
|
5725 {
|
|
5726 int t_cmd;
|
|
5727
|
|
5728 if (cap->cmdchar == 't' || cap->cmdchar == 'T')
|
|
5729 t_cmd = TRUE;
|
|
5730 else
|
|
5731 t_cmd = FALSE;
|
|
5732
|
|
5733 cap->oap->motion_type = MCHAR;
|
|
5734 if (cap->arg == BACKWARD)
|
|
5735 cap->oap->inclusive = FALSE;
|
|
5736 else
|
|
5737 cap->oap->inclusive = TRUE;
|
|
5738 if (IS_SPECIAL(cap->nchar) || searchc(cap, t_cmd) == FAIL)
|
|
5739 clearopbeep(cap->oap);
|
|
5740 else
|
|
5741 {
|
|
5742 curwin->w_set_curswant = TRUE;
|
|
5743 #ifdef FEAT_VIRTUALEDIT
|
|
5744 /* Include a Tab for "tx" and for "dfx". */
|
|
5745 if (gchar_cursor() == TAB && virtual_active() && cap->arg == FORWARD
|
|
5746 && (t_cmd || cap->oap->op_type != OP_NOP))
|
|
5747 {
|
|
5748 colnr_T scol, ecol;
|
|
5749
|
|
5750 getvcol(curwin, &curwin->w_cursor, &scol, NULL, &ecol);
|
|
5751 curwin->w_cursor.coladd = ecol - scol;
|
|
5752 }
|
|
5753 else
|
|
5754 curwin->w_cursor.coladd = 0;
|
|
5755 #endif
|
|
5756 #ifdef FEAT_VISUAL
|
|
5757 adjust_for_sel(cap);
|
|
5758 #endif
|
|
5759 #ifdef FEAT_FOLDING
|
|
5760 if ((fdo_flags & FDO_HOR) && KeyTyped && cap->oap->op_type == OP_NOP)
|
|
5761 foldOpenCursor();
|
|
5762 #endif
|
|
5763 }
|
|
5764 }
|
|
5765
|
|
5766 /*
|
|
5767 * "[" and "]" commands.
|
|
5768 * cap->arg is BACKWARD for "[" and FORWARD for "]".
|
|
5769 */
|
|
5770 static void
|
|
5771 nv_brackets(cap)
|
|
5772 cmdarg_T *cap;
|
|
5773 {
|
|
5774 pos_T new_pos;
|
|
5775 pos_T prev_pos;
|
|
5776 pos_T *pos = NULL; /* init for GCC */
|
|
5777 pos_T old_pos; /* cursor position before command */
|
|
5778 int flag;
|
|
5779 long n;
|
|
5780 int findc;
|
|
5781 int c;
|
|
5782
|
|
5783 cap->oap->motion_type = MCHAR;
|
|
5784 cap->oap->inclusive = FALSE;
|
|
5785 old_pos = curwin->w_cursor;
|
|
5786 #ifdef FEAT_VIRTUALEDIT
|
|
5787 curwin->w_cursor.coladd = 0; /* TODO: don't do this for an error. */
|
|
5788 #endif
|
|
5789
|
|
5790 #ifdef FEAT_SEARCHPATH
|
|
5791 /*
|
|
5792 * "[f" or "]f" : Edit file under the cursor (same as "gf")
|
|
5793 */
|
|
5794 if (cap->nchar == 'f')
|
|
5795 nv_gotofile(cap);
|
|
5796 else
|
|
5797 #endif
|
|
5798
|
|
5799 #ifdef FEAT_FIND_ID
|
|
5800 /*
|
|
5801 * Find the occurence(s) of the identifier or define under cursor
|
|
5802 * in current and included files or jump to the first occurence.
|
|
5803 *
|
|
5804 * search list jump
|
|
5805 * fwd bwd fwd bwd fwd bwd
|
|
5806 * identifier "]i" "[i" "]I" "[I" "]^I" "[^I"
|
|
5807 * define "]d" "[d" "]D" "[D" "]^D" "[^D"
|
|
5808 */
|
|
5809 if (vim_strchr((char_u *)
|
|
5810 #ifdef EBCDIC
|
|
5811 "iI\005dD\067",
|
|
5812 #else
|
|
5813 "iI\011dD\004",
|
|
5814 #endif
|
|
5815 cap->nchar) != NULL)
|
|
5816 {
|
|
5817 char_u *ptr;
|
|
5818 int len;
|
|
5819
|
|
5820 if ((len = find_ident_under_cursor(&ptr, FIND_IDENT)) == 0)
|
|
5821 clearop(cap->oap);
|
|
5822 else
|
|
5823 {
|
|
5824 find_pattern_in_path(ptr, 0, len, TRUE,
|
|
5825 cap->count0 == 0 ? !isupper(cap->nchar) : FALSE,
|
|
5826 ((cap->nchar & 0xf) == ('d' & 0xf)) ? FIND_DEFINE : FIND_ANY,
|
|
5827 cap->count1,
|
|
5828 isupper(cap->nchar) ? ACTION_SHOW_ALL :
|
|
5829 islower(cap->nchar) ? ACTION_SHOW : ACTION_GOTO,
|
|
5830 cap->cmdchar == ']' ? curwin->w_cursor.lnum + 1 : (linenr_T)1,
|
|
5831 (linenr_T)MAXLNUM);
|
|
5832 curwin->w_set_curswant = TRUE;
|
|
5833 }
|
|
5834 }
|
|
5835 else
|
|
5836 #endif
|
|
5837
|
|
5838 /*
|
|
5839 * "[{", "[(", "]}" or "])": go to Nth unclosed '{', '(', '}' or ')'
|
|
5840 * "[#", "]#": go to start/end of Nth innermost #if..#endif construct.
|
|
5841 * "[/", "[*", "]/", "]*": go to Nth comment start/end.
|
|
5842 * "[m" or "]m" search for prev/next start of (Java) method.
|
|
5843 * "[M" or "]M" search for prev/next end of (Java) method.
|
|
5844 */
|
|
5845 if ( (cap->cmdchar == '['
|
|
5846 && vim_strchr((char_u *)"{(*/#mM", cap->nchar) != NULL)
|
|
5847 || (cap->cmdchar == ']'
|
|
5848 && vim_strchr((char_u *)"})*/#mM", cap->nchar) != NULL))
|
|
5849 {
|
|
5850 if (cap->nchar == '*')
|
|
5851 cap->nchar = '/';
|
|
5852 new_pos.lnum = 0;
|
|
5853 prev_pos.lnum = 0;
|
|
5854 if (cap->nchar == 'm' || cap->nchar == 'M')
|
|
5855 {
|
|
5856 if (cap->cmdchar == '[')
|
|
5857 findc = '{';
|
|
5858 else
|
|
5859 findc = '}';
|
|
5860 n = 9999;
|
|
5861 }
|
|
5862 else
|
|
5863 {
|
|
5864 findc = cap->nchar;
|
|
5865 n = cap->count1;
|
|
5866 }
|
|
5867 for ( ; n > 0; --n)
|
|
5868 {
|
|
5869 if ((pos = findmatchlimit(cap->oap, findc,
|
|
5870 (cap->cmdchar == '[') ? FM_BACKWARD : FM_FORWARD, 0)) == NULL)
|
|
5871 {
|
|
5872 if (new_pos.lnum == 0) /* nothing found */
|
|
5873 {
|
|
5874 if (cap->nchar != 'm' && cap->nchar != 'M')
|
|
5875 clearopbeep(cap->oap);
|
|
5876 }
|
|
5877 else
|
|
5878 pos = &new_pos; /* use last one found */
|
|
5879 break;
|
|
5880 }
|
|
5881 prev_pos = new_pos;
|
|
5882 curwin->w_cursor = *pos;
|
|
5883 new_pos = *pos;
|
|
5884 }
|
|
5885 curwin->w_cursor = old_pos;
|
|
5886
|
|
5887 /*
|
|
5888 * Handle "[m", "]m", "[M" and "[M". The findmatchlimit() only
|
|
5889 * brought us to the match for "[m" and "]M" when inside a method.
|
|
5890 * Try finding the '{' or '}' we want to be at.
|
|
5891 * Also repeat for the given count.
|
|
5892 */
|
|
5893 if (cap->nchar == 'm' || cap->nchar == 'M')
|
|
5894 {
|
|
5895 /* norm is TRUE for "]M" and "[m" */
|
|
5896 int norm = ((findc == '{') == (cap->nchar == 'm'));
|
|
5897
|
|
5898 n = cap->count1;
|
|
5899 /* found a match: we were inside a method */
|
|
5900 if (prev_pos.lnum != 0)
|
|
5901 {
|
|
5902 pos = &prev_pos;
|
|
5903 curwin->w_cursor = prev_pos;
|
|
5904 if (norm)
|
|
5905 --n;
|
|
5906 }
|
|
5907 else
|
|
5908 pos = NULL;
|
|
5909 while (n > 0)
|
|
5910 {
|
|
5911 for (;;)
|
|
5912 {
|
|
5913 if ((findc == '{' ? dec_cursor() : inc_cursor()) < 0)
|
|
5914 {
|
|
5915 /* if not found anything, that's an error */
|
|
5916 if (pos == NULL)
|
|
5917 clearopbeep(cap->oap);
|
|
5918 n = 0;
|
|
5919 break;
|
|
5920 }
|
|
5921 c = gchar_cursor();
|
|
5922 if (c == '{' || c == '}')
|
|
5923 {
|
|
5924 /* Must have found end/start of class: use it.
|
|
5925 * Or found the place to be at. */
|
|
5926 if ((c == findc && norm) || (n == 1 && !norm))
|
|
5927 {
|
|
5928 new_pos = curwin->w_cursor;
|
|
5929 pos = &new_pos;
|
|
5930 n = 0;
|
|
5931 }
|
|
5932 /* if no match found at all, we started outside of the
|
|
5933 * class and we're inside now. Just go on. */
|
|
5934 else if (new_pos.lnum == 0)
|
|
5935 {
|
|
5936 new_pos = curwin->w_cursor;
|
|
5937 pos = &new_pos;
|
|
5938 }
|
|
5939 /* found start/end of other method: go to match */
|
|
5940 else if ((pos = findmatchlimit(cap->oap, findc,
|
|
5941 (cap->cmdchar == '[') ? FM_BACKWARD : FM_FORWARD,
|
|
5942 0)) == NULL)
|
|
5943 n = 0;
|
|
5944 else
|
|
5945 curwin->w_cursor = *pos;
|
|
5946 break;
|
|
5947 }
|
|
5948 }
|
|
5949 --n;
|
|
5950 }
|
|
5951 curwin->w_cursor = old_pos;
|
|
5952 if (pos == NULL && new_pos.lnum != 0)
|
|
5953 clearopbeep(cap->oap);
|
|
5954 }
|
|
5955 if (pos != NULL)
|
|
5956 {
|
|
5957 setpcmark();
|
|
5958 curwin->w_cursor = *pos;
|
|
5959 curwin->w_set_curswant = TRUE;
|
|
5960 #ifdef FEAT_FOLDING
|
|
5961 if ((fdo_flags & FDO_BLOCK) && KeyTyped
|
|
5962 && cap->oap->op_type == OP_NOP)
|
|
5963 foldOpenCursor();
|
|
5964 #endif
|
|
5965 }
|
|
5966 }
|
|
5967
|
|
5968 /*
|
|
5969 * "[[", "[]", "]]" and "][": move to start or end of function
|
|
5970 */
|
|
5971 else if (cap->nchar == '[' || cap->nchar == ']')
|
|
5972 {
|
|
5973 if (cap->nchar == cap->cmdchar) /* "]]" or "[[" */
|
|
5974 flag = '{';
|
|
5975 else
|
|
5976 flag = '}'; /* "][" or "[]" */
|
|
5977
|
|
5978 curwin->w_set_curswant = TRUE;
|
|
5979 /*
|
|
5980 * Imitate strange Vi behaviour: When using "]]" with an operator
|
|
5981 * we also stop at '}'.
|
|
5982 */
|
|
5983 if (!findpar(cap->oap, cap->arg, cap->count1, flag,
|
|
5984 (cap->oap->op_type != OP_NOP
|
|
5985 && cap->arg == FORWARD && flag == '{')))
|
|
5986 clearopbeep(cap->oap);
|
|
5987 else
|
|
5988 {
|
|
5989 if (cap->oap->op_type == OP_NOP)
|
|
5990 beginline(BL_WHITE | BL_FIX);
|
|
5991 #ifdef FEAT_FOLDING
|
|
5992 if ((fdo_flags & FDO_BLOCK) && KeyTyped && cap->oap->op_type == OP_NOP)
|
|
5993 foldOpenCursor();
|
|
5994 #endif
|
|
5995 }
|
|
5996 }
|
|
5997
|
|
5998 /*
|
|
5999 * "[p", "[P", "]P" and "]p": put with indent adjustment
|
|
6000 */
|
|
6001 else if (cap->nchar == 'p' || cap->nchar == 'P')
|
|
6002 {
|
|
6003 if (!checkclearopq(cap->oap))
|
|
6004 {
|
|
6005 prep_redo_cmd(cap);
|
|
6006 do_put(cap->oap->regname,
|
|
6007 (cap->cmdchar == ']' && cap->nchar == 'p') ? FORWARD : BACKWARD,
|
|
6008 cap->count1, PUT_FIXINDENT);
|
|
6009 }
|
|
6010 }
|
|
6011
|
|
6012 /*
|
|
6013 * "['", "[`", "]'" and "]`": jump to next mark
|
|
6014 */
|
|
6015 else if (cap->nchar == '\'' || cap->nchar == '`')
|
|
6016 {
|
|
6017 pos = &curwin->w_cursor;
|
|
6018 for (n = cap->count1; n > 0; --n)
|
|
6019 {
|
|
6020 prev_pos = *pos;
|
|
6021 pos = getnextmark(pos, cap->cmdchar == '[' ? BACKWARD : FORWARD,
|
|
6022 cap->nchar == '\'');
|
|
6023 if (pos == NULL)
|
|
6024 break;
|
|
6025 }
|
|
6026 if (pos == NULL)
|
|
6027 pos = &prev_pos;
|
|
6028 nv_cursormark(cap, cap->nchar == '\'', pos);
|
|
6029 }
|
|
6030
|
|
6031 #ifdef FEAT_MOUSE
|
|
6032 /*
|
|
6033 * [ or ] followed by a middle mouse click: put selected text with
|
|
6034 * indent adjustment. Any other button just does as usual.
|
|
6035 */
|
|
6036 else if (cap->nchar >= K_LEFTMOUSE && cap->nchar <= K_RIGHTRELEASE)
|
|
6037 {
|
|
6038 (void)do_mouse(cap->oap, cap->nchar,
|
|
6039 (cap->cmdchar == ']') ? FORWARD : BACKWARD,
|
|
6040 cap->count1, PUT_FIXINDENT);
|
|
6041 }
|
|
6042 #endif /* FEAT_MOUSE */
|
|
6043
|
|
6044 #ifdef FEAT_FOLDING
|
|
6045 /*
|
|
6046 * "[z" and "]z": move to start or end of open fold.
|
|
6047 */
|
|
6048 else if (cap->nchar == 'z')
|
|
6049 {
|
|
6050 if (foldMoveTo(FALSE, cap->cmdchar == ']' ? FORWARD : BACKWARD,
|
|
6051 cap->count1) == FAIL)
|
|
6052 clearopbeep(cap->oap);
|
|
6053 }
|
|
6054 #endif
|
|
6055
|
|
6056 #ifdef FEAT_DIFF
|
|
6057 /*
|
|
6058 * "[c" and "]c": move to next or previous diff-change.
|
|
6059 */
|
|
6060 else if (cap->nchar == 'c')
|
|
6061 {
|
|
6062 if (diff_move_to(cap->cmdchar == ']' ? FORWARD : BACKWARD,
|
|
6063 cap->count1) == FAIL)
|
|
6064 clearopbeep(cap->oap);
|
|
6065 }
|
|
6066 #endif
|
|
6067
|
236
|
6068 #ifdef FEAT_SYN_HL
|
|
6069 /*
|
|
6070 * "[s", "[S", "]s" and "]S": move to next spell error.
|
|
6071 */
|
|
6072 else if (cap->nchar == 's' || cap->nchar == 'S')
|
|
6073 {
|
|
6074 if (spell_move_to(cap->cmdchar == ']' ? FORWARD : BACKWARD,
|
|
6075 cap->nchar == 's' ? TRUE : FALSE) == FAIL)
|
|
6076 clearopbeep(cap->oap);
|
|
6077 }
|
|
6078 #endif
|
|
6079
|
7
|
6080 /* Not a valid cap->nchar. */
|
|
6081 else
|
|
6082 clearopbeep(cap->oap);
|
|
6083 }
|
|
6084
|
|
6085 /*
|
|
6086 * Handle Normal mode "%" command.
|
|
6087 */
|
|
6088 static void
|
|
6089 nv_percent(cap)
|
|
6090 cmdarg_T *cap;
|
|
6091 {
|
|
6092 pos_T *pos;
|
|
6093 #ifdef FEAT_FOLDING
|
|
6094 linenr_T lnum = curwin->w_cursor.lnum;
|
|
6095 #endif
|
|
6096
|
|
6097 cap->oap->inclusive = TRUE;
|
|
6098 if (cap->count0) /* {cnt}% : goto {cnt} percentage in file */
|
|
6099 {
|
|
6100 if (cap->count0 > 100)
|
|
6101 clearopbeep(cap->oap);
|
|
6102 else
|
|
6103 {
|
|
6104 cap->oap->motion_type = MLINE;
|
|
6105 setpcmark();
|
|
6106 /* Round up, so CTRL-G will give same value. Watch out for a
|
|
6107 * large line count, the line number must not go negative! */
|
|
6108 if (curbuf->b_ml.ml_line_count > 1000000)
|
|
6109 curwin->w_cursor.lnum = (curbuf->b_ml.ml_line_count + 99L)
|
|
6110 / 100L * cap->count0;
|
|
6111 else
|
|
6112 curwin->w_cursor.lnum = (curbuf->b_ml.ml_line_count *
|
|
6113 cap->count0 + 99L) / 100L;
|
|
6114 if (curwin->w_cursor.lnum > curbuf->b_ml.ml_line_count)
|
|
6115 curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count;
|
|
6116 beginline(BL_SOL | BL_FIX);
|
|
6117 }
|
|
6118 }
|
|
6119 else /* "%" : go to matching paren */
|
|
6120 {
|
|
6121 cap->oap->motion_type = MCHAR;
|
|
6122 cap->oap->use_reg_one = TRUE;
|
|
6123 if ((pos = findmatch(cap->oap, NUL)) == NULL)
|
|
6124 clearopbeep(cap->oap);
|
|
6125 else
|
|
6126 {
|
|
6127 setpcmark();
|
|
6128 curwin->w_cursor = *pos;
|
|
6129 curwin->w_set_curswant = TRUE;
|
|
6130 #ifdef FEAT_VIRTUALEDIT
|
|
6131 curwin->w_cursor.coladd = 0;
|
|
6132 #endif
|
|
6133 #ifdef FEAT_VISUAL
|
|
6134 adjust_for_sel(cap);
|
|
6135 #endif
|
|
6136 }
|
|
6137 }
|
|
6138 #ifdef FEAT_FOLDING
|
|
6139 if (cap->oap->op_type == OP_NOP
|
|
6140 && lnum != curwin->w_cursor.lnum
|
|
6141 && (fdo_flags & FDO_PERCENT)
|
|
6142 && KeyTyped)
|
|
6143 foldOpenCursor();
|
|
6144 #endif
|
|
6145 }
|
|
6146
|
|
6147 /*
|
|
6148 * Handle "(" and ")" commands.
|
|
6149 * cap->arg is BACKWARD for "(" and FORWARD for ")".
|
|
6150 */
|
|
6151 static void
|
|
6152 nv_brace(cap)
|
|
6153 cmdarg_T *cap;
|
|
6154 {
|
|
6155 cap->oap->motion_type = MCHAR;
|
|
6156 cap->oap->use_reg_one = TRUE;
|
|
6157 if (cap->cmdchar == ')')
|
|
6158 cap->oap->inclusive = FALSE;
|
|
6159 else
|
|
6160 cap->oap->inclusive = TRUE;
|
|
6161 curwin->w_set_curswant = TRUE;
|
|
6162
|
|
6163 if (findsent(cap->arg, cap->count1) == FAIL)
|
|
6164 clearopbeep(cap->oap);
|
|
6165 else
|
|
6166 {
|
|
6167 #ifdef FEAT_VIRTUALEDIT
|
|
6168 curwin->w_cursor.coladd = 0;
|
|
6169 #endif
|
|
6170 #ifdef FEAT_FOLDING
|
|
6171 if ((fdo_flags & FDO_BLOCK) && KeyTyped && cap->oap->op_type == OP_NOP)
|
|
6172 foldOpenCursor();
|
|
6173 #endif
|
|
6174 }
|
|
6175 }
|
|
6176
|
|
6177 /*
|
|
6178 * "m" command: Mark a position.
|
|
6179 */
|
|
6180 static void
|
|
6181 nv_mark(cap)
|
|
6182 cmdarg_T *cap;
|
|
6183 {
|
|
6184 if (!checkclearop(cap->oap))
|
|
6185 {
|
|
6186 if (setmark(cap->nchar) == FAIL)
|
|
6187 clearopbeep(cap->oap);
|
|
6188 }
|
|
6189 }
|
|
6190
|
|
6191 /*
|
|
6192 * "{" and "}" commands.
|
|
6193 * cmd->arg is BACKWARD for "{" and FORWARD for "}".
|
|
6194 */
|
|
6195 static void
|
|
6196 nv_findpar(cap)
|
|
6197 cmdarg_T *cap;
|
|
6198 {
|
|
6199 cap->oap->motion_type = MCHAR;
|
|
6200 cap->oap->inclusive = FALSE;
|
|
6201 cap->oap->use_reg_one = TRUE;
|
|
6202 curwin->w_set_curswant = TRUE;
|
|
6203 if (!findpar(cap->oap, cap->arg, cap->count1, NUL, FALSE))
|
|
6204 clearopbeep(cap->oap);
|
|
6205 else
|
|
6206 {
|
|
6207 #ifdef FEAT_VIRTUALEDIT
|
|
6208 curwin->w_cursor.coladd = 0;
|
|
6209 #endif
|
|
6210 #ifdef FEAT_FOLDING
|
|
6211 if ((fdo_flags & FDO_BLOCK) && KeyTyped && cap->oap->op_type == OP_NOP)
|
|
6212 foldOpenCursor();
|
|
6213 #endif
|
|
6214 }
|
|
6215 }
|
|
6216
|
|
6217 /*
|
|
6218 * "u" command: Undo or make lower case.
|
|
6219 */
|
|
6220 static void
|
|
6221 nv_undo(cap)
|
|
6222 cmdarg_T *cap;
|
|
6223 {
|
|
6224 if (cap->oap->op_type == OP_LOWER
|
|
6225 #ifdef FEAT_VISUAL
|
|
6226 || VIsual_active
|
|
6227 #endif
|
|
6228 )
|
|
6229 {
|
|
6230 /* translate "<Visual>u" to "<Visual>gu" and "guu" to "gugu" */
|
|
6231 cap->cmdchar = 'g';
|
|
6232 cap->nchar = 'u';
|
|
6233 nv_operator(cap);
|
|
6234 }
|
|
6235 else
|
|
6236 nv_kundo(cap);
|
|
6237 }
|
|
6238
|
|
6239 /*
|
|
6240 * <Undo> command.
|
|
6241 */
|
|
6242 static void
|
|
6243 nv_kundo(cap)
|
|
6244 cmdarg_T *cap;
|
|
6245 {
|
|
6246 if (!checkclearopq(cap->oap))
|
|
6247 {
|
|
6248 u_undo((int)cap->count1);
|
|
6249 curwin->w_set_curswant = TRUE;
|
|
6250 }
|
|
6251 }
|
|
6252
|
|
6253 /*
|
|
6254 * Handle the "r" command.
|
|
6255 */
|
|
6256 static void
|
|
6257 nv_replace(cap)
|
|
6258 cmdarg_T *cap;
|
|
6259 {
|
|
6260 char_u *ptr;
|
|
6261 int had_ctrl_v;
|
|
6262 long n;
|
|
6263
|
|
6264 if (checkclearop(cap->oap))
|
|
6265 return;
|
|
6266
|
|
6267 /* get another character */
|
|
6268 if (cap->nchar == Ctrl_V)
|
|
6269 {
|
|
6270 had_ctrl_v = Ctrl_V;
|
|
6271 cap->nchar = get_literal();
|
|
6272 /* Don't redo a multibyte character with CTRL-V. */
|
|
6273 if (cap->nchar > DEL)
|
|
6274 had_ctrl_v = NUL;
|
|
6275 }
|
|
6276 else
|
|
6277 had_ctrl_v = NUL;
|
|
6278
|
|
6279 #ifdef FEAT_VISUAL
|
|
6280 /* Visual mode "r" */
|
|
6281 if (VIsual_active)
|
|
6282 {
|
|
6283 nv_operator(cap);
|
|
6284 return;
|
|
6285 }
|
|
6286 #endif
|
|
6287
|
|
6288 #ifdef FEAT_VIRTUALEDIT
|
|
6289 /* Break tabs, etc. */
|
|
6290 if (virtual_active())
|
|
6291 {
|
|
6292 if (u_save_cursor() == FAIL)
|
|
6293 return;
|
|
6294 if (gchar_cursor() == NUL)
|
|
6295 {
|
|
6296 /* Add extra space and put the cursor on the first one. */
|
|
6297 coladvance_force((colnr_T)(getviscol() + cap->count1));
|
|
6298 curwin->w_cursor.col -= cap->count1;
|
|
6299 }
|
|
6300 else if (gchar_cursor() == TAB)
|
|
6301 coladvance_force(getviscol());
|
|
6302 }
|
|
6303 #endif
|
|
6304
|
|
6305 /*
|
|
6306 * Check for a special key or not enough characters to replace.
|
|
6307 */
|
|
6308 ptr = ml_get_cursor();
|
|
6309 if (IS_SPECIAL(cap->nchar) || STRLEN(ptr) < (unsigned)cap->count1
|
|
6310 #ifdef FEAT_MBYTE
|
|
6311 || (has_mbyte && mb_charlen(ptr) < cap->count1)
|
|
6312 #endif
|
|
6313 )
|
|
6314 {
|
|
6315 clearopbeep(cap->oap);
|
|
6316 return;
|
|
6317 }
|
|
6318
|
|
6319 /*
|
|
6320 * Replacing with a TAB is done by edit() when it is complicated because
|
|
6321 * 'expandtab' or 'smarttab' is set. CTRL-V TAB inserts a literal TAB.
|
|
6322 * Other characters are done below to avoid problems with things like
|
|
6323 * CTRL-V 048 (for edit() this would be R CTRL-V 0 ESC).
|
|
6324 */
|
|
6325 if (had_ctrl_v != Ctrl_V && cap->nchar == '\t' && (curbuf->b_p_et || p_sta))
|
|
6326 {
|
|
6327 stuffnumReadbuff(cap->count1);
|
|
6328 stuffcharReadbuff('R');
|
|
6329 stuffcharReadbuff('\t');
|
|
6330 stuffcharReadbuff(ESC);
|
|
6331 return;
|
|
6332 }
|
|
6333
|
|
6334 /* save line for undo */
|
|
6335 if (u_save_cursor() == FAIL)
|
|
6336 return;
|
|
6337
|
|
6338 if (had_ctrl_v != Ctrl_V && (cap->nchar == '\r' || cap->nchar == '\n'))
|
|
6339 {
|
|
6340 /*
|
|
6341 * Replace character(s) by a single newline.
|
|
6342 * Strange vi behaviour: Only one newline is inserted.
|
|
6343 * Delete the characters here.
|
|
6344 * Insert the newline with an insert command, takes care of
|
|
6345 * autoindent. The insert command depends on being on the last
|
|
6346 * character of a line or not.
|
|
6347 */
|
|
6348 #ifdef FEAT_MBYTE
|
|
6349 (void)del_chars(cap->count1, FALSE); /* delete the characters */
|
|
6350 #else
|
|
6351 (void)del_bytes(cap->count1, FALSE); /* delete the characters */
|
|
6352 #endif
|
|
6353 stuffcharReadbuff('\r');
|
|
6354 stuffcharReadbuff(ESC);
|
|
6355
|
|
6356 /* Give 'r' to edit(), to get the redo command right. */
|
|
6357 invoke_edit(cap, TRUE, 'r', FALSE);
|
|
6358 }
|
|
6359 else
|
|
6360 {
|
|
6361 prep_redo(cap->oap->regname, cap->count1,
|
|
6362 NUL, 'r', NUL, had_ctrl_v, cap->nchar);
|
|
6363
|
|
6364 curbuf->b_op_start = curwin->w_cursor;
|
|
6365 #ifdef FEAT_MBYTE
|
|
6366 if (has_mbyte)
|
|
6367 {
|
|
6368 int old_State = State;
|
|
6369
|
|
6370 if (cap->ncharC1 != 0)
|
|
6371 AppendCharToRedobuff(cap->ncharC1);
|
|
6372 if (cap->ncharC2 != 0)
|
|
6373 AppendCharToRedobuff(cap->ncharC2);
|
|
6374
|
|
6375 /* This is slow, but it handles replacing a single-byte with a
|
|
6376 * multi-byte and the other way around. Also handles adding
|
|
6377 * composing characters for utf-8. */
|
|
6378 for (n = cap->count1; n > 0; --n)
|
|
6379 {
|
|
6380 State = REPLACE;
|
|
6381 ins_char(cap->nchar);
|
|
6382 State = old_State;
|
|
6383 if (cap->ncharC1 != 0)
|
|
6384 ins_char(cap->ncharC1);
|
|
6385 if (cap->ncharC2 != 0)
|
|
6386 ins_char(cap->ncharC2);
|
|
6387 }
|
|
6388 }
|
|
6389 else
|
|
6390 #endif
|
|
6391 {
|
|
6392 /*
|
|
6393 * Replace the characters within one line.
|
|
6394 */
|
|
6395 for (n = cap->count1; n > 0; --n)
|
|
6396 {
|
|
6397 /*
|
|
6398 * Get ptr again, because u_save and/or showmatch() will have
|
|
6399 * released the line. At the same time we let know that the
|
|
6400 * line will be changed.
|
|
6401 */
|
|
6402 ptr = ml_get_buf(curbuf, curwin->w_cursor.lnum, TRUE);
|
|
6403 ptr[curwin->w_cursor.col] = cap->nchar;
|
|
6404 if (p_sm && msg_silent == 0)
|
|
6405 showmatch(cap->nchar);
|
|
6406 ++curwin->w_cursor.col;
|
|
6407 }
|
|
6408 #ifdef FEAT_NETBEANS_INTG
|
|
6409 if (usingNetbeans)
|
|
6410 {
|
|
6411 colnr_T start = (colnr_T)(curwin->w_cursor.col - cap->count1);
|
|
6412
|
33
|
6413 netbeans_removed(curbuf, curwin->w_cursor.lnum, start,
|
|
6414 (long)cap->count1);
|
7
|
6415 netbeans_inserted(curbuf, curwin->w_cursor.lnum, start,
|
33
|
6416 &ptr[start], (int)cap->count1);
|
7
|
6417 }
|
|
6418 #endif
|
|
6419
|
|
6420 /* mark the buffer as changed and prepare for displaying */
|
|
6421 changed_bytes(curwin->w_cursor.lnum,
|
|
6422 (colnr_T)(curwin->w_cursor.col - cap->count1));
|
|
6423 }
|
|
6424 --curwin->w_cursor.col; /* cursor on the last replaced char */
|
|
6425 #ifdef FEAT_MBYTE
|
|
6426 /* if the character on the left of the current cursor is a multi-byte
|
|
6427 * character, move two characters left */
|
|
6428 if (has_mbyte)
|
|
6429 mb_adjust_cursor();
|
|
6430 #endif
|
|
6431 curbuf->b_op_end = curwin->w_cursor;
|
|
6432 curwin->w_set_curswant = TRUE;
|
|
6433 set_last_insert(cap->nchar);
|
|
6434 }
|
|
6435 }
|
|
6436
|
|
6437 #ifdef FEAT_VISUAL
|
|
6438 /*
|
|
6439 * 'o': Exchange start and end of Visual area.
|
|
6440 * 'O': same, but in block mode exchange left and right corners.
|
|
6441 */
|
|
6442 static void
|
|
6443 v_swap_corners(cmdchar)
|
|
6444 int cmdchar;
|
|
6445 {
|
|
6446 pos_T old_cursor;
|
|
6447 colnr_T left, right;
|
|
6448
|
|
6449 if (cmdchar == 'O' && VIsual_mode == Ctrl_V)
|
|
6450 {
|
|
6451 old_cursor = curwin->w_cursor;
|
|
6452 getvcols(curwin, &old_cursor, &VIsual, &left, &right);
|
|
6453 curwin->w_cursor.lnum = VIsual.lnum;
|
|
6454 coladvance(left);
|
|
6455 VIsual = curwin->w_cursor;
|
|
6456
|
|
6457 curwin->w_cursor.lnum = old_cursor.lnum;
|
|
6458 curwin->w_curswant = right;
|
|
6459 /* 'selection "exclusive" and cursor at right-bottom corner: move it
|
|
6460 * right one column */
|
|
6461 if (old_cursor.lnum >= VIsual.lnum && *p_sel == 'e')
|
|
6462 ++curwin->w_curswant;
|
|
6463 coladvance(curwin->w_curswant);
|
|
6464 if (curwin->w_cursor.col == old_cursor.col
|
|
6465 #ifdef FEAT_VIRTUALEDIT
|
|
6466 && (!virtual_active()
|
|
6467 || curwin->w_cursor.coladd == old_cursor.coladd)
|
|
6468 #endif
|
|
6469 )
|
|
6470 {
|
|
6471 curwin->w_cursor.lnum = VIsual.lnum;
|
|
6472 if (old_cursor.lnum <= VIsual.lnum && *p_sel == 'e')
|
|
6473 ++right;
|
|
6474 coladvance(right);
|
|
6475 VIsual = curwin->w_cursor;
|
|
6476
|
|
6477 curwin->w_cursor.lnum = old_cursor.lnum;
|
|
6478 coladvance(left);
|
|
6479 curwin->w_curswant = left;
|
|
6480 }
|
|
6481 }
|
|
6482 else
|
|
6483 {
|
|
6484 old_cursor = curwin->w_cursor;
|
|
6485 curwin->w_cursor = VIsual;
|
|
6486 VIsual = old_cursor;
|
|
6487 curwin->w_set_curswant = TRUE;
|
|
6488 }
|
|
6489 }
|
|
6490 #endif /* FEAT_VISUAL */
|
|
6491
|
|
6492 /*
|
|
6493 * "R" (cap->arg is FALSE) and "gR" (cap->arg is TRUE).
|
|
6494 */
|
|
6495 static void
|
|
6496 nv_Replace(cap)
|
|
6497 cmdarg_T *cap;
|
|
6498 {
|
|
6499 #ifdef FEAT_VISUAL
|
|
6500 if (VIsual_active) /* "R" is replace lines */
|
|
6501 {
|
|
6502 cap->cmdchar = 'c';
|
|
6503 cap->nchar = NUL;
|
|
6504 VIsual_mode = 'V';
|
|
6505 nv_operator(cap);
|
|
6506 }
|
|
6507 else
|
|
6508 #endif
|
|
6509 if (!checkclearopq(cap->oap))
|
|
6510 {
|
|
6511 if (!curbuf->b_p_ma)
|
|
6512 EMSG(_(e_modifiable));
|
|
6513 else
|
|
6514 {
|
|
6515 #ifdef FEAT_VIRTUALEDIT
|
|
6516 if (virtual_active())
|
|
6517 coladvance(getviscol());
|
|
6518 #endif
|
|
6519 invoke_edit(cap, FALSE, cap->arg ? 'V' : 'R', FALSE);
|
|
6520 }
|
|
6521 }
|
|
6522 }
|
|
6523
|
|
6524 #ifdef FEAT_VREPLACE
|
|
6525 /*
|
|
6526 * "gr".
|
|
6527 */
|
|
6528 static void
|
|
6529 nv_vreplace(cap)
|
|
6530 cmdarg_T *cap;
|
|
6531 {
|
|
6532 # ifdef FEAT_VISUAL
|
|
6533 if (VIsual_active)
|
|
6534 {
|
|
6535 cap->cmdchar = 'r';
|
|
6536 cap->nchar = cap->extra_char;
|
|
6537 nv_replace(cap); /* Do same as "r" in Visual mode for now */
|
|
6538 }
|
|
6539 else
|
|
6540 # endif
|
|
6541 if (!checkclearopq(cap->oap))
|
|
6542 {
|
|
6543 if (!curbuf->b_p_ma)
|
|
6544 EMSG(_(e_modifiable));
|
|
6545 else
|
|
6546 {
|
|
6547 if (cap->extra_char == Ctrl_V) /* get another character */
|
|
6548 cap->extra_char = get_literal();
|
|
6549 stuffcharReadbuff(cap->extra_char);
|
|
6550 stuffcharReadbuff(ESC);
|
|
6551 # ifdef FEAT_VIRTUALEDIT
|
|
6552 if (virtual_active())
|
|
6553 coladvance(getviscol());
|
|
6554 # endif
|
|
6555 invoke_edit(cap, TRUE, 'v', FALSE);
|
|
6556 }
|
|
6557 }
|
|
6558 }
|
|
6559 #endif
|
|
6560
|
|
6561 /*
|
|
6562 * Swap case for "~" command, when it does not work like an operator.
|
|
6563 */
|
|
6564 static void
|
|
6565 n_swapchar(cap)
|
|
6566 cmdarg_T *cap;
|
|
6567 {
|
|
6568 long n;
|
|
6569 pos_T startpos;
|
|
6570 int did_change = 0;
|
|
6571 #ifdef FEAT_NETBEANS_INTG
|
|
6572 pos_T pos;
|
|
6573 char_u *ptr;
|
|
6574 int count;
|
|
6575 #endif
|
|
6576
|
|
6577 if (checkclearopq(cap->oap))
|
|
6578 return;
|
|
6579
|
|
6580 if (lineempty(curwin->w_cursor.lnum) && vim_strchr(p_ww, '~') == NULL)
|
|
6581 {
|
|
6582 clearopbeep(cap->oap);
|
|
6583 return;
|
|
6584 }
|
|
6585
|
|
6586 prep_redo_cmd(cap);
|
|
6587
|
|
6588 if (u_save_cursor() == FAIL)
|
|
6589 return;
|
|
6590
|
|
6591 startpos = curwin->w_cursor;
|
|
6592 #ifdef FEAT_NETBEANS_INTG
|
|
6593 pos = startpos;
|
|
6594 #endif
|
|
6595 for (n = cap->count1; n > 0; --n)
|
|
6596 {
|
|
6597 did_change |= swapchar(cap->oap->op_type, &curwin->w_cursor);
|
|
6598 inc_cursor();
|
|
6599 if (gchar_cursor() == NUL)
|
|
6600 {
|
|
6601 if (vim_strchr(p_ww, '~') != NULL
|
|
6602 && curwin->w_cursor.lnum < curbuf->b_ml.ml_line_count)
|
|
6603 {
|
|
6604 #ifdef FEAT_NETBEANS_INTG
|
|
6605 if (usingNetbeans)
|
|
6606 {
|
|
6607 if (did_change)
|
|
6608 {
|
|
6609 ptr = ml_get(pos.lnum);
|
|
6610 count = STRLEN(ptr) - pos.col;
|
33
|
6611 netbeans_removed(curbuf, pos.lnum, pos.col,
|
|
6612 (long)count);
|
7
|
6613 netbeans_inserted(curbuf, pos.lnum, pos.col,
|
33
|
6614 &ptr[pos.col], count);
|
7
|
6615 }
|
|
6616 pos.col = 0;
|
|
6617 pos.lnum++;
|
|
6618 }
|
|
6619 #endif
|
|
6620 ++curwin->w_cursor.lnum;
|
|
6621 curwin->w_cursor.col = 0;
|
|
6622 if (n > 1)
|
|
6623 {
|
|
6624 if (u_savesub(curwin->w_cursor.lnum) == FAIL)
|
|
6625 break;
|
|
6626 u_clearline();
|
|
6627 }
|
|
6628 }
|
|
6629 else
|
|
6630 break;
|
|
6631 }
|
|
6632 }
|
|
6633 #ifdef FEAT_NETBEANS_INTG
|
|
6634 if (did_change && usingNetbeans)
|
|
6635 {
|
|
6636 ptr = ml_get(pos.lnum);
|
|
6637 count = curwin->w_cursor.col - pos.col;
|
33
|
6638 netbeans_removed(curbuf, pos.lnum, pos.col, (long)count);
|
|
6639 netbeans_inserted(curbuf, pos.lnum, pos.col, &ptr[pos.col], count);
|
7
|
6640 }
|
|
6641 #endif
|
|
6642
|
|
6643
|
|
6644 check_cursor();
|
|
6645 curwin->w_set_curswant = TRUE;
|
|
6646 if (did_change)
|
|
6647 {
|
|
6648 changed_lines(startpos.lnum, startpos.col, curwin->w_cursor.lnum + 1,
|
|
6649 0L);
|
|
6650 curbuf->b_op_start = startpos;
|
|
6651 curbuf->b_op_end = curwin->w_cursor;
|
|
6652 if (curbuf->b_op_end.col > 0)
|
|
6653 --curbuf->b_op_end.col;
|
|
6654 }
|
|
6655 }
|
|
6656
|
|
6657 /*
|
|
6658 * Move cursor to mark.
|
|
6659 */
|
|
6660 static void
|
|
6661 nv_cursormark(cap, flag, pos)
|
|
6662 cmdarg_T *cap;
|
|
6663 int flag;
|
|
6664 pos_T *pos;
|
|
6665 {
|
|
6666 if (check_mark(pos) == FAIL)
|
|
6667 clearop(cap->oap);
|
|
6668 else
|
|
6669 {
|
|
6670 if (cap->cmdchar == '\''
|
|
6671 || cap->cmdchar == '`'
|
|
6672 || cap->cmdchar == '['
|
|
6673 || cap->cmdchar == ']')
|
|
6674 setpcmark();
|
|
6675 curwin->w_cursor = *pos;
|
|
6676 if (flag)
|
|
6677 beginline(BL_WHITE | BL_FIX);
|
|
6678 else
|
|
6679 check_cursor();
|
|
6680 }
|
|
6681 cap->oap->motion_type = flag ? MLINE : MCHAR;
|
|
6682 if (cap->cmdchar == '`')
|
|
6683 cap->oap->use_reg_one = TRUE;
|
|
6684 cap->oap->inclusive = FALSE; /* ignored if not MCHAR */
|
|
6685 curwin->w_set_curswant = TRUE;
|
|
6686 }
|
|
6687
|
|
6688 #ifdef FEAT_VISUAL
|
|
6689 /*
|
|
6690 * Handle commands that are operators in Visual mode.
|
|
6691 */
|
|
6692 static void
|
|
6693 v_visop(cap)
|
|
6694 cmdarg_T *cap;
|
|
6695 {
|
|
6696 static char_u trans[] = "YyDdCcxdXdAAIIrr";
|
|
6697
|
|
6698 /* Uppercase means linewise, except in block mode, then "D" deletes till
|
|
6699 * the end of the line, and "C" replaces til EOL */
|
|
6700 if (isupper(cap->cmdchar))
|
|
6701 {
|
|
6702 if (VIsual_mode != Ctrl_V)
|
|
6703 VIsual_mode = 'V';
|
|
6704 else if (cap->cmdchar == 'C' || cap->cmdchar == 'D')
|
|
6705 curwin->w_curswant = MAXCOL;
|
|
6706 }
|
|
6707 cap->cmdchar = *(vim_strchr(trans, cap->cmdchar) + 1);
|
|
6708 nv_operator(cap);
|
|
6709 }
|
|
6710 #endif
|
|
6711
|
|
6712 /*
|
|
6713 * "s" and "S" commands.
|
|
6714 */
|
|
6715 static void
|
|
6716 nv_subst(cap)
|
|
6717 cmdarg_T *cap;
|
|
6718 {
|
|
6719 #ifdef FEAT_VISUAL
|
|
6720 if (VIsual_active) /* "vs" and "vS" are the same as "vc" */
|
|
6721 {
|
|
6722 if (cap->cmdchar == 'S')
|
|
6723 VIsual_mode = 'V';
|
|
6724 cap->cmdchar = 'c';
|
|
6725 nv_operator(cap);
|
|
6726 }
|
|
6727 else
|
|
6728 #endif
|
|
6729 nv_optrans(cap);
|
|
6730 }
|
|
6731
|
|
6732 /*
|
|
6733 * Abbreviated commands.
|
|
6734 */
|
|
6735 static void
|
|
6736 nv_abbrev(cap)
|
|
6737 cmdarg_T *cap;
|
|
6738 {
|
|
6739 if (cap->cmdchar == K_DEL || cap->cmdchar == K_KDEL)
|
|
6740 cap->cmdchar = 'x'; /* DEL key behaves like 'x' */
|
|
6741
|
|
6742 #ifdef FEAT_VISUAL
|
|
6743 /* in Visual mode these commands are operators */
|
|
6744 if (VIsual_active)
|
|
6745 v_visop(cap);
|
|
6746 else
|
|
6747 #endif
|
|
6748 nv_optrans(cap);
|
|
6749 }
|
|
6750
|
|
6751 /*
|
|
6752 * Translate a command into another command.
|
|
6753 */
|
|
6754 static void
|
|
6755 nv_optrans(cap)
|
|
6756 cmdarg_T *cap;
|
|
6757 {
|
|
6758 static char_u *(ar[8]) = {(char_u *)"dl", (char_u *)"dh",
|
|
6759 (char_u *)"d$", (char_u *)"c$",
|
|
6760 (char_u *)"cl", (char_u *)"cc",
|
|
6761 (char_u *)"yy", (char_u *)":s\r"};
|
|
6762 static char_u *str = (char_u *)"xXDCsSY&";
|
|
6763
|
|
6764 if (!checkclearopq(cap->oap))
|
|
6765 {
|
164
|
6766 /* In Vi "2D" doesn't delete the next line. Can't translate it
|
|
6767 * either, because "2." should also not use the count. */
|
|
6768 if (cap->cmdchar == 'D' && vim_strchr(p_cpo, CPO_HASH) != NULL)
|
|
6769 {
|
|
6770 cap->oap->start = curwin->w_cursor;
|
|
6771 cap->oap->op_type = OP_DELETE;
|
|
6772 cap->count1 = 1;
|
|
6773 nv_dollar(cap);
|
|
6774 finish_op = TRUE;
|
|
6775 ResetRedobuff();
|
|
6776 AppendCharToRedobuff('D');
|
|
6777 }
|
|
6778 else
|
|
6779 {
|
|
6780 if (cap->count0)
|
|
6781 stuffnumReadbuff(cap->count0);
|
|
6782 stuffReadbuff(ar[(int)(vim_strchr(str, cap->cmdchar) - str)]);
|
|
6783 }
|
7
|
6784 }
|
|
6785 cap->opcount = 0;
|
|
6786 }
|
|
6787
|
|
6788 /*
|
|
6789 * "'" and "`" commands. Also for "g'" and "g`".
|
|
6790 * cap->arg is TRUE for "'" and "g'".
|
|
6791 */
|
|
6792 static void
|
|
6793 nv_gomark(cap)
|
|
6794 cmdarg_T *cap;
|
|
6795 {
|
|
6796 pos_T *pos;
|
|
6797 int c;
|
|
6798 #ifdef FEAT_FOLDING
|
|
6799 linenr_T lnum = curwin->w_cursor.lnum;
|
|
6800 int old_KeyTyped = KeyTyped; /* getting file may reset it */
|
|
6801 #endif
|
|
6802
|
|
6803 if (cap->cmdchar == 'g')
|
|
6804 c = cap->extra_char;
|
|
6805 else
|
|
6806 c = cap->nchar;
|
|
6807 pos = getmark(c, (cap->oap->op_type == OP_NOP));
|
|
6808 if (pos == (pos_T *)-1) /* jumped to other file */
|
|
6809 {
|
|
6810 if (cap->arg)
|
|
6811 {
|
|
6812 check_cursor_lnum();
|
|
6813 beginline(BL_WHITE | BL_FIX);
|
|
6814 }
|
|
6815 else
|
|
6816 check_cursor();
|
|
6817 }
|
|
6818 else
|
|
6819 nv_cursormark(cap, cap->arg, pos);
|
|
6820
|
|
6821 #ifdef FEAT_VIRTUALEDIT
|
|
6822 /* May need to clear the coladd that a mark includes. */
|
|
6823 if (!virtual_active())
|
|
6824 curwin->w_cursor.coladd = 0;
|
|
6825 #endif
|
|
6826 #ifdef FEAT_FOLDING
|
|
6827 if (cap->oap->op_type == OP_NOP
|
|
6828 && (pos == (pos_T *)-1 || lnum != curwin->w_cursor.lnum)
|
|
6829 && (fdo_flags & FDO_MARK)
|
|
6830 && old_KeyTyped)
|
|
6831 foldOpenCursor();
|
|
6832 #endif
|
|
6833 }
|
|
6834
|
|
6835 /*
|
|
6836 * Handle CTRL-O, CTRL-I, "g;" and "g," commands.
|
|
6837 */
|
|
6838 static void
|
|
6839 nv_pcmark(cap)
|
|
6840 cmdarg_T *cap;
|
|
6841 {
|
|
6842 #ifdef FEAT_JUMPLIST
|
|
6843 pos_T *pos;
|
|
6844 # ifdef FEAT_FOLDING
|
|
6845 linenr_T lnum = curwin->w_cursor.lnum;
|
|
6846 int old_KeyTyped = KeyTyped; /* getting file may reset it */
|
|
6847 # endif
|
|
6848
|
|
6849 if (!checkclearopq(cap->oap))
|
|
6850 {
|
|
6851 if (cap->cmdchar == 'g')
|
|
6852 pos = movechangelist((int)cap->count1);
|
|
6853 else
|
|
6854 pos = movemark((int)cap->count1);
|
|
6855 if (pos == (pos_T *)-1) /* jump to other file */
|
|
6856 {
|
|
6857 curwin->w_set_curswant = TRUE;
|
|
6858 check_cursor();
|
|
6859 }
|
|
6860 else if (pos != NULL) /* can jump */
|
|
6861 nv_cursormark(cap, FALSE, pos);
|
|
6862 else if (cap->cmdchar == 'g')
|
|
6863 {
|
|
6864 if (curbuf->b_changelistlen == 0)
|
|
6865 EMSG(_("E664: changelist is empty"));
|
|
6866 else if (cap->count1 < 0)
|
|
6867 EMSG(_("E662: At start of changelist"));
|
|
6868 else
|
|
6869 EMSG(_("E663: At end of changelist"));
|
|
6870 }
|
|
6871 else
|
|
6872 clearopbeep(cap->oap);
|
|
6873 # ifdef FEAT_FOLDING
|
|
6874 if (cap->oap->op_type == OP_NOP
|
|
6875 && (pos == (pos_T *)-1 || lnum != curwin->w_cursor.lnum)
|
|
6876 && (fdo_flags & FDO_MARK)
|
|
6877 && old_KeyTyped)
|
|
6878 foldOpenCursor();
|
|
6879 # endif
|
|
6880 }
|
|
6881 #else
|
|
6882 clearopbeep(cap->oap);
|
|
6883 #endif
|
|
6884 }
|
|
6885
|
|
6886 /*
|
|
6887 * Handle '"' command.
|
|
6888 */
|
|
6889 static void
|
|
6890 nv_regname(cap)
|
|
6891 cmdarg_T *cap;
|
|
6892 {
|
|
6893 if (checkclearop(cap->oap))
|
|
6894 return;
|
|
6895 #ifdef FEAT_EVAL
|
|
6896 if (cap->nchar == '=')
|
|
6897 cap->nchar = get_expr_register();
|
|
6898 #endif
|
|
6899 if (cap->nchar != NUL && valid_yank_reg(cap->nchar, FALSE))
|
|
6900 {
|
|
6901 cap->oap->regname = cap->nchar;
|
|
6902 cap->opcount = cap->count0; /* remember count before '"' */
|
|
6903 #ifdef FEAT_EVAL
|
|
6904 set_reg_var(cap->oap->regname);
|
|
6905 #endif
|
|
6906 }
|
|
6907 else
|
|
6908 clearopbeep(cap->oap);
|
|
6909 }
|
|
6910
|
|
6911 #ifdef FEAT_VISUAL
|
|
6912 /*
|
|
6913 * Handle "v", "V" and "CTRL-V" commands.
|
|
6914 * Also for "gh", "gH" and "g^H" commands: Always start Select mode, cap->arg
|
|
6915 * is TRUE.
|
167
|
6916 * Handle CTRL-Q just like CTRL-V.
|
7
|
6917 */
|
|
6918 static void
|
|
6919 nv_visual(cap)
|
|
6920 cmdarg_T *cap;
|
|
6921 {
|
167
|
6922 if (cap->cmdchar == Ctrl_Q)
|
|
6923 cap->cmdchar = Ctrl_V;
|
|
6924
|
7
|
6925 /* 'v', 'V' and CTRL-V can be used while an operator is pending to make it
|
|
6926 * characterwise, linewise, or blockwise. */
|
|
6927 if (cap->oap->op_type != OP_NOP)
|
|
6928 {
|
|
6929 cap->oap->motion_force = cap->cmdchar;
|
|
6930 finish_op = FALSE; /* operator doesn't finish now but later */
|
|
6931 return;
|
|
6932 }
|
|
6933
|
|
6934 VIsual_select = cap->arg;
|
|
6935 if (VIsual_active) /* change Visual mode */
|
|
6936 {
|
|
6937 if (VIsual_mode == cap->cmdchar) /* stop visual mode */
|
|
6938 end_visual_mode();
|
|
6939 else /* toggle char/block mode */
|
|
6940 { /* or char/line mode */
|
|
6941 VIsual_mode = cap->cmdchar;
|
|
6942 showmode();
|
|
6943 }
|
|
6944 redraw_curbuf_later(INVERTED); /* update the inversion */
|
|
6945 }
|
|
6946 else /* start Visual mode */
|
|
6947 {
|
|
6948 check_visual_highlight();
|
|
6949 if (cap->count0) /* use previously selected part */
|
|
6950 {
|
|
6951 if (resel_VIsual_mode == NUL) /* there is none */
|
|
6952 {
|
|
6953 beep_flush();
|
|
6954 return;
|
|
6955 }
|
|
6956 VIsual = curwin->w_cursor;
|
|
6957
|
|
6958 VIsual_active = TRUE;
|
|
6959 VIsual_reselect = TRUE;
|
|
6960 if (!cap->arg)
|
|
6961 /* start Select mode when 'selectmode' contains "cmd" */
|
|
6962 may_start_select('c');
|
|
6963 #ifdef FEAT_MOUSE
|
|
6964 setmouse();
|
|
6965 #endif
|
|
6966 if (p_smd)
|
|
6967 redraw_cmdline = TRUE; /* show visual mode later */
|
|
6968 /*
|
|
6969 * For V and ^V, we multiply the number of lines even if there
|
|
6970 * was only one -- webb
|
|
6971 */
|
|
6972 if (resel_VIsual_mode != 'v' || resel_VIsual_line_count > 1)
|
|
6973 {
|
|
6974 curwin->w_cursor.lnum +=
|
|
6975 resel_VIsual_line_count * cap->count0 - 1;
|
|
6976 if (curwin->w_cursor.lnum > curbuf->b_ml.ml_line_count)
|
|
6977 curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count;
|
|
6978 }
|
|
6979 VIsual_mode = resel_VIsual_mode;
|
|
6980 if (VIsual_mode == 'v')
|
|
6981 {
|
|
6982 if (resel_VIsual_line_count <= 1)
|
|
6983 curwin->w_cursor.col += resel_VIsual_col * cap->count0 - 1;
|
|
6984 else
|
|
6985 curwin->w_cursor.col = resel_VIsual_col;
|
|
6986 check_cursor_col();
|
|
6987 }
|
|
6988 if (resel_VIsual_col == MAXCOL)
|
|
6989 {
|
|
6990 curwin->w_curswant = MAXCOL;
|
|
6991 coladvance((colnr_T)MAXCOL);
|
|
6992 }
|
|
6993 else if (VIsual_mode == Ctrl_V)
|
|
6994 {
|
|
6995 validate_virtcol();
|
|
6996 curwin->w_curswant = curwin->w_virtcol
|
|
6997 + resel_VIsual_col * cap->count0 - 1;
|
|
6998 coladvance(curwin->w_curswant);
|
|
6999 }
|
|
7000 else
|
|
7001 curwin->w_set_curswant = TRUE;
|
|
7002 redraw_curbuf_later(INVERTED); /* show the inversion */
|
|
7003 }
|
|
7004 else
|
|
7005 {
|
|
7006 if (!cap->arg)
|
|
7007 /* start Select mode when 'selectmode' contains "cmd" */
|
|
7008 may_start_select('c');
|
|
7009 n_start_visual_mode(cap->cmdchar);
|
|
7010 }
|
|
7011 }
|
|
7012 }
|
|
7013
|
|
7014 /*
|
|
7015 * Start selection for Shift-movement keys.
|
|
7016 */
|
|
7017 void
|
|
7018 start_selection()
|
|
7019 {
|
|
7020 /* if 'selectmode' contains "key", start Select mode */
|
|
7021 may_start_select('k');
|
|
7022 n_start_visual_mode('v');
|
|
7023 }
|
|
7024
|
|
7025 /*
|
|
7026 * Start Select mode, if "c" is in 'selectmode' and not in a mapping or menu.
|
|
7027 */
|
|
7028 void
|
|
7029 may_start_select(c)
|
|
7030 int c;
|
|
7031 {
|
|
7032 VIsual_select = (stuff_empty() && typebuf_typed()
|
|
7033 && (vim_strchr(p_slm, c) != NULL));
|
|
7034 }
|
|
7035
|
|
7036 /*
|
|
7037 * Start Visual mode "c".
|
|
7038 * Should set VIsual_select before calling this.
|
|
7039 */
|
|
7040 static void
|
|
7041 n_start_visual_mode(c)
|
|
7042 int c;
|
|
7043 {
|
|
7044 VIsual_mode = c;
|
|
7045 VIsual_active = TRUE;
|
|
7046 VIsual_reselect = TRUE;
|
|
7047 #ifdef FEAT_VIRTUALEDIT
|
|
7048 /* Corner case: the 0 position in a tab may change when going into
|
|
7049 * virtualedit. Recalculate curwin->w_cursor to avoid bad hilighting.
|
|
7050 */
|
|
7051 if (c == Ctrl_V && (ve_flags & VE_BLOCK) && gchar_cursor() == TAB)
|
|
7052 coladvance(curwin->w_virtcol);
|
|
7053 #endif
|
|
7054 VIsual = curwin->w_cursor;
|
|
7055
|
|
7056 #ifdef FEAT_FOLDING
|
|
7057 foldAdjustVisual();
|
|
7058 #endif
|
|
7059
|
|
7060 #ifdef FEAT_MOUSE
|
|
7061 setmouse();
|
|
7062 #endif
|
|
7063 if (p_smd)
|
|
7064 redraw_cmdline = TRUE; /* show visual mode later */
|
|
7065 #ifdef FEAT_CLIPBOARD
|
|
7066 /* Make sure the clipboard gets updated. Needed because start and
|
|
7067 * end may still be the same, and the selection needs to be owned */
|
|
7068 clip_star.vmode = NUL;
|
|
7069 #endif
|
|
7070
|
|
7071 /* Only need to redraw this line, unless still need to redraw an old
|
|
7072 * Visual area (when 'lazyredraw' is set). */
|
|
7073 if (curwin->w_redr_type < INVERTED)
|
|
7074 {
|
|
7075 curwin->w_old_cursor_lnum = curwin->w_cursor.lnum;
|
|
7076 curwin->w_old_visual_lnum = curwin->w_cursor.lnum;
|
|
7077 }
|
|
7078 }
|
|
7079
|
|
7080 #endif /* FEAT_VISUAL */
|
|
7081
|
|
7082 /*
|
|
7083 * CTRL-W: Window commands
|
|
7084 */
|
|
7085 static void
|
|
7086 nv_window(cap)
|
|
7087 cmdarg_T *cap;
|
|
7088 {
|
|
7089 #ifdef FEAT_WINDOWS
|
|
7090 if (!checkclearop(cap->oap))
|
|
7091 do_window(cap->nchar, cap->count0, NUL); /* everything is in window.c */
|
|
7092 #else
|
|
7093 (void)checkclearop(cap->oap);
|
|
7094 #endif
|
|
7095 }
|
|
7096
|
|
7097 /*
|
|
7098 * CTRL-Z: Suspend
|
|
7099 */
|
|
7100 static void
|
|
7101 nv_suspend(cap)
|
|
7102 cmdarg_T *cap;
|
|
7103 {
|
|
7104 clearop(cap->oap);
|
|
7105 #ifdef FEAT_VISUAL
|
|
7106 if (VIsual_active)
|
|
7107 end_visual_mode(); /* stop Visual mode */
|
|
7108 #endif
|
|
7109 do_cmdline_cmd((char_u *)"st");
|
|
7110 }
|
|
7111
|
|
7112 /*
|
|
7113 * Commands starting with "g".
|
|
7114 */
|
|
7115 static void
|
|
7116 nv_g_cmd(cap)
|
|
7117 cmdarg_T *cap;
|
|
7118 {
|
|
7119 oparg_T *oap = cap->oap;
|
|
7120 #ifdef FEAT_VISUAL
|
|
7121 pos_T tpos;
|
|
7122 #endif
|
|
7123 int i;
|
|
7124 int flag = FALSE;
|
|
7125
|
|
7126 switch (cap->nchar)
|
|
7127 {
|
|
7128 #ifdef MEM_PROFILE
|
|
7129 /*
|
|
7130 * "g^A": dump log of used memory.
|
|
7131 */
|
|
7132 case Ctrl_A:
|
|
7133 vim_mem_profile_dump();
|
|
7134 break;
|
|
7135 #endif
|
|
7136
|
|
7137 #ifdef FEAT_VREPLACE
|
|
7138 /*
|
|
7139 * "gR": Enter virtual replace mode.
|
|
7140 */
|
|
7141 case 'R':
|
|
7142 cap->arg = TRUE;
|
|
7143 nv_Replace(cap);
|
|
7144 break;
|
|
7145
|
|
7146 case 'r':
|
|
7147 nv_vreplace(cap);
|
|
7148 break;
|
|
7149 #endif
|
|
7150
|
|
7151 case '&':
|
|
7152 do_cmdline_cmd((char_u *)"%s//~/&");
|
|
7153 break;
|
|
7154
|
|
7155 #ifdef FEAT_VISUAL
|
|
7156 /*
|
|
7157 * "gv": Reselect the previous Visual area. If Visual already active,
|
|
7158 * exchange previous and current Visual area.
|
|
7159 */
|
|
7160 case 'v':
|
|
7161 if (checkclearop(oap))
|
|
7162 break;
|
|
7163
|
|
7164 if ( curbuf->b_visual_start.lnum == 0
|
|
7165 || curbuf->b_visual_start.lnum > curbuf->b_ml.ml_line_count
|
|
7166 || curbuf->b_visual_end.lnum == 0)
|
|
7167 beep_flush();
|
|
7168 else
|
|
7169 {
|
|
7170 /* set w_cursor to the start of the Visual area, tpos to the end */
|
|
7171 if (VIsual_active)
|
|
7172 {
|
|
7173 i = VIsual_mode;
|
|
7174 VIsual_mode = curbuf->b_visual_mode;
|
|
7175 curbuf->b_visual_mode = i;
|
|
7176 # ifdef FEAT_EVAL
|
|
7177 curbuf->b_visual_mode_eval = i;
|
|
7178 # endif
|
|
7179 i = curwin->w_curswant;
|
|
7180 curwin->w_curswant = curbuf->b_visual_curswant;
|
|
7181 curbuf->b_visual_curswant = i;
|
|
7182
|
|
7183 tpos = curbuf->b_visual_end;
|
|
7184 curbuf->b_visual_end = curwin->w_cursor;
|
|
7185 curwin->w_cursor = curbuf->b_visual_start;
|
|
7186 curbuf->b_visual_start = VIsual;
|
|
7187 }
|
|
7188 else
|
|
7189 {
|
|
7190 VIsual_mode = curbuf->b_visual_mode;
|
|
7191 curwin->w_curswant = curbuf->b_visual_curswant;
|
|
7192 tpos = curbuf->b_visual_end;
|
|
7193 curwin->w_cursor = curbuf->b_visual_start;
|
|
7194 }
|
|
7195
|
|
7196 VIsual_active = TRUE;
|
|
7197 VIsual_reselect = TRUE;
|
|
7198
|
|
7199 /* Set Visual to the start and w_cursor to the end of the Visual
|
|
7200 * area. Make sure they are on an existing character. */
|
|
7201 check_cursor();
|
|
7202 VIsual = curwin->w_cursor;
|
|
7203 curwin->w_cursor = tpos;
|
|
7204 check_cursor();
|
|
7205 update_topline();
|
|
7206 /*
|
|
7207 * When called from normal "g" command: start Select mode when
|
|
7208 * 'selectmode' contains "cmd". When called for K_SELECT, always
|
|
7209 * start Select mode.
|
|
7210 */
|
|
7211 if (cap->arg)
|
|
7212 VIsual_select = TRUE;
|
|
7213 else
|
|
7214 may_start_select('c');
|
|
7215 #ifdef FEAT_MOUSE
|
|
7216 setmouse();
|
|
7217 #endif
|
|
7218 #ifdef FEAT_CLIPBOARD
|
|
7219 /* Make sure the clipboard gets updated. Needed because start and
|
|
7220 * end are still the same, and the selection needs to be owned */
|
|
7221 clip_star.vmode = NUL;
|
|
7222 #endif
|
|
7223 redraw_curbuf_later(INVERTED);
|
|
7224 showmode();
|
|
7225 }
|
|
7226 break;
|
|
7227 /*
|
|
7228 * "gV": Don't reselect the previous Visual area after a Select mode
|
|
7229 * mapping of menu.
|
|
7230 */
|
|
7231 case 'V':
|
|
7232 VIsual_reselect = FALSE;
|
|
7233 break;
|
|
7234
|
|
7235 /*
|
|
7236 * "gh": start Select mode.
|
|
7237 * "gH": start Select line mode.
|
|
7238 * "g^H": start Select block mode.
|
|
7239 */
|
|
7240 case K_BS:
|
|
7241 cap->nchar = Ctrl_H;
|
|
7242 /* FALLTHROUGH */
|
|
7243 case 'h':
|
|
7244 case 'H':
|
|
7245 case Ctrl_H:
|
|
7246 # ifdef EBCDIC
|
|
7247 /* EBCDIC: 'v'-'h' != '^v'-'^h' */
|
|
7248 if (cap->nchar == Ctrl_H)
|
|
7249 cap->cmdchar = Ctrl_V;
|
|
7250 else
|
|
7251 # endif
|
|
7252 cap->cmdchar = cap->nchar + ('v' - 'h');
|
|
7253 cap->arg = TRUE;
|
|
7254 nv_visual(cap);
|
|
7255 break;
|
|
7256 #endif /* FEAT_VISUAL */
|
|
7257
|
|
7258 /*
|
|
7259 * "gj" and "gk" two new funny movement keys -- up and down
|
|
7260 * movement based on *screen* line rather than *file* line.
|
|
7261 */
|
|
7262 case 'j':
|
|
7263 case K_DOWN:
|
|
7264 /* with 'nowrap' it works just like the normal "j" command; also when
|
|
7265 * in a closed fold */
|
|
7266 if (!curwin->w_p_wrap
|
|
7267 #ifdef FEAT_FOLDING
|
|
7268 || hasFolding(curwin->w_cursor.lnum, NULL, NULL)
|
|
7269 #endif
|
|
7270 )
|
|
7271 {
|
|
7272 oap->motion_type = MLINE;
|
|
7273 i = cursor_down(cap->count1, oap->op_type == OP_NOP);
|
|
7274 }
|
|
7275 else
|
|
7276 i = nv_screengo(oap, FORWARD, cap->count1);
|
|
7277 if (i == FAIL)
|
|
7278 clearopbeep(oap);
|
|
7279 break;
|
|
7280
|
|
7281 case 'k':
|
|
7282 case K_UP:
|
|
7283 /* with 'nowrap' it works just like the normal "k" command; also when
|
|
7284 * in a closed fold */
|
|
7285 if (!curwin->w_p_wrap
|
|
7286 #ifdef FEAT_FOLDING
|
|
7287 || hasFolding(curwin->w_cursor.lnum, NULL, NULL)
|
|
7288 #endif
|
|
7289 )
|
|
7290 {
|
|
7291 oap->motion_type = MLINE;
|
|
7292 i = cursor_up(cap->count1, oap->op_type == OP_NOP);
|
|
7293 }
|
|
7294 else
|
|
7295 i = nv_screengo(oap, BACKWARD, cap->count1);
|
|
7296 if (i == FAIL)
|
|
7297 clearopbeep(oap);
|
|
7298 break;
|
|
7299
|
|
7300 /*
|
|
7301 * "gJ": join two lines without inserting a space.
|
|
7302 */
|
|
7303 case 'J':
|
|
7304 nv_join(cap);
|
|
7305 break;
|
|
7306
|
|
7307 /*
|
|
7308 * "g0", "g^" and "g$": Like "0", "^" and "$" but for screen lines.
|
|
7309 * "gm": middle of "g0" and "g$".
|
|
7310 */
|
|
7311 case '^':
|
|
7312 flag = TRUE;
|
|
7313 /* FALLTHROUGH */
|
|
7314
|
|
7315 case '0':
|
|
7316 case 'm':
|
|
7317 case K_HOME:
|
|
7318 case K_KHOME:
|
|
7319 oap->motion_type = MCHAR;
|
|
7320 oap->inclusive = FALSE;
|
|
7321 if (curwin->w_p_wrap
|
|
7322 #ifdef FEAT_VERTSPLIT
|
|
7323 && curwin->w_width != 0
|
|
7324 #endif
|
|
7325 )
|
|
7326 {
|
|
7327 int width1 = W_WIDTH(curwin) - curwin_col_off();
|
|
7328 int width2 = width1 + curwin_col_off2();
|
|
7329
|
|
7330 validate_virtcol();
|
|
7331 i = 0;
|
|
7332 if (curwin->w_virtcol >= (colnr_T)width1 && width2 > 0)
|
|
7333 i = (curwin->w_virtcol - width1) / width2 * width2 + width1;
|
|
7334 }
|
|
7335 else
|
|
7336 i = curwin->w_leftcol;
|
|
7337 /* Go to the middle of the screen line. When 'number' is on and lines
|
|
7338 * are wrapping the middle can be more to the left.*/
|
|
7339 if (cap->nchar == 'm')
|
|
7340 i += (W_WIDTH(curwin) - curwin_col_off()
|
|
7341 + ((curwin->w_p_wrap && i > 0)
|
|
7342 ? curwin_col_off2() : 0)) / 2;
|
|
7343 coladvance((colnr_T)i);
|
|
7344 if (flag)
|
|
7345 {
|
|
7346 do
|
|
7347 i = gchar_cursor();
|
|
7348 while (vim_iswhite(i) && oneright() == OK);
|
|
7349 }
|
|
7350 curwin->w_set_curswant = TRUE;
|
|
7351 break;
|
|
7352
|
|
7353 case '_':
|
|
7354 /* "g_": to the last non-blank character in the line or <count> lines
|
|
7355 * downward. */
|
|
7356 cap->oap->motion_type = MCHAR;
|
|
7357 cap->oap->inclusive = TRUE;
|
|
7358 curwin->w_curswant = MAXCOL;
|
|
7359 if (cursor_down((long)(cap->count1 - 1),
|
|
7360 cap->oap->op_type == OP_NOP) == FAIL)
|
|
7361 clearopbeep(cap->oap);
|
|
7362 else
|
|
7363 {
|
|
7364 char_u *ptr = ml_get_curline();
|
|
7365
|
|
7366 /* In Visual mode we may end up after the line. */
|
|
7367 if (curwin->w_cursor.col > 0 && ptr[curwin->w_cursor.col] == NUL)
|
|
7368 --curwin->w_cursor.col;
|
|
7369
|
|
7370 /* Decrease the cursor column until it's on a non-blank. */
|
|
7371 while (curwin->w_cursor.col > 0
|
|
7372 && vim_iswhite(ptr[curwin->w_cursor.col]))
|
|
7373 --curwin->w_cursor.col;
|
|
7374 curwin->w_set_curswant = TRUE;
|
|
7375 }
|
|
7376 break;
|
|
7377
|
|
7378 case '$':
|
|
7379 case K_END:
|
|
7380 case K_KEND:
|
|
7381 {
|
|
7382 int col_off = curwin_col_off();
|
|
7383
|
|
7384 oap->motion_type = MCHAR;
|
|
7385 oap->inclusive = TRUE;
|
|
7386 if (curwin->w_p_wrap
|
|
7387 #ifdef FEAT_VERTSPLIT
|
|
7388 && curwin->w_width != 0
|
|
7389 #endif
|
|
7390 )
|
|
7391 {
|
|
7392 curwin->w_curswant = MAXCOL; /* so we stay at the end */
|
|
7393 if (cap->count1 == 1)
|
|
7394 {
|
|
7395 int width1 = W_WIDTH(curwin) - col_off;
|
|
7396 int width2 = width1 + curwin_col_off2();
|
|
7397
|
|
7398 validate_virtcol();
|
|
7399 i = width1 - 1;
|
|
7400 if (curwin->w_virtcol >= (colnr_T)width1)
|
|
7401 i += ((curwin->w_virtcol - width1) / width2 + 1)
|
|
7402 * width2;
|
|
7403 coladvance((colnr_T)i);
|
|
7404 #if defined(FEAT_LINEBREAK) || defined(FEAT_MBYTE)
|
|
7405 if (curwin->w_cursor.col > 0 && curwin->w_p_wrap)
|
|
7406 {
|
|
7407 /*
|
|
7408 * Check for landing on a character that got split at
|
|
7409 * the end of the line. We do not want to advance to
|
|
7410 * the next screen line.
|
|
7411 */
|
|
7412 validate_virtcol();
|
|
7413 if (curwin->w_virtcol > (colnr_T)i)
|
|
7414 --curwin->w_cursor.col;
|
|
7415 }
|
|
7416 #endif
|
|
7417 }
|
|
7418 else if (nv_screengo(oap, FORWARD, cap->count1 - 1) == FAIL)
|
|
7419 clearopbeep(oap);
|
|
7420 }
|
|
7421 else
|
|
7422 {
|
|
7423 i = curwin->w_leftcol + W_WIDTH(curwin) - col_off - 1;
|
|
7424 coladvance((colnr_T)i);
|
40
|
7425
|
|
7426 /* Make sure we stick in this column. */
|
|
7427 validate_virtcol();
|
|
7428 curwin->w_curswant = curwin->w_virtcol;
|
|
7429 curwin->w_set_curswant = FALSE;
|
7
|
7430 }
|
|
7431 }
|
|
7432 break;
|
|
7433
|
|
7434 /*
|
|
7435 * "g*" and "g#", like "*" and "#" but without using "\<" and "\>"
|
|
7436 */
|
|
7437 case '*':
|
|
7438 case '#':
|
|
7439 #if POUND != '#'
|
|
7440 case POUND: /* pound sign (sometimes equal to '#') */
|
|
7441 #endif
|
|
7442 case Ctrl_RSB: /* :tag or :tselect for current identifier */
|
|
7443 case ']': /* :tselect for current identifier */
|
|
7444 nv_ident(cap);
|
|
7445 break;
|
|
7446
|
|
7447 /*
|
|
7448 * ge and gE: go back to end of word
|
|
7449 */
|
|
7450 case 'e':
|
|
7451 case 'E':
|
|
7452 oap->motion_type = MCHAR;
|
|
7453 curwin->w_set_curswant = TRUE;
|
|
7454 oap->inclusive = TRUE;
|
|
7455 if (bckend_word(cap->count1, cap->nchar == 'E', FALSE) == FAIL)
|
|
7456 clearopbeep(oap);
|
|
7457 break;
|
|
7458
|
|
7459 /*
|
|
7460 * "g CTRL-G": display info about cursor position
|
|
7461 */
|
|
7462 case Ctrl_G:
|
|
7463 cursor_pos_info();
|
|
7464 break;
|
|
7465
|
|
7466 /*
|
|
7467 * "gi": start Insert at the last position.
|
|
7468 */
|
|
7469 case 'i':
|
|
7470 if (curbuf->b_last_insert.lnum != 0)
|
|
7471 {
|
|
7472 curwin->w_cursor = curbuf->b_last_insert;
|
|
7473 check_cursor_lnum();
|
|
7474 i = (int)STRLEN(ml_get_curline());
|
|
7475 if (curwin->w_cursor.col > (colnr_T)i)
|
|
7476 {
|
|
7477 #ifdef FEAT_VIRTUALEDIT
|
|
7478 if (virtual_active())
|
|
7479 curwin->w_cursor.coladd += curwin->w_cursor.col - i;
|
|
7480 #endif
|
|
7481 curwin->w_cursor.col = i;
|
|
7482 }
|
|
7483 }
|
|
7484 cap->cmdchar = 'i';
|
|
7485 nv_edit(cap);
|
|
7486 break;
|
|
7487
|
|
7488 /*
|
|
7489 * "gI": Start insert in column 1.
|
|
7490 */
|
|
7491 case 'I':
|
|
7492 beginline(0);
|
|
7493 if (!checkclearopq(oap))
|
|
7494 invoke_edit(cap, FALSE, 'g', FALSE);
|
|
7495 break;
|
|
7496
|
|
7497 #ifdef FEAT_SEARCHPATH
|
|
7498 /*
|
|
7499 * "gf": goto file, edit file under cursor
|
|
7500 * "]f" and "[f": can also be used.
|
|
7501 */
|
|
7502 case 'f':
|
|
7503 nv_gotofile(cap);
|
|
7504 break;
|
|
7505 #endif
|
|
7506
|
|
7507 /* "g'm" and "g`m": jump to mark without setting pcmark */
|
|
7508 case '\'':
|
|
7509 cap->arg = TRUE;
|
|
7510 /*FALLTHROUGH*/
|
|
7511 case '`':
|
|
7512 nv_gomark(cap);
|
|
7513 break;
|
|
7514
|
|
7515 /*
|
|
7516 * "gs": Goto sleep.
|
|
7517 */
|
|
7518 case 's':
|
|
7519 do_sleep(cap->count1 * 1000L);
|
|
7520 break;
|
|
7521
|
|
7522 /*
|
|
7523 * "ga": Display the ascii value of the character under the
|
|
7524 * cursor. It is displayed in decimal, hex, and octal. -- webb
|
|
7525 */
|
|
7526 case 'a':
|
|
7527 do_ascii(NULL);
|
|
7528 break;
|
|
7529
|
|
7530 #ifdef FEAT_MBYTE
|
|
7531 /*
|
|
7532 * "g8": Display the bytes used for the UTF-8 character under the
|
|
7533 * cursor. It is displayed in hex.
|
|
7534 */
|
|
7535 case '8':
|
|
7536 show_utf8();
|
|
7537 break;
|
|
7538 #endif
|
|
7539
|
|
7540 /*
|
|
7541 * "gg": Goto the first line in file. With a count it goes to
|
|
7542 * that line number like for "G". -- webb
|
|
7543 */
|
|
7544 case 'g':
|
|
7545 cap->arg = FALSE;
|
|
7546 nv_goto(cap);
|
|
7547 break;
|
|
7548
|
|
7549 /*
|
|
7550 * Two-character operators:
|
|
7551 * "gq" Format text
|
|
7552 * "gw" Format text and keep cursor position
|
|
7553 * "g~" Toggle the case of the text.
|
|
7554 * "gu" Change text to lower case.
|
|
7555 * "gU" Change text to upper case.
|
|
7556 * "g?" rot13 encoding
|
|
7557 */
|
|
7558 case 'q':
|
|
7559 case 'w':
|
|
7560 oap->cursor_start = curwin->w_cursor;
|
|
7561 /*FALLTHROUGH*/
|
|
7562 case '~':
|
|
7563 case 'u':
|
|
7564 case 'U':
|
|
7565 case '?':
|
|
7566 nv_operator(cap);
|
|
7567 break;
|
|
7568
|
|
7569 /*
|
|
7570 * "gd": Find first occurence of pattern under the cursor in the
|
|
7571 * current function
|
|
7572 * "gD": idem, but in the current file.
|
|
7573 */
|
|
7574 case 'd':
|
|
7575 case 'D':
|
|
7576 nv_gd(oap, cap->nchar);
|
|
7577 break;
|
|
7578
|
|
7579 #ifdef FEAT_MOUSE
|
|
7580 /*
|
|
7581 * g<*Mouse> : <C-*mouse>
|
|
7582 */
|
|
7583 case K_MIDDLEMOUSE:
|
|
7584 case K_MIDDLEDRAG:
|
|
7585 case K_MIDDLERELEASE:
|
|
7586 case K_LEFTMOUSE:
|
|
7587 case K_LEFTDRAG:
|
|
7588 case K_LEFTRELEASE:
|
|
7589 case K_RIGHTMOUSE:
|
|
7590 case K_RIGHTDRAG:
|
|
7591 case K_RIGHTRELEASE:
|
|
7592 case K_X1MOUSE:
|
|
7593 case K_X1DRAG:
|
|
7594 case K_X1RELEASE:
|
|
7595 case K_X2MOUSE:
|
|
7596 case K_X2DRAG:
|
|
7597 case K_X2RELEASE:
|
|
7598 mod_mask = MOD_MASK_CTRL;
|
|
7599 (void)do_mouse(oap, cap->nchar, BACKWARD, cap->count1, 0);
|
|
7600 break;
|
|
7601 #endif
|
|
7602
|
|
7603 case K_IGNORE:
|
|
7604 break;
|
|
7605
|
|
7606 /*
|
|
7607 * "gP" and "gp": same as "P" and "p" but leave cursor just after new text
|
|
7608 */
|
|
7609 case 'p':
|
|
7610 case 'P':
|
|
7611 nv_put(cap);
|
|
7612 break;
|
|
7613
|
|
7614 #ifdef FEAT_BYTEOFF
|
|
7615 /* "go": goto byte count from start of buffer */
|
|
7616 case 'o':
|
|
7617 goto_byte(cap->count0);
|
|
7618 break;
|
|
7619 #endif
|
|
7620
|
|
7621 /* "gQ": improved Ex mode */
|
|
7622 case 'Q':
|
|
7623 #ifdef FEAT_CMDWIN
|
|
7624 if (cmdwin_type != 0)
|
|
7625 {
|
|
7626 clearopbeep(cap->oap);
|
|
7627 break;
|
|
7628 }
|
|
7629 #endif
|
|
7630 if (!checkclearopq(oap))
|
|
7631 do_exmode(TRUE);
|
|
7632 break;
|
|
7633
|
|
7634 #ifdef FEAT_JUMPLIST
|
|
7635 case ',':
|
|
7636 nv_pcmark(cap);
|
|
7637 break;
|
|
7638
|
|
7639 case ';':
|
|
7640 cap->count1 = -cap->count1;
|
|
7641 nv_pcmark(cap);
|
|
7642 break;
|
|
7643 #endif
|
|
7644
|
|
7645 default:
|
|
7646 clearopbeep(oap);
|
|
7647 break;
|
|
7648 }
|
|
7649 }
|
|
7650
|
|
7651 /*
|
|
7652 * Handle "o" and "O" commands.
|
|
7653 */
|
|
7654 static void
|
|
7655 n_opencmd(cap)
|
|
7656 cmdarg_T *cap;
|
|
7657 {
|
|
7658 if (!checkclearopq(cap->oap))
|
|
7659 {
|
|
7660 #ifdef FEAT_FOLDING
|
|
7661 if (cap->cmdchar == 'O')
|
|
7662 /* Open above the first line of a folded sequence of lines */
|
|
7663 (void)hasFolding(curwin->w_cursor.lnum,
|
|
7664 &curwin->w_cursor.lnum, NULL);
|
|
7665 else
|
|
7666 /* Open below the last line of a folded sequence of lines */
|
|
7667 (void)hasFolding(curwin->w_cursor.lnum,
|
|
7668 NULL, &curwin->w_cursor.lnum);
|
|
7669 #endif
|
|
7670 if (u_save((linenr_T)(curwin->w_cursor.lnum -
|
|
7671 (cap->cmdchar == 'O' ? 1 : 0)),
|
|
7672 (linenr_T)(curwin->w_cursor.lnum +
|
|
7673 (cap->cmdchar == 'o' ? 1 : 0))
|
|
7674 ) == OK
|
|
7675 && open_line(cap->cmdchar == 'O' ? BACKWARD : FORWARD,
|
|
7676 #ifdef FEAT_COMMENTS
|
|
7677 has_format_option(FO_OPEN_COMS) ? OPENLINE_DO_COM :
|
|
7678 #endif
|
|
7679 0, 0))
|
|
7680 {
|
164
|
7681 /* When '#' is in 'cpoptions' ignore the count. */
|
|
7682 if (vim_strchr(p_cpo, CPO_HASH) != NULL)
|
|
7683 cap->count1 = 1;
|
7
|
7684 invoke_edit(cap, FALSE, cap->cmdchar, TRUE);
|
|
7685 }
|
|
7686 }
|
|
7687 }
|
|
7688
|
|
7689 /*
|
|
7690 * "." command: redo last change.
|
|
7691 */
|
|
7692 static void
|
|
7693 nv_dot(cap)
|
|
7694 cmdarg_T *cap;
|
|
7695 {
|
|
7696 if (!checkclearopq(cap->oap))
|
|
7697 {
|
|
7698 /*
|
|
7699 * If "restart_edit" is TRUE, the last but one command is repeated
|
|
7700 * instead of the last command (inserting text). This is used for
|
|
7701 * CTRL-O <.> in insert mode.
|
|
7702 */
|
|
7703 if (start_redo(cap->count0, restart_edit != 0 && !arrow_used) == FAIL)
|
|
7704 clearopbeep(cap->oap);
|
|
7705 }
|
|
7706 }
|
|
7707
|
|
7708 /*
|
|
7709 * CTRL-R: undo undo
|
|
7710 */
|
|
7711 static void
|
|
7712 nv_redo(cap)
|
|
7713 cmdarg_T *cap;
|
|
7714 {
|
|
7715 if (!checkclearopq(cap->oap))
|
|
7716 {
|
|
7717 u_redo((int)cap->count1);
|
|
7718 curwin->w_set_curswant = TRUE;
|
|
7719 }
|
|
7720 }
|
|
7721
|
|
7722 /*
|
|
7723 * Handle "U" command.
|
|
7724 */
|
|
7725 static void
|
|
7726 nv_Undo(cap)
|
|
7727 cmdarg_T *cap;
|
|
7728 {
|
|
7729 /* In Visual mode and typing "gUU" triggers an operator */
|
|
7730 if (cap->oap->op_type == OP_UPPER
|
|
7731 #ifdef FEAT_VISUAL
|
|
7732 || VIsual_active
|
|
7733 #endif
|
|
7734 )
|
|
7735 {
|
|
7736 /* translate "gUU" to "gUgU" */
|
|
7737 cap->cmdchar = 'g';
|
|
7738 cap->nchar = 'U';
|
|
7739 nv_operator(cap);
|
|
7740 }
|
|
7741 else if (!checkclearopq(cap->oap))
|
|
7742 {
|
|
7743 u_undoline();
|
|
7744 curwin->w_set_curswant = TRUE;
|
|
7745 }
|
|
7746 }
|
|
7747
|
|
7748 /*
|
|
7749 * '~' command: If tilde is not an operator and Visual is off: swap case of a
|
|
7750 * single character.
|
|
7751 */
|
|
7752 static void
|
|
7753 nv_tilde(cap)
|
|
7754 cmdarg_T *cap;
|
|
7755 {
|
|
7756 if (!p_to
|
|
7757 #ifdef FEAT_VISUAL
|
|
7758 && !VIsual_active
|
|
7759 #endif
|
|
7760 && cap->oap->op_type != OP_TILDE)
|
|
7761 n_swapchar(cap);
|
|
7762 else
|
|
7763 nv_operator(cap);
|
|
7764 }
|
|
7765
|
|
7766 /*
|
|
7767 * Handle an operator command.
|
|
7768 * The actual work is done by do_pending_operator().
|
|
7769 */
|
|
7770 static void
|
|
7771 nv_operator(cap)
|
|
7772 cmdarg_T *cap;
|
|
7773 {
|
|
7774 int op_type;
|
|
7775
|
|
7776 op_type = get_op_type(cap->cmdchar, cap->nchar);
|
|
7777
|
|
7778 if (op_type == cap->oap->op_type) /* double operator works on lines */
|
|
7779 nv_lineop(cap);
|
|
7780 else if (!checkclearop(cap->oap))
|
|
7781 {
|
|
7782 cap->oap->start = curwin->w_cursor;
|
|
7783 cap->oap->op_type = op_type;
|
|
7784 }
|
|
7785 }
|
|
7786
|
|
7787 /*
|
|
7788 * Handle linewise operator "dd", "yy", etc.
|
|
7789 *
|
|
7790 * "_" is is a strange motion command that helps make operators more logical.
|
|
7791 * It is actually implemented, but not documented in the real Vi. This motion
|
|
7792 * command actually refers to "the current line". Commands like "dd" and "yy"
|
|
7793 * are really an alternate form of "d_" and "y_". It does accept a count, so
|
|
7794 * "d3_" works to delete 3 lines.
|
|
7795 */
|
|
7796 static void
|
|
7797 nv_lineop(cap)
|
|
7798 cmdarg_T *cap;
|
|
7799 {
|
|
7800 cap->oap->motion_type = MLINE;
|
|
7801 if (cursor_down(cap->count1 - 1L, cap->oap->op_type == OP_NOP) == FAIL)
|
|
7802 clearopbeep(cap->oap);
|
|
7803 else if ( cap->oap->op_type == OP_DELETE
|
|
7804 || cap->oap->op_type == OP_LSHIFT
|
|
7805 || cap->oap->op_type == OP_RSHIFT)
|
|
7806 beginline(BL_SOL | BL_FIX);
|
|
7807 else if (cap->oap->op_type != OP_YANK) /* 'Y' does not move cursor */
|
|
7808 beginline(BL_WHITE | BL_FIX);
|
|
7809 }
|
|
7810
|
|
7811 /*
|
|
7812 * <Home> command.
|
|
7813 */
|
|
7814 static void
|
|
7815 nv_home(cap)
|
|
7816 cmdarg_T *cap;
|
|
7817 {
|
180
|
7818 /* CTRL-HOME is like "gg" */
|
|
7819 if (mod_mask & MOD_MASK_CTRL)
|
|
7820 nv_goto(cap);
|
|
7821 else
|
|
7822 {
|
|
7823 cap->count0 = 1;
|
|
7824 nv_pipe(cap);
|
|
7825 }
|
229
|
7826 ins_at_eol = FALSE; /* Don't move cursor past eol (only necessary in a
|
|
7827 one-character line). */
|
7
|
7828 }
|
|
7829
|
|
7830 /*
|
|
7831 * "|" command.
|
|
7832 */
|
|
7833 static void
|
|
7834 nv_pipe(cap)
|
|
7835 cmdarg_T *cap;
|
|
7836 {
|
|
7837 cap->oap->motion_type = MCHAR;
|
|
7838 cap->oap->inclusive = FALSE;
|
|
7839 beginline(0);
|
|
7840 if (cap->count0 > 0)
|
|
7841 {
|
|
7842 coladvance((colnr_T)(cap->count0 - 1));
|
|
7843 curwin->w_curswant = (colnr_T)(cap->count0 - 1);
|
|
7844 }
|
|
7845 else
|
|
7846 curwin->w_curswant = 0;
|
|
7847 /* keep curswant at the column where we wanted to go, not where
|
|
7848 we ended; differs if line is too short */
|
|
7849 curwin->w_set_curswant = FALSE;
|
|
7850 }
|
|
7851
|
|
7852 /*
|
|
7853 * Handle back-word command "b" and "B".
|
|
7854 * cap->arg is 1 for "B"
|
|
7855 */
|
|
7856 static void
|
|
7857 nv_bck_word(cap)
|
|
7858 cmdarg_T *cap;
|
|
7859 {
|
|
7860 cap->oap->motion_type = MCHAR;
|
|
7861 cap->oap->inclusive = FALSE;
|
|
7862 curwin->w_set_curswant = TRUE;
|
|
7863 if (bck_word(cap->count1, cap->arg, FALSE) == FAIL)
|
|
7864 clearopbeep(cap->oap);
|
|
7865 #ifdef FEAT_FOLDING
|
|
7866 else if ((fdo_flags & FDO_HOR) && KeyTyped && cap->oap->op_type == OP_NOP)
|
|
7867 foldOpenCursor();
|
|
7868 #endif
|
|
7869 }
|
|
7870
|
|
7871 /*
|
|
7872 * Handle word motion commands "e", "E", "w" and "W".
|
|
7873 * cap->arg is TRUE for "E" and "W".
|
|
7874 */
|
|
7875 static void
|
|
7876 nv_wordcmd(cap)
|
|
7877 cmdarg_T *cap;
|
|
7878 {
|
|
7879 int n;
|
|
7880 int word_end;
|
|
7881 int flag = FALSE;
|
|
7882
|
|
7883 /*
|
|
7884 * Set inclusive for the "E" and "e" command.
|
|
7885 */
|
|
7886 if (cap->cmdchar == 'e' || cap->cmdchar == 'E')
|
|
7887 word_end = TRUE;
|
|
7888 else
|
|
7889 word_end = FALSE;
|
|
7890 cap->oap->inclusive = word_end;
|
|
7891
|
|
7892 /*
|
|
7893 * "cw" and "cW" are a special case.
|
|
7894 */
|
|
7895 if (!word_end && cap->oap->op_type == OP_CHANGE)
|
|
7896 {
|
|
7897 n = gchar_cursor();
|
|
7898 if (n != NUL) /* not an empty line */
|
|
7899 {
|
|
7900 if (vim_iswhite(n))
|
|
7901 {
|
|
7902 /*
|
|
7903 * Reproduce a funny Vi behaviour: "cw" on a blank only
|
|
7904 * changes one character, not all blanks until the start of
|
|
7905 * the next word. Only do this when the 'w' flag is included
|
|
7906 * in 'cpoptions'.
|
|
7907 */
|
|
7908 if (cap->count1 == 1 && vim_strchr(p_cpo, CPO_CW) != NULL)
|
|
7909 {
|
|
7910 cap->oap->inclusive = TRUE;
|
|
7911 cap->oap->motion_type = MCHAR;
|
|
7912 return;
|
|
7913 }
|
|
7914 }
|
|
7915 else
|
|
7916 {
|
|
7917 /*
|
|
7918 * This is a little strange. To match what the real Vi does,
|
|
7919 * we effectively map 'cw' to 'ce', and 'cW' to 'cE', provided
|
|
7920 * that we are not on a space or a TAB. This seems impolite
|
|
7921 * at first, but it's really more what we mean when we say
|
|
7922 * 'cw'.
|
|
7923 * Another strangeness: When standing on the end of a word
|
|
7924 * "ce" will change until the end of the next wordt, but "cw"
|
|
7925 * will change only one character! This is done by setting
|
|
7926 * flag.
|
|
7927 */
|
|
7928 cap->oap->inclusive = TRUE;
|
|
7929 word_end = TRUE;
|
|
7930 flag = TRUE;
|
|
7931 }
|
|
7932 }
|
|
7933 }
|
|
7934
|
|
7935 cap->oap->motion_type = MCHAR;
|
|
7936 curwin->w_set_curswant = TRUE;
|
|
7937 if (word_end)
|
|
7938 n = end_word(cap->count1, cap->arg, flag, FALSE);
|
|
7939 else
|
|
7940 n = fwd_word(cap->count1, cap->arg, cap->oap->op_type != OP_NOP);
|
|
7941
|
|
7942 /* Don't leave the cursor on the NUL past a line */
|
|
7943 if (curwin->w_cursor.col && gchar_cursor() == NUL)
|
|
7944 {
|
|
7945 --curwin->w_cursor.col;
|
|
7946 cap->oap->inclusive = TRUE;
|
|
7947 }
|
|
7948
|
|
7949 if (n == FAIL && cap->oap->op_type == OP_NOP)
|
|
7950 clearopbeep(cap->oap);
|
|
7951 else
|
|
7952 {
|
|
7953 #ifdef FEAT_VISUAL
|
|
7954 adjust_for_sel(cap);
|
|
7955 #endif
|
|
7956 #ifdef FEAT_FOLDING
|
|
7957 if ((fdo_flags & FDO_HOR) && KeyTyped && cap->oap->op_type == OP_NOP)
|
|
7958 foldOpenCursor();
|
|
7959 #endif
|
|
7960 }
|
|
7961 }
|
|
7962
|
|
7963 /*
|
|
7964 * "0" and "^" commands.
|
|
7965 * cap->arg is the argument for beginline().
|
|
7966 */
|
|
7967 static void
|
|
7968 nv_beginline(cap)
|
|
7969 cmdarg_T *cap;
|
|
7970 {
|
|
7971 cap->oap->motion_type = MCHAR;
|
|
7972 cap->oap->inclusive = FALSE;
|
|
7973 beginline(cap->arg);
|
|
7974 #ifdef FEAT_FOLDING
|
|
7975 if ((fdo_flags & FDO_HOR) && KeyTyped && cap->oap->op_type == OP_NOP)
|
|
7976 foldOpenCursor();
|
|
7977 #endif
|
|
7978 }
|
|
7979
|
|
7980 #ifdef FEAT_VISUAL
|
|
7981 /*
|
|
7982 * In exclusive Visual mode, may include the last character.
|
|
7983 */
|
|
7984 static void
|
|
7985 adjust_for_sel(cap)
|
|
7986 cmdarg_T *cap;
|
|
7987 {
|
|
7988 if (VIsual_active && cap->oap->inclusive && *p_sel == 'e'
|
|
7989 && gchar_cursor() != NUL && lt(VIsual, curwin->w_cursor))
|
|
7990 {
|
|
7991 # ifdef FEAT_MBYTE
|
|
7992 if (has_mbyte)
|
|
7993 inc_cursor();
|
|
7994 else
|
|
7995 # endif
|
|
7996 ++curwin->w_cursor.col;
|
|
7997 cap->oap->inclusive = FALSE;
|
|
7998 }
|
|
7999 }
|
|
8000
|
|
8001 /*
|
|
8002 * Exclude last character at end of Visual area for 'selection' == "exclusive".
|
|
8003 * Should check VIsual_mode before calling this.
|
|
8004 * Returns TRUE when backed up to the previous line.
|
|
8005 */
|
|
8006 static int
|
|
8007 unadjust_for_sel()
|
|
8008 {
|
|
8009 pos_T *pp;
|
|
8010
|
|
8011 if (*p_sel == 'e' && !equalpos(VIsual, curwin->w_cursor))
|
|
8012 {
|
|
8013 if (lt(VIsual, curwin->w_cursor))
|
|
8014 pp = &curwin->w_cursor;
|
|
8015 else
|
|
8016 pp = &VIsual;
|
|
8017 #ifdef FEAT_VIRTUALEDIT
|
|
8018 if (pp->coladd > 0)
|
|
8019 --pp->coladd;
|
|
8020 else
|
|
8021 #endif
|
|
8022 if (pp->col > 0)
|
|
8023 {
|
|
8024 --pp->col;
|
|
8025 #ifdef FEAT_MBYTE
|
|
8026 mb_adjustpos(pp);
|
|
8027 #endif
|
|
8028 }
|
|
8029 else if (pp->lnum > 1)
|
|
8030 {
|
|
8031 --pp->lnum;
|
|
8032 pp->col = (colnr_T)STRLEN(ml_get(pp->lnum));
|
|
8033 return TRUE;
|
|
8034 }
|
|
8035 }
|
|
8036 return FALSE;
|
|
8037 }
|
|
8038
|
|
8039 /*
|
|
8040 * SELECT key in Normal or Visual mode: end of Select mode mapping.
|
|
8041 */
|
|
8042 static void
|
|
8043 nv_select(cap)
|
|
8044 cmdarg_T *cap;
|
|
8045 {
|
|
8046 if (VIsual_active)
|
|
8047 VIsual_select = TRUE;
|
|
8048 else if (VIsual_reselect)
|
|
8049 {
|
|
8050 cap->nchar = 'v'; /* fake "gv" command */
|
|
8051 cap->arg = TRUE;
|
|
8052 nv_g_cmd(cap);
|
|
8053 }
|
|
8054 }
|
|
8055
|
|
8056 #endif
|
|
8057
|
|
8058 /*
|
|
8059 * "G", "gg", CTRL-END, CTRL-HOME.
|
|
8060 * cap->arg is TRUE for "G".
|
|
8061 */
|
|
8062 static void
|
|
8063 nv_goto(cap)
|
|
8064 cmdarg_T *cap;
|
|
8065 {
|
|
8066 linenr_T lnum;
|
|
8067
|
|
8068 if (cap->arg)
|
|
8069 lnum = curbuf->b_ml.ml_line_count;
|
|
8070 else
|
|
8071 lnum = 1L;
|
|
8072 cap->oap->motion_type = MLINE;
|
|
8073 setpcmark();
|
|
8074
|
|
8075 /* When a count is given, use it instead of the default lnum */
|
|
8076 if (cap->count0 != 0)
|
|
8077 lnum = cap->count0;
|
|
8078 if (lnum < 1L)
|
|
8079 lnum = 1L;
|
|
8080 else if (lnum > curbuf->b_ml.ml_line_count)
|
|
8081 lnum = curbuf->b_ml.ml_line_count;
|
|
8082 curwin->w_cursor.lnum = lnum;
|
|
8083 beginline(BL_SOL | BL_FIX);
|
|
8084 #ifdef FEAT_FOLDING
|
|
8085 if ((fdo_flags & FDO_JUMP) && KeyTyped && cap->oap->op_type == OP_NOP)
|
|
8086 foldOpenCursor();
|
|
8087 #endif
|
|
8088 }
|
|
8089
|
|
8090 /*
|
|
8091 * CTRL-\ in Normal mode.
|
|
8092 */
|
|
8093 static void
|
|
8094 nv_normal(cap)
|
|
8095 cmdarg_T *cap;
|
|
8096 {
|
|
8097 if (cap->nchar == Ctrl_N || cap->nchar == Ctrl_G)
|
|
8098 {
|
|
8099 clearop(cap->oap);
|
|
8100 if (restart_edit != 0 && p_smd)
|
|
8101 clear_cmdline = TRUE; /* unshow mode later */
|
|
8102 restart_edit = 0;
|
|
8103 #ifdef FEAT_CMDWIN
|
|
8104 if (cmdwin_type != 0)
|
|
8105 cmdwin_result = Ctrl_C;
|
|
8106 #endif
|
|
8107 #ifdef FEAT_VISUAL
|
|
8108 if (VIsual_active)
|
|
8109 {
|
|
8110 end_visual_mode(); /* stop Visual */
|
|
8111 redraw_curbuf_later(INVERTED);
|
|
8112 }
|
|
8113 #endif
|
|
8114 /* CTRL-\ CTRL-G restarts Insert mode when 'insertmode' is set. */
|
|
8115 if (cap->nchar == Ctrl_G && p_im)
|
|
8116 restart_edit = 'a';
|
|
8117 }
|
|
8118 else
|
|
8119 clearopbeep(cap->oap);
|
|
8120 }
|
|
8121
|
|
8122 /*
|
|
8123 * ESC in Normal mode: beep, but don't flush buffers.
|
|
8124 * Don't even beep if we are canceling a command.
|
|
8125 */
|
|
8126 static void
|
|
8127 nv_esc(cap)
|
|
8128 cmdarg_T *cap;
|
|
8129 {
|
|
8130 int no_reason;
|
|
8131
|
|
8132 no_reason = (cap->oap->op_type == OP_NOP
|
|
8133 && cap->opcount == 0
|
|
8134 && cap->count0 == 0
|
|
8135 && cap->oap->regname == 0
|
|
8136 && !p_im);
|
|
8137
|
|
8138 if (cap->arg) /* TRUE for CTRL-C */
|
|
8139 {
|
|
8140 if (restart_edit == 0
|
|
8141 #ifdef FEAT_CMDWIN
|
|
8142 && cmdwin_type == 0
|
|
8143 #endif
|
|
8144 #ifdef FEAT_VISUAL
|
|
8145 && !VIsual_active
|
|
8146 #endif
|
|
8147 && no_reason)
|
|
8148 MSG(_("Type :quit<Enter> to exit Vim"));
|
|
8149
|
|
8150 /* Don't reset "restart_edit" when 'insertmode' is set, it won't be
|
|
8151 * set again below when halfway a mapping. */
|
|
8152 if (!p_im)
|
|
8153 restart_edit = 0;
|
|
8154 #ifdef FEAT_CMDWIN
|
|
8155 if (cmdwin_type != 0)
|
|
8156 {
|
|
8157 cmdwin_result = K_IGNORE;
|
|
8158 got_int = FALSE; /* don't stop executing autocommands et al. */
|
|
8159 return;
|
|
8160 }
|
|
8161 #endif
|
|
8162 }
|
|
8163
|
|
8164 #ifdef FEAT_VISUAL
|
|
8165 if (VIsual_active)
|
|
8166 {
|
|
8167 end_visual_mode(); /* stop Visual */
|
|
8168 check_cursor_col(); /* make sure cursor is not beyond EOL */
|
|
8169 curwin->w_set_curswant = TRUE;
|
|
8170 redraw_curbuf_later(INVERTED);
|
|
8171 }
|
|
8172 else
|
|
8173 #endif
|
|
8174 if (no_reason)
|
|
8175 vim_beep();
|
|
8176 clearop(cap->oap);
|
|
8177
|
|
8178 /* A CTRL-C is often used at the start of a menu. When 'insertmode' is
|
|
8179 * set return to Insert mode afterwards. */
|
|
8180 if (restart_edit == 0 && goto_im()
|
|
8181 #ifdef FEAT_EX_EXTRA
|
|
8182 && ex_normal_busy == 0
|
|
8183 #endif
|
|
8184 )
|
|
8185 restart_edit = 'a';
|
|
8186 }
|
|
8187
|
|
8188 /*
|
|
8189 * Handle "A", "a", "I", "i" and <Insert> commands.
|
|
8190 */
|
|
8191 static void
|
|
8192 nv_edit(cap)
|
|
8193 cmdarg_T *cap;
|
|
8194 {
|
|
8195 /* <Insert> is equal to "i" */
|
|
8196 if (cap->cmdchar == K_INS || cap->cmdchar == K_KINS)
|
|
8197 cap->cmdchar = 'i';
|
|
8198
|
|
8199 #ifdef FEAT_VISUAL
|
|
8200 /* in Visual mode "A" and "I" are an operator */
|
|
8201 if (VIsual_active && (cap->cmdchar == 'A' || cap->cmdchar == 'I'))
|
|
8202 v_visop(cap);
|
|
8203
|
|
8204 /* in Visual mode and after an operator "a" and "i" are for text objects */
|
|
8205 else
|
|
8206 #endif
|
|
8207 if ((cap->cmdchar == 'a' || cap->cmdchar == 'i')
|
|
8208 && (cap->oap->op_type != OP_NOP
|
|
8209 #ifdef FEAT_VISUAL
|
|
8210 || VIsual_active
|
|
8211 #endif
|
|
8212 ))
|
|
8213 {
|
|
8214 #ifdef FEAT_TEXTOBJ
|
|
8215 nv_object(cap);
|
|
8216 #else
|
|
8217 clearopbeep(cap->oap);
|
|
8218 #endif
|
|
8219 }
|
|
8220 else if (!curbuf->b_p_ma && !p_im)
|
|
8221 {
|
|
8222 /* Only give this error when 'insertmode' is off. */
|
|
8223 EMSG(_(e_modifiable));
|
|
8224 clearop(cap->oap);
|
|
8225 }
|
|
8226 else if (!checkclearopq(cap->oap))
|
|
8227 {
|
|
8228 switch (cap->cmdchar)
|
|
8229 {
|
|
8230 case 'A': /* "A"ppend after the line */
|
|
8231 curwin->w_set_curswant = TRUE;
|
|
8232 #ifdef FEAT_VIRTUALEDIT
|
|
8233 if (ve_flags == VE_ALL)
|
|
8234 {
|
|
8235 int save_State = State;
|
|
8236
|
|
8237 /* Pretent Insert mode here to allow the cursor on the
|
|
8238 * character past the end of the line */
|
|
8239 State = INSERT;
|
|
8240 coladvance((colnr_T)MAXCOL);
|
|
8241 State = save_State;
|
|
8242 }
|
|
8243 else
|
|
8244 #endif
|
|
8245 curwin->w_cursor.col += (colnr_T)STRLEN(ml_get_cursor());
|
|
8246 break;
|
|
8247
|
|
8248 case 'I': /* "I"nsert before the first non-blank */
|
164
|
8249 if (vim_strchr(p_cpo, CPO_INSEND) == NULL)
|
|
8250 beginline(BL_WHITE);
|
|
8251 else
|
|
8252 beginline(BL_WHITE|BL_FIX);
|
7
|
8253 break;
|
|
8254
|
|
8255 case 'a': /* "a"ppend is like "i"nsert on the next character. */
|
|
8256 #ifdef FEAT_VIRTUALEDIT
|
|
8257 /* increment coladd when in virtual space, increment the
|
|
8258 * column otherwise, also to append after an unprintable char */
|
|
8259 if (virtual_active()
|
|
8260 && (curwin->w_cursor.coladd > 0
|
|
8261 || *ml_get_cursor() == NUL
|
|
8262 || *ml_get_cursor() == TAB))
|
|
8263 curwin->w_cursor.coladd++;
|
|
8264 else
|
|
8265 #endif
|
|
8266 if (*ml_get_cursor() != NUL)
|
|
8267 inc_cursor();
|
|
8268 break;
|
|
8269 }
|
|
8270
|
|
8271 #ifdef FEAT_VIRTUALEDIT
|
|
8272 if (curwin->w_cursor.coladd && cap->cmdchar != 'A')
|
|
8273 {
|
|
8274 int save_State = State;
|
|
8275
|
|
8276 /* Pretent Insert mode here to allow the cursor on the
|
|
8277 * character past the end of the line */
|
|
8278 State = INSERT;
|
|
8279 coladvance(getviscol());
|
|
8280 State = save_State;
|
|
8281 }
|
|
8282 #endif
|
|
8283
|
|
8284 invoke_edit(cap, FALSE, cap->cmdchar, FALSE);
|
|
8285 }
|
|
8286 }
|
|
8287
|
|
8288 /*
|
|
8289 * Invoke edit() and take care of "restart_edit" and the return value.
|
|
8290 */
|
|
8291 static void
|
|
8292 invoke_edit(cap, repl, cmd, startln)
|
|
8293 cmdarg_T *cap;
|
|
8294 int repl; /* "r" or "gr" command */
|
|
8295 int cmd;
|
|
8296 int startln;
|
|
8297 {
|
|
8298 int restart_edit_save = 0;
|
|
8299
|
|
8300 /* Complicated: When the user types "a<C-O>a" we don't want to do Insert
|
|
8301 * mode recursively. But when doing "a<C-O>." or "a<C-O>rx" we do allow
|
|
8302 * it. */
|
|
8303 if (repl || !stuff_empty())
|
|
8304 restart_edit_save = restart_edit;
|
|
8305 else
|
|
8306 restart_edit_save = 0;
|
|
8307
|
|
8308 /* Always reset "restart_edit", this is not a restarted edit. */
|
|
8309 restart_edit = 0;
|
|
8310
|
|
8311 if (edit(cmd, startln, cap->count1))
|
|
8312 cap->retval |= CA_COMMAND_BUSY;
|
|
8313
|
|
8314 if (restart_edit == 0)
|
|
8315 restart_edit = restart_edit_save;
|
|
8316 }
|
|
8317
|
|
8318 #ifdef FEAT_TEXTOBJ
|
|
8319 /*
|
|
8320 * "a" or "i" while an operator is pending or in Visual mode: object motion.
|
|
8321 */
|
|
8322 static void
|
|
8323 nv_object(cap)
|
|
8324 cmdarg_T *cap;
|
|
8325 {
|
|
8326 int flag;
|
|
8327 int include;
|
|
8328 char_u *mps_save;
|
|
8329
|
|
8330 if (cap->cmdchar == 'i')
|
|
8331 include = FALSE; /* "ix" = inner object: exclude white space */
|
|
8332 else
|
|
8333 include = TRUE; /* "ax" = an object: include white space */
|
|
8334
|
|
8335 /* Make sure (), [], {} and <> are in 'matchpairs' */
|
|
8336 mps_save = curbuf->b_p_mps;
|
|
8337 curbuf->b_p_mps = (char_u *)"(:),{:},[:],<:>";
|
|
8338
|
|
8339 switch (cap->nchar)
|
|
8340 {
|
|
8341 case 'w': /* "aw" = a word */
|
|
8342 flag = current_word(cap->oap, cap->count1, include, FALSE);
|
|
8343 break;
|
|
8344 case 'W': /* "aW" = a WORD */
|
|
8345 flag = current_word(cap->oap, cap->count1, include, TRUE);
|
|
8346 break;
|
|
8347 case 'b': /* "ab" = a braces block */
|
|
8348 case '(':
|
|
8349 case ')':
|
|
8350 flag = current_block(cap->oap, cap->count1, include, '(', ')');
|
|
8351 break;
|
|
8352 case 'B': /* "aB" = a Brackets block */
|
|
8353 case '{':
|
|
8354 case '}':
|
|
8355 flag = current_block(cap->oap, cap->count1, include, '{', '}');
|
|
8356 break;
|
|
8357 case '[': /* "a[" = a [] block */
|
|
8358 case ']':
|
|
8359 flag = current_block(cap->oap, cap->count1, include, '[', ']');
|
|
8360 break;
|
|
8361 case '<': /* "a<" = a <> block */
|
|
8362 case '>':
|
|
8363 flag = current_block(cap->oap, cap->count1, include, '<', '>');
|
|
8364 break;
|
|
8365 case 'p': /* "ap" = a paragraph */
|
|
8366 flag = current_par(cap->oap, cap->count1, include, 'p');
|
|
8367 break;
|
|
8368 case 's': /* "as" = a sentence */
|
|
8369 flag = current_sent(cap->oap, cap->count1, include);
|
|
8370 break;
|
12
|
8371 case '"': /* "a"" = a double quoted string */
|
|
8372 case '\'': /* "a'" = a single quoted string */
|
|
8373 case '`': /* "a`" = a backtick quoted string */
|
|
8374 flag = current_quote(cap->oap, cap->count1, include,
|
|
8375 cap->nchar);
|
|
8376 break;
|
7
|
8377 #if 0 /* TODO */
|
|
8378 case 'S': /* "aS" = a section */
|
|
8379 case 'f': /* "af" = a filename */
|
|
8380 case 'u': /* "au" = a URL */
|
|
8381 #endif
|
|
8382 default:
|
|
8383 flag = FAIL;
|
|
8384 break;
|
|
8385 }
|
|
8386
|
|
8387 curbuf->b_p_mps = mps_save;
|
|
8388 if (flag == FAIL)
|
|
8389 clearopbeep(cap->oap);
|
|
8390 adjust_cursor_col();
|
|
8391 curwin->w_set_curswant = TRUE;
|
|
8392 }
|
|
8393 #endif
|
|
8394
|
|
8395 /*
|
|
8396 * "q" command: Start/stop recording.
|
|
8397 * "q:", "q/", "q?": edit command-line in command-line window.
|
|
8398 */
|
|
8399 static void
|
|
8400 nv_record(cap)
|
|
8401 cmdarg_T *cap;
|
|
8402 {
|
|
8403 if (cap->oap->op_type == OP_FORMAT)
|
|
8404 {
|
|
8405 /* "gqq" is the same as "gqgq": format line */
|
|
8406 cap->cmdchar = 'g';
|
|
8407 cap->nchar = 'q';
|
|
8408 nv_operator(cap);
|
|
8409 }
|
|
8410 else if (!checkclearop(cap->oap))
|
|
8411 {
|
|
8412 #ifdef FEAT_CMDWIN
|
|
8413 if (cap->nchar == ':' || cap->nchar == '/' || cap->nchar == '?')
|
|
8414 {
|
|
8415 stuffcharReadbuff(cap->nchar);
|
|
8416 stuffcharReadbuff(K_CMDWIN);
|
|
8417 }
|
|
8418 else
|
|
8419 #endif
|
|
8420 /* (stop) recording into a named register, unless executing a
|
|
8421 * register */
|
|
8422 if (!Exec_reg && do_record(cap->nchar) == FAIL)
|
|
8423 clearopbeep(cap->oap);
|
|
8424 }
|
|
8425 }
|
|
8426
|
|
8427 /*
|
|
8428 * Handle the "@r" command.
|
|
8429 */
|
|
8430 static void
|
|
8431 nv_at(cap)
|
|
8432 cmdarg_T *cap;
|
|
8433 {
|
|
8434 if (checkclearop(cap->oap))
|
|
8435 return;
|
|
8436 #ifdef FEAT_EVAL
|
|
8437 if (cap->nchar == '=')
|
|
8438 {
|
|
8439 if (get_expr_register() == NUL)
|
|
8440 return;
|
|
8441 }
|
|
8442 #endif
|
|
8443 while (cap->count1-- && !got_int)
|
|
8444 {
|
|
8445 if (do_execreg(cap->nchar, FALSE, FALSE) == FAIL)
|
|
8446 {
|
|
8447 clearopbeep(cap->oap);
|
|
8448 break;
|
|
8449 }
|
|
8450 line_breakcheck();
|
|
8451 }
|
|
8452 }
|
|
8453
|
|
8454 /*
|
|
8455 * Handle the CTRL-U and CTRL-D commands.
|
|
8456 */
|
|
8457 static void
|
|
8458 nv_halfpage(cap)
|
|
8459 cmdarg_T *cap;
|
|
8460 {
|
|
8461 if ((cap->cmdchar == Ctrl_U && curwin->w_cursor.lnum == 1)
|
|
8462 || (cap->cmdchar == Ctrl_D
|
|
8463 && curwin->w_cursor.lnum == curbuf->b_ml.ml_line_count))
|
|
8464 clearopbeep(cap->oap);
|
|
8465 else if (!checkclearop(cap->oap))
|
|
8466 halfpage(cap->cmdchar == Ctrl_D, cap->count0);
|
|
8467 }
|
|
8468
|
|
8469 /*
|
|
8470 * Handle "J" or "gJ" command.
|
|
8471 */
|
|
8472 static void
|
|
8473 nv_join(cap)
|
|
8474 cmdarg_T *cap;
|
|
8475 {
|
|
8476 #ifdef FEAT_VISUAL
|
|
8477 if (VIsual_active) /* join the visual lines */
|
|
8478 nv_operator(cap);
|
|
8479 else
|
|
8480 #endif
|
|
8481 if (!checkclearop(cap->oap))
|
|
8482 {
|
|
8483 if (cap->count0 <= 1)
|
|
8484 cap->count0 = 2; /* default for join is two lines! */
|
|
8485 if (curwin->w_cursor.lnum + cap->count0 - 1 >
|
|
8486 curbuf->b_ml.ml_line_count)
|
|
8487 clearopbeep(cap->oap); /* beyond last line */
|
|
8488 else
|
|
8489 {
|
|
8490 prep_redo(cap->oap->regname, cap->count0,
|
|
8491 NUL, cap->cmdchar, NUL, NUL, cap->nchar);
|
|
8492 do_do_join(cap->count0, cap->nchar == NUL);
|
|
8493 }
|
|
8494 }
|
|
8495 }
|
|
8496
|
|
8497 /*
|
|
8498 * "P", "gP", "p" and "gp" commands.
|
|
8499 */
|
|
8500 static void
|
|
8501 nv_put(cap)
|
|
8502 cmdarg_T *cap;
|
|
8503 {
|
|
8504 #ifdef FEAT_VISUAL
|
|
8505 int regname = 0;
|
|
8506 void *reg1 = NULL, *reg2 = NULL;
|
84
|
8507 int empty = FALSE;
|
236
|
8508 int was_visual = FALSE;
|
7
|
8509 #endif
|
|
8510 int dir;
|
|
8511 int flags = 0;
|
|
8512
|
|
8513 if (cap->oap->op_type != OP_NOP)
|
|
8514 {
|
|
8515 #ifdef FEAT_DIFF
|
|
8516 /* "dp" is ":diffput" */
|
|
8517 if (cap->oap->op_type == OP_DELETE && cap->cmdchar == 'p')
|
|
8518 {
|
|
8519 clearop(cap->oap);
|
|
8520 nv_diffgetput(TRUE);
|
|
8521 }
|
|
8522 else
|
|
8523 #endif
|
|
8524 clearopbeep(cap->oap);
|
|
8525 }
|
|
8526 else
|
|
8527 {
|
|
8528 dir = (cap->cmdchar == 'P'
|
|
8529 || (cap->cmdchar == 'g' && cap->nchar == 'P'))
|
|
8530 ? BACKWARD : FORWARD;
|
|
8531 prep_redo_cmd(cap);
|
|
8532 if (cap->cmdchar == 'g')
|
|
8533 flags |= PUT_CURSEND;
|
|
8534
|
|
8535 #ifdef FEAT_VISUAL
|
|
8536 if (VIsual_active)
|
|
8537 {
|
|
8538 /* Putting in Visual mode: The put text replaces the selected
|
|
8539 * text. First delete the selected text, then put the new text.
|
|
8540 * Need to save and restore the registers that the delete
|
|
8541 * overwrites if the old contents is being put.
|
|
8542 */
|
236
|
8543 was_visual = TRUE;
|
7
|
8544 regname = cap->oap->regname;
|
|
8545 # ifdef FEAT_CLIPBOARD
|
|
8546 adjust_clip_reg(®name);
|
|
8547 # endif
|
|
8548 if (regname == 0 || VIM_ISDIGIT(regname)
|
|
8549 # ifdef FEAT_CLIPBOARD
|
|
8550 || (clip_unnamed && (regname == '*' || regname == '+'))
|
|
8551 # endif
|
|
8552
|
|
8553 )
|
|
8554 {
|
|
8555 /* the delete is going to overwrite the register we want to
|
|
8556 * put, save it first. */
|
|
8557 reg1 = get_register(regname, TRUE);
|
|
8558 }
|
|
8559
|
|
8560 /* Now delete the selected text. */
|
|
8561 cap->cmdchar = 'd';
|
|
8562 cap->nchar = NUL;
|
|
8563 cap->oap->regname = NUL;
|
|
8564 nv_operator(cap);
|
|
8565 do_pending_operator(cap, 0, FALSE);
|
84
|
8566 empty = (curbuf->b_ml.ml_flags & ML_EMPTY);
|
7
|
8567
|
|
8568 /* delete PUT_LINE_BACKWARD; */
|
|
8569 cap->oap->regname = regname;
|
|
8570
|
|
8571 if (reg1 != NULL)
|
|
8572 {
|
|
8573 /* Delete probably changed the register we want to put, save
|
|
8574 * it first. Then put back what was there before the delete. */
|
|
8575 reg2 = get_register(regname, FALSE);
|
|
8576 put_register(regname, reg1);
|
|
8577 }
|
|
8578
|
|
8579 /* When deleted a linewise Visual area, put the register as
|
|
8580 * lines to avoid it joined with the next line. When deletion was
|
|
8581 * characterwise, split a line when putting lines. */
|
|
8582 if (VIsual_mode == 'V')
|
|
8583 flags |= PUT_LINE;
|
|
8584 else if (VIsual_mode == 'v')
|
|
8585 flags |= PUT_LINE_SPLIT;
|
|
8586 if (VIsual_mode == Ctrl_V && dir == FORWARD)
|
|
8587 flags |= PUT_LINE_FORWARD;
|
|
8588 dir = BACKWARD;
|
|
8589 if ((VIsual_mode != 'V'
|
|
8590 && curwin->w_cursor.col < curbuf->b_op_start.col)
|
|
8591 || (VIsual_mode == 'V'
|
|
8592 && curwin->w_cursor.lnum < curbuf->b_op_start.lnum))
|
|
8593 /* cursor is at the end of the line or end of file, put
|
|
8594 * forward. */
|
|
8595 dir = FORWARD;
|
|
8596 }
|
|
8597 #endif
|
|
8598 do_put(cap->oap->regname, dir, cap->count1, flags);
|
|
8599
|
|
8600 #ifdef FEAT_VISUAL
|
|
8601 /* If a register was saved, put it back now. */
|
|
8602 if (reg2 != NULL)
|
|
8603 put_register(regname, reg2);
|
236
|
8604
|
|
8605 /* What to reselect with "gv"? Selecting the just put text seems to
|
|
8606 * be the most useful, since the original text was removed. */
|
|
8607 if (was_visual)
|
|
8608 {
|
|
8609 curbuf->b_visual_start = curbuf->b_op_start;
|
|
8610 curbuf->b_visual_end = curbuf->b_op_end;
|
|
8611 }
|
|
8612
|
84
|
8613 /* When all lines were selected and deleted do_put() leaves an empty
|
236
|
8614 * line that needs to be deleted now. */
|
84
|
8615 if (empty && *ml_get(curbuf->b_ml.ml_line_count) == NUL)
|
|
8616 ml_delete(curbuf->b_ml.ml_line_count, TRUE);
|
7
|
8617 #endif
|
|
8618 auto_format(FALSE, TRUE);
|
|
8619 }
|
|
8620 }
|
|
8621
|
|
8622 /*
|
|
8623 * "o" and "O" commands.
|
|
8624 */
|
|
8625 static void
|
|
8626 nv_open(cap)
|
|
8627 cmdarg_T *cap;
|
|
8628 {
|
|
8629 #ifdef FEAT_DIFF
|
|
8630 /* "do" is ":diffget" */
|
|
8631 if (cap->oap->op_type == OP_DELETE && cap->cmdchar == 'o')
|
|
8632 {
|
|
8633 clearop(cap->oap);
|
|
8634 nv_diffgetput(FALSE);
|
|
8635 }
|
|
8636 else
|
|
8637 #endif
|
|
8638 #ifdef FEAT_VISUAL
|
|
8639 if (VIsual_active) /* switch start and end of visual */
|
|
8640 v_swap_corners(cap->cmdchar);
|
|
8641 else
|
|
8642 #endif
|
|
8643 n_opencmd(cap);
|
|
8644 }
|
|
8645
|
|
8646 #ifdef FEAT_SNIFF
|
|
8647 /*ARGSUSED*/
|
|
8648 static void
|
|
8649 nv_sniff(cap)
|
|
8650 cmdarg_T *cap;
|
|
8651 {
|
|
8652 ProcessSniffRequests();
|
|
8653 }
|
|
8654 #endif
|
|
8655
|
|
8656 #ifdef FEAT_NETBEANS_INTG
|
|
8657 static void
|
|
8658 nv_nbcmd(cap)
|
|
8659 cmdarg_T *cap;
|
|
8660 {
|
|
8661 netbeans_keycommand(cap->nchar);
|
|
8662 }
|
|
8663 #endif
|
|
8664
|
|
8665 #ifdef FEAT_DND
|
|
8666 /*ARGSUSED*/
|
|
8667 static void
|
|
8668 nv_drop(cap)
|
|
8669 cmdarg_T *cap;
|
|
8670 {
|
|
8671 do_put('~', BACKWARD, 1L, PUT_CURSEND);
|
|
8672 }
|
|
8673 #endif
|
203
|
8674
|
|
8675 #ifdef FEAT_AUTOCMD
|
|
8676 /*
|
|
8677 * Trigger CursorHold event.
|
|
8678 * When waiting for a character for 'updatetime' K_CURSORHOLD is put in the
|
|
8679 * input buffer. "did_cursorhold" is set to avoid retriggering.
|
|
8680 */
|
|
8681 /*ARGSUSED*/
|
|
8682 static void
|
|
8683 nv_cursorhold(cap)
|
|
8684 cmdarg_T *cap;
|
|
8685 {
|
|
8686 apply_autocmds(EVENT_CURSORHOLD, NULL, NULL, FALSE, curbuf);
|
|
8687 did_cursorhold = TRUE;
|
226
|
8688 cap->retval |= CA_COMMAND_BUSY; /* don't call edit() now */
|
|
8689 }
|
|
8690 #endif
|
|
8691
|