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