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