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