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