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