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 /*
|
|
11 * ex_docmd.c: functions for executing an Ex command line.
|
|
12 */
|
|
13
|
|
14 #include "vim.h"
|
|
15
|
|
16 #ifdef HAVE_FCNTL_H
|
|
17 # include <fcntl.h> /* for chdir() */
|
|
18 #endif
|
|
19
|
|
20 static int quitmore = 0;
|
|
21 static int ex_pressedreturn = FALSE;
|
|
22 #ifndef FEAT_PRINTER
|
|
23 # define ex_hardcopy ex_ni
|
|
24 #endif
|
|
25
|
|
26 #ifdef FEAT_USR_CMDS
|
|
27 typedef struct ucmd
|
|
28 {
|
|
29 char_u *uc_name; /* The command name */
|
|
30 long_u uc_argt; /* The argument type */
|
|
31 char_u *uc_rep; /* The command's replacement string */
|
|
32 long uc_def; /* The default value for a range/count */
|
|
33 scid_T uc_scriptID; /* SID where the command was defined */
|
|
34 int uc_compl; /* completion type */
|
|
35 # if defined(FEAT_EVAL) && defined(FEAT_CMDL_COMPL)
|
|
36 char_u *uc_compl_arg; /* completion argument if any */
|
|
37 # endif
|
|
38 } ucmd_T;
|
|
39
|
|
40 #define UC_BUFFER 1 /* -buffer: local to current buffer */
|
|
41
|
|
42 garray_T ucmds = {0, 0, sizeof(ucmd_T), 4, NULL};
|
|
43
|
|
44 #define USER_CMD(i) (&((ucmd_T *)(ucmds.ga_data))[i])
|
|
45 #define USER_CMD_GA(gap, i) (&((ucmd_T *)((gap)->ga_data))[i])
|
|
46
|
|
47 static void do_ucmd __ARGS((exarg_T *eap));
|
|
48 static void ex_command __ARGS((exarg_T *eap));
|
|
49 static void ex_comclear __ARGS((exarg_T *eap));
|
|
50 static void ex_delcommand __ARGS((exarg_T *eap));
|
|
51 # ifdef FEAT_CMDL_COMPL
|
|
52 static char_u *get_user_command_name __ARGS((int idx));
|
|
53 # endif
|
|
54
|
|
55 #else
|
|
56 # define ex_command ex_ni
|
|
57 # define ex_comclear ex_ni
|
|
58 # define ex_delcommand ex_ni
|
|
59 #endif
|
|
60
|
|
61 #ifdef FEAT_EVAL
|
|
62 static char_u *do_one_cmd __ARGS((char_u **, int, struct condstack *, char_u *(*getline)(int, void *, int), void *cookie));
|
|
63 #else
|
|
64 static char_u *do_one_cmd __ARGS((char_u **, int, char_u *(*getline)(int, void *, int), void *cookie));
|
|
65 static int if_level = 0; /* depth in :if */
|
|
66 #endif
|
|
67 static int checkforcmd __ARGS((char_u **pp, char *cmd, int len));
|
|
68 static char_u *find_command __ARGS((exarg_T *eap, int *full));
|
|
69
|
|
70 static void ex_abbreviate __ARGS((exarg_T *eap));
|
|
71 static void ex_map __ARGS((exarg_T *eap));
|
|
72 static void ex_unmap __ARGS((exarg_T *eap));
|
|
73 static void ex_mapclear __ARGS((exarg_T *eap));
|
|
74 static void ex_abclear __ARGS((exarg_T *eap));
|
|
75 #ifndef FEAT_MENU
|
|
76 # define ex_emenu ex_ni
|
|
77 # define ex_menu ex_ni
|
|
78 # define ex_menutranslate ex_ni
|
|
79 #endif
|
|
80 #ifdef FEAT_AUTOCMD
|
|
81 static void ex_autocmd __ARGS((exarg_T *eap));
|
|
82 static void ex_doautocmd __ARGS((exarg_T *eap));
|
|
83 #else
|
|
84 # define ex_autocmd ex_ni
|
|
85 # define ex_doautocmd ex_ni
|
|
86 # define ex_doautoall ex_ni
|
|
87 #endif
|
|
88 #ifdef FEAT_LISTCMDS
|
|
89 static void ex_bunload __ARGS((exarg_T *eap));
|
|
90 static void ex_buffer __ARGS((exarg_T *eap));
|
|
91 static void ex_bmodified __ARGS((exarg_T *eap));
|
|
92 static void ex_bnext __ARGS((exarg_T *eap));
|
|
93 static void ex_bprevious __ARGS((exarg_T *eap));
|
|
94 static void ex_brewind __ARGS((exarg_T *eap));
|
|
95 static void ex_blast __ARGS((exarg_T *eap));
|
|
96 #else
|
|
97 # define ex_bunload ex_ni
|
|
98 # define ex_buffer ex_ni
|
|
99 # define ex_bmodified ex_ni
|
|
100 # define ex_bnext ex_ni
|
|
101 # define ex_bprevious ex_ni
|
|
102 # define ex_brewind ex_ni
|
|
103 # define ex_blast ex_ni
|
|
104 # define buflist_list ex_ni
|
|
105 # define ex_checktime ex_ni
|
|
106 #endif
|
|
107 #if !defined(FEAT_LISTCMDS) || !defined(FEAT_WINDOWS)
|
|
108 # define ex_buffer_all ex_ni
|
|
109 #endif
|
|
110 static char_u *getargcmd __ARGS((char_u **));
|
|
111 static char_u *skip_cmd_arg __ARGS((char_u *p, int rembs));
|
|
112 static int getargopt __ARGS((exarg_T *eap));
|
|
113 #ifndef FEAT_QUICKFIX
|
|
114 # define ex_make ex_ni
|
41
|
115 # define ex_cbuffer ex_ni
|
7
|
116 # define ex_cc ex_ni
|
|
117 # define ex_cnext ex_ni
|
|
118 # define ex_cfile ex_ni
|
|
119 # define qf_list ex_ni
|
|
120 # define qf_age ex_ni
|
|
121 # define ex_helpgrep ex_ni
|
41
|
122 # define ex_vimgrep ex_ni
|
7
|
123 #endif
|
|
124 #if !defined(FEAT_QUICKFIX) || !defined(FEAT_WINDOWS)
|
|
125 # define ex_cclose ex_ni
|
|
126 # define ex_copen ex_ni
|
|
127 # define ex_cwindow ex_ni
|
|
128 #endif
|
|
129
|
|
130 static int check_more __ARGS((int, int));
|
|
131 static linenr_T get_address __ARGS((char_u **, int skip, int to_other_file));
|
|
132 #if !defined(FEAT_PERL) || !defined(FEAT_PYTHON) || !defined(FEAT_TCL) \
|
14
|
133 || !defined(FEAT_RUBY) || !defined(FEAT_MZSCHEME)
|
7
|
134 static void ex_script_ni __ARGS((exarg_T *eap));
|
|
135 #endif
|
|
136 static char_u *invalid_range __ARGS((exarg_T *eap));
|
|
137 static void correct_range __ARGS((exarg_T *eap));
|
|
138 static char_u *repl_cmdline __ARGS((exarg_T *eap, char_u *src, int srclen, char_u *repl, char_u **cmdlinep));
|
|
139 static void ex_highlight __ARGS((exarg_T *eap));
|
|
140 static void ex_colorscheme __ARGS((exarg_T *eap));
|
|
141 static void ex_quit __ARGS((exarg_T *eap));
|
|
142 static void ex_cquit __ARGS((exarg_T *eap));
|
|
143 static void ex_quit_all __ARGS((exarg_T *eap));
|
|
144 #ifdef FEAT_WINDOWS
|
|
145 static void ex_close __ARGS((exarg_T *eap));
|
|
146 static void ex_win_close __ARGS((exarg_T *eap, win_T *win));
|
|
147 static void ex_only __ARGS((exarg_T *eap));
|
|
148 static void ex_all __ARGS((exarg_T *eap));
|
|
149 static void ex_resize __ARGS((exarg_T *eap));
|
|
150 static void ex_stag __ARGS((exarg_T *eap));
|
|
151 #else
|
|
152 # define ex_close ex_ni
|
|
153 # define ex_only ex_ni
|
|
154 # define ex_all ex_ni
|
|
155 # define ex_resize ex_ni
|
|
156 # define ex_splitview ex_ni
|
|
157 # define ex_stag ex_ni
|
|
158 #endif
|
|
159 #if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
|
|
160 static void ex_pclose __ARGS((exarg_T *eap));
|
|
161 static void ex_ptag __ARGS((exarg_T *eap));
|
|
162 static void ex_pedit __ARGS((exarg_T *eap));
|
|
163 #else
|
|
164 # define ex_pclose ex_ni
|
|
165 # define ex_ptag ex_ni
|
|
166 # define ex_pedit ex_ni
|
|
167 #endif
|
|
168 static void ex_hide __ARGS((exarg_T *eap));
|
|
169 static void ex_stop __ARGS((exarg_T *eap));
|
|
170 static void ex_exit __ARGS((exarg_T *eap));
|
|
171 static void ex_print __ARGS((exarg_T *eap));
|
|
172 #ifdef FEAT_BYTEOFF
|
|
173 static void ex_goto __ARGS((exarg_T *eap));
|
|
174 #else
|
|
175 # define ex_goto ex_ni
|
|
176 #endif
|
|
177 static void ex_shell __ARGS((exarg_T *eap));
|
|
178 static void ex_preserve __ARGS((exarg_T *eap));
|
|
179 static void ex_recover __ARGS((exarg_T *eap));
|
|
180 #ifndef FEAT_LISTCMDS
|
|
181 # define ex_argedit ex_ni
|
|
182 # define ex_argadd ex_ni
|
|
183 # define ex_argdelete ex_ni
|
|
184 # define ex_listdo ex_ni
|
|
185 #endif
|
|
186 static void ex_mode __ARGS((exarg_T *eap));
|
|
187 static void ex_wrongmodifier __ARGS((exarg_T *eap));
|
|
188 static void ex_find __ARGS((exarg_T *eap));
|
|
189 static void ex_edit __ARGS((exarg_T *eap));
|
|
190 #if !defined(FEAT_GUI) && !defined(FEAT_CLIENTSERVER)
|
|
191 # define ex_drop ex_ni
|
|
192 #endif
|
|
193 #ifndef FEAT_GUI
|
|
194 # define ex_gui ex_nogui
|
|
195 static void ex_nogui __ARGS((exarg_T *eap));
|
|
196 #endif
|
|
197 #if defined(FEAT_GUI_W32) && defined(FEAT_MENU) && defined(FEAT_TEAROFF)
|
|
198 static void ex_tearoff __ARGS((exarg_T *eap));
|
|
199 #else
|
|
200 # define ex_tearoff ex_ni
|
|
201 #endif
|
11
|
202 #if (defined(FEAT_GUI_MSWIN) || defined(FEAT_GUI_KDE) || defined(FEAT_GUI_GTK)) && defined(FEAT_MENU)
|
7
|
203 static void ex_popup __ARGS((exarg_T *eap));
|
|
204 #else
|
|
205 # define ex_popup ex_ni
|
|
206 #endif
|
|
207 #ifndef FEAT_GUI_MSWIN
|
|
208 # define ex_simalt ex_ni
|
|
209 #endif
|
11
|
210 #if !defined(FEAT_GUI_MSWIN) && !defined(FEAT_GUI_GTK) && !defined(FEAT_GUI_MOTIF) && !defined(FEAT_GUI_KDE)
|
7
|
211 # define gui_mch_find_dialog ex_ni
|
|
212 # define gui_mch_replace_dialog ex_ni
|
|
213 #endif
|
11
|
214 #if !defined(FEAT_GUI_GTK) && !defined(FEAT_GUI_KDE)
|
7
|
215 # define ex_helpfind ex_ni
|
|
216 #endif
|
|
217 #ifndef FEAT_CSCOPE
|
|
218 # define do_cscope ex_ni
|
|
219 # define do_scscope ex_ni
|
|
220 # define do_cstag ex_ni
|
|
221 #endif
|
|
222 #ifndef FEAT_SYN_HL
|
|
223 # define ex_syntax ex_ni
|
|
224 #endif
|
14
|
225 #ifndef FEAT_MZSCHEME
|
|
226 # define ex_mzscheme ex_script_ni
|
|
227 # define ex_mzfile ex_ni
|
|
228 #endif
|
7
|
229 #ifndef FEAT_PERL
|
|
230 # define ex_perl ex_script_ni
|
|
231 # define ex_perldo ex_ni
|
|
232 #endif
|
|
233 #ifndef FEAT_PYTHON
|
|
234 # define ex_python ex_script_ni
|
|
235 # define ex_pyfile ex_ni
|
|
236 #endif
|
|
237 #ifndef FEAT_TCL
|
|
238 # define ex_tcl ex_script_ni
|
|
239 # define ex_tcldo ex_ni
|
|
240 # define ex_tclfile ex_ni
|
|
241 #endif
|
|
242 #ifndef FEAT_RUBY
|
|
243 # define ex_ruby ex_script_ni
|
|
244 # define ex_rubydo ex_ni
|
|
245 # define ex_rubyfile ex_ni
|
|
246 #endif
|
|
247 #ifndef FEAT_SNIFF
|
|
248 # define ex_sniff ex_ni
|
|
249 #endif
|
|
250 #ifndef FEAT_KEYMAP
|
|
251 # define ex_loadkeymap ex_ni
|
|
252 #endif
|
|
253 static void ex_swapname __ARGS((exarg_T *eap));
|
|
254 static void ex_syncbind __ARGS((exarg_T *eap));
|
|
255 static void ex_read __ARGS((exarg_T *eap));
|
|
256 static void ex_cd __ARGS((exarg_T *eap));
|
|
257 static void ex_pwd __ARGS((exarg_T *eap));
|
|
258 static void ex_equal __ARGS((exarg_T *eap));
|
|
259 static void ex_sleep __ARGS((exarg_T *eap));
|
|
260 static void do_exmap __ARGS((exarg_T *eap, int isabbrev));
|
|
261 static void ex_winsize __ARGS((exarg_T *eap));
|
|
262 #ifdef FEAT_WINDOWS
|
|
263 static void ex_wincmd __ARGS((exarg_T *eap));
|
|
264 #else
|
|
265 # define ex_wincmd ex_ni
|
|
266 #endif
|
11
|
267 #if defined(FEAT_GUI) || defined(UNIX) || defined(VMS) || defined(MSWIN)
|
7
|
268 static void ex_winpos __ARGS((exarg_T *eap));
|
|
269 #else
|
|
270 # define ex_winpos ex_ni
|
|
271 #endif
|
|
272 static void ex_operators __ARGS((exarg_T *eap));
|
|
273 static void ex_put __ARGS((exarg_T *eap));
|
|
274 static void ex_copymove __ARGS((exarg_T *eap));
|
|
275 static void ex_submagic __ARGS((exarg_T *eap));
|
|
276 static void ex_join __ARGS((exarg_T *eap));
|
|
277 static void ex_at __ARGS((exarg_T *eap));
|
|
278 static void ex_bang __ARGS((exarg_T *eap));
|
|
279 static void ex_undo __ARGS((exarg_T *eap));
|
|
280 static void ex_redo __ARGS((exarg_T *eap));
|
|
281 static void ex_redir __ARGS((exarg_T *eap));
|
|
282 static void ex_redraw __ARGS((exarg_T *eap));
|
|
283 static void ex_redrawstatus __ARGS((exarg_T *eap));
|
|
284 static void close_redir __ARGS((void));
|
|
285 static void ex_mkrc __ARGS((exarg_T *eap));
|
|
286 static void ex_mark __ARGS((exarg_T *eap));
|
|
287 #ifdef FEAT_USR_CMDS
|
|
288 static char_u *uc_fun_cmd __ARGS((void));
|
|
289 #endif
|
|
290 #ifdef FEAT_EX_EXTRA
|
|
291 static void ex_normal __ARGS((exarg_T *eap));
|
|
292 static void ex_startinsert __ARGS((exarg_T *eap));
|
|
293 static void ex_stopinsert __ARGS((exarg_T *eap));
|
|
294 #else
|
|
295 # define ex_normal ex_ni
|
|
296 # define ex_align ex_ni
|
|
297 # define ex_retab ex_ni
|
|
298 # define ex_startinsert ex_ni
|
|
299 # define ex_stopinsert ex_ni
|
|
300 # define ex_helptags ex_ni
|
|
301 #endif
|
|
302 #ifdef FEAT_FIND_ID
|
|
303 static void ex_checkpath __ARGS((exarg_T *eap));
|
|
304 static void ex_findpat __ARGS((exarg_T *eap));
|
|
305 #else
|
|
306 # define ex_findpat ex_ni
|
|
307 # define ex_checkpath ex_ni
|
|
308 #endif
|
|
309 #if defined(FEAT_FIND_ID) && defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
|
|
310 static void ex_psearch __ARGS((exarg_T *eap));
|
|
311 #else
|
|
312 # define ex_psearch ex_ni
|
|
313 #endif
|
|
314 static void ex_tag __ARGS((exarg_T *eap));
|
|
315 static void ex_tag_cmd __ARGS((exarg_T *eap, char_u *name));
|
|
316 #ifndef FEAT_EVAL
|
|
317 # define ex_scriptnames ex_ni
|
|
318 # define ex_finish ex_ni
|
|
319 # define ex_echo ex_ni
|
|
320 # define ex_echohl ex_ni
|
|
321 # define ex_execute ex_ni
|
|
322 # define ex_call ex_ni
|
|
323 # define ex_if ex_ni
|
|
324 # define ex_endif ex_ni
|
|
325 # define ex_else ex_ni
|
|
326 # define ex_while ex_ni
|
72
|
327 # define ex_for ex_ni
|
7
|
328 # define ex_continue ex_ni
|
|
329 # define ex_break ex_ni
|
|
330 # define ex_endwhile ex_ni
|
72
|
331 # define ex_endfor ex_ni
|
7
|
332 # define ex_throw ex_ni
|
|
333 # define ex_try ex_ni
|
|
334 # define ex_catch ex_ni
|
|
335 # define ex_finally ex_ni
|
|
336 # define ex_endtry ex_ni
|
|
337 # define ex_endfunction ex_ni
|
|
338 # define ex_let ex_ni
|
|
339 # define ex_unlet ex_ni
|
|
340 # define ex_function ex_ni
|
|
341 # define ex_delfunction ex_ni
|
|
342 # define ex_return ex_ni
|
|
343 #endif
|
|
344 static char_u *arg_all __ARGS((void));
|
|
345 #ifdef FEAT_SESSION
|
|
346 static int makeopens __ARGS((FILE *fd, char_u *dirnow));
|
|
347 static int put_view __ARGS((FILE *fd, win_T *wp, int add_edit, unsigned *flagp));
|
|
348 static void ex_loadview __ARGS((exarg_T *eap));
|
|
349 static char_u *get_view_file __ARGS((int c));
|
|
350 #else
|
|
351 # define ex_loadview ex_ni
|
|
352 #endif
|
|
353 #ifndef FEAT_EVAL
|
|
354 # define ex_compiler ex_ni
|
|
355 #endif
|
|
356 #ifdef FEAT_VIMINFO
|
|
357 static void ex_viminfo __ARGS((exarg_T *eap));
|
|
358 #else
|
|
359 # define ex_viminfo ex_ni
|
|
360 #endif
|
|
361 static void ex_behave __ARGS((exarg_T *eap));
|
|
362 #ifdef FEAT_AUTOCMD
|
|
363 static void ex_filetype __ARGS((exarg_T *eap));
|
|
364 static void ex_setfiletype __ARGS((exarg_T *eap));
|
|
365 #else
|
|
366 # define ex_filetype ex_ni
|
|
367 # define ex_setfiletype ex_ni
|
|
368 #endif
|
|
369 #ifndef FEAT_DIFF
|
16
|
370 # define ex_diffoff ex_ni
|
7
|
371 # define ex_diffpatch ex_ni
|
|
372 # define ex_diffgetput ex_ni
|
|
373 # define ex_diffsplit ex_ni
|
|
374 # define ex_diffthis ex_ni
|
|
375 # define ex_diffupdate ex_ni
|
|
376 #endif
|
|
377 static void ex_digraphs __ARGS((exarg_T *eap));
|
|
378 static void ex_set __ARGS((exarg_T *eap));
|
|
379 #if !defined(FEAT_EVAL) || !defined(FEAT_AUTOCMD)
|
|
380 # define ex_options ex_ni
|
|
381 #endif
|
|
382 #ifdef FEAT_SEARCH_EXTRA
|
|
383 static void ex_nohlsearch __ARGS((exarg_T *eap));
|
|
384 static void ex_match __ARGS((exarg_T *eap));
|
|
385 #else
|
|
386 # define ex_nohlsearch ex_ni
|
|
387 # define ex_match ex_ni
|
|
388 #endif
|
|
389 #ifdef FEAT_CRYPT
|
|
390 static void ex_X __ARGS((exarg_T *eap));
|
|
391 #else
|
|
392 # define ex_X ex_ni
|
|
393 #endif
|
|
394 #ifdef FEAT_FOLDING
|
|
395 static void ex_fold __ARGS((exarg_T *eap));
|
|
396 static void ex_foldopen __ARGS((exarg_T *eap));
|
|
397 static void ex_folddo __ARGS((exarg_T *eap));
|
|
398 #else
|
|
399 # define ex_fold ex_ni
|
|
400 # define ex_foldopen ex_ni
|
|
401 # define ex_folddo ex_ni
|
|
402 #endif
|
|
403 #if !((defined(HAVE_LOCALE_H) || defined(X_LOCALE)) \
|
|
404 && (defined(FEAT_GETTEXT) || defined(FEAT_MBYTE)))
|
|
405 # define ex_language ex_ni
|
|
406 #endif
|
|
407 #ifndef FEAT_SIGNS
|
|
408 # define ex_sign ex_ni
|
|
409 #endif
|
|
410 #ifndef FEAT_SUN_WORKSHOP
|
|
411 # define ex_wsverb ex_ni
|
|
412 #endif
|
33
|
413 #ifndef FEAT_NETBEANS_INTG
|
|
414 # define ex_nbkey ex_ni
|
|
415 #endif
|
7
|
416
|
|
417 #ifndef FEAT_EVAL
|
|
418 # define ex_debug ex_ni
|
|
419 # define ex_breakadd ex_ni
|
|
420 # define ex_debuggreedy ex_ni
|
|
421 # define ex_breakdel ex_ni
|
|
422 # define ex_breaklist ex_ni
|
|
423 #endif
|
|
424
|
|
425 #ifndef FEAT_CMDHIST
|
|
426 # define ex_history ex_ni
|
|
427 #endif
|
|
428 #ifndef FEAT_JUMPLIST
|
|
429 # define ex_jumps ex_ni
|
|
430 # define ex_changes ex_ni
|
|
431 #endif
|
|
432
|
|
433 /*
|
|
434 * Declare cmdnames[].
|
|
435 */
|
|
436 #define DO_DECLARE_EXCMD
|
|
437 #include "ex_cmds.h"
|
|
438
|
|
439 /*
|
|
440 * Table used to quickly search for a command, based on its first character.
|
|
441 */
|
|
442 cmdidx_T cmdidxs[27] =
|
|
443 {
|
|
444 CMD_append,
|
|
445 CMD_buffer,
|
|
446 CMD_change,
|
|
447 CMD_delete,
|
|
448 CMD_edit,
|
|
449 CMD_file,
|
|
450 CMD_global,
|
|
451 CMD_help,
|
|
452 CMD_insert,
|
|
453 CMD_join,
|
|
454 CMD_k,
|
|
455 CMD_list,
|
|
456 CMD_move,
|
|
457 CMD_next,
|
|
458 CMD_open,
|
|
459 CMD_print,
|
|
460 CMD_quit,
|
|
461 CMD_read,
|
|
462 CMD_substitute,
|
|
463 CMD_t,
|
|
464 CMD_undo,
|
|
465 CMD_vglobal,
|
|
466 CMD_write,
|
|
467 CMD_xit,
|
|
468 CMD_yank,
|
|
469 CMD_z,
|
|
470 CMD_bang
|
|
471 };
|
|
472
|
|
473 static char_u dollar_command[2] = {'$', 0};
|
|
474
|
|
475
|
|
476 #ifdef FEAT_EVAL
|
72
|
477 /* Struct for storing a line inside a while/for loop */
|
7
|
478 typedef struct
|
|
479 {
|
|
480 char_u *line; /* command line */
|
|
481 linenr_T lnum; /* sourcing_lnum of the line */
|
|
482 } wcmd_T;
|
|
483
|
|
484 /*
|
72
|
485 * Structure used to store info for line position in a while or for loop.
|
7
|
486 * This is required, because do_one_cmd() may invoke ex_function(), which
|
72
|
487 * reads more lines that may come from the while/for loop.
|
|
488 */
|
|
489 struct loop_cookie
|
7
|
490 {
|
|
491 garray_T *lines_gap; /* growarray with line info */
|
|
492 int current_line; /* last read line from growarray */
|
|
493 int repeating; /* TRUE when looping a second time */
|
|
494 /* When "repeating" is FALSE use "getline" and "cookie" to get lines */
|
|
495 char_u *(*getline) __ARGS((int, void *, int));
|
|
496 void *cookie;
|
|
497 };
|
|
498
|
72
|
499 static char_u *get_loop_line __ARGS((int c, void *cookie, int indent));
|
|
500 static int store_loop_line __ARGS((garray_T *gap, char_u *line));
|
7
|
501 static void free_cmdlines __ARGS((garray_T *gap));
|
8
|
502
|
|
503 /* Struct to save a few things while debugging. Used in do_cmdline() only. */
|
|
504 struct dbg_stuff
|
|
505 {
|
|
506 int trylevel;
|
|
507 int force_abort;
|
|
508 except_T *caught_stack;
|
|
509 char_u *vv_exception;
|
|
510 char_u *vv_throwpoint;
|
|
511 int did_emsg;
|
|
512 int got_int;
|
|
513 int did_throw;
|
|
514 int need_rethrow;
|
|
515 int check_cstack;
|
|
516 except_T *current_exception;
|
|
517 };
|
|
518
|
|
519 static void save_dbg_stuff __ARGS((struct dbg_stuff *dsp));
|
|
520 static void restore_dbg_stuff __ARGS((struct dbg_stuff *dsp));
|
|
521
|
|
522 static void
|
|
523 save_dbg_stuff(dsp)
|
|
524 struct dbg_stuff *dsp;
|
|
525 {
|
|
526 dsp->trylevel = trylevel; trylevel = 0;
|
|
527 dsp->force_abort = force_abort; force_abort = FALSE;
|
|
528 dsp->caught_stack = caught_stack; caught_stack = NULL;
|
|
529 dsp->vv_exception = v_exception(NULL);
|
|
530 dsp->vv_throwpoint = v_throwpoint(NULL);
|
|
531
|
|
532 /* Necessary for debugging an inactive ":catch", ":finally", ":endtry" */
|
|
533 dsp->did_emsg = did_emsg; did_emsg = FALSE;
|
|
534 dsp->got_int = got_int; got_int = FALSE;
|
|
535 dsp->did_throw = did_throw; did_throw = FALSE;
|
|
536 dsp->need_rethrow = need_rethrow; need_rethrow = FALSE;
|
|
537 dsp->check_cstack = check_cstack; check_cstack = FALSE;
|
|
538 dsp->current_exception = current_exception; current_exception = NULL;
|
|
539 }
|
|
540
|
|
541 static void
|
|
542 restore_dbg_stuff(dsp)
|
|
543 struct dbg_stuff *dsp;
|
|
544 {
|
|
545 suppress_errthrow = FALSE;
|
|
546 trylevel = dsp->trylevel;
|
|
547 force_abort = dsp->force_abort;
|
|
548 caught_stack = dsp->caught_stack;
|
|
549 (void)v_exception(dsp->vv_exception);
|
|
550 (void)v_throwpoint(dsp->vv_throwpoint);
|
|
551 did_emsg = dsp->did_emsg;
|
|
552 got_int = dsp->got_int;
|
|
553 did_throw = dsp->did_throw;
|
|
554 need_rethrow = dsp->need_rethrow;
|
|
555 check_cstack = dsp->check_cstack;
|
|
556 current_exception = dsp->current_exception;
|
|
557 }
|
7
|
558 #endif
|
|
559
|
|
560
|
|
561 /*
|
|
562 * do_exmode(): Repeatedly get commands for the "Ex" mode, until the ":vi"
|
|
563 * command is given.
|
|
564 */
|
|
565 void
|
|
566 do_exmode(improved)
|
|
567 int improved; /* TRUE for "improved Ex" mode */
|
|
568 {
|
|
569 int save_msg_scroll;
|
|
570 int prev_msg_row;
|
|
571 linenr_T prev_line;
|
|
572
|
|
573 save_msg_scroll = msg_scroll;
|
|
574 ++RedrawingDisabled; /* don't redisplay the window */
|
|
575 ++no_wait_return; /* don't wait for return */
|
|
576 if (improved)
|
|
577 exmode_active = EXMODE_VIM;
|
|
578 else
|
|
579 {
|
|
580 settmode(TMODE_COOK);
|
|
581 exmode_active = EXMODE_NORMAL;
|
|
582 }
|
|
583
|
|
584 State = NORMAL;
|
|
585 #ifdef FEAT_GUI
|
|
586 /* Ignore scrollbar and mouse events in Ex mode */
|
|
587 ++hold_gui_events;
|
|
588 #endif
|
|
589 #ifdef FEAT_SNIFF
|
|
590 want_sniff_request = 0; /* No K_SNIFF wanted */
|
|
591 #endif
|
|
592
|
|
593 MSG(_("Entering Ex mode. Type \"visual\" to go to Normal mode."));
|
|
594 while (exmode_active)
|
|
595 {
|
|
596 msg_scroll = TRUE;
|
|
597 need_wait_return = FALSE;
|
|
598 ex_pressedreturn = FALSE;
|
|
599 ex_no_reprint = FALSE;
|
|
600 prev_msg_row = msg_row;
|
|
601 prev_line = curwin->w_cursor.lnum;
|
|
602 #ifdef FEAT_SNIFF
|
|
603 ProcessSniffRequests();
|
|
604 #endif
|
|
605 if (improved)
|
|
606 {
|
|
607 cmdline_row = msg_row;
|
|
608 do_cmdline(NULL, getexline, NULL, 0);
|
|
609 }
|
|
610 else
|
|
611 do_cmdline(NULL, getexmodeline, NULL, DOCMD_NOWAIT);
|
|
612 lines_left = Rows - 1;
|
|
613
|
|
614 if (prev_line != curwin->w_cursor.lnum && !ex_no_reprint)
|
|
615 {
|
|
616 if (ex_pressedreturn)
|
|
617 {
|
|
618 /* go up one line, to overwrite the ":<CR>" line, so the
|
|
619 * output doensn't contain empty lines. */
|
|
620 msg_row = prev_msg_row;
|
|
621 if (prev_msg_row == Rows - 1)
|
|
622 msg_row--;
|
|
623 }
|
|
624 msg_col = 0;
|
|
625 print_line_no_prefix(curwin->w_cursor.lnum, FALSE);
|
|
626 msg_clr_eos();
|
|
627 }
|
|
628 else if (ex_pressedreturn) /* must be at EOF */
|
|
629 EMSG(_("E501: At end-of-file"));
|
|
630 }
|
|
631
|
|
632 #ifdef FEAT_GUI
|
|
633 --hold_gui_events;
|
|
634 #endif
|
|
635 if (!improved)
|
|
636 settmode(TMODE_RAW);
|
|
637 --RedrawingDisabled;
|
|
638 --no_wait_return;
|
|
639 update_screen(CLEAR);
|
|
640 need_wait_return = FALSE;
|
|
641 msg_scroll = save_msg_scroll;
|
|
642 }
|
|
643
|
|
644 /*
|
|
645 * Execute a simple command line. Used for translated commands like "*".
|
|
646 */
|
|
647 int
|
|
648 do_cmdline_cmd(cmd)
|
|
649 char_u *cmd;
|
|
650 {
|
|
651 return do_cmdline(cmd, NULL, NULL,
|
|
652 DOCMD_VERBOSE|DOCMD_NOWAIT|DOCMD_KEYTYPED);
|
|
653 }
|
|
654
|
|
655 /*
|
|
656 * do_cmdline(): execute one Ex command line
|
|
657 *
|
|
658 * 1. Execute "cmdline" when it is not NULL.
|
|
659 * If "cmdline" is NULL, or more lines are needed, getline() is used.
|
|
660 * 2. Split up in parts separated with '|'.
|
|
661 *
|
|
662 * This function can be called recursively!
|
|
663 *
|
|
664 * flags:
|
|
665 * DOCMD_VERBOSE - The command will be included in the error message.
|
|
666 * DOCMD_NOWAIT - Don't call wait_return() and friends.
|
|
667 * DOCMD_REPEAT - Repeat execution until getline() returns NULL.
|
|
668 * DOCMD_KEYTYPED - Don't reset KeyTyped.
|
|
669 * DOCMD_EXCRESET - Reset the exception environment (used for debugging).
|
|
670 * DOCMD_KEEPLINE - Store first typed line (for repeating with ".").
|
|
671 *
|
|
672 * return FAIL if cmdline could not be executed, OK otherwise
|
|
673 */
|
|
674 int
|
|
675 do_cmdline(cmdline, getline, cookie, flags)
|
|
676 char_u *cmdline;
|
|
677 char_u *(*getline) __ARGS((int, void *, int));
|
|
678 void *cookie; /* argument for getline() */
|
|
679 int flags;
|
|
680 {
|
|
681 char_u *next_cmdline; /* next cmd to execute */
|
|
682 char_u *cmdline_copy = NULL; /* copy of cmd line */
|
|
683 int used_getline = FALSE; /* used "getline" to obtain command */
|
|
684 static int recursive = 0; /* recursive depth */
|
|
685 int msg_didout_before_start = 0;
|
|
686 int count = 0; /* line number count */
|
|
687 int did_inc = FALSE; /* incremented RedrawingDisabled */
|
|
688 int retval = OK;
|
|
689 #ifdef FEAT_EVAL
|
|
690 struct condstack cstack; /* conditional stack */
|
72
|
691 garray_T lines_ga; /* keep lines for ":while"/":for" */
|
7
|
692 int current_line = 0; /* active line in lines_ga */
|
|
693 char_u *fname = NULL; /* function or script name */
|
|
694 linenr_T *breakpoint = NULL; /* ptr to breakpoint field in cookie */
|
|
695 int *dbg_tick = NULL; /* ptr to dbg_tick field in cookie */
|
8
|
696 struct dbg_stuff debug_saved; /* saved things for debug mode */
|
7
|
697 int initial_trylevel;
|
|
698 struct msglist **saved_msg_list = NULL;
|
|
699 struct msglist *private_msg_list;
|
|
700
|
|
701 /* "getline" and "cookie" passed to do_one_cmd() */
|
|
702 char_u *(*cmd_getline) __ARGS((int, void *, int));
|
|
703 void *cmd_cookie;
|
72
|
704 struct loop_cookie cmd_loop_cookie;
|
7
|
705 void *real_cookie;
|
|
706 #else
|
|
707 # define cmd_getline getline
|
|
708 # define cmd_cookie cookie
|
|
709 #endif
|
|
710 static int call_depth = 0; /* recursiveness */
|
|
711
|
|
712 #ifdef FEAT_EVAL
|
|
713 /* For every pair of do_cmdline()/do_one_cmd() calls, use an extra memory
|
|
714 * location for storing error messages to be converted to an exception.
|
|
715 * This ensures that the do_errthrow() call in do_one_cmd() does not combine
|
|
716 * the messages stored by an earlier invocation of do_one_cmd() with the
|
|
717 * command name of the later one. This would happen when BufWritePost
|
|
718 * autocommands are executed after a write error. */
|
|
719 saved_msg_list = msg_list;
|
|
720 msg_list = &private_msg_list;
|
|
721 private_msg_list = NULL;
|
|
722 #endif
|
|
723
|
|
724 /* It's possible to create an endless loop with ":execute", catch that
|
|
725 * here. The value of 200 allows nested function calls, ":source", etc. */
|
|
726 if (call_depth == 200)
|
|
727 {
|
|
728 EMSG(_("E169: Command too recursive"));
|
|
729 #ifdef FEAT_EVAL
|
|
730 /* When converting to an exception, we do not include the command name
|
|
731 * since this is not an error of the specific command. */
|
|
732 do_errthrow((struct condstack *)NULL, (char_u *)NULL);
|
|
733 msg_list = saved_msg_list;
|
|
734 #endif
|
|
735 return FAIL;
|
|
736 }
|
|
737 ++call_depth;
|
|
738
|
|
739 #ifdef FEAT_EVAL
|
|
740 cstack.cs_idx = -1;
|
72
|
741 cstack.cs_looplevel = 0;
|
7
|
742 cstack.cs_trylevel = 0;
|
|
743 cstack.cs_emsg_silent_list = NULL;
|
72
|
744 cstack.cs_lflags = 0;
|
7
|
745 ga_init2(&lines_ga, (int)sizeof(wcmd_T), 10);
|
|
746
|
|
747 real_cookie = getline_cookie(getline, cookie);
|
|
748
|
|
749 /* Inside a function use a higher nesting level. */
|
|
750 if (getline_equal(getline, cookie, get_func_line)
|
|
751 && ex_nesting_level == func_level(real_cookie))
|
|
752 ++ex_nesting_level;
|
|
753
|
|
754 /* Get the function or script name and the address where the next breakpoint
|
|
755 * line and the debug tick for a function or script are stored. */
|
|
756 if (getline_equal(getline, cookie, get_func_line))
|
|
757 {
|
|
758 fname = func_name(real_cookie);
|
|
759 breakpoint = func_breakpoint(real_cookie);
|
|
760 dbg_tick = func_dbg_tick(real_cookie);
|
|
761 }
|
|
762 else if (getline_equal(getline, cookie, getsourceline))
|
|
763 {
|
|
764 fname = sourcing_name;
|
|
765 breakpoint = source_breakpoint(real_cookie);
|
|
766 dbg_tick = source_dbg_tick(real_cookie);
|
|
767 }
|
|
768
|
|
769 /*
|
|
770 * Initialize "force_abort" and "suppress_errthrow" at the top level.
|
|
771 */
|
|
772 if (!recursive)
|
|
773 {
|
|
774 force_abort = FALSE;
|
|
775 suppress_errthrow = FALSE;
|
|
776 }
|
|
777
|
|
778 /*
|
|
779 * If requested, store and reset the global values controlling the
|
|
780 * exception handling (used when debugging).
|
|
781 */
|
|
782 else if (flags & DOCMD_EXCRESET)
|
8
|
783 save_dbg_stuff(&debug_saved);
|
7
|
784
|
|
785 initial_trylevel = trylevel;
|
|
786
|
|
787 /*
|
|
788 * "did_throw" will be set to TRUE when an exception is being thrown.
|
|
789 */
|
|
790 did_throw = FALSE;
|
|
791 #endif
|
|
792 /*
|
|
793 * "did_emsg" will be set to TRUE when emsg() is used, in which case we
|
72
|
794 * cancel the whole command line, and any if/endif or loop.
|
7
|
795 * If force_abort is set, we cancel everything.
|
|
796 */
|
|
797 did_emsg = FALSE;
|
|
798
|
|
799 /*
|
|
800 * KeyTyped is only set when calling vgetc(). Reset it here when not
|
|
801 * calling vgetc() (sourced command lines).
|
|
802 */
|
|
803 if (!(flags & DOCMD_KEYTYPED) && !getline_equal(getline, cookie, getexline))
|
|
804 KeyTyped = FALSE;
|
|
805
|
|
806 /*
|
|
807 * Continue executing command lines:
|
72
|
808 * - when inside an ":if", ":while" or ":for"
|
7
|
809 * - for multiple commands on one line, separated with '|'
|
|
810 * - when repeating until there are no more lines (for ":source")
|
|
811 */
|
|
812 next_cmdline = cmdline;
|
|
813 do
|
|
814 {
|
72
|
815 /* stop skipping cmds for an error msg after all endif/while/for */
|
7
|
816 if (next_cmdline == NULL
|
|
817 #ifdef FEAT_EVAL
|
|
818 && !force_abort
|
|
819 && cstack.cs_idx < 0
|
|
820 && !(getline_equal(getline, cookie, get_func_line)
|
|
821 && func_has_abort(real_cookie))
|
|
822 #endif
|
|
823 )
|
|
824 did_emsg = FALSE;
|
|
825
|
|
826 /*
|
72
|
827 * 1. If repeating a line in a loop, get a line from lines_ga.
|
7
|
828 * 2. If no line given: Get an allocated line with getline().
|
|
829 * 3. If a line is given: Make a copy, so we can mess with it.
|
|
830 */
|
|
831
|
|
832 #ifdef FEAT_EVAL
|
|
833 /* 1. If repeating, get a previous line from lines_ga. */
|
72
|
834 if (cstack.cs_looplevel > 0 && current_line < lines_ga.ga_len)
|
7
|
835 {
|
|
836 /* Each '|' separated command is stored separately in lines_ga, to
|
|
837 * be able to jump to it. Don't use next_cmdline now. */
|
|
838 vim_free(cmdline_copy);
|
|
839 cmdline_copy = NULL;
|
|
840
|
|
841 /* Check if a function has returned or, unless it has an unclosed
|
|
842 * try conditional, aborted. */
|
|
843 if (getline_equal(getline, cookie, get_func_line)
|
|
844 && func_has_ended(real_cookie))
|
|
845 {
|
|
846 retval = FAIL;
|
|
847 break;
|
|
848 }
|
|
849
|
|
850 /* Check if a sourced file hit a ":finish" command. */
|
|
851 if (source_finished(getline, cookie))
|
|
852 {
|
|
853 retval = FAIL;
|
|
854 break;
|
|
855 }
|
|
856
|
|
857 /* If breakpoints have been added/deleted need to check for it. */
|
|
858 if (breakpoint != NULL && dbg_tick != NULL
|
|
859 && *dbg_tick != debug_tick)
|
|
860 {
|
|
861 *breakpoint = dbg_find_breakpoint(
|
|
862 getline_equal(getline, cookie, getsourceline),
|
|
863 fname, sourcing_lnum);
|
|
864 *dbg_tick = debug_tick;
|
|
865 }
|
|
866
|
|
867 next_cmdline = ((wcmd_T *)(lines_ga.ga_data))[current_line].line;
|
|
868 sourcing_lnum = ((wcmd_T *)(lines_ga.ga_data))[current_line].lnum;
|
|
869
|
|
870 /* Did we encounter a breakpoint? */
|
|
871 if (breakpoint != NULL && *breakpoint != 0
|
|
872 && *breakpoint <= sourcing_lnum)
|
|
873 {
|
|
874 dbg_breakpoint(fname, sourcing_lnum);
|
|
875 /* Find next breakpoint. */
|
|
876 *breakpoint = dbg_find_breakpoint(
|
|
877 getline_equal(getline, cookie, getsourceline),
|
|
878 fname, sourcing_lnum);
|
|
879 *dbg_tick = debug_tick;
|
|
880 }
|
|
881 }
|
|
882
|
72
|
883 if (cstack.cs_looplevel > 0)
|
|
884 {
|
|
885 /* Inside a while/for loop we need to store the lines and use them
|
7
|
886 * again. Pass a different "getline" function to do_one_cmd()
|
|
887 * below, so that it stores lines in or reads them from
|
|
888 * "lines_ga". Makes it possible to define a function inside a
|
72
|
889 * while/for loop. */
|
|
890 cmd_getline = get_loop_line;
|
|
891 cmd_cookie = (void *)&cmd_loop_cookie;
|
|
892 cmd_loop_cookie.lines_gap = &lines_ga;
|
|
893 cmd_loop_cookie.current_line = current_line;
|
|
894 cmd_loop_cookie.getline = getline;
|
|
895 cmd_loop_cookie.cookie = cookie;
|
|
896 cmd_loop_cookie.repeating = (current_line < lines_ga.ga_len);
|
7
|
897 }
|
|
898 else
|
|
899 {
|
|
900 cmd_getline = getline;
|
|
901 cmd_cookie = cookie;
|
|
902 }
|
|
903 #endif
|
|
904
|
|
905 /* 2. If no line given, get an allocated line with getline(). */
|
|
906 if (next_cmdline == NULL)
|
|
907 {
|
|
908 /*
|
|
909 * Need to set msg_didout for the first line after an ":if",
|
|
910 * otherwise the ":if" will be overwritten.
|
|
911 */
|
|
912 if (count == 1 && getline_equal(getline, cookie, getexline))
|
|
913 msg_didout = TRUE;
|
|
914 if (getline == NULL || (next_cmdline = getline(':', cookie,
|
|
915 #ifdef FEAT_EVAL
|
|
916 cstack.cs_idx < 0 ? 0 : (cstack.cs_idx + 1) * 2
|
|
917 #else
|
|
918 0
|
|
919 #endif
|
|
920 )) == NULL)
|
|
921 {
|
|
922 /* Don't call wait_return for aborted command line. The NULL
|
|
923 * returned for the end of a sourced file or executed function
|
|
924 * doesn't do this. */
|
|
925 if (KeyTyped && !(flags & DOCMD_REPEAT))
|
|
926 need_wait_return = FALSE;
|
|
927 retval = FAIL;
|
|
928 break;
|
|
929 }
|
|
930 used_getline = TRUE;
|
|
931
|
|
932 /*
|
|
933 * Keep the first typed line. Clear it when more lines are typed.
|
|
934 */
|
|
935 if (flags & DOCMD_KEEPLINE)
|
|
936 {
|
|
937 vim_free(repeat_cmdline);
|
|
938 if (count == 0)
|
|
939 repeat_cmdline = vim_strsave(next_cmdline);
|
|
940 else
|
|
941 repeat_cmdline = NULL;
|
|
942 }
|
|
943 }
|
|
944
|
|
945 /* 3. Make a copy of the command so we can mess with it. */
|
|
946 else if (cmdline_copy == NULL)
|
|
947 {
|
|
948 next_cmdline = vim_strsave(next_cmdline);
|
|
949 if (next_cmdline == NULL)
|
|
950 {
|
|
951 EMSG(_(e_outofmem));
|
|
952 retval = FAIL;
|
|
953 break;
|
|
954 }
|
|
955 }
|
|
956 cmdline_copy = next_cmdline;
|
|
957
|
|
958 #ifdef FEAT_EVAL
|
|
959 /*
|
72
|
960 * Save the current line when inside a ":while" or ":for", and when
|
|
961 * the command looks like a ":while" or ":for", because we may need it
|
|
962 * later. When there is a '|' and another command, it is stored
|
|
963 * separately, because we need to be able to jump back to it from an
|
|
964 * :endwhile/:endfor.
|
7
|
965 */
|
72
|
966 if (current_line == lines_ga.ga_len
|
|
967 && (cstack.cs_looplevel || has_loop_cmd(next_cmdline)))
|
|
968 {
|
|
969 if (store_loop_line(&lines_ga, next_cmdline) == FAIL)
|
7
|
970 {
|
|
971 retval = FAIL;
|
|
972 break;
|
|
973 }
|
|
974 }
|
|
975 did_endif = FALSE;
|
|
976 #endif
|
|
977
|
|
978 if (count++ == 0)
|
|
979 {
|
|
980 /*
|
|
981 * All output from the commands is put below each other, without
|
|
982 * waiting for a return. Don't do this when executing commands
|
|
983 * from a script or when being called recursive (e.g. for ":e
|
|
984 * +command file").
|
|
985 */
|
|
986 if (!(flags & DOCMD_NOWAIT) && !recursive)
|
|
987 {
|
|
988 msg_didout_before_start = msg_didout;
|
|
989 msg_didany = FALSE; /* no output yet */
|
|
990 msg_start();
|
|
991 msg_scroll = TRUE; /* put messages below each other */
|
|
992 ++no_wait_return; /* dont wait for return until finished */
|
|
993 ++RedrawingDisabled;
|
|
994 did_inc = TRUE;
|
|
995 }
|
|
996 }
|
|
997
|
|
998 if (p_verbose >= 15 && sourcing_name != NULL)
|
|
999 {
|
|
1000 int c = -1;
|
|
1001
|
|
1002 ++no_wait_return;
|
|
1003 msg_scroll = TRUE; /* always scroll up, don't overwrite */
|
|
1004 /* Truncate long lines, smsg() can't handle that. */
|
|
1005 if (STRLEN(cmdline_copy) > 200)
|
|
1006 {
|
|
1007 c = cmdline_copy[200];
|
|
1008 cmdline_copy[200] = NUL;
|
|
1009 }
|
|
1010 smsg((char_u *)_("line %ld: %s"),
|
|
1011 (long)sourcing_lnum, cmdline_copy);
|
|
1012 msg_puts((char_u *)"\n"); /* don't overwrite this either */
|
|
1013 if (c >= 0)
|
|
1014 cmdline_copy[200] = c;
|
|
1015 cmdline_row = msg_row;
|
|
1016 --no_wait_return;
|
|
1017 }
|
|
1018
|
|
1019 /*
|
|
1020 * 2. Execute one '|' separated command.
|
|
1021 * do_one_cmd() will return NULL if there is no trailing '|'.
|
|
1022 * "cmdline_copy" can change, e.g. for '%' and '#' expansion.
|
|
1023 */
|
|
1024 ++recursive;
|
|
1025 next_cmdline = do_one_cmd(&cmdline_copy, flags & DOCMD_VERBOSE,
|
|
1026 #ifdef FEAT_EVAL
|
|
1027 &cstack,
|
|
1028 #endif
|
|
1029 cmd_getline, cmd_cookie);
|
|
1030 --recursive;
|
|
1031
|
|
1032 #ifdef FEAT_EVAL
|
72
|
1033 if (cmd_cookie == (void *)&cmd_loop_cookie)
|
|
1034 /* Use "current_line" from "cmd_loop_cookie", it may have been
|
7
|
1035 * incremented when defining a function. */
|
72
|
1036 current_line = cmd_loop_cookie.current_line;
|
7
|
1037 #endif
|
|
1038
|
|
1039 if (next_cmdline == NULL)
|
|
1040 {
|
|
1041 vim_free(cmdline_copy);
|
|
1042 cmdline_copy = NULL;
|
|
1043 #ifdef FEAT_CMDHIST
|
|
1044 /*
|
|
1045 * If the command was typed, remember it for the ':' register.
|
|
1046 * Do this AFTER executing the command to make :@: work.
|
|
1047 */
|
|
1048 if (getline_equal(getline, cookie, getexline)
|
|
1049 && new_last_cmdline != NULL)
|
|
1050 {
|
|
1051 vim_free(last_cmdline);
|
|
1052 last_cmdline = new_last_cmdline;
|
|
1053 new_last_cmdline = NULL;
|
|
1054 }
|
|
1055 #endif
|
|
1056 }
|
|
1057 else
|
|
1058 {
|
|
1059 /* need to copy the command after the '|' to cmdline_copy, for the
|
|
1060 * next do_one_cmd() */
|
|
1061 mch_memmove(cmdline_copy, next_cmdline, STRLEN(next_cmdline) + 1);
|
|
1062 next_cmdline = cmdline_copy;
|
|
1063 }
|
|
1064
|
|
1065
|
|
1066 #ifdef FEAT_EVAL
|
|
1067 /* reset did_emsg for a function that is not aborted by an error */
|
|
1068 if (did_emsg && !force_abort
|
|
1069 && getline_equal(getline, cookie, get_func_line)
|
|
1070 && !func_has_abort(real_cookie))
|
|
1071 did_emsg = FALSE;
|
|
1072
|
72
|
1073 if (cstack.cs_looplevel > 0)
|
7
|
1074 {
|
|
1075 ++current_line;
|
|
1076
|
|
1077 /*
|
72
|
1078 * An ":endwhile", ":endfor" and ":continue" is handled here.
|
|
1079 * If we were executing commands, jump back to the ":while" or
|
|
1080 * ":for".
|
|
1081 * If we were not executing commands, decrement cs_looplevel.
|
7
|
1082 */
|
72
|
1083 if (cstack.cs_lflags & (CSL_HAD_CONT | CSL_HAD_ENDLOOP))
|
|
1084 {
|
|
1085 cstack.cs_lflags &= ~(CSL_HAD_CONT | CSL_HAD_ENDLOOP);
|
|
1086
|
|
1087 /* Jump back to the matching ":while" or ":for". Be careful
|
|
1088 * not to use a cs_line[] from an entry that isn't a ":while"
|
|
1089 * or ":for": It would make "current_line" invalid and can
|
|
1090 * cause a crash. */
|
7
|
1091 if (!did_emsg && !got_int && !did_throw
|
|
1092 && cstack.cs_idx >= 0
|
72
|
1093 && (cstack.cs_flags[cstack.cs_idx]
|
|
1094 & (CSF_WHILE | CSF_FOR))
|
7
|
1095 && cstack.cs_line[cstack.cs_idx] >= 0
|
|
1096 && (cstack.cs_flags[cstack.cs_idx] & CSF_ACTIVE))
|
|
1097 {
|
|
1098 current_line = cstack.cs_line[cstack.cs_idx];
|
72
|
1099 /* remember we jumped there */
|
|
1100 cstack.cs_lflags |= CSL_HAD_LOOP;
|
7
|
1101 line_breakcheck(); /* check if CTRL-C typed */
|
|
1102
|
72
|
1103 /* Check for the next breakpoint at or after the ":while"
|
|
1104 * or ":for". */
|
7
|
1105 if (breakpoint != NULL)
|
|
1106 {
|
|
1107 *breakpoint = dbg_find_breakpoint(
|
|
1108 getline_equal(getline, cookie, getsourceline),
|
|
1109 fname,
|
|
1110 ((wcmd_T *)lines_ga.ga_data)[current_line].lnum-1);
|
|
1111 *dbg_tick = debug_tick;
|
|
1112 }
|
|
1113 }
|
72
|
1114 else
|
7
|
1115 {
|
72
|
1116 /* can only get here with ":endwhile" or ":endfor" */
|
7
|
1117 if (cstack.cs_idx >= 0)
|
77
|
1118 rewind_conditionals(&cstack, cstack.cs_idx - 1,
|
|
1119 CSF_WHILE | CSF_FOR, &cstack.cs_looplevel);
|
7
|
1120 }
|
|
1121 }
|
|
1122
|
|
1123 /*
|
72
|
1124 * For a ":while" or ":for" we need to remember the line number.
|
7
|
1125 */
|
72
|
1126 else if (cstack.cs_lflags & CSL_HAD_LOOP)
|
|
1127 {
|
|
1128 cstack.cs_lflags &= ~CSL_HAD_LOOP;
|
7
|
1129 cstack.cs_line[cstack.cs_idx] = current_line - 1;
|
|
1130 }
|
|
1131 }
|
|
1132
|
|
1133 /*
|
|
1134 * When not inside any ":while" loop, clear remembered lines.
|
|
1135 */
|
72
|
1136 if (cstack.cs_looplevel == 0)
|
7
|
1137 {
|
|
1138 if (lines_ga.ga_len > 0)
|
|
1139 {
|
|
1140 sourcing_lnum =
|
|
1141 ((wcmd_T *)lines_ga.ga_data)[lines_ga.ga_len - 1].lnum;
|
|
1142 free_cmdlines(&lines_ga);
|
|
1143 }
|
|
1144 current_line = 0;
|
|
1145 }
|
|
1146
|
|
1147 /*
|
72
|
1148 * A ":finally" makes did_emsg, got_int, and did_throw pending for
|
|
1149 * being restored at the ":endtry". Reset them here and set the
|
|
1150 * ACTIVE and FINALLY flags, so that the finally clause gets executed.
|
|
1151 * This includes the case where a missing ":endif", ":endwhile" or
|
|
1152 * ":endfor" was detected by the ":finally" itself.
|
7
|
1153 */
|
72
|
1154 if (cstack.cs_lflags & CSL_HAD_FINA)
|
|
1155 {
|
|
1156 cstack.cs_lflags &= ~CSL_HAD_FINA;
|
|
1157 report_make_pending(cstack.cs_pending[cstack.cs_idx]
|
|
1158 & (CSTP_ERROR | CSTP_INTERRUPT | CSTP_THROW),
|
7
|
1159 did_throw ? (void *)current_exception : NULL);
|
|
1160 did_emsg = got_int = did_throw = FALSE;
|
|
1161 cstack.cs_flags[cstack.cs_idx] |= CSF_ACTIVE | CSF_FINALLY;
|
|
1162 }
|
|
1163
|
|
1164 /* Update global "trylevel" for recursive calls to do_cmdline() from
|
|
1165 * within this loop. */
|
|
1166 trylevel = initial_trylevel + cstack.cs_trylevel;
|
|
1167
|
|
1168 /*
|
|
1169 * If the outermost try conditional (accross function calls and sourced
|
|
1170 * files) is aborted because of an error, an interrupt, or an uncaught
|
|
1171 * exception, cancel everything. If it is left normally, reset
|
|
1172 * force_abort to get the non-EH compatible abortion behavior for
|
|
1173 * the rest of the script.
|
|
1174 */
|
|
1175 if (trylevel == 0 && !did_emsg && !got_int && !did_throw)
|
|
1176 force_abort = FALSE;
|
|
1177
|
|
1178 /* Convert an interrupt to an exception if appropriate. */
|
|
1179 (void)do_intthrow(&cstack);
|
|
1180 #endif /* FEAT_EVAL */
|
|
1181
|
|
1182 }
|
|
1183 /*
|
|
1184 * Continue executing command lines when:
|
|
1185 * - no CTRL-C typed, no aborting error, no exception thrown or try
|
|
1186 * conditionals need to be checked for executing finally clauses or
|
|
1187 * catching an interrupt exception
|
|
1188 * - didn't get an error message or lines are not typed
|
72
|
1189 * - there is a command after '|', inside a :if, :while, :for or :try, or
|
7
|
1190 * looping for ":source" command or function call.
|
|
1191 */
|
|
1192 while (!((got_int
|
|
1193 #ifdef FEAT_EVAL
|
|
1194 || (did_emsg && force_abort) || did_throw
|
|
1195 #endif
|
|
1196 )
|
|
1197 #ifdef FEAT_EVAL
|
|
1198 && cstack.cs_trylevel == 0
|
|
1199 #endif
|
|
1200 )
|
|
1201 && !(did_emsg && used_getline
|
|
1202 && (getline_equal(getline, cookie, getexmodeline)
|
|
1203 || getline_equal(getline, cookie, getexline)))
|
|
1204 && (next_cmdline != NULL
|
|
1205 #ifdef FEAT_EVAL
|
|
1206 || cstack.cs_idx >= 0
|
|
1207 #endif
|
|
1208 || (flags & DOCMD_REPEAT)));
|
|
1209
|
|
1210 vim_free(cmdline_copy);
|
|
1211 #ifdef FEAT_EVAL
|
|
1212 free_cmdlines(&lines_ga);
|
|
1213 ga_clear(&lines_ga);
|
|
1214
|
|
1215 if (cstack.cs_idx >= 0)
|
|
1216 {
|
|
1217 /*
|
|
1218 * If a sourced file or executed function ran to its end, report the
|
|
1219 * unclosed conditional.
|
|
1220 */
|
|
1221 if (!got_int && !did_throw
|
|
1222 && ((getline_equal(getline, cookie, getsourceline)
|
|
1223 && !source_finished(getline, cookie))
|
|
1224 || (getline_equal(getline, cookie, get_func_line)
|
|
1225 && !func_has_ended(real_cookie))))
|
|
1226 {
|
|
1227 if (cstack.cs_flags[cstack.cs_idx] & CSF_TRY)
|
|
1228 EMSG(_(e_endtry));
|
|
1229 else if (cstack.cs_flags[cstack.cs_idx] & CSF_WHILE)
|
|
1230 EMSG(_(e_endwhile));
|
72
|
1231 else if (cstack.cs_flags[cstack.cs_idx] & CSF_FOR)
|
|
1232 EMSG(_(e_endfor));
|
7
|
1233 else
|
|
1234 EMSG(_(e_endif));
|
|
1235 }
|
|
1236
|
|
1237 /*
|
|
1238 * Reset "trylevel" in case of a ":finish" or ":return" or a missing
|
|
1239 * ":endtry" in a sourced file or executed function. If the try
|
|
1240 * conditional is in its finally clause, ignore anything pending.
|
|
1241 * If it is in a catch clause, finish the caught exception.
|
77
|
1242 * Also cleanup any "cs_forinfo" structures.
|
7
|
1243 */
|
|
1244 do
|
77
|
1245 {
|
|
1246 int idx = cleanup_conditionals(&cstack, 0, TRUE);
|
|
1247
|
|
1248 if (idx == cstack.cs_idx)
|
|
1249 --idx; /* remove at least one */
|
|
1250 rewind_conditionals(&cstack, idx, CSF_WHILE | CSF_FOR,
|
|
1251 &cstack.cs_looplevel);
|
|
1252 }
|
|
1253 while (cstack.cs_idx >= 0);
|
7
|
1254 trylevel = initial_trylevel;
|
|
1255 }
|
|
1256
|
72
|
1257 /* If a missing ":endtry", ":endwhile", ":endfor", or ":endif" or a memory
|
|
1258 * lack was reported above and the error message is to be converted to an
|
7
|
1259 * exception, do this now after rewinding the cstack. */
|
|
1260 do_errthrow(&cstack, getline_equal(getline, cookie, get_func_line)
|
|
1261 ? (char_u *)"endfunction" : (char_u *)NULL);
|
|
1262
|
|
1263 if (trylevel == 0)
|
|
1264 {
|
|
1265 /*
|
|
1266 * When an exception is being thrown out of the outermost try
|
|
1267 * conditional, discard the uncaught exception, disable the conversion
|
|
1268 * of interrupts or errors to exceptions, and ensure that no more
|
|
1269 * commands are executed.
|
|
1270 */
|
|
1271 if (did_throw)
|
|
1272 {
|
|
1273 void *p = NULL;
|
|
1274 char_u *saved_sourcing_name;
|
|
1275 int saved_sourcing_lnum;
|
|
1276 struct msglist *messages = NULL, *next;
|
|
1277
|
|
1278 /*
|
|
1279 * If the uncaught exception is a user exception, report it as an
|
|
1280 * error. If it is an error exception, display the saved error
|
|
1281 * message now. For an interrupt exception, do nothing; the
|
|
1282 * interrupt message is given elsewhere.
|
|
1283 */
|
|
1284 switch (current_exception->type)
|
|
1285 {
|
|
1286 case ET_USER:
|
|
1287 sprintf((char *)IObuff, _("E605: Exception not caught: %s"),
|
|
1288 current_exception->value);
|
|
1289 p = vim_strsave(IObuff);
|
|
1290 break;
|
|
1291 case ET_ERROR:
|
|
1292 messages = current_exception->messages;
|
|
1293 current_exception->messages = NULL;
|
|
1294 break;
|
|
1295 case ET_INTERRUPT:
|
|
1296 break;
|
|
1297 default:
|
|
1298 p = vim_strsave((char_u *)_(e_internal));
|
|
1299 }
|
|
1300
|
|
1301 saved_sourcing_name = sourcing_name;
|
|
1302 saved_sourcing_lnum = sourcing_lnum;
|
|
1303 sourcing_name = current_exception->throw_name;
|
|
1304 sourcing_lnum = current_exception->throw_lnum;
|
|
1305 current_exception->throw_name = NULL;
|
|
1306
|
|
1307 discard_current_exception(); /* uses IObuff if 'verbose' */
|
|
1308 suppress_errthrow = TRUE;
|
|
1309 force_abort = TRUE;
|
|
1310
|
|
1311 if (messages != NULL)
|
|
1312 {
|
|
1313 do
|
|
1314 {
|
|
1315 next = messages->next;
|
|
1316 emsg(messages->msg);
|
|
1317 vim_free(messages->msg);
|
|
1318 vim_free(messages);
|
|
1319 messages = next;
|
|
1320 }
|
|
1321 while (messages != NULL);
|
|
1322 }
|
|
1323 else if (p != NULL)
|
|
1324 {
|
|
1325 emsg(p);
|
|
1326 vim_free(p);
|
|
1327 }
|
|
1328 vim_free(sourcing_name);
|
|
1329 sourcing_name = saved_sourcing_name;
|
|
1330 sourcing_lnum = saved_sourcing_lnum;
|
|
1331 }
|
|
1332
|
|
1333 /*
|
|
1334 * On an interrupt or an aborting error not converted to an exception,
|
|
1335 * disable the conversion of errors to exceptions. (Interrupts are not
|
|
1336 * converted any more, here.) This enables also the interrupt message
|
|
1337 * when force_abort is set and did_emsg unset in case of an interrupt
|
|
1338 * from a finally clause after an error.
|
|
1339 */
|
|
1340 else if (got_int || (did_emsg && force_abort))
|
|
1341 suppress_errthrow = TRUE;
|
|
1342 }
|
|
1343
|
|
1344 /*
|
|
1345 * The current cstack will be freed when do_cmdline() returns. An uncaught
|
|
1346 * exception will have to be rethrown in the previous cstack. If a function
|
|
1347 * has just returned or a script file was just finished and the previous
|
|
1348 * cstack belongs to the same function or, respectively, script file, it
|
|
1349 * will have to be checked for finally clauses to be executed due to the
|
|
1350 * ":return" or ":finish". This is done in do_one_cmd().
|
|
1351 */
|
|
1352 if (did_throw)
|
|
1353 need_rethrow = TRUE;
|
|
1354 if ((getline_equal(getline, cookie, getsourceline)
|
|
1355 && ex_nesting_level > source_level(real_cookie))
|
|
1356 || (getline_equal(getline, cookie, get_func_line)
|
|
1357 && ex_nesting_level > func_level(real_cookie) + 1))
|
|
1358 {
|
|
1359 if (!did_throw)
|
|
1360 check_cstack = TRUE;
|
|
1361 }
|
|
1362 else
|
|
1363 {
|
|
1364 /* When leaving a function, reduce nesting level. */
|
|
1365 if (getline_equal(getline, cookie, get_func_line))
|
|
1366 --ex_nesting_level;
|
|
1367 /*
|
|
1368 * Go to debug mode when returning from a function in which we are
|
|
1369 * single-stepping.
|
|
1370 */
|
|
1371 if ((getline_equal(getline, cookie, getsourceline)
|
|
1372 || getline_equal(getline, cookie, get_func_line))
|
|
1373 && ex_nesting_level + 1 <= debug_break_level)
|
|
1374 do_debug(getline_equal(getline, cookie, getsourceline)
|
|
1375 ? (char_u *)_("End of sourced file")
|
|
1376 : (char_u *)_("End of function"));
|
|
1377 }
|
|
1378
|
|
1379 /*
|
|
1380 * Restore the exception environment (done after returning from the
|
|
1381 * debugger).
|
|
1382 */
|
|
1383 if (flags & DOCMD_EXCRESET)
|
8
|
1384 restore_dbg_stuff(&debug_saved);
|
7
|
1385
|
|
1386 msg_list = saved_msg_list;
|
|
1387 #endif /* FEAT_EVAL */
|
|
1388
|
|
1389 /*
|
|
1390 * If there was too much output to fit on the command line, ask the user to
|
|
1391 * hit return before redrawing the screen. With the ":global" command we do
|
|
1392 * this only once after the command is finished.
|
|
1393 */
|
|
1394 if (did_inc)
|
|
1395 {
|
|
1396 --RedrawingDisabled;
|
|
1397 --no_wait_return;
|
|
1398 msg_scroll = FALSE;
|
|
1399
|
|
1400 /*
|
|
1401 * When just finished an ":if"-":else" which was typed, no need to
|
|
1402 * wait for hit-return. Also for an error situation.
|
|
1403 */
|
|
1404 if (retval == FAIL
|
|
1405 #ifdef FEAT_EVAL
|
|
1406 || (did_endif && KeyTyped && !did_emsg)
|
|
1407 #endif
|
|
1408 )
|
|
1409 {
|
|
1410 need_wait_return = FALSE;
|
|
1411 msg_didany = FALSE; /* don't wait when restarting edit */
|
|
1412 }
|
|
1413 else if (need_wait_return)
|
|
1414 {
|
|
1415 /*
|
|
1416 * The msg_start() above clears msg_didout. The wait_return we do
|
|
1417 * here should not overwrite the command that may be shown before
|
|
1418 * doing that.
|
|
1419 */
|
|
1420 msg_didout |= msg_didout_before_start;
|
|
1421 wait_return(FALSE);
|
|
1422 }
|
|
1423 }
|
|
1424
|
|
1425 #ifndef FEAT_EVAL
|
|
1426 /*
|
|
1427 * Reset if_level, in case a sourced script file contains more ":if" than
|
|
1428 * ":endif" (could be ":if x | foo | endif").
|
|
1429 */
|
|
1430 if_level = 0;
|
|
1431 #endif
|
|
1432
|
|
1433 --call_depth;
|
|
1434 return retval;
|
|
1435 }
|
|
1436
|
|
1437 #ifdef FEAT_EVAL
|
|
1438 /*
|
72
|
1439 * Obtain a line when inside a ":while" or ":for" loop.
|
7
|
1440 */
|
|
1441 static char_u *
|
72
|
1442 get_loop_line(c, cookie, indent)
|
7
|
1443 int c;
|
|
1444 void *cookie;
|
|
1445 int indent;
|
|
1446 {
|
72
|
1447 struct loop_cookie *cp = (struct loop_cookie *)cookie;
|
7
|
1448 wcmd_T *wp;
|
|
1449 char_u *line;
|
|
1450
|
|
1451 if (cp->current_line + 1 >= cp->lines_gap->ga_len)
|
|
1452 {
|
|
1453 if (cp->repeating)
|
72
|
1454 return NULL; /* trying to read past ":endwhile"/":endfor" */
|
|
1455
|
|
1456 /* First time inside the ":while"/":for": get line normally. */
|
7
|
1457 if (cp->getline == NULL)
|
|
1458 line = getcmdline(c, 0L, indent);
|
|
1459 else
|
|
1460 line = cp->getline(c, cp->cookie, indent);
|
72
|
1461 if (store_loop_line(cp->lines_gap, line) == OK)
|
7
|
1462 ++cp->current_line;
|
|
1463
|
|
1464 return line;
|
|
1465 }
|
|
1466
|
|
1467 KeyTyped = FALSE;
|
|
1468 ++cp->current_line;
|
|
1469 wp = (wcmd_T *)(cp->lines_gap->ga_data) + cp->current_line;
|
|
1470 sourcing_lnum = wp->lnum;
|
|
1471 return vim_strsave(wp->line);
|
|
1472 }
|
|
1473
|
|
1474 /*
|
|
1475 * Store a line in "gap" so that a ":while" loop can execute it again.
|
|
1476 */
|
|
1477 static int
|
72
|
1478 store_loop_line(gap, line)
|
7
|
1479 garray_T *gap;
|
|
1480 char_u *line;
|
|
1481 {
|
|
1482 if (ga_grow(gap, 1) == FAIL)
|
|
1483 return FAIL;
|
|
1484 ((wcmd_T *)(gap->ga_data))[gap->ga_len].line = vim_strsave(line);
|
|
1485 ((wcmd_T *)(gap->ga_data))[gap->ga_len].lnum = sourcing_lnum;
|
|
1486 ++gap->ga_len;
|
|
1487 return OK;
|
|
1488 }
|
|
1489
|
|
1490 /*
|
72
|
1491 * Free the lines stored for a ":while" or ":for" loop.
|
7
|
1492 */
|
|
1493 static void
|
|
1494 free_cmdlines(gap)
|
|
1495 garray_T *gap;
|
|
1496 {
|
|
1497 while (gap->ga_len > 0)
|
|
1498 {
|
|
1499 vim_free(((wcmd_T *)(gap->ga_data))[gap->ga_len - 1].line);
|
|
1500 --gap->ga_len;
|
|
1501 }
|
|
1502 }
|
|
1503 #endif
|
|
1504
|
|
1505 /*
|
72
|
1506 * If "getline" is get_loop_line(), return TRUE if the getline it uses equals
|
7
|
1507 * "func". * Otherwise return TRUE when "getline" equals "func".
|
|
1508 */
|
|
1509 /*ARGSUSED*/
|
|
1510 int
|
|
1511 getline_equal(getline, cookie, func)
|
|
1512 char_u *(*getline) __ARGS((int, void *, int));
|
|
1513 void *cookie; /* argument for getline() */
|
|
1514 char_u *(*func) __ARGS((int, void *, int));
|
|
1515 {
|
|
1516 #ifdef FEAT_EVAL
|
|
1517 char_u *(*gp) __ARGS((int, void *, int));
|
72
|
1518 struct loop_cookie *cp;
|
|
1519
|
|
1520 /* When "getline" is "get_loop_line()" use the "cookie" to find the
|
7
|
1521 * function that's orignally used to obtain the lines. This may be nested
|
|
1522 * several levels. */
|
|
1523 gp = getline;
|
72
|
1524 cp = (struct loop_cookie *)cookie;
|
|
1525 while (gp == get_loop_line)
|
7
|
1526 {
|
|
1527 gp = cp->getline;
|
|
1528 cp = cp->cookie;
|
|
1529 }
|
|
1530 return gp == func;
|
|
1531 #else
|
|
1532 return getline == func;
|
|
1533 #endif
|
|
1534 }
|
|
1535
|
|
1536 #if defined(FEAT_EVAL) || defined(FEAT_MBYTE) || defined(PROTO)
|
|
1537 /*
|
72
|
1538 * If "getline" is get_loop_line(), return the cookie used by the original
|
7
|
1539 * getline function. Otherwise return "cookie".
|
|
1540 */
|
|
1541 /*ARGSUSED*/
|
|
1542 void *
|
|
1543 getline_cookie(getline, cookie)
|
|
1544 char_u *(*getline) __ARGS((int, void *, int));
|
|
1545 void *cookie; /* argument for getline() */
|
|
1546 {
|
|
1547 # ifdef FEAT_EVAL
|
|
1548 char_u *(*gp) __ARGS((int, void *, int));
|
72
|
1549 struct loop_cookie *cp;
|
|
1550
|
|
1551 /* When "getline" is "get_loop_line()" use the "cookie" to find the
|
7
|
1552 * cookie that's orignally used to obtain the lines. This may be nested
|
|
1553 * several levels. */
|
|
1554 gp = getline;
|
72
|
1555 cp = (struct loop_cookie *)cookie;
|
|
1556 while (gp == get_loop_line)
|
7
|
1557 {
|
|
1558 gp = cp->getline;
|
|
1559 cp = cp->cookie;
|
|
1560 }
|
|
1561 return cp;
|
|
1562 # else
|
|
1563 return cookie;
|
|
1564 # endif
|
|
1565 }
|
|
1566 #endif
|
|
1567
|
|
1568 /*
|
|
1569 * Execute one Ex command.
|
|
1570 *
|
|
1571 * If 'sourcing' is TRUE, the command will be included in the error message.
|
|
1572 *
|
|
1573 * 1. skip comment lines and leading space
|
|
1574 * 2. handle command modifiers
|
|
1575 * 3. parse range
|
|
1576 * 4. parse command
|
|
1577 * 5. parse arguments
|
|
1578 * 6. switch on command name
|
|
1579 *
|
|
1580 * Note: "getline" can be NULL.
|
|
1581 *
|
|
1582 * This function may be called recursively!
|
|
1583 */
|
|
1584 #if (_MSC_VER == 1200)
|
|
1585 /*
|
8
|
1586 * Avoid optimisation bug in VC++ version 6.0
|
7
|
1587 */
|
|
1588 # pragma optimize( "g", off )
|
|
1589 #endif
|
|
1590 static char_u *
|
|
1591 do_one_cmd(cmdlinep, sourcing,
|
|
1592 #ifdef FEAT_EVAL
|
|
1593 cstack,
|
|
1594 #endif
|
|
1595 getline, cookie)
|
|
1596 char_u **cmdlinep;
|
|
1597 int sourcing;
|
|
1598 #ifdef FEAT_EVAL
|
|
1599 struct condstack *cstack;
|
|
1600 #endif
|
|
1601 char_u *(*getline) __ARGS((int, void *, int));
|
|
1602 void *cookie; /* argument for getline() */
|
|
1603 {
|
|
1604 char_u *p;
|
|
1605 linenr_T lnum;
|
|
1606 long n;
|
|
1607 char_u *errormsg = NULL; /* error message */
|
|
1608 exarg_T ea; /* Ex command arguments */
|
|
1609 long verbose_save = -1;
|
|
1610 int save_msg_scroll = 0;
|
|
1611 int did_silent = 0;
|
|
1612 int did_esilent = 0;
|
28
|
1613 #ifdef HAVE_SANDBOX
|
|
1614 int did_sandbox = FALSE;
|
|
1615 #endif
|
7
|
1616 cmdmod_T save_cmdmod;
|
|
1617 int ni; /* set when Not Implemented */
|
|
1618
|
|
1619 vim_memset(&ea, 0, sizeof(ea));
|
|
1620 ea.line1 = 1;
|
|
1621 ea.line2 = 1;
|
|
1622 #ifdef FEAT_EVAL
|
|
1623 ++ex_nesting_level;
|
|
1624 #endif
|
|
1625
|
|
1626 /* when not editing the last file :q has to be typed twice */
|
|
1627 if (quitmore
|
|
1628 #ifdef FEAT_EVAL
|
|
1629 /* avoid that a function call in 'statusline' does this */
|
|
1630 && !getline_equal(getline, cookie, get_func_line)
|
|
1631 #endif
|
|
1632 )
|
|
1633 --quitmore;
|
|
1634
|
|
1635 /*
|
|
1636 * Reset browse, confirm, etc.. They are restored when returning, for
|
|
1637 * recursive calls.
|
|
1638 */
|
|
1639 save_cmdmod = cmdmod;
|
|
1640 vim_memset(&cmdmod, 0, sizeof(cmdmod));
|
|
1641
|
|
1642 /*
|
|
1643 * Repeat until no more command modifiers are found.
|
|
1644 */
|
|
1645 ea.cmd = *cmdlinep;
|
|
1646 for (;;)
|
|
1647 {
|
|
1648 /*
|
|
1649 * 1. skip comment lines and leading white space and colons
|
|
1650 */
|
|
1651 while (*ea.cmd == ' ' || *ea.cmd == '\t' || *ea.cmd == ':')
|
|
1652 ++ea.cmd;
|
|
1653
|
|
1654 /* in ex mode, an empty line works like :+ */
|
|
1655 if (*ea.cmd == NUL && exmode_active
|
|
1656 && (getline_equal(getline, cookie, getexmodeline)
|
|
1657 || getline_equal(getline, cookie, getexline)))
|
|
1658 {
|
|
1659 ea.cmd = (char_u *)"+";
|
|
1660 ex_pressedreturn = TRUE;
|
|
1661 }
|
|
1662
|
|
1663 /* ignore comment and empty lines */
|
|
1664 if (*ea.cmd == '"' || *ea.cmd == NUL)
|
|
1665 goto doend;
|
|
1666
|
|
1667 /*
|
|
1668 * 2. handle command modifiers.
|
|
1669 */
|
|
1670 p = ea.cmd;
|
|
1671 if (VIM_ISDIGIT(*ea.cmd))
|
|
1672 p = skipwhite(skipdigits(ea.cmd));
|
|
1673 switch (*p)
|
|
1674 {
|
|
1675 /* When adding an entry, also modify cmd_exists(). */
|
|
1676 case 'a': if (!checkforcmd(&ea.cmd, "aboveleft", 3))
|
|
1677 break;
|
|
1678 #ifdef FEAT_WINDOWS
|
|
1679 cmdmod.split |= WSP_ABOVE;
|
|
1680 #endif
|
|
1681 continue;
|
|
1682
|
|
1683 case 'b': if (checkforcmd(&ea.cmd, "belowright", 3))
|
|
1684 {
|
|
1685 #ifdef FEAT_WINDOWS
|
|
1686 cmdmod.split |= WSP_BELOW;
|
|
1687 #endif
|
|
1688 continue;
|
|
1689 }
|
|
1690 if (checkforcmd(&ea.cmd, "browse", 3))
|
|
1691 {
|
|
1692 #ifdef FEAT_BROWSE
|
|
1693 cmdmod.browse = TRUE;
|
|
1694 #endif
|
|
1695 continue;
|
|
1696 }
|
|
1697 if (!checkforcmd(&ea.cmd, "botright", 2))
|
|
1698 break;
|
|
1699 #ifdef FEAT_WINDOWS
|
|
1700 cmdmod.split |= WSP_BOT;
|
|
1701 #endif
|
|
1702 continue;
|
|
1703
|
|
1704 case 'c': if (!checkforcmd(&ea.cmd, "confirm", 4))
|
|
1705 break;
|
|
1706 #if defined(FEAT_GUI_DIALOG) || defined(FEAT_CON_DIALOG)
|
|
1707 cmdmod.confirm = TRUE;
|
|
1708 #endif
|
|
1709 continue;
|
|
1710
|
|
1711 case 'k': if (checkforcmd(&ea.cmd, "keepmarks", 3))
|
|
1712 {
|
|
1713 cmdmod.keepmarks = TRUE;
|
|
1714 continue;
|
|
1715 }
|
22
|
1716 if (checkforcmd(&ea.cmd, "keepalt", 5))
|
|
1717 {
|
|
1718 cmdmod.keepalt = TRUE;
|
|
1719 continue;
|
|
1720 }
|
7
|
1721 if (!checkforcmd(&ea.cmd, "keepjumps", 5))
|
|
1722 break;
|
|
1723 cmdmod.keepjumps = TRUE;
|
|
1724 continue;
|
|
1725
|
|
1726 /* ":hide" and ":hide | cmd" are not modifiers */
|
|
1727 case 'h': if (p != ea.cmd || !checkforcmd(&p, "hide", 3)
|
|
1728 || *p == NUL || ends_excmd(*p))
|
|
1729 break;
|
|
1730 ea.cmd = p;
|
|
1731 cmdmod.hide = TRUE;
|
|
1732 continue;
|
|
1733
|
|
1734 case 'l': if (checkforcmd(&ea.cmd, "lockmarks", 3))
|
|
1735 {
|
|
1736 cmdmod.lockmarks = TRUE;
|
|
1737 continue;
|
|
1738 }
|
|
1739
|
|
1740 if (!checkforcmd(&ea.cmd, "leftabove", 5))
|
|
1741 break;
|
|
1742 #ifdef FEAT_WINDOWS
|
|
1743 cmdmod.split |= WSP_ABOVE;
|
|
1744 #endif
|
|
1745 continue;
|
|
1746
|
|
1747 case 'r': if (!checkforcmd(&ea.cmd, "rightbelow", 6))
|
|
1748 break;
|
|
1749 #ifdef FEAT_WINDOWS
|
|
1750 cmdmod.split |= WSP_BELOW;
|
|
1751 #endif
|
|
1752 continue;
|
|
1753
|
28
|
1754 case 's': if (checkforcmd(&ea.cmd, "sandbox", 3))
|
|
1755 {
|
|
1756 #ifdef HAVE_SANDBOX
|
|
1757 if (!did_sandbox)
|
|
1758 ++sandbox;
|
|
1759 did_sandbox = TRUE;
|
|
1760 #endif
|
|
1761 continue;
|
|
1762 }
|
|
1763 if (!checkforcmd(&ea.cmd, "silent", 3))
|
7
|
1764 break;
|
|
1765 ++did_silent;
|
|
1766 ++msg_silent;
|
|
1767 save_msg_scroll = msg_scroll;
|
|
1768 if (*ea.cmd == '!' && !vim_iswhite(ea.cmd[-1]))
|
|
1769 {
|
|
1770 /* ":silent!", but not "silent !cmd" */
|
|
1771 ea.cmd = skipwhite(ea.cmd + 1);
|
|
1772 ++emsg_silent;
|
|
1773 ++did_esilent;
|
|
1774 }
|
|
1775 continue;
|
|
1776
|
|
1777 case 't': if (!checkforcmd(&ea.cmd, "topleft", 2))
|
|
1778 break;
|
|
1779 #ifdef FEAT_WINDOWS
|
|
1780 cmdmod.split |= WSP_TOP;
|
|
1781 #endif
|
|
1782 continue;
|
|
1783
|
|
1784 case 'v': if (checkforcmd(&ea.cmd, "vertical", 4))
|
|
1785 {
|
|
1786 #ifdef FEAT_VERTSPLIT
|
|
1787 cmdmod.split |= WSP_VERT;
|
|
1788 #endif
|
|
1789 continue;
|
|
1790 }
|
|
1791 if (!checkforcmd(&p, "verbose", 4))
|
|
1792 break;
|
|
1793 if (verbose_save < 0)
|
|
1794 verbose_save = p_verbose;
|
8
|
1795 if (vim_isdigit(*ea.cmd))
|
|
1796 p_verbose = atoi((char *)ea.cmd);
|
|
1797 else
|
7
|
1798 p_verbose = 1;
|
|
1799 ea.cmd = p;
|
|
1800 continue;
|
|
1801 }
|
|
1802 break;
|
|
1803 }
|
|
1804
|
|
1805 #ifdef FEAT_EVAL
|
|
1806 ea.skip = did_emsg || got_int || did_throw || (cstack->cs_idx >= 0
|
|
1807 && !(cstack->cs_flags[cstack->cs_idx] & CSF_ACTIVE));
|
|
1808 #else
|
|
1809 ea.skip = (if_level > 0);
|
|
1810 #endif
|
|
1811
|
|
1812 #ifdef FEAT_EVAL
|
|
1813 /* May go to debug mode. If this happens and the ">quit" debug command is
|
|
1814 * used, throw an interrupt exception and skip the next command. */
|
|
1815 dbg_check_breakpoint(&ea);
|
|
1816 if (!ea.skip && got_int)
|
|
1817 {
|
|
1818 ea.skip = TRUE;
|
|
1819 (void)do_intthrow(cstack);
|
|
1820 }
|
|
1821 #endif
|
|
1822
|
|
1823 /*
|
|
1824 * 3. parse a range specifier of the form: addr [,addr] [;addr] ..
|
|
1825 *
|
|
1826 * where 'addr' is:
|
|
1827 *
|
|
1828 * % (entire file)
|
|
1829 * $ [+-NUM]
|
|
1830 * 'x [+-NUM] (where x denotes a currently defined mark)
|
|
1831 * . [+-NUM]
|
|
1832 * [+-NUM]..
|
|
1833 * NUM
|
|
1834 *
|
|
1835 * The ea.cmd pointer is updated to point to the first character following the
|
|
1836 * range spec. If an initial address is found, but no second, the upper bound
|
|
1837 * is equal to the lower.
|
|
1838 */
|
|
1839
|
|
1840 /* repeat for all ',' or ';' separated addresses */
|
|
1841 for (;;)
|
|
1842 {
|
|
1843 ea.line1 = ea.line2;
|
|
1844 ea.line2 = curwin->w_cursor.lnum; /* default is current line number */
|
|
1845 ea.cmd = skipwhite(ea.cmd);
|
|
1846 lnum = get_address(&ea.cmd, ea.skip, ea.addr_count == 0);
|
|
1847 if (ea.cmd == NULL) /* error detected */
|
|
1848 goto doend;
|
|
1849 if (lnum == MAXLNUM)
|
|
1850 {
|
|
1851 if (*ea.cmd == '%') /* '%' - all lines */
|
|
1852 {
|
|
1853 ++ea.cmd;
|
|
1854 ea.line1 = 1;
|
|
1855 ea.line2 = curbuf->b_ml.ml_line_count;
|
|
1856 ++ea.addr_count;
|
|
1857 }
|
|
1858 /* '*' - visual area */
|
|
1859 else if (*ea.cmd == '*' && vim_strchr(p_cpo, CPO_STAR) == NULL)
|
|
1860 {
|
|
1861 pos_T *fp;
|
|
1862
|
|
1863 ++ea.cmd;
|
|
1864 if (!ea.skip)
|
|
1865 {
|
|
1866 fp = getmark('<', FALSE);
|
|
1867 if (check_mark(fp) == FAIL)
|
|
1868 goto doend;
|
|
1869 ea.line1 = fp->lnum;
|
|
1870 fp = getmark('>', FALSE);
|
|
1871 if (check_mark(fp) == FAIL)
|
|
1872 goto doend;
|
|
1873 ea.line2 = fp->lnum;
|
|
1874 ++ea.addr_count;
|
|
1875 }
|
|
1876 }
|
|
1877 }
|
|
1878 else
|
|
1879 ea.line2 = lnum;
|
|
1880 ea.addr_count++;
|
|
1881
|
|
1882 if (*ea.cmd == ';')
|
|
1883 {
|
|
1884 if (!ea.skip)
|
|
1885 curwin->w_cursor.lnum = ea.line2;
|
|
1886 }
|
|
1887 else if (*ea.cmd != ',')
|
|
1888 break;
|
|
1889 ++ea.cmd;
|
|
1890 }
|
|
1891
|
|
1892 /* One address given: set start and end lines */
|
|
1893 if (ea.addr_count == 1)
|
|
1894 {
|
|
1895 ea.line1 = ea.line2;
|
|
1896 /* ... but only implicit: really no address given */
|
|
1897 if (lnum == MAXLNUM)
|
|
1898 ea.addr_count = 0;
|
|
1899 }
|
|
1900
|
|
1901 /* Don't leave the cursor on an illegal line (caused by ';') */
|
|
1902 check_cursor_lnum();
|
|
1903
|
|
1904 /*
|
|
1905 * 4. parse command
|
|
1906 */
|
|
1907
|
|
1908 /*
|
|
1909 * Skip ':' and any white space
|
|
1910 */
|
|
1911 ea.cmd = skipwhite(ea.cmd);
|
|
1912 while (*ea.cmd == ':')
|
|
1913 ea.cmd = skipwhite(ea.cmd + 1);
|
|
1914
|
|
1915 /*
|
|
1916 * If we got a line, but no command, then go to the line.
|
|
1917 * If we find a '|' or '\n' we set ea.nextcmd.
|
|
1918 */
|
|
1919 if (*ea.cmd == NUL || *ea.cmd == '"' ||
|
|
1920 (ea.nextcmd = check_nextcmd(ea.cmd)) != NULL)
|
|
1921 {
|
|
1922 /*
|
|
1923 * strange vi behaviour:
|
|
1924 * ":3" jumps to line 3
|
|
1925 * ":3|..." prints line 3
|
|
1926 * ":|" prints current line
|
|
1927 */
|
|
1928 if (ea.skip) /* skip this if inside :if */
|
|
1929 goto doend;
|
|
1930 if (*ea.cmd == '|')
|
|
1931 {
|
|
1932 ea.cmdidx = CMD_print;
|
|
1933 ea.argt = RANGE+COUNT+TRLBAR;
|
|
1934 if ((errormsg = invalid_range(&ea)) == NULL)
|
|
1935 {
|
|
1936 correct_range(&ea);
|
|
1937 ex_print(&ea);
|
|
1938 }
|
|
1939 }
|
|
1940 else if (ea.addr_count != 0)
|
|
1941 {
|
|
1942 if (ea.line2 < 0)
|
|
1943 errormsg = invalid_range(&ea);
|
|
1944 else
|
|
1945 {
|
|
1946 if (ea.line2 == 0)
|
|
1947 curwin->w_cursor.lnum = 1;
|
|
1948 else if (ea.line2 > curbuf->b_ml.ml_line_count)
|
|
1949 curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count;
|
|
1950 else
|
|
1951 curwin->w_cursor.lnum = ea.line2;
|
|
1952 beginline(BL_SOL | BL_FIX);
|
|
1953 }
|
|
1954 }
|
|
1955 goto doend;
|
|
1956 }
|
|
1957
|
|
1958 /* Find the command and let "p" point to after it. */
|
|
1959 p = find_command(&ea, NULL);
|
|
1960
|
|
1961 #ifdef FEAT_USR_CMDS
|
|
1962 if (p == NULL)
|
|
1963 {
|
|
1964 if (!ea.skip)
|
|
1965 errormsg = (char_u *)_("E464: Ambiguous use of user-defined command");
|
|
1966 goto doend;
|
|
1967 }
|
|
1968 /* Check for wrong commands. */
|
|
1969 if (*p == '!' && ea.cmd[1] == 0151 && ea.cmd[0] == 78)
|
|
1970 {
|
|
1971 errormsg = uc_fun_cmd();
|
|
1972 goto doend;
|
|
1973 }
|
|
1974 #endif
|
|
1975 if (ea.cmdidx == CMD_SIZE)
|
|
1976 {
|
|
1977 if (!ea.skip)
|
|
1978 {
|
|
1979 STRCPY(IObuff, _("E492: Not an editor command"));
|
|
1980 if (!sourcing)
|
|
1981 {
|
|
1982 STRCAT(IObuff, ": ");
|
|
1983 STRNCAT(IObuff, *cmdlinep, 40);
|
|
1984 }
|
|
1985 errormsg = IObuff;
|
|
1986 }
|
|
1987 goto doend;
|
|
1988 }
|
|
1989
|
|
1990 ni = (
|
|
1991 #ifdef FEAT_USR_CMDS
|
|
1992 !USER_CMDIDX(ea.cmdidx) &&
|
|
1993 #endif
|
|
1994 cmdnames[ea.cmdidx].cmd_func == ex_ni);
|
|
1995
|
|
1996 #ifndef FEAT_EVAL
|
|
1997 /*
|
|
1998 * When the expression evaluation is disabled, recognize the ":if" and
|
|
1999 * ":endif" commands and ignore everything in between it.
|
|
2000 */
|
|
2001 if (ea.cmdidx == CMD_if)
|
|
2002 ++if_level;
|
|
2003 if (if_level)
|
|
2004 {
|
|
2005 if (ea.cmdidx == CMD_endif)
|
|
2006 --if_level;
|
|
2007 goto doend;
|
|
2008 }
|
|
2009
|
|
2010 #endif
|
|
2011
|
|
2012 if (*p == '!' && ea.cmdidx != CMD_substitute) /* forced commands */
|
|
2013 {
|
|
2014 ++p;
|
|
2015 ea.forceit = TRUE;
|
|
2016 }
|
|
2017 else
|
|
2018 ea.forceit = FALSE;
|
|
2019
|
|
2020 /*
|
|
2021 * 5. parse arguments
|
|
2022 */
|
|
2023 #ifdef FEAT_USR_CMDS
|
|
2024 if (!USER_CMDIDX(ea.cmdidx))
|
|
2025 #endif
|
|
2026 ea.argt = cmdnames[(int)ea.cmdidx].cmd_argt;
|
|
2027
|
|
2028 if (!ea.skip)
|
|
2029 {
|
|
2030 #ifdef HAVE_SANDBOX
|
|
2031 if (sandbox != 0 && !(ea.argt & SBOXOK))
|
|
2032 {
|
|
2033 /* Command not allowed in sandbox. */
|
|
2034 errormsg = (char_u *)_(e_sandbox);
|
|
2035 goto doend;
|
|
2036 }
|
|
2037 #endif
|
|
2038 if (!curbuf->b_p_ma && (ea.argt & MODIFY))
|
|
2039 {
|
|
2040 /* Command not allowed in non-'modifiable' buffer */
|
|
2041 errormsg = (char_u *)_(e_modifiable);
|
|
2042 goto doend;
|
|
2043 }
|
|
2044 #ifdef FEAT_CMDWIN
|
|
2045 if (cmdwin_type != 0 && !(ea.argt & CMDWIN)
|
|
2046 # ifdef FEAT_USR_CMDS
|
|
2047 && !USER_CMDIDX(ea.cmdidx)
|
|
2048 # endif
|
|
2049 )
|
|
2050 {
|
|
2051 /* Command not allowed in cmdline window. */
|
|
2052 errormsg = (char_u *)_(e_cmdwin);
|
|
2053 goto doend;
|
|
2054 }
|
|
2055 #endif
|
|
2056
|
|
2057 if (!ni && !(ea.argt & RANGE) && ea.addr_count > 0)
|
|
2058 {
|
|
2059 /* no range allowed */
|
|
2060 errormsg = (char_u *)_(e_norange);
|
|
2061 goto doend;
|
|
2062 }
|
|
2063 }
|
|
2064
|
|
2065 if (!ni && !(ea.argt & BANG) && ea.forceit) /* no <!> allowed */
|
|
2066 {
|
|
2067 errormsg = (char_u *)_(e_nobang);
|
|
2068 goto doend;
|
|
2069 }
|
|
2070
|
|
2071 /*
|
|
2072 * Don't complain about the range if it is not used
|
|
2073 * (could happen if line_count is accidentally set to 0).
|
|
2074 */
|
|
2075 if (!ea.skip && !ni)
|
|
2076 {
|
|
2077 /*
|
|
2078 * If the range is backwards, ask for confirmation and, if given, swap
|
|
2079 * ea.line1 & ea.line2 so it's forwards again.
|
|
2080 * When global command is busy, don't ask, will fail below.
|
|
2081 */
|
|
2082 if (!global_busy && ea.line1 > ea.line2)
|
|
2083 {
|
|
2084 if (sourcing)
|
|
2085 {
|
|
2086 errormsg = (char_u *)_("E493: Backwards range given");
|
|
2087 goto doend;
|
|
2088 }
|
|
2089 else
|
|
2090 {
|
|
2091 int msg_silent_save = msg_silent;
|
|
2092
|
|
2093 msg_silent = 0;
|
|
2094 if (ask_yesno((char_u *)
|
|
2095 _("Backwards range given, OK to swap"), FALSE) != 'y')
|
|
2096 goto doend;
|
|
2097 msg_silent = msg_silent_save;
|
|
2098 }
|
|
2099 lnum = ea.line1;
|
|
2100 ea.line1 = ea.line2;
|
|
2101 ea.line2 = lnum;
|
|
2102 }
|
|
2103 if ((errormsg = invalid_range(&ea)) != NULL)
|
|
2104 goto doend;
|
|
2105 }
|
|
2106
|
|
2107 if ((ea.argt & NOTADR) && ea.addr_count == 0) /* default is 1, not cursor */
|
|
2108 ea.line2 = 1;
|
|
2109
|
|
2110 correct_range(&ea);
|
|
2111
|
|
2112 #ifdef FEAT_FOLDING
|
|
2113 if (((ea.argt & WHOLEFOLD) || ea.addr_count >= 2) && !global_busy)
|
|
2114 {
|
|
2115 /* Put the first line at the start of a closed fold, put the last line
|
|
2116 * at the end of a closed fold. */
|
|
2117 (void)hasFolding(ea.line1, &ea.line1, NULL);
|
|
2118 (void)hasFolding(ea.line2, NULL, &ea.line2);
|
|
2119 }
|
|
2120 #endif
|
|
2121
|
|
2122 #ifdef FEAT_QUICKFIX
|
|
2123 /*
|
41
|
2124 * For the ":make" and ":grep" commands we insert the 'makeprg'/'grepprg'
|
7
|
2125 * option here, so things like % get expanded.
|
41
|
2126 * Don't do it when ":vimgrep" is used for ":grep".
|
7
|
2127 */
|
41
|
2128 if ((ea.cmdidx == CMD_make
|
|
2129 || ea.cmdidx == CMD_grep || ea.cmdidx == CMD_grepadd)
|
42
|
2130 && !grep_internal(ea.cmdidx))
|
7
|
2131 {
|
|
2132 char_u *new_cmdline;
|
|
2133 char_u *program;
|
|
2134 char_u *pos;
|
|
2135 char_u *ptr;
|
|
2136 int len;
|
|
2137 int i;
|
|
2138
|
|
2139 if (ea.cmdidx == CMD_grep || ea.cmdidx == CMD_grepadd)
|
|
2140 {
|
|
2141 if (*curbuf->b_p_gp == NUL)
|
|
2142 program = p_gp;
|
|
2143 else
|
|
2144 program = curbuf->b_p_gp;
|
|
2145 }
|
|
2146 else
|
|
2147 {
|
|
2148 if (*curbuf->b_p_mp == NUL)
|
|
2149 program = p_mp;
|
|
2150 else
|
|
2151 program = curbuf->b_p_mp;
|
|
2152 }
|
|
2153
|
|
2154 p = skipwhite(p);
|
|
2155
|
|
2156 if ((pos = (char_u *)strstr((char *)program, "$*")) != NULL)
|
|
2157 { /* replace $* by given arguments */
|
|
2158 i = 1;
|
|
2159 while ((pos = (char_u *)strstr((char *)pos + 2, "$*")) != NULL)
|
|
2160 ++i;
|
|
2161 len = (int)STRLEN(p);
|
|
2162 new_cmdline = alloc((int)(STRLEN(program) + i * (len - 2) + 1));
|
|
2163 if (new_cmdline == NULL)
|
|
2164 goto doend; /* out of memory */
|
|
2165 ptr = new_cmdline;
|
|
2166 while ((pos = (char_u *)strstr((char *)program, "$*")) != NULL)
|
|
2167 {
|
|
2168 i = (int)(pos - program);
|
|
2169 STRNCPY(ptr, program, i);
|
|
2170 STRCPY(ptr += i, p);
|
|
2171 ptr += len;
|
|
2172 program = pos + 2;
|
|
2173 }
|
|
2174 STRCPY(ptr, program);
|
|
2175 }
|
|
2176 else
|
|
2177 {
|
|
2178 new_cmdline = alloc((int)(STRLEN(program) + STRLEN(p) + 2));
|
|
2179 if (new_cmdline == NULL)
|
|
2180 goto doend; /* out of memory */
|
|
2181 STRCPY(new_cmdline, program);
|
|
2182 STRCAT(new_cmdline, " ");
|
|
2183 STRCAT(new_cmdline, p);
|
|
2184 }
|
|
2185 msg_make(p);
|
|
2186 /* 'ea.cmd' is not set here, because it is not used at CMD_make */
|
|
2187 vim_free(*cmdlinep);
|
|
2188 *cmdlinep = new_cmdline;
|
|
2189 p = new_cmdline;
|
|
2190 }
|
|
2191 #endif
|
|
2192
|
|
2193 /*
|
|
2194 * Skip to start of argument.
|
|
2195 * Don't do this for the ":!" command, because ":!! -l" needs the space.
|
|
2196 */
|
|
2197 if (ea.cmdidx == CMD_bang)
|
|
2198 ea.arg = p;
|
|
2199 else
|
|
2200 ea.arg = skipwhite(p);
|
|
2201
|
|
2202 /*
|
|
2203 * Check for "++opt=val" argument.
|
|
2204 * Must be first, allow ":w ++enc=utf8 !cmd"
|
|
2205 */
|
|
2206 if (ea.argt & ARGOPT)
|
|
2207 while (ea.arg[0] == '+' && ea.arg[1] == '+')
|
|
2208 if (getargopt(&ea) == FAIL && !ni)
|
|
2209 {
|
|
2210 errormsg = (char_u *)_(e_invarg);
|
|
2211 goto doend;
|
|
2212 }
|
|
2213
|
|
2214 if (ea.cmdidx == CMD_write || ea.cmdidx == CMD_update)
|
|
2215 {
|
|
2216 if (*ea.arg == '>') /* append */
|
|
2217 {
|
|
2218 if (*++ea.arg != '>') /* typed wrong */
|
|
2219 {
|
|
2220 errormsg = (char_u *)_("E494: Use w or w>>");
|
|
2221 goto doend;
|
|
2222 }
|
|
2223 ea.arg = skipwhite(ea.arg + 1);
|
|
2224 ea.append = TRUE;
|
|
2225 }
|
|
2226 else if (*ea.arg == '!' && ea.cmdidx == CMD_write) /* :w !filter */
|
|
2227 {
|
|
2228 ++ea.arg;
|
|
2229 ea.usefilter = TRUE;
|
|
2230 }
|
|
2231 }
|
|
2232
|
|
2233 if (ea.cmdidx == CMD_read)
|
|
2234 {
|
|
2235 if (ea.forceit)
|
|
2236 {
|
|
2237 ea.usefilter = TRUE; /* :r! filter if ea.forceit */
|
|
2238 ea.forceit = FALSE;
|
|
2239 }
|
|
2240 else if (*ea.arg == '!') /* :r !filter */
|
|
2241 {
|
|
2242 ++ea.arg;
|
|
2243 ea.usefilter = TRUE;
|
|
2244 }
|
|
2245 }
|
|
2246
|
|
2247 if (ea.cmdidx == CMD_lshift || ea.cmdidx == CMD_rshift)
|
|
2248 {
|
|
2249 ea.amount = 1;
|
|
2250 while (*ea.arg == *ea.cmd) /* count number of '>' or '<' */
|
|
2251 {
|
|
2252 ++ea.arg;
|
|
2253 ++ea.amount;
|
|
2254 }
|
|
2255 ea.arg = skipwhite(ea.arg);
|
|
2256 }
|
|
2257
|
|
2258 /*
|
|
2259 * Check for "+command" argument, before checking for next command.
|
|
2260 * Don't do this for ":read !cmd" and ":write !cmd".
|
|
2261 */
|
|
2262 if ((ea.argt & EDITCMD) && !ea.usefilter)
|
|
2263 ea.do_ecmd_cmd = getargcmd(&ea.arg);
|
|
2264
|
|
2265 /*
|
|
2266 * Check for '|' to separate commands and '"' to start comments.
|
|
2267 * Don't do this for ":read !cmd" and ":write !cmd".
|
|
2268 */
|
|
2269 if ((ea.argt & TRLBAR) && !ea.usefilter)
|
|
2270 separate_nextcmd(&ea);
|
|
2271
|
|
2272 /*
|
|
2273 * Check for <newline> to end a shell command.
|
|
2274 * Also do this for ":read !cmd" and ":write !cmd".
|
|
2275 */
|
|
2276 else if (ea.cmdidx == CMD_bang || ea.usefilter)
|
|
2277 {
|
|
2278 for (p = ea.arg; *p; ++p)
|
|
2279 {
|
|
2280 /* Remove one backslash before a newline, so that it's possible to
|
|
2281 * pass a newline to the shell and also a newline that is preceded
|
|
2282 * with a backslash. This makes it impossible to end a shell
|
|
2283 * command in a backslash, but that doesn't appear useful.
|
|
2284 * Halving the number of backslashes is incompatible with previous
|
|
2285 * versions. */
|
|
2286 if (*p == '\\' && p[1] == '\n')
|
|
2287 mch_memmove(p, p + 1, STRLEN(p));
|
|
2288 else if (*p == '\n')
|
|
2289 {
|
|
2290 ea.nextcmd = p + 1;
|
|
2291 *p = NUL;
|
|
2292 break;
|
|
2293 }
|
|
2294 }
|
|
2295 }
|
|
2296
|
|
2297 if ((ea.argt & DFLALL) && ea.addr_count == 0)
|
|
2298 {
|
|
2299 ea.line1 = 1;
|
|
2300 ea.line2 = curbuf->b_ml.ml_line_count;
|
|
2301 }
|
|
2302
|
|
2303 /* accept numbered register only when no count allowed (:put) */
|
|
2304 if ( (ea.argt & REGSTR)
|
|
2305 && *ea.arg != NUL
|
|
2306 #ifdef FEAT_USR_CMDS
|
|
2307 && valid_yank_reg(*ea.arg, (ea.cmdidx != CMD_put
|
|
2308 && USER_CMDIDX(ea.cmdidx)))
|
|
2309 /* Do not allow register = for user commands */
|
|
2310 && (!USER_CMDIDX(ea.cmdidx) || *ea.arg != '=')
|
|
2311 #else
|
|
2312 && valid_yank_reg(*ea.arg, ea.cmdidx != CMD_put)
|
|
2313 #endif
|
|
2314 && !((ea.argt & COUNT) && VIM_ISDIGIT(*ea.arg)))
|
|
2315 {
|
|
2316 ea.regname = *ea.arg++;
|
|
2317 #ifdef FEAT_EVAL
|
|
2318 /* for '=' register: accept the rest of the line as an expression */
|
|
2319 if (ea.arg[-1] == '=' && ea.arg[0] != NUL)
|
|
2320 {
|
|
2321 set_expr_line(vim_strsave(ea.arg));
|
|
2322 ea.arg += STRLEN(ea.arg);
|
|
2323 }
|
|
2324 #endif
|
|
2325 ea.arg = skipwhite(ea.arg);
|
|
2326 }
|
|
2327
|
|
2328 /*
|
|
2329 * Check for a count. When accepting a BUFNAME, don't use "123foo" as a
|
|
2330 * count, it's a buffer name.
|
|
2331 */
|
|
2332 if ((ea.argt & COUNT) && VIM_ISDIGIT(*ea.arg)
|
|
2333 && (!(ea.argt & BUFNAME) || *(p = skipdigits(ea.arg)) == NUL
|
|
2334 || vim_iswhite(*p)))
|
|
2335 {
|
|
2336 n = getdigits(&ea.arg);
|
|
2337 ea.arg = skipwhite(ea.arg);
|
|
2338 if (n <= 0 && !ni)
|
|
2339 {
|
|
2340 errormsg = (char_u *)_(e_zerocount);
|
|
2341 goto doend;
|
|
2342 }
|
|
2343 if (ea.argt & NOTADR) /* e.g. :buffer 2, :sleep 3 */
|
|
2344 {
|
|
2345 ea.line2 = n;
|
|
2346 if (ea.addr_count == 0)
|
|
2347 ea.addr_count = 1;
|
|
2348 }
|
|
2349 else
|
|
2350 {
|
|
2351 ea.line1 = ea.line2;
|
|
2352 ea.line2 += n - 1;
|
|
2353 ++ea.addr_count;
|
|
2354 /*
|
|
2355 * Be vi compatible: no error message for out of range.
|
|
2356 */
|
|
2357 if (ea.line2 > curbuf->b_ml.ml_line_count)
|
|
2358 ea.line2 = curbuf->b_ml.ml_line_count;
|
|
2359 }
|
|
2360 }
|
|
2361 /* no arguments allowed */
|
9
|
2362 if (!ni && !(ea.argt & EXTRA) && *ea.arg != NUL
|
|
2363 && vim_strchr((char_u *)"|\"", *ea.arg) == NULL)
|
7
|
2364 {
|
|
2365 errormsg = (char_u *)_(e_trailing);
|
|
2366 goto doend;
|
|
2367 }
|
|
2368
|
|
2369 if (!ni && (ea.argt & NEEDARG) && *ea.arg == NUL)
|
|
2370 {
|
|
2371 errormsg = (char_u *)_(e_argreq);
|
|
2372 goto doend;
|
|
2373 }
|
|
2374
|
|
2375 #ifdef FEAT_EVAL
|
|
2376 /*
|
|
2377 * Skip the command when it's not going to be executed.
|
|
2378 * The commands like :if, :endif, etc. always need to be executed.
|
|
2379 * Also make an exception for commands that handle a trailing command
|
|
2380 * themselves.
|
|
2381 */
|
|
2382 if (ea.skip)
|
|
2383 {
|
|
2384 switch (ea.cmdidx)
|
|
2385 {
|
|
2386 /* commands that need evaluation */
|
|
2387 case CMD_while:
|
|
2388 case CMD_endwhile:
|
72
|
2389 case CMD_for:
|
|
2390 case CMD_endfor:
|
7
|
2391 case CMD_if:
|
|
2392 case CMD_elseif:
|
|
2393 case CMD_else:
|
|
2394 case CMD_endif:
|
|
2395 case CMD_try:
|
|
2396 case CMD_catch:
|
|
2397 case CMD_finally:
|
|
2398 case CMD_endtry:
|
|
2399 case CMD_function:
|
|
2400 break;
|
|
2401
|
|
2402 /* Commands that handle '|' themselves. Check: A command should
|
|
2403 * either have the TRLBAR flag, appear in this list or appear in
|
|
2404 * the list at ":help :bar". */
|
|
2405 case CMD_aboveleft:
|
|
2406 case CMD_and:
|
|
2407 case CMD_belowright:
|
|
2408 case CMD_botright:
|
|
2409 case CMD_browse:
|
|
2410 case CMD_call:
|
|
2411 case CMD_confirm:
|
|
2412 case CMD_delfunction:
|
|
2413 case CMD_djump:
|
|
2414 case CMD_dlist:
|
|
2415 case CMD_dsearch:
|
|
2416 case CMD_dsplit:
|
|
2417 case CMD_echo:
|
|
2418 case CMD_echoerr:
|
|
2419 case CMD_echomsg:
|
|
2420 case CMD_echon:
|
|
2421 case CMD_execute:
|
|
2422 case CMD_help:
|
|
2423 case CMD_hide:
|
|
2424 case CMD_ijump:
|
|
2425 case CMD_ilist:
|
|
2426 case CMD_isearch:
|
|
2427 case CMD_isplit:
|
22
|
2428 case CMD_keepalt:
|
7
|
2429 case CMD_keepjumps:
|
|
2430 case CMD_keepmarks:
|
|
2431 case CMD_leftabove:
|
|
2432 case CMD_let:
|
|
2433 case CMD_lockmarks:
|
|
2434 case CMD_match:
|
14
|
2435 case CMD_mzscheme:
|
7
|
2436 case CMD_perl:
|
|
2437 case CMD_psearch:
|
|
2438 case CMD_python:
|
|
2439 case CMD_return:
|
|
2440 case CMD_rightbelow:
|
|
2441 case CMD_ruby:
|
|
2442 case CMD_silent:
|
|
2443 case CMD_smagic:
|
|
2444 case CMD_snomagic:
|
|
2445 case CMD_substitute:
|
|
2446 case CMD_syntax:
|
|
2447 case CMD_tcl:
|
|
2448 case CMD_throw:
|
|
2449 case CMD_tilde:
|
|
2450 case CMD_topleft:
|
|
2451 case CMD_unlet:
|
|
2452 case CMD_verbose:
|
|
2453 case CMD_vertical:
|
|
2454 break;
|
|
2455
|
|
2456 default: goto doend;
|
|
2457 }
|
|
2458 }
|
|
2459 #endif
|
|
2460
|
|
2461 if (ea.argt & XFILE)
|
|
2462 {
|
|
2463 if (expand_filename(&ea, cmdlinep, &errormsg) == FAIL)
|
|
2464 goto doend;
|
|
2465 }
|
|
2466
|
|
2467 #ifdef FEAT_LISTCMDS
|
|
2468 /*
|
|
2469 * Accept buffer name. Cannot be used at the same time with a buffer
|
|
2470 * number. Don't do this for a user command.
|
|
2471 */
|
|
2472 if ((ea.argt & BUFNAME) && *ea.arg != NUL && ea.addr_count == 0
|
|
2473 # ifdef FEAT_USR_CMDS
|
|
2474 && !USER_CMDIDX(ea.cmdidx)
|
|
2475 # endif
|
|
2476 )
|
|
2477 {
|
|
2478 /*
|
|
2479 * :bdelete, :bwipeout and :bunload take several arguments, separated
|
|
2480 * by spaces: find next space (skipping over escaped characters).
|
|
2481 * The others take one argument: ignore trailing spaces.
|
|
2482 */
|
|
2483 if (ea.cmdidx == CMD_bdelete || ea.cmdidx == CMD_bwipeout
|
|
2484 || ea.cmdidx == CMD_bunload)
|
|
2485 p = skiptowhite_esc(ea.arg);
|
|
2486 else
|
|
2487 {
|
|
2488 p = ea.arg + STRLEN(ea.arg);
|
|
2489 while (p > ea.arg && vim_iswhite(p[-1]))
|
|
2490 --p;
|
|
2491 }
|
|
2492 ea.line2 = buflist_findpat(ea.arg, p, (ea.argt & BUFUNL) != 0, FALSE);
|
|
2493 if (ea.line2 < 0) /* failed */
|
|
2494 goto doend;
|
|
2495 ea.addr_count = 1;
|
|
2496 ea.arg = skipwhite(p);
|
|
2497 }
|
|
2498 #endif
|
|
2499
|
|
2500 /*
|
|
2501 * 6. switch on command name
|
|
2502 *
|
|
2503 * The "ea" structure holds the arguments that can be used.
|
|
2504 */
|
|
2505 ea.cmdlinep = cmdlinep;
|
|
2506 ea.getline = getline;
|
|
2507 ea.cookie = cookie;
|
|
2508 #ifdef FEAT_EVAL
|
|
2509 ea.cstack = cstack;
|
|
2510 #endif
|
|
2511
|
|
2512 #ifdef FEAT_USR_CMDS
|
|
2513 if (USER_CMDIDX(ea.cmdidx))
|
|
2514 {
|
|
2515 /*
|
|
2516 * Execute a user-defined command.
|
|
2517 */
|
|
2518 do_ucmd(&ea);
|
|
2519 }
|
|
2520 else
|
|
2521 #endif
|
|
2522 {
|
|
2523 /*
|
|
2524 * Call the function to execute the command.
|
|
2525 */
|
|
2526 ea.errmsg = NULL;
|
|
2527 (cmdnames[ea.cmdidx].cmd_func)(&ea);
|
|
2528 if (ea.errmsg != NULL)
|
|
2529 errormsg = (char_u *)_(ea.errmsg);
|
|
2530 }
|
|
2531
|
|
2532 #ifdef FEAT_EVAL
|
|
2533 /*
|
|
2534 * If the command just executed called do_cmdline(), any throw or ":return"
|
|
2535 * or ":finish" encountered there must also check the cstack of the still
|
|
2536 * active do_cmdline() that called this do_one_cmd(). Rethrow an uncaught
|
|
2537 * exception, or reanimate a returned function or finished script file and
|
|
2538 * return or finish it again.
|
|
2539 */
|
|
2540 if (need_rethrow)
|
|
2541 do_throw(cstack);
|
|
2542 else if (check_cstack)
|
|
2543 {
|
|
2544 if (source_finished(getline, cookie))
|
|
2545 do_finish(&ea, TRUE);
|
|
2546 else if (getline_equal(getline, cookie, get_func_line)
|
|
2547 && current_func_returned())
|
|
2548 do_return(&ea, TRUE, FALSE, NULL);
|
|
2549 }
|
|
2550 need_rethrow = check_cstack = FALSE;
|
|
2551 #endif
|
|
2552
|
|
2553 doend:
|
|
2554 if (curwin->w_cursor.lnum == 0) /* can happen with zero line number */
|
|
2555 curwin->w_cursor.lnum = 1;
|
|
2556
|
|
2557 if (errormsg != NULL && *errormsg != NUL && !did_emsg)
|
|
2558 {
|
|
2559 if (sourcing)
|
|
2560 {
|
|
2561 if (errormsg != IObuff)
|
|
2562 {
|
|
2563 STRCPY(IObuff, errormsg);
|
|
2564 errormsg = IObuff;
|
|
2565 }
|
|
2566 STRCAT(errormsg, ": ");
|
|
2567 STRNCAT(errormsg, *cmdlinep, IOSIZE - STRLEN(IObuff));
|
|
2568 }
|
|
2569 emsg(errormsg);
|
|
2570 }
|
|
2571 #ifdef FEAT_EVAL
|
|
2572 do_errthrow(cstack,
|
|
2573 (ea.cmdidx != CMD_SIZE
|
|
2574 # ifdef FEAT_USR_CMDS
|
|
2575 && !USER_CMDIDX(ea.cmdidx)
|
|
2576 # endif
|
|
2577 ) ? cmdnames[(int)ea.cmdidx].cmd_name : (char_u *)NULL);
|
|
2578 #endif
|
|
2579
|
|
2580 if (verbose_save >= 0)
|
|
2581 p_verbose = verbose_save;
|
|
2582
|
|
2583 cmdmod = save_cmdmod;
|
|
2584
|
|
2585 if (did_silent > 0)
|
|
2586 {
|
|
2587 /* messages could be enabled for a serious error, need to check if the
|
|
2588 * counters don't become negative */
|
|
2589 msg_silent -= did_silent;
|
|
2590 if (msg_silent < 0)
|
|
2591 msg_silent = 0;
|
|
2592 emsg_silent -= did_esilent;
|
|
2593 if (emsg_silent < 0)
|
|
2594 emsg_silent = 0;
|
|
2595 /* Restore msg_scroll, it's set by file I/O commands, even when no
|
|
2596 * message is actually displayed. */
|
|
2597 msg_scroll = save_msg_scroll;
|
|
2598 }
|
|
2599
|
28
|
2600 #ifdef HAVE_SANDBOX
|
|
2601 if (did_sandbox)
|
|
2602 --sandbox;
|
|
2603 #endif
|
|
2604
|
7
|
2605 if (ea.nextcmd && *ea.nextcmd == NUL) /* not really a next command */
|
|
2606 ea.nextcmd = NULL;
|
|
2607
|
|
2608 #ifdef FEAT_EVAL
|
|
2609 --ex_nesting_level;
|
|
2610 #endif
|
|
2611
|
|
2612 return ea.nextcmd;
|
|
2613 }
|
|
2614 #if (_MSC_VER == 1200)
|
|
2615 # pragma optimize( "", on )
|
|
2616 #endif
|
|
2617
|
|
2618 /*
|
|
2619 * Check for a command modifier command with optional tail.
|
|
2620 * If there is a match advance "pp" to the argument and return TRUE.
|
|
2621 */
|
|
2622 static int
|
|
2623 checkforcmd(pp, cmd, len)
|
|
2624 char_u **pp; /* start of command line */
|
|
2625 char *cmd; /* name of command */
|
|
2626 int len; /* required length */
|
|
2627 {
|
|
2628 int i;
|
|
2629
|
|
2630 for (i = 0; cmd[i] != NUL; ++i)
|
|
2631 if (cmd[i] != (*pp)[i])
|
|
2632 break;
|
|
2633 if (i >= len && !isalpha((*pp)[i]))
|
|
2634 {
|
|
2635 *pp = skipwhite(*pp + i);
|
|
2636 return TRUE;
|
|
2637 }
|
|
2638 return FALSE;
|
|
2639 }
|
|
2640
|
|
2641 /*
|
|
2642 * Find an Ex command by its name, either built-in or user.
|
|
2643 * Name can be found at eap->cmd.
|
|
2644 * Returns pointer to char after the command name.
|
|
2645 * Returns NULL for an ambiguous user command.
|
|
2646 */
|
|
2647 /*ARGSUSED*/
|
|
2648 static char_u *
|
|
2649 find_command(eap, full)
|
|
2650 exarg_T *eap;
|
|
2651 int *full;
|
|
2652 {
|
|
2653 int len;
|
|
2654 char_u *p;
|
|
2655
|
|
2656 /*
|
|
2657 * Isolate the command and search for it in the command table.
|
|
2658 * Exeptions:
|
|
2659 * - the 'k' command can directly be followed by any character.
|
|
2660 * - the 's' command can be followed directly by 'c', 'g', 'i', 'I' or 'r'
|
|
2661 * but :sre[wind] is another command, as are :scrip[tnames],
|
|
2662 * :scs[cope], :sim[alt], :sig[ns] and :sil[ent].
|
|
2663 */
|
|
2664 p = eap->cmd;
|
|
2665 if (*p == 'k')
|
|
2666 {
|
|
2667 eap->cmdidx = CMD_k;
|
|
2668 ++p;
|
|
2669 }
|
|
2670 else if (p[0] == 's'
|
|
2671 && ((p[1] == 'c' && p[2] != 's' && p[2] != 'r' && p[3] != 'i' && p[4] != 'p')
|
|
2672 || p[1] == 'g'
|
|
2673 || (p[1] == 'i' && p[2] != 'm' && p[2] != 'l' && p[2] != 'g')
|
|
2674 || p[1] == 'I'
|
|
2675 || (p[1] == 'r' && p[2] != 'e')))
|
|
2676 {
|
|
2677 eap->cmdidx = CMD_substitute;
|
|
2678 ++p;
|
|
2679 }
|
|
2680 else
|
|
2681 {
|
|
2682 while (ASCII_ISALPHA(*p))
|
|
2683 ++p;
|
|
2684 /* check for non-alpha command */
|
|
2685 if (p == eap->cmd && vim_strchr((char_u *)"@*!=><&~#", *p) != NULL)
|
|
2686 ++p;
|
|
2687 len = (int)(p - eap->cmd);
|
|
2688
|
|
2689 if (ASCII_ISLOWER(*eap->cmd))
|
|
2690 eap->cmdidx = cmdidxs[CharOrdLow(*eap->cmd)];
|
|
2691 else
|
|
2692 eap->cmdidx = cmdidxs[26];
|
|
2693
|
|
2694 for ( ; (int)eap->cmdidx < (int)CMD_SIZE;
|
|
2695 eap->cmdidx = (cmdidx_T)((int)eap->cmdidx + 1))
|
|
2696 if (STRNCMP(cmdnames[(int)eap->cmdidx].cmd_name, (char *)eap->cmd,
|
|
2697 (size_t)len) == 0)
|
|
2698 {
|
|
2699 #ifdef FEAT_EVAL
|
|
2700 if (full != NULL
|
|
2701 && cmdnames[(int)eap->cmdidx].cmd_name[len] == NUL)
|
|
2702 *full = TRUE;
|
|
2703 #endif
|
|
2704 break;
|
|
2705 }
|
|
2706
|
|
2707 #ifdef FEAT_USR_CMDS
|
|
2708 /* Look for a user defined command as a last resort */
|
|
2709 if (eap->cmdidx == CMD_SIZE && *eap->cmd >= 'A' && *eap->cmd <= 'Z')
|
|
2710 {
|
|
2711 ucmd_T *cmd;
|
|
2712 int j, k, matchlen = 0;
|
|
2713 int found = FALSE, possible = FALSE;
|
|
2714 char_u *cp, *np; /* Point into typed cmd and test name */
|
|
2715 garray_T *gap;
|
|
2716 int amb_local = FALSE; /* Found ambiguous buffer-local
|
|
2717 command, only full match global
|
|
2718 is accepted. */
|
|
2719
|
|
2720 /* User defined commands may contain numbers */
|
|
2721 while (ASCII_ISALNUM(*p))
|
|
2722 ++p;
|
|
2723 len = (int)(p - eap->cmd);
|
|
2724
|
|
2725 /*
|
|
2726 * Look for buffer-local user commands first, then global ones.
|
|
2727 */
|
|
2728 gap = &curbuf->b_ucmds;
|
|
2729 for (;;)
|
|
2730 {
|
|
2731 for (j = 0; j < gap->ga_len; ++j)
|
|
2732 {
|
|
2733 cmd = USER_CMD_GA(gap, j);
|
|
2734 cp = eap->cmd;
|
|
2735 np = cmd->uc_name;
|
|
2736 k = 0;
|
|
2737 while (k < len && *np != NUL && *cp++ == *np++)
|
|
2738 k++;
|
|
2739 if (k == len || (*np == NUL && vim_isdigit(eap->cmd[k])))
|
|
2740 {
|
|
2741 /* If finding a second match, the command is
|
|
2742 * ambiguous. But not if a buffer-local command
|
|
2743 * wasn't a full match and a global command is a full
|
|
2744 * match. */
|
|
2745 if (k == len && found && *np != NUL)
|
|
2746 {
|
|
2747 if (gap == &ucmds)
|
|
2748 return NULL;
|
|
2749 amb_local = TRUE;
|
|
2750 }
|
|
2751
|
|
2752 if (!found || (k == len && *np == NUL))
|
|
2753 {
|
|
2754 /* If we matched up to a digit, then there could
|
|
2755 * be another command including the digit that we
|
|
2756 * should use instead.
|
|
2757 */
|
|
2758 if (k == len)
|
|
2759 found = TRUE;
|
|
2760 else
|
|
2761 possible = TRUE;
|
|
2762
|
|
2763 if (gap == &ucmds)
|
|
2764 eap->cmdidx = CMD_USER;
|
|
2765 else
|
|
2766 eap->cmdidx = CMD_USER_BUF;
|
|
2767 eap->argt = cmd->uc_argt;
|
|
2768 eap->useridx = j;
|
|
2769
|
|
2770 /* Do not search for further abbreviations
|
|
2771 * if this is an exact match. */
|
|
2772 matchlen = k;
|
|
2773 if (k == len && *np == NUL)
|
|
2774 {
|
|
2775 if (full != NULL)
|
|
2776 *full = TRUE;
|
|
2777 amb_local = FALSE;
|
|
2778 break;
|
|
2779 }
|
|
2780 }
|
|
2781 }
|
|
2782 }
|
|
2783
|
|
2784 /* Stop if we found a full match or searched all. */
|
|
2785 if (j < gap->ga_len || gap == &ucmds)
|
|
2786 break;
|
|
2787 gap = &ucmds;
|
|
2788 }
|
|
2789
|
|
2790 /* Only found ambiguous matches. */
|
|
2791 if (amb_local)
|
|
2792 return NULL;
|
|
2793
|
|
2794 /* The match we found may be followed immediately by a
|
|
2795 * number. Move *p back to point to it.
|
|
2796 */
|
|
2797 if (found || possible)
|
|
2798 p += matchlen - len;
|
|
2799 }
|
|
2800 #endif
|
|
2801
|
|
2802 if (len == 0)
|
|
2803 eap->cmdidx = CMD_SIZE;
|
|
2804 }
|
|
2805
|
|
2806 return p;
|
|
2807 }
|
|
2808
|
|
2809 #if defined(FEAT_EVAL) || defined(PROTO)
|
|
2810 /*
|
|
2811 * Return > 0 if an Ex command "name" exists.
|
|
2812 * Return 2 if there is an exact match.
|
|
2813 * Return 3 if there is an ambiguous match.
|
|
2814 */
|
|
2815 int
|
|
2816 cmd_exists(name)
|
|
2817 char_u *name;
|
|
2818 {
|
|
2819 exarg_T ea;
|
|
2820 int full = FALSE;
|
|
2821 int i;
|
|
2822 int j;
|
|
2823 static struct cmdmod
|
|
2824 {
|
|
2825 char *name;
|
|
2826 int minlen;
|
|
2827 } cmdmods[] = {
|
|
2828 {"aboveleft", 3},
|
|
2829 {"belowright", 3},
|
|
2830 {"botright", 2},
|
|
2831 {"browse", 3},
|
|
2832 {"confirm", 4},
|
|
2833 {"hide", 3},
|
22
|
2834 {"keepalt", 5},
|
7
|
2835 {"keepjumps", 5},
|
|
2836 {"keepmarks", 3},
|
|
2837 {"leftabove", 5},
|
|
2838 {"lockmarks", 3},
|
|
2839 {"rightbelow", 6},
|
28
|
2840 {"sandbox", 3},
|
7
|
2841 {"silent", 3},
|
|
2842 {"topleft", 2},
|
|
2843 {"verbose", 4},
|
|
2844 {"vertical", 4},
|
|
2845 };
|
|
2846
|
|
2847 /* Check command modifiers. */
|
|
2848 for (i = 0; i < sizeof(cmdmods) / sizeof(struct cmdmod); ++i)
|
|
2849 {
|
|
2850 for (j = 0; name[j] != NUL; ++j)
|
|
2851 if (name[j] != cmdmods[i].name[j])
|
|
2852 break;
|
|
2853 if (name[j] == NUL && j >= cmdmods[i].minlen)
|
|
2854 return (cmdmods[i].name[j] == NUL ? 2 : 1);
|
|
2855 }
|
|
2856
|
|
2857 /* Check built-in commands and user defined commands. */
|
|
2858 ea.cmd = name;
|
|
2859 ea.cmdidx = (cmdidx_T)0;
|
|
2860 if (find_command(&ea, &full) == NULL)
|
|
2861 return 3;
|
|
2862 return (ea.cmdidx == CMD_SIZE ? 0 : (full ? 2 : 1));
|
|
2863 }
|
|
2864 #endif
|
|
2865
|
|
2866 /*
|
|
2867 * This is all pretty much copied from do_one_cmd(), with all the extra stuff
|
|
2868 * we don't need/want deleted. Maybe this could be done better if we didn't
|
|
2869 * repeat all this stuff. The only problem is that they may not stay
|
|
2870 * perfectly compatible with each other, but then the command line syntax
|
|
2871 * probably won't change that much -- webb.
|
|
2872 */
|
|
2873 char_u *
|
|
2874 set_one_cmd_context(xp, buff)
|
|
2875 expand_T *xp;
|
|
2876 char_u *buff; /* buffer for command string */
|
|
2877 {
|
|
2878 char_u *p;
|
|
2879 char_u *cmd, *arg;
|
|
2880 int i = 0;
|
|
2881 cmdidx_T cmdidx;
|
|
2882 long_u argt = 0;
|
|
2883 #if defined(FEAT_USR_CMDS) && defined(FEAT_CMDL_COMPL)
|
|
2884 int compl = EXPAND_NOTHING;
|
|
2885 #endif
|
|
2886 #ifdef FEAT_CMDL_COMPL
|
|
2887 int delim;
|
|
2888 #endif
|
|
2889 int forceit = FALSE;
|
|
2890 int usefilter = FALSE; /* filter instead of file name */
|
|
2891
|
|
2892 xp->xp_pattern = buff;
|
|
2893 xp->xp_context = EXPAND_COMMANDS; /* Default until we get past command */
|
|
2894 xp->xp_backslash = XP_BS_NONE;
|
|
2895 #if defined(FEAT_USR_CMDS) && defined(FEAT_EVAL) && defined(FEAT_CMDL_COMPL)
|
|
2896 xp->xp_arg = NULL;
|
|
2897 #endif
|
|
2898
|
|
2899 /*
|
|
2900 * 2. skip comment lines and leading space, colons or bars
|
|
2901 */
|
|
2902 for (cmd = buff; vim_strchr((char_u *)" \t:|", *cmd) != NULL; cmd++)
|
|
2903 ;
|
|
2904 xp->xp_pattern = cmd;
|
|
2905
|
|
2906 if (*cmd == NUL)
|
|
2907 return NULL;
|
|
2908 if (*cmd == '"') /* ignore comment lines */
|
|
2909 {
|
|
2910 xp->xp_context = EXPAND_NOTHING;
|
|
2911 return NULL;
|
|
2912 }
|
|
2913
|
|
2914 /*
|
|
2915 * 3. parse a range specifier of the form: addr [,addr] [;addr] ..
|
|
2916 */
|
|
2917 cmd = skip_range(cmd, &xp->xp_context);
|
|
2918
|
|
2919 /*
|
|
2920 * 4. parse command
|
|
2921 */
|
|
2922
|
|
2923 cmd = skipwhite(cmd);
|
|
2924 xp->xp_pattern = cmd;
|
|
2925 if (*cmd == NUL)
|
|
2926 return NULL;
|
|
2927 if (*cmd == '"')
|
|
2928 {
|
|
2929 xp->xp_context = EXPAND_NOTHING;
|
|
2930 return NULL;
|
|
2931 }
|
|
2932
|
|
2933 if (*cmd == '|' || *cmd == '\n')
|
|
2934 return cmd + 1; /* There's another command */
|
|
2935
|
|
2936 /*
|
|
2937 * Isolate the command and search for it in the command table.
|
|
2938 * Exceptions:
|
|
2939 * - the 'k' command can directly be followed by any character, but
|
22
|
2940 * do accept "keepmarks", "keepalt" and "keepjumps".
|
7
|
2941 * - the 's' command can be followed directly by 'c', 'g', 'i', 'I' or 'r'
|
|
2942 */
|
|
2943 if (*cmd == 'k' && cmd[1] != 'e')
|
|
2944 {
|
|
2945 cmdidx = CMD_k;
|
|
2946 p = cmd + 1;
|
|
2947 }
|
|
2948 else
|
|
2949 {
|
|
2950 p = cmd;
|
|
2951 while (ASCII_ISALPHA(*p) || *p == '*') /* Allow * wild card */
|
|
2952 ++p;
|
|
2953 /* check for non-alpha command */
|
|
2954 if (p == cmd && vim_strchr((char_u *)"@*!=><&~#", *p) != NULL)
|
|
2955 ++p;
|
|
2956 i = (int)(p - cmd);
|
|
2957
|
|
2958 if (i == 0)
|
|
2959 {
|
|
2960 xp->xp_context = EXPAND_UNSUCCESSFUL;
|
|
2961 return NULL;
|
|
2962 }
|
|
2963 for (cmdidx = (cmdidx_T)0; (int)cmdidx < (int)CMD_SIZE;
|
|
2964 cmdidx = (cmdidx_T)((int)cmdidx + 1))
|
|
2965 if (STRNCMP(cmdnames[(int)cmdidx].cmd_name, cmd, (size_t)i) == 0)
|
|
2966 break;
|
|
2967
|
|
2968 #ifdef FEAT_USR_CMDS
|
|
2969 if (cmd[0] >= 'A' && cmd[0] <= 'Z')
|
|
2970 {
|
|
2971 while (ASCII_ISALNUM(*p) || *p == '*') /* Allow * wild card */
|
|
2972 ++p;
|
|
2973 i = (int)(p - cmd);
|
|
2974 }
|
|
2975 #endif
|
|
2976 }
|
|
2977
|
|
2978 /*
|
|
2979 * If the cursor is touching the command, and it ends in an alpha-numeric
|
|
2980 * character, complete the command name.
|
|
2981 */
|
|
2982 if (*p == NUL && ASCII_ISALNUM(p[-1]))
|
|
2983 return NULL;
|
|
2984
|
|
2985 if (cmdidx == CMD_SIZE)
|
|
2986 {
|
|
2987 if (*cmd == 's' && vim_strchr((char_u *)"cgriI", cmd[1]) != NULL)
|
|
2988 {
|
|
2989 cmdidx = CMD_substitute;
|
|
2990 p = cmd + 1;
|
|
2991 }
|
|
2992 #ifdef FEAT_USR_CMDS
|
|
2993 else if (cmd[0] >= 'A' && cmd[0] <= 'Z')
|
|
2994 {
|
|
2995 /* Look for a user defined command as a last resort */
|
|
2996 ucmd_T *uc;
|
|
2997 int j, k, matchlen = 0;
|
|
2998 int found = FALSE, possible = FALSE;
|
|
2999 char_u *cp, *np; /* Point into typed cmd and test name */
|
|
3000 garray_T *gap;
|
|
3001
|
|
3002 gap = &curbuf->b_ucmds;
|
|
3003 for (;;)
|
|
3004 {
|
|
3005 uc = USER_CMD_GA(gap, 0);
|
|
3006 for (j = 0; j < gap->ga_len; ++j, ++uc)
|
|
3007 {
|
|
3008 cp = cmd;
|
|
3009 np = uc->uc_name;
|
|
3010 k = 0;
|
|
3011 while (k < i && *np != NUL && *cp++ == *np++)
|
|
3012 k++;
|
|
3013 if (k == i || (*np == NUL && VIM_ISDIGIT(cmd[k])))
|
|
3014 {
|
|
3015 if (k == i && found)
|
|
3016 {
|
|
3017 /* Ambiguous abbreviation */
|
|
3018 xp->xp_context = EXPAND_UNSUCCESSFUL;
|
|
3019 return NULL;
|
|
3020 }
|
|
3021 if (!found)
|
|
3022 {
|
|
3023 /* If we matched up to a digit, then there could
|
|
3024 * be another command including the digit that we
|
|
3025 * should use instead.
|
|
3026 */
|
|
3027 if (k == i)
|
|
3028 found = TRUE;
|
|
3029 else
|
|
3030 possible = TRUE;
|
|
3031
|
|
3032 if (gap == &ucmds)
|
|
3033 cmdidx = CMD_USER;
|
|
3034 else
|
|
3035 cmdidx = CMD_USER_BUF;
|
|
3036 argt = uc->uc_argt;
|
|
3037 #ifdef FEAT_CMDL_COMPL
|
|
3038 compl = uc->uc_compl;
|
|
3039 # ifdef FEAT_EVAL
|
|
3040 xp->xp_arg = uc->uc_compl_arg;
|
|
3041 xp->xp_scriptID = uc->uc_scriptID;
|
|
3042 # endif
|
|
3043 #endif
|
|
3044 /* Do not search for further abbreviations
|
|
3045 * if this is an exact match
|
|
3046 */
|
|
3047 matchlen = k;
|
|
3048 if (k == i && *np == NUL)
|
|
3049 break;
|
|
3050 }
|
|
3051 }
|
|
3052 }
|
|
3053 if (gap == &ucmds || j < gap->ga_len)
|
|
3054 break;
|
|
3055 gap = &ucmds;
|
|
3056 }
|
|
3057
|
|
3058 /* The match we found may be followed immediately by a
|
|
3059 * number. Move *p back to point to it.
|
|
3060 */
|
|
3061 if (found || possible)
|
|
3062 p += matchlen - i;
|
|
3063 }
|
|
3064 #endif
|
|
3065 }
|
|
3066 if (cmdidx == CMD_SIZE)
|
|
3067 {
|
|
3068 /* Not still touching the command and it was an illegal one */
|
|
3069 xp->xp_context = EXPAND_UNSUCCESSFUL;
|
|
3070 return NULL;
|
|
3071 }
|
|
3072
|
|
3073 xp->xp_context = EXPAND_NOTHING; /* Default now that we're past command */
|
|
3074
|
|
3075 if (*p == '!') /* forced commands */
|
|
3076 {
|
|
3077 forceit = TRUE;
|
|
3078 ++p;
|
|
3079 }
|
|
3080
|
|
3081 /*
|
|
3082 * 5. parse arguments
|
|
3083 */
|
|
3084 #ifdef FEAT_USR_CMDS
|
|
3085 if (!USER_CMDIDX(cmdidx))
|
|
3086 #endif
|
|
3087 argt = cmdnames[(int)cmdidx].cmd_argt;
|
|
3088
|
|
3089 arg = skipwhite(p);
|
|
3090
|
|
3091 if (cmdidx == CMD_write || cmdidx == CMD_update)
|
|
3092 {
|
|
3093 if (*arg == '>') /* append */
|
|
3094 {
|
|
3095 if (*++arg == '>')
|
|
3096 ++arg;
|
|
3097 arg = skipwhite(arg);
|
|
3098 }
|
|
3099 else if (*arg == '!' && cmdidx == CMD_write) /* :w !filter */
|
|
3100 {
|
|
3101 ++arg;
|
|
3102 usefilter = TRUE;
|
|
3103 }
|
|
3104 }
|
|
3105
|
|
3106 if (cmdidx == CMD_read)
|
|
3107 {
|
|
3108 usefilter = forceit; /* :r! filter if forced */
|
|
3109 if (*arg == '!') /* :r !filter */
|
|
3110 {
|
|
3111 ++arg;
|
|
3112 usefilter = TRUE;
|
|
3113 }
|
|
3114 }
|
|
3115
|
|
3116 if (cmdidx == CMD_lshift || cmdidx == CMD_rshift)
|
|
3117 {
|
|
3118 while (*arg == *cmd) /* allow any number of '>' or '<' */
|
|
3119 ++arg;
|
|
3120 arg = skipwhite(arg);
|
|
3121 }
|
|
3122
|
|
3123 /* Does command allow "+command"? */
|
|
3124 if ((argt & EDITCMD) && !usefilter && *arg == '+')
|
|
3125 {
|
|
3126 /* Check if we're in the +command */
|
|
3127 p = arg + 1;
|
|
3128 arg = skip_cmd_arg(arg, FALSE);
|
|
3129
|
|
3130 /* Still touching the command after '+'? */
|
|
3131 if (*arg == NUL)
|
|
3132 return p;
|
|
3133
|
|
3134 /* Skip space(s) after +command to get to the real argument */
|
|
3135 arg = skipwhite(arg);
|
|
3136 }
|
|
3137
|
|
3138 /*
|
|
3139 * Check for '|' to separate commands and '"' to start comments.
|
|
3140 * Don't do this for ":read !cmd" and ":write !cmd".
|
|
3141 */
|
|
3142 if ((argt & TRLBAR) && !usefilter)
|
|
3143 {
|
|
3144 p = arg;
|
|
3145 /* ":redir @" is not the start of a comment */
|
|
3146 if (cmdidx == CMD_redir && p[0] == '@' && p[1] == '"')
|
|
3147 p += 2;
|
|
3148 while (*p)
|
|
3149 {
|
|
3150 if (*p == Ctrl_V)
|
|
3151 {
|
|
3152 if (p[1] != NUL)
|
|
3153 ++p;
|
|
3154 }
|
|
3155 else if ( (*p == '"' && !(argt & NOTRLCOM))
|
|
3156 || *p == '|' || *p == '\n')
|
|
3157 {
|
|
3158 if (*(p - 1) != '\\')
|
|
3159 {
|
|
3160 if (*p == '|' || *p == '\n')
|
|
3161 return p + 1;
|
|
3162 return NULL; /* It's a comment */
|
|
3163 }
|
|
3164 }
|
39
|
3165 mb_ptr_adv(p);
|
7
|
3166 }
|
|
3167 }
|
|
3168
|
|
3169 /* no arguments allowed */
|
|
3170 if (!(argt & EXTRA) && *arg != NUL &&
|
|
3171 vim_strchr((char_u *)"|\"", *arg) == NULL)
|
|
3172 return NULL;
|
|
3173
|
|
3174 /* Find start of last argument (argument just before cursor): */
|
|
3175 p = buff + STRLEN(buff);
|
|
3176 while (p != arg && *p != ' ' && *p != TAB)
|
|
3177 p--;
|
|
3178 if (*p == ' ' || *p == TAB)
|
|
3179 p++;
|
|
3180 xp->xp_pattern = p;
|
|
3181
|
42
|
3182 if ((argt & XFILE)
|
|
3183 #ifdef FEAT_QUICKFIX
|
|
3184 || cmdidx == CMD_vimgrep
|
|
3185 || cmdidx == CMD_vimgrepadd
|
|
3186 || grep_internal(cmdidx)
|
|
3187 #endif
|
|
3188 )
|
7
|
3189 {
|
|
3190 int in_quote = FALSE;
|
|
3191 char_u *bow = NULL; /* Beginning of word */
|
|
3192
|
|
3193 /*
|
|
3194 * Allow spaces within back-quotes to count as part of the argument
|
|
3195 * being expanded.
|
|
3196 */
|
|
3197 xp->xp_pattern = skipwhite(arg);
|
|
3198 for (p = xp->xp_pattern; *p; )
|
|
3199 {
|
40
|
3200 if (*p == '\\' && p[1] != NUL)
|
7
|
3201 ++p;
|
|
3202 #ifdef SPACE_IN_FILENAME
|
|
3203 else if (vim_iswhite(*p) && (!(argt & NOSPC) || usefilter))
|
|
3204 #else
|
|
3205 else if (vim_iswhite(*p))
|
|
3206 #endif
|
|
3207 {
|
|
3208 p = skipwhite(p);
|
|
3209 if (in_quote)
|
|
3210 bow = p;
|
|
3211 else
|
|
3212 xp->xp_pattern = p;
|
|
3213 --p;
|
|
3214 }
|
|
3215 else if (*p == '`')
|
|
3216 {
|
|
3217 if (!in_quote)
|
|
3218 {
|
|
3219 xp->xp_pattern = p;
|
|
3220 bow = p + 1;
|
|
3221 }
|
|
3222 in_quote = !in_quote;
|
|
3223 }
|
39
|
3224 mb_ptr_adv(p);
|
7
|
3225 }
|
|
3226
|
|
3227 /*
|
|
3228 * If we are still inside the quotes, and we passed a space, just
|
|
3229 * expand from there.
|
|
3230 */
|
|
3231 if (bow != NULL && in_quote)
|
|
3232 xp->xp_pattern = bow;
|
|
3233 xp->xp_context = EXPAND_FILES;
|
|
3234
|
|
3235 /* Check for environment variable */
|
|
3236 if (*xp->xp_pattern == '$'
|
|
3237 #if defined(MSDOS) || defined(MSWIN) || defined(OS2)
|
|
3238 || *xp->xp_pattern == '%'
|
|
3239 #endif
|
|
3240 )
|
|
3241 {
|
|
3242 for (p = xp->xp_pattern + 1; *p != NUL; ++p)
|
|
3243 if (!vim_isIDc(*p))
|
|
3244 break;
|
|
3245 if (*p == NUL)
|
|
3246 {
|
|
3247 xp->xp_context = EXPAND_ENV_VARS;
|
|
3248 ++xp->xp_pattern;
|
17
|
3249 #if defined(FEAT_USR_CMDS) && defined(FEAT_CMDL_COMPL)
|
|
3250 /* Avoid that the assignment uses EXPAND_FILES again. */
|
|
3251 if (compl != EXPAND_USER_DEFINED)
|
|
3252 compl = EXPAND_ENV_VARS;
|
|
3253 #endif
|
7
|
3254 }
|
|
3255 }
|
|
3256 }
|
|
3257
|
|
3258 /*
|
|
3259 * 6. switch on command name
|
|
3260 */
|
|
3261 switch (cmdidx)
|
|
3262 {
|
|
3263 case CMD_cd:
|
|
3264 case CMD_chdir:
|
|
3265 case CMD_lcd:
|
|
3266 case CMD_lchdir:
|
|
3267 if (xp->xp_context == EXPAND_FILES)
|
|
3268 xp->xp_context = EXPAND_DIRECTORIES;
|
|
3269 break;
|
|
3270 case CMD_help:
|
|
3271 xp->xp_context = EXPAND_HELP;
|
|
3272 xp->xp_pattern = arg;
|
|
3273 break;
|
|
3274
|
|
3275 /* Command modifiers: return the argument. */
|
|
3276 case CMD_aboveleft:
|
|
3277 case CMD_belowright:
|
|
3278 case CMD_botright:
|
|
3279 case CMD_browse:
|
|
3280 case CMD_confirm:
|
|
3281 case CMD_folddoclosed:
|
|
3282 case CMD_folddoopen:
|
|
3283 case CMD_hide:
|
22
|
3284 case CMD_keepalt:
|
7
|
3285 case CMD_keepjumps:
|
|
3286 case CMD_keepmarks:
|
|
3287 case CMD_leftabove:
|
|
3288 case CMD_lockmarks:
|
|
3289 case CMD_rightbelow:
|
|
3290 case CMD_silent:
|
|
3291 case CMD_topleft:
|
|
3292 case CMD_verbose:
|
|
3293 case CMD_vertical:
|
|
3294 return arg;
|
|
3295
|
|
3296 #ifdef FEAT_SEARCH_EXTRA
|
|
3297 case CMD_match:
|
|
3298 if (*arg == NUL || !ends_excmd(*arg))
|
|
3299 {
|
|
3300 /* Dummy call to clear variables. */
|
|
3301 set_context_in_highlight_cmd(xp, (char_u *)"link n");
|
|
3302 xp->xp_context = EXPAND_HIGHLIGHT;
|
|
3303 xp->xp_pattern = arg;
|
|
3304 arg = skipwhite(skiptowhite(arg));
|
|
3305 if (*arg != NUL)
|
|
3306 {
|
|
3307 xp->xp_context = EXPAND_NOTHING;
|
|
3308 arg = skip_regexp(arg + 1, *arg, p_magic, NULL);
|
|
3309 }
|
|
3310 }
|
|
3311 return find_nextcmd(arg);
|
|
3312 #endif
|
|
3313
|
|
3314 #ifdef FEAT_CMDL_COMPL
|
|
3315 /*
|
|
3316 * All completion for the +cmdline_compl feature goes here.
|
|
3317 */
|
|
3318
|
|
3319 # ifdef FEAT_USR_CMDS
|
|
3320 case CMD_command:
|
|
3321 /* Check for attributes */
|
|
3322 while (*arg == '-')
|
|
3323 {
|
|
3324 arg++; /* Skip "-" */
|
|
3325 p = skiptowhite(arg);
|
|
3326 if (*p == NUL)
|
|
3327 {
|
|
3328 /* Cursor is still in the attribute */
|
|
3329 p = vim_strchr(arg, '=');
|
|
3330 if (p == NULL)
|
|
3331 {
|
|
3332 /* No "=", so complete attribute names */
|
|
3333 xp->xp_context = EXPAND_USER_CMD_FLAGS;
|
|
3334 xp->xp_pattern = arg;
|
|
3335 return NULL;
|
|
3336 }
|
|
3337
|
|
3338 /* For the -complete and -nargs attributes, we complete
|
|
3339 * their arguments as well.
|
|
3340 */
|
|
3341 if (STRNICMP(arg, "complete", p - arg) == 0)
|
|
3342 {
|
|
3343 xp->xp_context = EXPAND_USER_COMPLETE;
|
|
3344 xp->xp_pattern = p + 1;
|
|
3345 return NULL;
|
|
3346 }
|
|
3347 else if (STRNICMP(arg, "nargs", p - arg) == 0)
|
|
3348 {
|
|
3349 xp->xp_context = EXPAND_USER_NARGS;
|
|
3350 xp->xp_pattern = p + 1;
|
|
3351 return NULL;
|
|
3352 }
|
|
3353 return NULL;
|
|
3354 }
|
|
3355 arg = skipwhite(p);
|
|
3356 }
|
|
3357
|
|
3358 /* After the attributes comes the new command name */
|
|
3359 p = skiptowhite(arg);
|
|
3360 if (*p == NUL)
|
|
3361 {
|
|
3362 xp->xp_context = EXPAND_USER_COMMANDS;
|
|
3363 xp->xp_pattern = arg;
|
|
3364 break;
|
|
3365 }
|
|
3366
|
|
3367 /* And finally comes a normal command */
|
|
3368 return skipwhite(p);
|
|
3369
|
|
3370 case CMD_delcommand:
|
|
3371 xp->xp_context = EXPAND_USER_COMMANDS;
|
|
3372 xp->xp_pattern = arg;
|
|
3373 break;
|
|
3374 # endif
|
|
3375
|
|
3376 case CMD_global:
|
|
3377 case CMD_vglobal:
|
|
3378 delim = *arg; /* get the delimiter */
|
|
3379 if (delim)
|
|
3380 ++arg; /* skip delimiter if there is one */
|
|
3381
|
|
3382 while (arg[0] != NUL && arg[0] != delim)
|
|
3383 {
|
|
3384 if (arg[0] == '\\' && arg[1] != NUL)
|
|
3385 ++arg;
|
|
3386 ++arg;
|
|
3387 }
|
|
3388 if (arg[0] != NUL)
|
|
3389 return arg + 1;
|
|
3390 break;
|
|
3391 case CMD_and:
|
|
3392 case CMD_substitute:
|
|
3393 delim = *arg;
|
|
3394 if (delim)
|
|
3395 {
|
|
3396 /* skip "from" part */
|
|
3397 ++arg;
|
|
3398 arg = skip_regexp(arg, delim, p_magic, NULL);
|
|
3399 }
|
|
3400 /* skip "to" part */
|
|
3401 while (arg[0] != NUL && arg[0] != delim)
|
|
3402 {
|
|
3403 if (arg[0] == '\\' && arg[1] != NUL)
|
|
3404 ++arg;
|
|
3405 ++arg;
|
|
3406 }
|
|
3407 if (arg[0] != NUL) /* skip delimiter */
|
|
3408 ++arg;
|
|
3409 while (arg[0] && vim_strchr((char_u *)"|\"#", arg[0]) == NULL)
|
|
3410 ++arg;
|
|
3411 if (arg[0] != NUL)
|
|
3412 return arg;
|
|
3413 break;
|
|
3414 case CMD_isearch:
|
|
3415 case CMD_dsearch:
|
|
3416 case CMD_ilist:
|
|
3417 case CMD_dlist:
|
|
3418 case CMD_ijump:
|
|
3419 case CMD_psearch:
|
|
3420 case CMD_djump:
|
|
3421 case CMD_isplit:
|
|
3422 case CMD_dsplit:
|
|
3423 arg = skipwhite(skipdigits(arg)); /* skip count */
|
|
3424 if (*arg == '/') /* Match regexp, not just whole words */
|
|
3425 {
|
|
3426 for (++arg; *arg && *arg != '/'; arg++)
|
|
3427 if (*arg == '\\' && arg[1] != NUL)
|
|
3428 arg++;
|
|
3429 if (*arg)
|
|
3430 {
|
|
3431 arg = skipwhite(arg + 1);
|
|
3432
|
|
3433 /* Check for trailing illegal characters */
|
|
3434 if (*arg && vim_strchr((char_u *)"|\"\n", *arg) == NULL)
|
|
3435 xp->xp_context = EXPAND_NOTHING;
|
|
3436 else
|
|
3437 return arg;
|
|
3438 }
|
|
3439 }
|
|
3440 break;
|
|
3441 #ifdef FEAT_AUTOCMD
|
|
3442 case CMD_autocmd:
|
|
3443 return set_context_in_autocmd(xp, arg, FALSE);
|
|
3444
|
|
3445 case CMD_doautocmd:
|
|
3446 return set_context_in_autocmd(xp, arg, TRUE);
|
|
3447 #endif
|
|
3448 case CMD_set:
|
|
3449 set_context_in_set_cmd(xp, arg, 0);
|
|
3450 break;
|
|
3451 case CMD_setglobal:
|
|
3452 set_context_in_set_cmd(xp, arg, OPT_GLOBAL);
|
|
3453 break;
|
|
3454 case CMD_setlocal:
|
|
3455 set_context_in_set_cmd(xp, arg, OPT_LOCAL);
|
|
3456 break;
|
|
3457 case CMD_tag:
|
|
3458 case CMD_stag:
|
|
3459 case CMD_ptag:
|
|
3460 case CMD_tselect:
|
|
3461 case CMD_stselect:
|
|
3462 case CMD_ptselect:
|
|
3463 case CMD_tjump:
|
|
3464 case CMD_stjump:
|
|
3465 case CMD_ptjump:
|
40
|
3466 if (*p_wop != NUL)
|
|
3467 xp->xp_context = EXPAND_TAGS_LISTFILES;
|
|
3468 else
|
|
3469 xp->xp_context = EXPAND_TAGS;
|
7
|
3470 xp->xp_pattern = arg;
|
|
3471 break;
|
|
3472 case CMD_augroup:
|
|
3473 xp->xp_context = EXPAND_AUGROUP;
|
|
3474 xp->xp_pattern = arg;
|
|
3475 break;
|
|
3476 #ifdef FEAT_SYN_HL
|
|
3477 case CMD_syntax:
|
|
3478 set_context_in_syntax_cmd(xp, arg);
|
|
3479 break;
|
|
3480 #endif
|
|
3481 #ifdef FEAT_EVAL
|
|
3482 case CMD_let:
|
|
3483 case CMD_if:
|
|
3484 case CMD_elseif:
|
|
3485 case CMD_while:
|
72
|
3486 case CMD_for:
|
7
|
3487 case CMD_echo:
|
|
3488 case CMD_echon:
|
|
3489 case CMD_execute:
|
|
3490 case CMD_echomsg:
|
|
3491 case CMD_echoerr:
|
|
3492 case CMD_call:
|
|
3493 case CMD_return:
|
|
3494 set_context_for_expression(xp, arg, cmdidx);
|
|
3495 break;
|
|
3496
|
|
3497 case CMD_unlet:
|
|
3498 while ((xp->xp_pattern = vim_strchr(arg, ' ')) != NULL)
|
|
3499 arg = xp->xp_pattern + 1;
|
|
3500 xp->xp_context = EXPAND_USER_VARS;
|
|
3501 xp->xp_pattern = arg;
|
|
3502 break;
|
|
3503
|
|
3504 case CMD_function:
|
|
3505 case CMD_delfunction:
|
|
3506 xp->xp_context = EXPAND_USER_FUNC;
|
|
3507 xp->xp_pattern = arg;
|
|
3508 break;
|
|
3509
|
|
3510 case CMD_echohl:
|
|
3511 xp->xp_context = EXPAND_HIGHLIGHT;
|
|
3512 xp->xp_pattern = arg;
|
|
3513 break;
|
|
3514 #endif
|
|
3515 case CMD_highlight:
|
|
3516 set_context_in_highlight_cmd(xp, arg);
|
|
3517 break;
|
|
3518 #ifdef FEAT_LISTCMDS
|
|
3519 case CMD_bdelete:
|
|
3520 case CMD_bwipeout:
|
|
3521 case CMD_bunload:
|
|
3522 while ((xp->xp_pattern = vim_strchr(arg, ' ')) != NULL)
|
|
3523 arg = xp->xp_pattern + 1;
|
|
3524 /*FALLTHROUGH*/
|
|
3525 case CMD_buffer:
|
|
3526 case CMD_sbuffer:
|
|
3527 case CMD_checktime:
|
|
3528 xp->xp_context = EXPAND_BUFFERS;
|
|
3529 xp->xp_pattern = arg;
|
|
3530 break;
|
|
3531 #endif
|
|
3532 #ifdef FEAT_USR_CMDS
|
|
3533 case CMD_USER:
|
|
3534 case CMD_USER_BUF:
|
|
3535 if (compl != EXPAND_NOTHING)
|
|
3536 {
|
|
3537 /* XFILE: file names are handled above */
|
|
3538 if (!(argt & XFILE))
|
|
3539 {
|
|
3540 # ifdef FEAT_MENU
|
|
3541 if (compl == EXPAND_MENUS)
|
|
3542 return set_context_in_menu_cmd(xp, cmd, arg, forceit);
|
|
3543 # endif
|
|
3544 if (compl == EXPAND_COMMANDS)
|
|
3545 return arg;
|
|
3546 if (compl == EXPAND_MAPPINGS)
|
|
3547 return set_context_in_map_cmd(xp, (char_u *)"map",
|
|
3548 arg, forceit, FALSE, FALSE, CMD_map);
|
|
3549 while ((xp->xp_pattern = vim_strchr(arg, ' ')) != NULL)
|
|
3550 arg = xp->xp_pattern + 1;
|
|
3551 xp->xp_pattern = arg;
|
|
3552 }
|
|
3553 xp->xp_context = compl;
|
|
3554 }
|
|
3555 break;
|
|
3556 #endif
|
|
3557 case CMD_map: case CMD_noremap:
|
|
3558 case CMD_nmap: case CMD_nnoremap:
|
|
3559 case CMD_vmap: case CMD_vnoremap:
|
|
3560 case CMD_omap: case CMD_onoremap:
|
|
3561 case CMD_imap: case CMD_inoremap:
|
|
3562 case CMD_cmap: case CMD_cnoremap:
|
|
3563 return set_context_in_map_cmd(xp, cmd, arg, forceit,
|
|
3564 FALSE, FALSE, cmdidx);
|
|
3565 case CMD_unmap:
|
|
3566 case CMD_nunmap:
|
|
3567 case CMD_vunmap:
|
|
3568 case CMD_ounmap:
|
|
3569 case CMD_iunmap:
|
|
3570 case CMD_cunmap:
|
|
3571 return set_context_in_map_cmd(xp, cmd, arg, forceit,
|
|
3572 FALSE, TRUE, cmdidx);
|
|
3573 case CMD_abbreviate: case CMD_noreabbrev:
|
|
3574 case CMD_cabbrev: case CMD_cnoreabbrev:
|
|
3575 case CMD_iabbrev: case CMD_inoreabbrev:
|
|
3576 return set_context_in_map_cmd(xp, cmd, arg, forceit,
|
|
3577 TRUE, FALSE, cmdidx);
|
|
3578 case CMD_unabbreviate:
|
|
3579 case CMD_cunabbrev:
|
|
3580 case CMD_iunabbrev:
|
|
3581 return set_context_in_map_cmd(xp, cmd, arg, forceit,
|
|
3582 TRUE, TRUE, cmdidx);
|
|
3583 #ifdef FEAT_MENU
|
|
3584 case CMD_menu: case CMD_noremenu: case CMD_unmenu:
|
|
3585 case CMD_amenu: case CMD_anoremenu: case CMD_aunmenu:
|
|
3586 case CMD_nmenu: case CMD_nnoremenu: case CMD_nunmenu:
|
|
3587 case CMD_vmenu: case CMD_vnoremenu: case CMD_vunmenu:
|
|
3588 case CMD_omenu: case CMD_onoremenu: case CMD_ounmenu:
|
|
3589 case CMD_imenu: case CMD_inoremenu: case CMD_iunmenu:
|
|
3590 case CMD_cmenu: case CMD_cnoremenu: case CMD_cunmenu:
|
|
3591 case CMD_tmenu: case CMD_tunmenu:
|
|
3592 case CMD_popup: case CMD_tearoff: case CMD_emenu:
|
|
3593 return set_context_in_menu_cmd(xp, cmd, arg, forceit);
|
|
3594 #endif
|
|
3595
|
|
3596 case CMD_colorscheme:
|
|
3597 xp->xp_context = EXPAND_COLORS;
|
|
3598 xp->xp_pattern = arg;
|
|
3599 break;
|
|
3600
|
|
3601 case CMD_compiler:
|
|
3602 xp->xp_context = EXPAND_COMPILER;
|
|
3603 xp->xp_pattern = arg;
|
|
3604 break;
|
|
3605
|
|
3606 #if (defined(HAVE_LOCALE_H) || defined(X_LOCALE)) \
|
|
3607 && (defined(FEAT_GETTEXT) || defined(FEAT_MBYTE))
|
|
3608 case CMD_language:
|
|
3609 if (*skiptowhite(arg) == NUL)
|
|
3610 {
|
|
3611 xp->xp_context = EXPAND_LANGUAGE;
|
|
3612 xp->xp_pattern = arg;
|
|
3613 }
|
|
3614 else
|
|
3615 xp->xp_context = EXPAND_NOTHING;
|
|
3616 break;
|
|
3617 #endif
|
|
3618
|
|
3619 #endif /* FEAT_CMDL_COMPL */
|
|
3620
|
|
3621 default:
|
|
3622 break;
|
|
3623 }
|
|
3624 return NULL;
|
|
3625 }
|
|
3626
|
|
3627 /*
|
|
3628 * skip a range specifier of the form: addr [,addr] [;addr] ..
|
|
3629 *
|
|
3630 * Backslashed delimiters after / or ? will be skipped, and commands will
|
|
3631 * not be expanded between /'s and ?'s or after "'".
|
|
3632 *
|
|
3633 * Returns the "cmd" pointer advanced to beyond the range.
|
|
3634 */
|
|
3635 char_u *
|
|
3636 skip_range(cmd, ctx)
|
|
3637 char_u *cmd;
|
|
3638 int *ctx; /* pointer to xp_context or NULL */
|
|
3639 {
|
|
3640 int delim;
|
|
3641
|
|
3642 while (*cmd != NUL && (vim_isspace(*cmd) || VIM_ISDIGIT(*cmd) ||
|
|
3643 vim_strchr((char_u *)".$%'/?-+,;", *cmd) != NULL))
|
|
3644 {
|
|
3645 if (*cmd == '\'')
|
|
3646 {
|
|
3647 if (*++cmd == NUL && ctx != NULL)
|
|
3648 *ctx = EXPAND_NOTHING;
|
|
3649 }
|
|
3650 else if (*cmd == '/' || *cmd == '?')
|
|
3651 {
|
|
3652 delim = *cmd++;
|
|
3653 while (*cmd != NUL && *cmd != delim)
|
|
3654 if (*cmd++ == '\\' && *cmd != NUL)
|
|
3655 ++cmd;
|
|
3656 if (*cmd == NUL && ctx != NULL)
|
|
3657 *ctx = EXPAND_NOTHING;
|
|
3658 }
|
|
3659 if (*cmd != NUL)
|
|
3660 ++cmd;
|
|
3661 }
|
|
3662 return cmd;
|
|
3663 }
|
|
3664
|
|
3665 /*
|
|
3666 * get a single EX address
|
|
3667 *
|
|
3668 * Set ptr to the next character after the part that was interpreted.
|
|
3669 * Set ptr to NULL when an error is encountered.
|
|
3670 *
|
|
3671 * Return MAXLNUM when no Ex address was found.
|
|
3672 */
|
|
3673 static linenr_T
|
|
3674 get_address(ptr, skip, to_other_file)
|
|
3675 char_u **ptr;
|
|
3676 int skip; /* only skip the address, don't use it */
|
|
3677 int to_other_file; /* flag: may jump to other file */
|
|
3678 {
|
|
3679 int c;
|
|
3680 int i;
|
|
3681 long n;
|
|
3682 char_u *cmd;
|
|
3683 pos_T pos;
|
|
3684 pos_T *fp;
|
|
3685 linenr_T lnum;
|
|
3686
|
|
3687 cmd = skipwhite(*ptr);
|
|
3688 lnum = MAXLNUM;
|
|
3689 do
|
|
3690 {
|
|
3691 switch (*cmd)
|
|
3692 {
|
|
3693 case '.': /* '.' - Cursor position */
|
|
3694 ++cmd;
|
|
3695 lnum = curwin->w_cursor.lnum;
|
|
3696 break;
|
|
3697
|
|
3698 case '$': /* '$' - last line */
|
|
3699 ++cmd;
|
|
3700 lnum = curbuf->b_ml.ml_line_count;
|
|
3701 break;
|
|
3702
|
|
3703 case '\'': /* ''' - mark */
|
|
3704 if (*++cmd == NUL)
|
|
3705 {
|
|
3706 cmd = NULL;
|
|
3707 goto error;
|
|
3708 }
|
|
3709 if (skip)
|
|
3710 ++cmd;
|
|
3711 else
|
|
3712 {
|
|
3713 /* Only accept a mark in another file when it is
|
|
3714 * used by itself: ":'M". */
|
|
3715 fp = getmark(*cmd, to_other_file && cmd[1] == NUL);
|
|
3716 ++cmd;
|
|
3717 if (fp == (pos_T *)-1)
|
|
3718 /* Jumped to another file. */
|
|
3719 lnum = curwin->w_cursor.lnum;
|
|
3720 else
|
|
3721 {
|
|
3722 if (check_mark(fp) == FAIL)
|
|
3723 {
|
|
3724 cmd = NULL;
|
|
3725 goto error;
|
|
3726 }
|
|
3727 lnum = fp->lnum;
|
|
3728 }
|
|
3729 }
|
|
3730 break;
|
|
3731
|
|
3732 case '/':
|
|
3733 case '?': /* '/' or '?' - search */
|
|
3734 c = *cmd++;
|
|
3735 if (skip) /* skip "/pat/" */
|
|
3736 {
|
|
3737 cmd = skip_regexp(cmd, c, (int)p_magic, NULL);
|
|
3738 if (*cmd == c)
|
|
3739 ++cmd;
|
|
3740 }
|
|
3741 else
|
|
3742 {
|
|
3743 pos = curwin->w_cursor; /* save curwin->w_cursor */
|
|
3744 /*
|
|
3745 * When '/' or '?' follows another address, start
|
|
3746 * from there.
|
|
3747 */
|
|
3748 if (lnum != MAXLNUM)
|
|
3749 curwin->w_cursor.lnum = lnum;
|
|
3750 /*
|
|
3751 * Start a forward search at the end of the line.
|
|
3752 * Start a backward search at the start of the line.
|
|
3753 * This makes sure we never match in the current
|
|
3754 * line, and can match anywhere in the
|
|
3755 * next/previous line.
|
|
3756 */
|
|
3757 if (c == '/')
|
|
3758 curwin->w_cursor.col = MAXCOL;
|
|
3759 else
|
|
3760 curwin->w_cursor.col = 0;
|
|
3761 searchcmdlen = 0;
|
|
3762 if (!do_search(NULL, c, cmd, 1L,
|
|
3763 SEARCH_HIS + SEARCH_MSG + SEARCH_START))
|
|
3764 {
|
|
3765 curwin->w_cursor = pos;
|
|
3766 cmd = NULL;
|
|
3767 goto error;
|
|
3768 }
|
|
3769 lnum = curwin->w_cursor.lnum;
|
|
3770 curwin->w_cursor = pos;
|
|
3771 /* adjust command string pointer */
|
|
3772 cmd += searchcmdlen;
|
|
3773 }
|
|
3774 break;
|
|
3775
|
|
3776 case '\\': /* "\?", "\/" or "\&", repeat search */
|
|
3777 ++cmd;
|
|
3778 if (*cmd == '&')
|
|
3779 i = RE_SUBST;
|
|
3780 else if (*cmd == '?' || *cmd == '/')
|
|
3781 i = RE_SEARCH;
|
|
3782 else
|
|
3783 {
|
|
3784 EMSG(_(e_backslash));
|
|
3785 cmd = NULL;
|
|
3786 goto error;
|
|
3787 }
|
|
3788
|
|
3789 if (!skip)
|
|
3790 {
|
|
3791 /*
|
|
3792 * When search follows another address, start from
|
|
3793 * there.
|
|
3794 */
|
|
3795 if (lnum != MAXLNUM)
|
|
3796 pos.lnum = lnum;
|
|
3797 else
|
|
3798 pos.lnum = curwin->w_cursor.lnum;
|
|
3799
|
|
3800 /*
|
|
3801 * Start the search just like for the above
|
|
3802 * do_search().
|
|
3803 */
|
|
3804 if (*cmd != '?')
|
|
3805 pos.col = MAXCOL;
|
|
3806 else
|
|
3807 pos.col = 0;
|
|
3808 if (searchit(curwin, curbuf, &pos,
|
|
3809 *cmd == '?' ? BACKWARD : FORWARD,
|
|
3810 (char_u *)"", 1L,
|
|
3811 SEARCH_MSG + SEARCH_START, i) != FAIL)
|
|
3812 lnum = pos.lnum;
|
|
3813 else
|
|
3814 {
|
|
3815 cmd = NULL;
|
|
3816 goto error;
|
|
3817 }
|
|
3818 }
|
|
3819 ++cmd;
|
|
3820 break;
|
|
3821
|
|
3822 default:
|
|
3823 if (VIM_ISDIGIT(*cmd)) /* absolute line number */
|
|
3824 lnum = getdigits(&cmd);
|
|
3825 }
|
|
3826
|
|
3827 for (;;)
|
|
3828 {
|
|
3829 cmd = skipwhite(cmd);
|
|
3830 if (*cmd != '-' && *cmd != '+' && !VIM_ISDIGIT(*cmd))
|
|
3831 break;
|
|
3832
|
|
3833 if (lnum == MAXLNUM)
|
|
3834 lnum = curwin->w_cursor.lnum; /* "+1" is same as ".+1" */
|
|
3835 if (VIM_ISDIGIT(*cmd))
|
|
3836 i = '+'; /* "number" is same as "+number" */
|
|
3837 else
|
|
3838 i = *cmd++;
|
|
3839 if (!VIM_ISDIGIT(*cmd)) /* '+' is '+1', but '+0' is not '+1' */
|
|
3840 n = 1;
|
|
3841 else
|
|
3842 n = getdigits(&cmd);
|
|
3843 if (i == '-')
|
|
3844 lnum -= n;
|
|
3845 else
|
|
3846 lnum += n;
|
|
3847 }
|
|
3848 } while (*cmd == '/' || *cmd == '?');
|
|
3849
|
|
3850 error:
|
|
3851 *ptr = cmd;
|
|
3852 return lnum;
|
|
3853 }
|
|
3854
|
|
3855 /*
|
|
3856 * Function called for command which is Not Implemented. NI!
|
|
3857 */
|
|
3858 void
|
|
3859 ex_ni(eap)
|
|
3860 exarg_T *eap;
|
|
3861 {
|
|
3862 if (!eap->skip)
|
|
3863 eap->errmsg = (char_u *)N_("E319: Sorry, the command is not available in this version");
|
|
3864 }
|
|
3865
|
|
3866 #if !defined(FEAT_PERL) || !defined(FEAT_PYTHON) || !defined(FEAT_TCL) \
|
14
|
3867 || !defined(FEAT_RUBY) || !defined(FEAT_MZSCHEME)
|
7
|
3868 /*
|
|
3869 * Function called for script command which is Not Implemented. NI!
|
|
3870 * Skips over ":perl <<EOF" constructs.
|
|
3871 */
|
|
3872 static void
|
|
3873 ex_script_ni(eap)
|
|
3874 exarg_T *eap;
|
|
3875 {
|
|
3876 if (!eap->skip)
|
|
3877 ex_ni(eap);
|
|
3878 else
|
|
3879 vim_free(script_get(eap, eap->arg));
|
|
3880 }
|
|
3881 #endif
|
|
3882
|
|
3883 /*
|
|
3884 * Check range in Ex command for validity.
|
|
3885 * Return NULL when valid, error message when invalid.
|
|
3886 */
|
|
3887 static char_u *
|
|
3888 invalid_range(eap)
|
|
3889 exarg_T *eap;
|
|
3890 {
|
|
3891 if ( eap->line1 < 0
|
|
3892 || eap->line2 < 0
|
|
3893 || eap->line1 > eap->line2
|
|
3894 || ((eap->argt & RANGE)
|
|
3895 && !(eap->argt & NOTADR)
|
|
3896 && eap->line2 > curbuf->b_ml.ml_line_count
|
|
3897 #ifdef FEAT_DIFF
|
|
3898 + (eap->cmdidx == CMD_diffget)
|
|
3899 #endif
|
|
3900 ))
|
|
3901 return (char_u *)_(e_invrange);
|
|
3902 return NULL;
|
|
3903 }
|
|
3904
|
|
3905 /*
|
|
3906 * Correct the range for zero line number, if required.
|
|
3907 */
|
|
3908 static void
|
|
3909 correct_range(eap)
|
|
3910 exarg_T *eap;
|
|
3911 {
|
|
3912 if (!(eap->argt & ZEROR)) /* zero in range not allowed */
|
|
3913 {
|
|
3914 if (eap->line1 == 0)
|
|
3915 eap->line1 = 1;
|
|
3916 if (eap->line2 == 0)
|
|
3917 eap->line2 = 1;
|
|
3918 }
|
|
3919 }
|
|
3920
|
|
3921 /*
|
|
3922 * Expand file name in Ex command argument.
|
|
3923 * Return FAIL for failure, OK otherwise.
|
|
3924 */
|
|
3925 int
|
|
3926 expand_filename(eap, cmdlinep, errormsgp)
|
|
3927 exarg_T *eap;
|
|
3928 char_u **cmdlinep;
|
|
3929 char_u **errormsgp;
|
|
3930 {
|
|
3931 int has_wildcards; /* need to expand wildcards */
|
|
3932 char_u *repl;
|
|
3933 int srclen;
|
|
3934 char_u *p;
|
|
3935 int n;
|
|
3936
|
|
3937 /*
|
|
3938 * Decide to expand wildcards *before* replacing '%', '#', etc. If
|
|
3939 * the file name contains a wildcard it should not cause expanding.
|
|
3940 * (it will be expanded anyway if there is a wildcard before replacing).
|
|
3941 */
|
|
3942 has_wildcards = mch_has_wildcard(eap->arg);
|
|
3943 for (p = eap->arg; *p; )
|
|
3944 {
|
9
|
3945 #ifdef FEAT_EVAL
|
|
3946 /* Skip over `=expr`, wildcards in it are not expanded. */
|
|
3947 if (p[0] == '`' && p[1] == '=')
|
|
3948 {
|
|
3949 p += 2;
|
|
3950 (void)skip_expr(&p);
|
|
3951 if (*p == '`')
|
|
3952 ++p;
|
|
3953 continue;
|
|
3954 }
|
|
3955 #endif
|
7
|
3956 /*
|
|
3957 * Quick check if this cannot be the start of a special string.
|
|
3958 * Also removes backslash before '%', '#' and '<'.
|
|
3959 */
|
|
3960 if (vim_strchr((char_u *)"%#<", *p) == NULL)
|
|
3961 {
|
|
3962 ++p;
|
|
3963 continue;
|
|
3964 }
|
|
3965
|
|
3966 /*
|
|
3967 * Try to find a match at this position.
|
|
3968 */
|
|
3969 repl = eval_vars(p, &srclen, &(eap->do_ecmd_lnum), errormsgp, eap->arg);
|
|
3970 if (*errormsgp != NULL) /* error detected */
|
|
3971 return FAIL;
|
|
3972 if (repl == NULL) /* no match found */
|
|
3973 {
|
|
3974 p += srclen;
|
|
3975 continue;
|
|
3976 }
|
|
3977
|
37
|
3978 /* Wildcards won't be expanded below, the replacement is taken
|
|
3979 * literally. But do expand "~/file", "~user/file" and "$HOME/file". */
|
|
3980 if (vim_strchr(repl, '$') != NULL || vim_strchr(repl, '~') != NULL)
|
|
3981 {
|
|
3982 char_u *l = repl;
|
|
3983
|
|
3984 repl = expand_env_save(repl);
|
|
3985 vim_free(l);
|
|
3986 }
|
|
3987
|
7
|
3988 /* Need to escape white space et al. with a backslash. Don't do this
|
|
3989 * for shell commands (may have to use quotes instead). Don't do this
|
|
3990 * for non-unix systems when there is a single argument (spaces don't
|
|
3991 * separate arguments then). */
|
|
3992 if (!eap->usefilter
|
|
3993 && eap->cmdidx != CMD_bang
|
|
3994 && eap->cmdidx != CMD_make
|
|
3995 && eap->cmdidx != CMD_grep
|
|
3996 && eap->cmdidx != CMD_grepadd
|
|
3997 #ifndef UNIX
|
|
3998 && !(eap->argt & NOSPC)
|
|
3999 #endif
|
|
4000 )
|
|
4001 {
|
|
4002 char_u *l;
|
|
4003 #ifdef BACKSLASH_IN_FILENAME
|
|
4004 /* Don't escape a backslash here, because rem_backslash() doesn't
|
|
4005 * remove it later. */
|
|
4006 static char_u *nobslash = (char_u *)" \t\"|";
|
|
4007 # define ESCAPE_CHARS nobslash
|
|
4008 #else
|
|
4009 # define ESCAPE_CHARS escape_chars
|
|
4010 #endif
|
|
4011
|
|
4012 for (l = repl; *l; ++l)
|
|
4013 if (vim_strchr(ESCAPE_CHARS, *l) != NULL)
|
|
4014 {
|
|
4015 l = vim_strsave_escaped(repl, ESCAPE_CHARS);
|
|
4016 if (l != NULL)
|
|
4017 {
|
|
4018 vim_free(repl);
|
|
4019 repl = l;
|
|
4020 }
|
|
4021 break;
|
|
4022 }
|
|
4023 }
|
|
4024
|
|
4025 /* For a shell command a '!' must be escaped. */
|
|
4026 if ((eap->usefilter || eap->cmdidx == CMD_bang)
|
|
4027 && vim_strchr(repl, '!') != NULL)
|
|
4028 {
|
|
4029 char_u *l;
|
|
4030
|
|
4031 l = vim_strsave_escaped(repl, (char_u *)"!");
|
|
4032 if (l != NULL)
|
|
4033 {
|
|
4034 vim_free(repl);
|
|
4035 repl = l;
|
|
4036 /* For a sh-like shell escape it another time. */
|
|
4037 if (strstr((char *)p_sh, "sh") != NULL)
|
|
4038 {
|
|
4039 l = vim_strsave_escaped(repl, (char_u *)"!");
|
|
4040 if (l != NULL)
|
|
4041 {
|
|
4042 vim_free(repl);
|
|
4043 repl = l;
|
|
4044 }
|
|
4045 }
|
|
4046 }
|
|
4047 }
|
|
4048
|
|
4049 p = repl_cmdline(eap, p, srclen, repl, cmdlinep);
|
|
4050 vim_free(repl);
|
|
4051 if (p == NULL)
|
|
4052 return FAIL;
|
|
4053 }
|
|
4054
|
|
4055 /*
|
|
4056 * One file argument: Expand wildcards.
|
|
4057 * Don't do this with ":r !command" or ":w !command".
|
|
4058 */
|
|
4059 if ((eap->argt & NOSPC) && !eap->usefilter)
|
|
4060 {
|
|
4061 /*
|
|
4062 * May do this twice:
|
|
4063 * 1. Replace environment variables.
|
|
4064 * 2. Replace any other wildcards, remove backslashes.
|
|
4065 */
|
|
4066 for (n = 1; n <= 2; ++n)
|
|
4067 {
|
|
4068 if (n == 2)
|
|
4069 {
|
|
4070 #ifdef UNIX
|
|
4071 /*
|
|
4072 * Only for Unix we check for more than one file name.
|
|
4073 * For other systems spaces are considered to be part
|
|
4074 * of the file name.
|
|
4075 * Only check here if there is no wildcard, otherwise
|
|
4076 * ExpandOne() will check for errors. This allows
|
|
4077 * ":e `ls ve*.c`" on Unix.
|
|
4078 */
|
|
4079 if (!has_wildcards)
|
|
4080 for (p = eap->arg; *p; ++p)
|
|
4081 {
|
|
4082 /* skip escaped characters */
|
|
4083 if (p[1] && (*p == '\\' || *p == Ctrl_V))
|
|
4084 ++p;
|
|
4085 else if (vim_iswhite(*p))
|
|
4086 {
|
|
4087 *errormsgp = (char_u *)_("E172: Only one file name allowed");
|
|
4088 return FAIL;
|
|
4089 }
|
|
4090 }
|
|
4091 #endif
|
|
4092
|
|
4093 /*
|
|
4094 * Halve the number of backslashes (this is Vi compatible).
|
|
4095 * For Unix and OS/2, when wildcards are expanded, this is
|
|
4096 * done by ExpandOne() below.
|
|
4097 */
|
|
4098 #if defined(UNIX) || defined(OS2)
|
|
4099 if (!has_wildcards)
|
|
4100 #endif
|
|
4101 backslash_halve(eap->arg);
|
|
4102 #ifdef MACOS_CLASSIC
|
|
4103 /*
|
|
4104 * translate unix-like path components
|
|
4105 */
|
|
4106 slash_n_colon_adjust(eap->arg);
|
|
4107 #endif
|
|
4108 }
|
|
4109
|
|
4110 if (has_wildcards)
|
|
4111 {
|
|
4112 if (n == 1)
|
|
4113 {
|
|
4114 /*
|
|
4115 * First loop: May expand environment variables. This
|
|
4116 * can be done much faster with expand_env() than with
|
|
4117 * something else (e.g., calling a shell).
|
|
4118 * After expanding environment variables, check again
|
|
4119 * if there are still wildcards present.
|
|
4120 */
|
|
4121 if (vim_strchr(eap->arg, '$') != NULL
|
|
4122 || vim_strchr(eap->arg, '~') != NULL)
|
|
4123 {
|
|
4124 expand_env_esc(eap->arg, NameBuff, MAXPATHL, TRUE);
|
|
4125 has_wildcards = mch_has_wildcard(NameBuff);
|
|
4126 p = NameBuff;
|
|
4127 }
|
|
4128 else
|
|
4129 p = NULL;
|
|
4130 }
|
|
4131 else /* n == 2 */
|
|
4132 {
|
|
4133 expand_T xpc;
|
|
4134
|
|
4135 ExpandInit(&xpc);
|
|
4136 xpc.xp_context = EXPAND_FILES;
|
|
4137 p = ExpandOne(&xpc, eap->arg, NULL,
|
|
4138 WILD_LIST_NOTFOUND|WILD_ADD_SLASH,
|
|
4139 WILD_EXPAND_FREE);
|
|
4140 ExpandCleanup(&xpc);
|
|
4141 if (p == NULL)
|
|
4142 return FAIL;
|
|
4143 }
|
|
4144 if (p != NULL)
|
|
4145 {
|
|
4146 (void)repl_cmdline(eap, eap->arg, (int)STRLEN(eap->arg),
|
|
4147 p, cmdlinep);
|
|
4148 if (n == 2) /* p came from ExpandOne() */
|
|
4149 vim_free(p);
|
|
4150 }
|
|
4151 }
|
|
4152 }
|
|
4153 }
|
|
4154 return OK;
|
|
4155 }
|
|
4156
|
|
4157 /*
|
|
4158 * Replace part of the command line, keeping eap->cmd, eap->arg and
|
|
4159 * eap->nextcmd correct.
|
|
4160 * "src" points to the part that is to be replaced, of length "srclen".
|
|
4161 * "repl" is the replacement string.
|
|
4162 * Returns a pointer to the character after the replaced string.
|
|
4163 * Returns NULL for failure.
|
|
4164 */
|
|
4165 static char_u *
|
|
4166 repl_cmdline(eap, src, srclen, repl, cmdlinep)
|
|
4167 exarg_T *eap;
|
|
4168 char_u *src;
|
|
4169 int srclen;
|
|
4170 char_u *repl;
|
|
4171 char_u **cmdlinep;
|
|
4172 {
|
|
4173 int len;
|
|
4174 int i;
|
|
4175 char_u *new_cmdline;
|
|
4176
|
|
4177 /*
|
|
4178 * The new command line is build in new_cmdline[].
|
|
4179 * First allocate it.
|
|
4180 * Careful: a "+cmd" argument may have been NUL terminated.
|
|
4181 */
|
|
4182 len = (int)STRLEN(repl);
|
|
4183 i = (int)(src - *cmdlinep) + (int)STRLEN(src + srclen) + len + 3;
|
|
4184 if (eap->nextcmd)
|
|
4185 i += (int)STRLEN(eap->nextcmd);/* add space for next command */
|
|
4186 if ((new_cmdline = alloc((unsigned)i)) == NULL)
|
|
4187 return NULL; /* out of memory! */
|
|
4188
|
|
4189 /*
|
|
4190 * Copy the stuff before the expanded part.
|
|
4191 * Copy the expanded stuff.
|
|
4192 * Copy what came after the expanded part.
|
|
4193 * Copy the next commands, if there are any.
|
|
4194 */
|
|
4195 i = (int)(src - *cmdlinep); /* length of part before match */
|
|
4196 mch_memmove(new_cmdline, *cmdlinep, (size_t)i);
|
|
4197 mch_memmove(new_cmdline + i, repl, (size_t)len);
|
|
4198 i += len; /* remember the end of the string */
|
|
4199 STRCPY(new_cmdline + i, src + srclen);
|
|
4200 src = new_cmdline + i; /* remember where to continue */
|
|
4201
|
|
4202 if (eap->nextcmd) /* append next command */
|
|
4203 {
|
|
4204 i = (int)STRLEN(new_cmdline) + 1;
|
|
4205 STRCPY(new_cmdline + i, eap->nextcmd);
|
|
4206 eap->nextcmd = new_cmdline + i;
|
|
4207 }
|
|
4208 eap->cmd = new_cmdline + (eap->cmd - *cmdlinep);
|
|
4209 eap->arg = new_cmdline + (eap->arg - *cmdlinep);
|
|
4210 if (eap->do_ecmd_cmd != NULL && eap->do_ecmd_cmd != dollar_command)
|
|
4211 eap->do_ecmd_cmd = new_cmdline + (eap->do_ecmd_cmd - *cmdlinep);
|
|
4212 vim_free(*cmdlinep);
|
|
4213 *cmdlinep = new_cmdline;
|
|
4214
|
|
4215 return src;
|
|
4216 }
|
|
4217
|
|
4218 /*
|
|
4219 * Check for '|' to separate commands and '"' to start comments.
|
|
4220 */
|
|
4221 void
|
|
4222 separate_nextcmd(eap)
|
|
4223 exarg_T *eap;
|
|
4224 {
|
|
4225 char_u *p;
|
|
4226
|
41
|
4227 p = eap->arg;
|
|
4228 #ifdef FEAT_QUICKFIX
|
42
|
4229 if (*p != NUL && (eap->cmdidx == CMD_vimgrep
|
|
4230 || eap->cmdidx == CMD_vimgrepadd
|
|
4231 || grep_internal(eap->cmdidx)))
|
41
|
4232 {
|
|
4233 /* Skip over the pattern. */
|
42
|
4234 if (vim_isIDc(*p))
|
|
4235 p = skiptowhite(p);
|
|
4236 else
|
|
4237 {
|
|
4238 p = skip_regexp(p + 1, *p, TRUE, NULL);
|
|
4239 if (*p == *eap->arg)
|
|
4240 ++p;
|
|
4241 }
|
41
|
4242 }
|
|
4243 #endif
|
|
4244
|
|
4245 for ( ; *p; mb_ptr_adv(p))
|
7
|
4246 {
|
|
4247 if (*p == Ctrl_V)
|
|
4248 {
|
|
4249 if (eap->argt & (USECTRLV | XFILE))
|
|
4250 ++p; /* skip CTRL-V and next char */
|
|
4251 else
|
|
4252 STRCPY(p, p + 1); /* remove CTRL-V and skip next char */
|
|
4253 if (*p == NUL) /* stop at NUL after CTRL-V */
|
|
4254 break;
|
|
4255 }
|
9
|
4256
|
|
4257 #ifdef FEAT_EVAL
|
|
4258 /* Skip over `=expr` when wildcards are expanded. */
|
|
4259 else if (p[0] == '`' && p[1] == '=')
|
|
4260 {
|
|
4261 p += 2;
|
|
4262 (void)skip_expr(&p);
|
|
4263 }
|
|
4264 #endif
|
|
4265
|
7
|
4266 /* Check for '"': start of comment or '|': next command */
|
|
4267 /* :@" and :*" do not start a comment!
|
|
4268 * :redir @" doesn't either. */
|
|
4269 else if ((*p == '"' && !(eap->argt & NOTRLCOM)
|
|
4270 && ((eap->cmdidx != CMD_at && eap->cmdidx != CMD_star)
|
|
4271 || p != eap->arg)
|
|
4272 && (eap->cmdidx != CMD_redir
|
|
4273 || p != eap->arg + 1 || p[-1] != '@'))
|
|
4274 || *p == '|' || *p == '\n')
|
|
4275 {
|
|
4276 /*
|
|
4277 * We remove the '\' before the '|', unless USECTRLV is used
|
|
4278 * AND 'b' is present in 'cpoptions'.
|
|
4279 */
|
|
4280 if ((vim_strchr(p_cpo, CPO_BAR) == NULL
|
|
4281 || !(eap->argt & USECTRLV)) && *(p - 1) == '\\')
|
|
4282 {
|
|
4283 mch_memmove(p - 1, p, STRLEN(p) + 1); /* remove the '\' */
|
|
4284 --p;
|
|
4285 }
|
|
4286 else
|
|
4287 {
|
|
4288 eap->nextcmd = check_nextcmd(p);
|
|
4289 *p = NUL;
|
|
4290 break;
|
|
4291 }
|
|
4292 }
|
41
|
4293 }
|
|
4294
|
7
|
4295 if (!(eap->argt & NOTRLCOM)) /* remove trailing spaces */
|
|
4296 del_trailing_spaces(eap->arg);
|
|
4297 }
|
|
4298
|
|
4299 /*
|
|
4300 * get + command from ex argument
|
|
4301 */
|
|
4302 static char_u *
|
|
4303 getargcmd(argp)
|
|
4304 char_u **argp;
|
|
4305 {
|
|
4306 char_u *arg = *argp;
|
|
4307 char_u *command = NULL;
|
|
4308
|
|
4309 if (*arg == '+') /* +[command] */
|
|
4310 {
|
|
4311 ++arg;
|
|
4312 if (vim_isspace(*arg))
|
|
4313 command = dollar_command;
|
|
4314 else
|
|
4315 {
|
|
4316 command = arg;
|
|
4317 arg = skip_cmd_arg(command, TRUE);
|
|
4318 if (*arg != NUL)
|
|
4319 *arg++ = NUL; /* terminate command with NUL */
|
|
4320 }
|
|
4321
|
|
4322 arg = skipwhite(arg); /* skip over spaces */
|
|
4323 *argp = arg;
|
|
4324 }
|
|
4325 return command;
|
|
4326 }
|
|
4327
|
|
4328 /*
|
|
4329 * Find end of "+command" argument. Skip over "\ " and "\\".
|
|
4330 */
|
|
4331 static char_u *
|
|
4332 skip_cmd_arg(p, rembs)
|
|
4333 char_u *p;
|
|
4334 int rembs; /* TRUE to halve the number of backslashes */
|
|
4335 {
|
|
4336 while (*p && !vim_isspace(*p))
|
|
4337 {
|
|
4338 if (*p == '\\' && p[1] != NUL)
|
|
4339 {
|
|
4340 if (rembs)
|
|
4341 mch_memmove(p, p + 1, STRLEN(p));
|
|
4342 else
|
|
4343 ++p;
|
|
4344 }
|
39
|
4345 mb_ptr_adv(p);
|
7
|
4346 }
|
|
4347 return p;
|
|
4348 }
|
|
4349
|
|
4350 /*
|
|
4351 * Get "++opt=arg" argument.
|
|
4352 * Return FAIL or OK.
|
|
4353 */
|
|
4354 static int
|
|
4355 getargopt(eap)
|
|
4356 exarg_T *eap;
|
|
4357 {
|
|
4358 char_u *arg = eap->arg + 2;
|
|
4359 int *pp = NULL;
|
|
4360 #ifdef FEAT_MBYTE
|
|
4361 char_u *p;
|
|
4362 #endif
|
|
4363
|
|
4364 /* ":edit ++[no]bin[ary] file" */
|
|
4365 if (STRNCMP(arg, "bin", 3) == 0 || STRNCMP(arg, "nobin", 5) == 0)
|
|
4366 {
|
|
4367 if (*arg == 'n')
|
|
4368 {
|
|
4369 arg += 2;
|
|
4370 eap->force_bin = FORCE_NOBIN;
|
|
4371 }
|
|
4372 else
|
|
4373 eap->force_bin = FORCE_BIN;
|
|
4374 if (!checkforcmd(&arg, "binary", 3))
|
|
4375 return FAIL;
|
|
4376 eap->arg = skipwhite(arg);
|
|
4377 return OK;
|
|
4378 }
|
|
4379
|
|
4380 if (STRNCMP(arg, "ff", 2) == 0)
|
|
4381 {
|
|
4382 arg += 2;
|
|
4383 pp = &eap->force_ff;
|
|
4384 }
|
|
4385 else if (STRNCMP(arg, "fileformat", 10) == 0)
|
|
4386 {
|
|
4387 arg += 10;
|
|
4388 pp = &eap->force_ff;
|
|
4389 }
|
|
4390 #ifdef FEAT_MBYTE
|
|
4391 else if (STRNCMP(arg, "enc", 3) == 0)
|
|
4392 {
|
|
4393 arg += 3;
|
|
4394 pp = &eap->force_enc;
|
|
4395 }
|
|
4396 else if (STRNCMP(arg, "encoding", 8) == 0)
|
|
4397 {
|
|
4398 arg += 8;
|
|
4399 pp = &eap->force_enc;
|
|
4400 }
|
|
4401 #endif
|
|
4402
|
|
4403 if (pp == NULL || *arg != '=')
|
|
4404 return FAIL;
|
|
4405
|
|
4406 ++arg;
|
|
4407 *pp = (int)(arg - eap->cmd);
|
|
4408 arg = skip_cmd_arg(arg, FALSE);
|
|
4409 eap->arg = skipwhite(arg);
|
|
4410 *arg = NUL;
|
|
4411
|
|
4412 #ifdef FEAT_MBYTE
|
|
4413 if (pp == &eap->force_ff)
|
|
4414 {
|
|
4415 #endif
|
|
4416 if (check_ff_value(eap->cmd + eap->force_ff) == FAIL)
|
|
4417 return FAIL;
|
|
4418 #ifdef FEAT_MBYTE
|
|
4419 }
|
|
4420 else
|
|
4421 {
|
|
4422 /* Make 'fileencoding' lower case. */
|
|
4423 for (p = eap->cmd + eap->force_enc; *p != NUL; ++p)
|
|
4424 *p = TOLOWER_ASC(*p);
|
|
4425 }
|
|
4426 #endif
|
|
4427
|
|
4428 return OK;
|
|
4429 }
|
|
4430
|
|
4431 /*
|
|
4432 * ":abbreviate" and friends.
|
|
4433 */
|
|
4434 static void
|
|
4435 ex_abbreviate(eap)
|
|
4436 exarg_T *eap;
|
|
4437 {
|
|
4438 do_exmap(eap, TRUE); /* almost the same as mapping */
|
|
4439 }
|
|
4440
|
|
4441 /*
|
|
4442 * ":map" and friends.
|
|
4443 */
|
|
4444 static void
|
|
4445 ex_map(eap)
|
|
4446 exarg_T *eap;
|
|
4447 {
|
|
4448 /*
|
|
4449 * If we are sourcing .exrc or .vimrc in current directory we
|
|
4450 * print the mappings for security reasons.
|
|
4451 */
|
|
4452 if (secure)
|
|
4453 {
|
|
4454 secure = 2;
|
|
4455 msg_outtrans(eap->cmd);
|
|
4456 msg_putchar('\n');
|
|
4457 }
|
|
4458 do_exmap(eap, FALSE);
|
|
4459 }
|
|
4460
|
|
4461 /*
|
|
4462 * ":unmap" and friends.
|
|
4463 */
|
|
4464 static void
|
|
4465 ex_unmap(eap)
|
|
4466 exarg_T *eap;
|
|
4467 {
|
|
4468 do_exmap(eap, FALSE);
|
|
4469 }
|
|
4470
|
|
4471 /*
|
|
4472 * ":mapclear" and friends.
|
|
4473 */
|
|
4474 static void
|
|
4475 ex_mapclear(eap)
|
|
4476 exarg_T *eap;
|
|
4477 {
|
|
4478 map_clear(eap->cmd, eap->arg, eap->forceit, FALSE);
|
|
4479 }
|
|
4480
|
|
4481 /*
|
|
4482 * ":abclear" and friends.
|
|
4483 */
|
|
4484 static void
|
|
4485 ex_abclear(eap)
|
|
4486 exarg_T *eap;
|
|
4487 {
|
|
4488 map_clear(eap->cmd, eap->arg, TRUE, TRUE);
|
|
4489 }
|
|
4490
|
|
4491 #ifdef FEAT_AUTOCMD
|
|
4492 static void
|
|
4493 ex_autocmd(eap)
|
|
4494 exarg_T *eap;
|
|
4495 {
|
|
4496 /*
|
|
4497 * Disallow auto commands from .exrc and .vimrc in current
|
|
4498 * directory for security reasons.
|
|
4499 */
|
|
4500 if (secure)
|
|
4501 {
|
|
4502 secure = 2;
|
|
4503 eap->errmsg = e_curdir;
|
|
4504 }
|
|
4505 else if (eap->cmdidx == CMD_autocmd)
|
|
4506 do_autocmd(eap->arg, eap->forceit);
|
|
4507 else
|
|
4508 do_augroup(eap->arg, eap->forceit);
|
|
4509 }
|
|
4510
|
|
4511 /*
|
|
4512 * ":doautocmd": Apply the automatic commands to the current buffer.
|
|
4513 */
|
|
4514 static void
|
|
4515 ex_doautocmd(eap)
|
|
4516 exarg_T *eap;
|
|
4517 {
|
|
4518 (void)do_doautocmd(eap->arg, TRUE);
|
23
|
4519 do_modelines(FALSE);
|
7
|
4520 }
|
|
4521 #endif
|
|
4522
|
|
4523 #ifdef FEAT_LISTCMDS
|
|
4524 /*
|
|
4525 * :[N]bunload[!] [N] [bufname] unload buffer
|
|
4526 * :[N]bdelete[!] [N] [bufname] delete buffer from buffer list
|
|
4527 * :[N]bwipeout[!] [N] [bufname] delete buffer really
|
|
4528 */
|
|
4529 static void
|
|
4530 ex_bunload(eap)
|
|
4531 exarg_T *eap;
|
|
4532 {
|
|
4533 eap->errmsg = do_bufdel(
|
|
4534 eap->cmdidx == CMD_bdelete ? DOBUF_DEL
|
|
4535 : eap->cmdidx == CMD_bwipeout ? DOBUF_WIPE
|
|
4536 : DOBUF_UNLOAD, eap->arg,
|
|
4537 eap->addr_count, (int)eap->line1, (int)eap->line2, eap->forceit);
|
|
4538 }
|
|
4539
|
|
4540 /*
|
|
4541 * :[N]buffer [N] to buffer N
|
|
4542 * :[N]sbuffer [N] to buffer N
|
|
4543 */
|
|
4544 static void
|
|
4545 ex_buffer(eap)
|
|
4546 exarg_T *eap;
|
|
4547 {
|
|
4548 if (*eap->arg)
|
|
4549 eap->errmsg = e_trailing;
|
|
4550 else
|
|
4551 {
|
|
4552 if (eap->addr_count == 0) /* default is current buffer */
|
|
4553 goto_buffer(eap, DOBUF_CURRENT, FORWARD, 0);
|
|
4554 else
|
|
4555 goto_buffer(eap, DOBUF_FIRST, FORWARD, (int)eap->line2);
|
|
4556 }
|
|
4557 }
|
|
4558
|
|
4559 /*
|
|
4560 * :[N]bmodified [N] to next mod. buffer
|
|
4561 * :[N]sbmodified [N] to next mod. buffer
|
|
4562 */
|
|
4563 static void
|
|
4564 ex_bmodified(eap)
|
|
4565 exarg_T *eap;
|
|
4566 {
|
|
4567 goto_buffer(eap, DOBUF_MOD, FORWARD, (int)eap->line2);
|
|
4568 }
|
|
4569
|
|
4570 /*
|
|
4571 * :[N]bnext [N] to next buffer
|
|
4572 * :[N]sbnext [N] split and to next buffer
|
|
4573 */
|
|
4574 static void
|
|
4575 ex_bnext(eap)
|
|
4576 exarg_T *eap;
|
|
4577 {
|
|
4578 goto_buffer(eap, DOBUF_CURRENT, FORWARD, (int)eap->line2);
|
|
4579 }
|
|
4580
|
|
4581 /*
|
|
4582 * :[N]bNext [N] to previous buffer
|
|
4583 * :[N]bprevious [N] to previous buffer
|
|
4584 * :[N]sbNext [N] split and to previous buffer
|
|
4585 * :[N]sbprevious [N] split and to previous buffer
|
|
4586 */
|
|
4587 static void
|
|
4588 ex_bprevious(eap)
|
|
4589 exarg_T *eap;
|
|
4590 {
|
|
4591 goto_buffer(eap, DOBUF_CURRENT, BACKWARD, (int)eap->line2);
|
|
4592 }
|
|
4593
|
|
4594 /*
|
|
4595 * :brewind to first buffer
|
|
4596 * :bfirst to first buffer
|
|
4597 * :sbrewind split and to first buffer
|
|
4598 * :sbfirst split and to first buffer
|
|
4599 */
|
|
4600 static void
|
|
4601 ex_brewind(eap)
|
|
4602 exarg_T *eap;
|
|
4603 {
|
|
4604 goto_buffer(eap, DOBUF_FIRST, FORWARD, 0);
|
|
4605 }
|
|
4606
|
|
4607 /*
|
|
4608 * :blast to last buffer
|
|
4609 * :sblast split and to last buffer
|
|
4610 */
|
|
4611 static void
|
|
4612 ex_blast(eap)
|
|
4613 exarg_T *eap;
|
|
4614 {
|
|
4615 goto_buffer(eap, DOBUF_LAST, BACKWARD, 0);
|
|
4616 }
|
|
4617 #endif
|
|
4618
|
|
4619 int
|
|
4620 ends_excmd(c)
|
|
4621 int c;
|
|
4622 {
|
|
4623 return (c == NUL || c == '|' || c == '"' || c == '\n');
|
|
4624 }
|
|
4625
|
|
4626 #if defined(FEAT_SYN_HL) || defined(FEAT_SEARCH_EXTRA) || defined(FEAT_EVAL) \
|
|
4627 || defined(PROTO)
|
|
4628 /*
|
|
4629 * Return the next command, after the first '|' or '\n'.
|
|
4630 * Return NULL if not found.
|
|
4631 */
|
|
4632 char_u *
|
|
4633 find_nextcmd(p)
|
|
4634 char_u *p;
|
|
4635 {
|
|
4636 while (*p != '|' && *p != '\n')
|
|
4637 {
|
|
4638 if (*p == NUL)
|
|
4639 return NULL;
|
|
4640 ++p;
|
|
4641 }
|
|
4642 return (p + 1);
|
|
4643 }
|
|
4644 #endif
|
|
4645
|
|
4646 /*
|
|
4647 * Check if *p is a separator between Ex commands.
|
|
4648 * Return NULL if it isn't, (p + 1) if it is.
|
|
4649 */
|
|
4650 char_u *
|
|
4651 check_nextcmd(p)
|
|
4652 char_u *p;
|
|
4653 {
|
|
4654 p = skipwhite(p);
|
|
4655 if (*p == '|' || *p == '\n')
|
|
4656 return (p + 1);
|
|
4657 else
|
|
4658 return NULL;
|
|
4659 }
|
|
4660
|
|
4661 /*
|
|
4662 * - if there are more files to edit
|
|
4663 * - and this is the last window
|
|
4664 * - and forceit not used
|
|
4665 * - and not repeated twice on a row
|
|
4666 * return FAIL and give error message if 'message' TRUE
|
|
4667 * return OK otherwise
|
|
4668 */
|
|
4669 static int
|
|
4670 check_more(message, forceit)
|
|
4671 int message; /* when FALSE check only, no messages */
|
|
4672 int forceit;
|
|
4673 {
|
|
4674 int n = ARGCOUNT - curwin->w_arg_idx - 1;
|
|
4675
|
|
4676 if (!forceit && only_one_window() && ARGCOUNT > 1 && !arg_had_last
|
|
4677 && n >= 0 && quitmore == 0)
|
|
4678 {
|
|
4679 if (message)
|
|
4680 {
|
|
4681 #if defined(FEAT_GUI_DIALOG) || defined(FEAT_CON_DIALOG)
|
|
4682 if ((p_confirm || cmdmod.confirm) && curbuf->b_fname != NULL)
|
|
4683 {
|
|
4684 char_u buff[IOSIZE];
|
|
4685
|
|
4686 if (n == 1)
|
|
4687 STRCPY(buff, _("1 more file to edit. Quit anyway?"));
|
|
4688 else
|
|
4689 sprintf((char *)buff,
|
|
4690 _("%d more files to edit. Quit anyway?"), n);
|
|
4691 if (vim_dialog_yesno(VIM_QUESTION, NULL, buff, 1) == VIM_YES)
|
|
4692 return OK;
|
|
4693 return FAIL;
|
|
4694 }
|
|
4695 #endif
|
|
4696 if (n == 1)
|
|
4697 EMSG(_("E173: 1 more file to edit"));
|
|
4698 else
|
|
4699 EMSGN(_("E173: %ld more files to edit"), n);
|
|
4700 quitmore = 2; /* next try to quit is allowed */
|
|
4701 }
|
|
4702 return FAIL;
|
|
4703 }
|
|
4704 return OK;
|
|
4705 }
|
|
4706
|
|
4707 #ifdef FEAT_CMDL_COMPL
|
|
4708 /*
|
|
4709 * Function given to ExpandGeneric() to obtain the list of command names.
|
|
4710 */
|
|
4711 /*ARGSUSED*/
|
|
4712 char_u *
|
|
4713 get_command_name(xp, idx)
|
|
4714 expand_T *xp;
|
|
4715 int idx;
|
|
4716 {
|
|
4717 if (idx >= (int)CMD_SIZE)
|
|
4718 # ifdef FEAT_USR_CMDS
|
|
4719 return get_user_command_name(idx);
|
|
4720 # else
|
|
4721 return NULL;
|
|
4722 # endif
|
|
4723 return cmdnames[idx].cmd_name;
|
|
4724 }
|
|
4725 #endif
|
|
4726
|
|
4727 #if defined(FEAT_USR_CMDS) || defined(PROTO)
|
|
4728 static int uc_add_command __ARGS((char_u *name, size_t name_len, char_u *rep, long argt, long def, int flags, int compl, char_u *compl_arg, int force));
|
|
4729 static void uc_list __ARGS((char_u *name, size_t name_len));
|
|
4730 static int uc_scan_attr __ARGS((char_u *attr, size_t len, long *argt, long *def, int *flags, int *compl, char_u **compl_arg));
|
|
4731 static char_u *uc_split_args __ARGS((char_u *arg, size_t *lenp));
|
|
4732 static size_t uc_check_code __ARGS((char_u *code, size_t len, char_u *buf, ucmd_T *cmd, exarg_T *eap, char_u **split_buf, size_t *split_len));
|
|
4733
|
|
4734 static int
|
|
4735 uc_add_command(name, name_len, rep, argt, def, flags, compl, compl_arg, force)
|
|
4736 char_u *name;
|
|
4737 size_t name_len;
|
|
4738 char_u *rep;
|
|
4739 long argt;
|
|
4740 long def;
|
|
4741 int flags;
|
|
4742 int compl;
|
|
4743 char_u *compl_arg;
|
|
4744 int force;
|
|
4745 {
|
|
4746 ucmd_T *cmd = NULL;
|
|
4747 char_u *p;
|
|
4748 int i;
|
|
4749 int cmp = 1;
|
|
4750 char_u *rep_buf = NULL;
|
|
4751 garray_T *gap;
|
|
4752
|
|
4753 replace_termcodes(rep, &rep_buf, FALSE, FALSE);
|
|
4754 if (rep_buf == NULL)
|
|
4755 {
|
|
4756 /* Can't replace termcodes - try using the string as is */
|
|
4757 rep_buf = vim_strsave(rep);
|
|
4758
|
|
4759 /* Give up if out of memory */
|
|
4760 if (rep_buf == NULL)
|
|
4761 return FAIL;
|
|
4762 }
|
|
4763
|
|
4764 /* get address of growarray: global or in curbuf */
|
|
4765 if (flags & UC_BUFFER)
|
|
4766 {
|
|
4767 gap = &curbuf->b_ucmds;
|
|
4768 if (gap->ga_itemsize == 0)
|
|
4769 ga_init2(gap, (int)sizeof(ucmd_T), 4);
|
|
4770 }
|
|
4771 else
|
|
4772 gap = &ucmds;
|
|
4773
|
|
4774 /* Search for the command in the already defined commands. */
|
|
4775 for (i = 0; i < gap->ga_len; ++i)
|
|
4776 {
|
|
4777 size_t len;
|
|
4778
|
|
4779 cmd = USER_CMD_GA(gap, i);
|
|
4780 len = STRLEN(cmd->uc_name);
|
|
4781 cmp = STRNCMP(name, cmd->uc_name, name_len);
|
|
4782 if (cmp == 0)
|
|
4783 {
|
|
4784 if (name_len < len)
|
|
4785 cmp = -1;
|
|
4786 else if (name_len > len)
|
|
4787 cmp = 1;
|
|
4788 }
|
|
4789
|
|
4790 if (cmp == 0)
|
|
4791 {
|
|
4792 if (!force)
|
|
4793 {
|
|
4794 EMSG(_("E174: Command already exists: add ! to replace it"));
|
|
4795 goto fail;
|
|
4796 }
|
|
4797
|
|
4798 vim_free(cmd->uc_rep);
|
|
4799 cmd->uc_rep = 0;
|
|
4800 break;
|
|
4801 }
|
|
4802
|
|
4803 /* Stop as soon as we pass the name to add */
|
|
4804 if (cmp < 0)
|
|
4805 break;
|
|
4806 }
|
|
4807
|
|
4808 /* Extend the array unless we're replacing an existing command */
|
|
4809 if (cmp != 0)
|
|
4810 {
|
|
4811 if (ga_grow(gap, 1) != OK)
|
|
4812 goto fail;
|
|
4813 if ((p = vim_strnsave(name, (int)name_len)) == NULL)
|
|
4814 goto fail;
|
|
4815
|
|
4816 cmd = USER_CMD_GA(gap, i);
|
|
4817 mch_memmove(cmd + 1, cmd, (gap->ga_len - i) * sizeof(ucmd_T));
|
|
4818
|
|
4819 ++gap->ga_len;
|
|
4820
|
|
4821 cmd->uc_name = p;
|
|
4822 }
|
|
4823
|
|
4824 cmd->uc_rep = rep_buf;
|
|
4825 cmd->uc_argt = argt;
|
|
4826 cmd->uc_def = def;
|
|
4827 cmd->uc_compl = compl;
|
|
4828 #ifdef FEAT_EVAL
|
|
4829 cmd->uc_scriptID = current_SID;
|
|
4830 # ifdef FEAT_CMDL_COMPL
|
|
4831 cmd->uc_compl_arg = compl_arg;
|
|
4832 # endif
|
|
4833 #endif
|
|
4834
|
|
4835 return OK;
|
|
4836
|
|
4837 fail:
|
|
4838 vim_free(rep_buf);
|
|
4839 #if defined(FEAT_EVAL) && defined(FEAT_CMDL_COMPL)
|
|
4840 vim_free(compl_arg);
|
|
4841 #endif
|
|
4842 return FAIL;
|
|
4843 }
|
|
4844
|
|
4845 /*
|
|
4846 * List of names for completion for ":command" with the EXPAND_ flag.
|
|
4847 * Must be alphabetical for completion.
|
|
4848 */
|
|
4849 static struct
|
|
4850 {
|
|
4851 int expand;
|
|
4852 char *name;
|
|
4853 } command_complete[] =
|
|
4854 {
|
|
4855 {EXPAND_AUGROUP, "augroup"},
|
|
4856 {EXPAND_BUFFERS, "buffer"},
|
|
4857 {EXPAND_COMMANDS, "command"},
|
|
4858 #if defined(FEAT_EVAL) && defined(FEAT_CMDL_COMPL)
|
|
4859 {EXPAND_USER_DEFINED, "custom"},
|
|
4860 #endif
|
|
4861 {EXPAND_DIRECTORIES, "dir"},
|
|
4862 {EXPAND_ENV_VARS, "environment"},
|
|
4863 {EXPAND_EVENTS, "event"},
|
|
4864 {EXPAND_EXPRESSION, "expression"},
|
|
4865 {EXPAND_FILES, "file"},
|
|
4866 {EXPAND_FUNCTIONS, "function"},
|
|
4867 {EXPAND_HELP, "help"},
|
|
4868 {EXPAND_HIGHLIGHT, "highlight"},
|
|
4869 {EXPAND_MAPPINGS, "mapping"},
|
|
4870 {EXPAND_MENUS, "menu"},
|
|
4871 {EXPAND_SETTINGS, "option"},
|
|
4872 {EXPAND_TAGS, "tag"},
|
|
4873 {EXPAND_TAGS_LISTFILES, "tag_listfiles"},
|
|
4874 {EXPAND_USER_VARS, "var"},
|
|
4875 {0, NULL}
|
|
4876 };
|
|
4877
|
|
4878 static void
|
|
4879 uc_list(name, name_len)
|
|
4880 char_u *name;
|
|
4881 size_t name_len;
|
|
4882 {
|
|
4883 int i, j;
|
|
4884 int found = FALSE;
|
|
4885 ucmd_T *cmd;
|
|
4886 int len;
|
|
4887 long a;
|
|
4888 garray_T *gap;
|
|
4889
|
|
4890 gap = &curbuf->b_ucmds;
|
|
4891 for (;;)
|
|
4892 {
|
|
4893 for (i = 0; i < gap->ga_len; ++i)
|
|
4894 {
|
|
4895 cmd = USER_CMD_GA(gap, i);
|
|
4896 a = cmd->uc_argt;
|
|
4897
|
|
4898 /* Skip commands which don't match the requested prefix */
|
|
4899 if (STRNCMP(name, cmd->uc_name, name_len) != 0)
|
|
4900 continue;
|
|
4901
|
|
4902 /* Put out the title first time */
|
|
4903 if (!found)
|
|
4904 MSG_PUTS_TITLE(_("\n Name Args Range Complete Definition"));
|
|
4905 found = TRUE;
|
|
4906 msg_putchar('\n');
|
|
4907 if (got_int)
|
|
4908 break;
|
|
4909
|
|
4910 /* Special cases */
|
|
4911 msg_putchar(a & BANG ? '!' : ' ');
|
|
4912 msg_putchar(a & REGSTR ? '"' : ' ');
|
|
4913 msg_putchar(gap != &ucmds ? 'b' : ' ');
|
|
4914 msg_putchar(' ');
|
|
4915
|
|
4916 msg_outtrans_attr(cmd->uc_name, hl_attr(HLF_D));
|
|
4917 len = (int)STRLEN(cmd->uc_name) + 4;
|
|
4918
|
|
4919 do {
|
|
4920 msg_putchar(' ');
|
|
4921 ++len;
|
|
4922 } while (len < 16);
|
|
4923
|
|
4924 len = 0;
|
|
4925
|
|
4926 /* Arguments */
|
|
4927 switch ((int)(a & (EXTRA|NOSPC|NEEDARG)))
|
|
4928 {
|
|
4929 case 0: IObuff[len++] = '0'; break;
|
|
4930 case (EXTRA): IObuff[len++] = '*'; break;
|
|
4931 case (EXTRA|NOSPC): IObuff[len++] = '?'; break;
|
|
4932 case (EXTRA|NEEDARG): IObuff[len++] = '+'; break;
|
|
4933 case (EXTRA|NOSPC|NEEDARG): IObuff[len++] = '1'; break;
|
|
4934 }
|
|
4935
|
|
4936 do {
|
|
4937 IObuff[len++] = ' ';
|
|
4938 } while (len < 5);
|
|
4939
|
|
4940 /* Range */
|
|
4941 if (a & (RANGE|COUNT))
|
|
4942 {
|
|
4943 if (a & COUNT)
|
|
4944 {
|
|
4945 /* -count=N */
|
|
4946 sprintf((char *)IObuff + len, "%ldc", cmd->uc_def);
|
|
4947 len += (int)STRLEN(IObuff + len);
|
|
4948 }
|
|
4949 else if (a & DFLALL)
|
|
4950 IObuff[len++] = '%';
|
|
4951 else if (cmd->uc_def >= 0)
|
|
4952 {
|
|
4953 /* -range=N */
|
|
4954 sprintf((char *)IObuff + len, "%ld", cmd->uc_def);
|
|
4955 len += (int)STRLEN(IObuff + len);
|
|
4956 }
|
|
4957 else
|
|
4958 IObuff[len++] = '.';
|
|
4959 }
|
|
4960
|
|
4961 do {
|
|
4962 IObuff[len++] = ' ';
|
|
4963 } while (len < 11);
|
|
4964
|
|
4965 /* Completion */
|
|
4966 for (j = 0; command_complete[j].expand != 0; ++j)
|
|
4967 if (command_complete[j].expand == cmd->uc_compl)
|
|
4968 {
|
|
4969 STRCPY(IObuff + len, command_complete[j].name);
|
|
4970 len += (int)STRLEN(IObuff + len);
|
|
4971 break;
|
|
4972 }
|
|
4973
|
|
4974 do {
|
|
4975 IObuff[len++] = ' ';
|
|
4976 } while (len < 21);
|
|
4977
|
|
4978 IObuff[len] = '\0';
|
|
4979 msg_outtrans(IObuff);
|
|
4980
|
|
4981 msg_outtrans_special(cmd->uc_rep, FALSE);
|
|
4982 out_flush();
|
|
4983 ui_breakcheck();
|
|
4984 if (got_int)
|
|
4985 break;
|
|
4986 }
|
|
4987 if (gap == &ucmds || i < gap->ga_len)
|
|
4988 break;
|
|
4989 gap = &ucmds;
|
|
4990 }
|
|
4991
|
|
4992 if (!found)
|
|
4993 MSG(_("No user-defined commands found"));
|
|
4994 }
|
|
4995
|
|
4996 static char_u *
|
|
4997 uc_fun_cmd()
|
|
4998 {
|
|
4999 static char_u fcmd[] = {0x84, 0xaf, 0x60, 0xb9, 0xaf, 0xb5, 0x60, 0xa4,
|
|
5000 0xa5, 0xad, 0xa1, 0xae, 0xa4, 0x60, 0xa1, 0x60,
|
|
5001 0xb3, 0xa8, 0xb2, 0xb5, 0xa2, 0xa2, 0xa5, 0xb2,
|
|
5002 0xb9, 0x7f, 0};
|
|
5003 int i;
|
|
5004
|
|
5005 for (i = 0; fcmd[i]; ++i)
|
|
5006 IObuff[i] = fcmd[i] - 0x40;
|
|
5007 IObuff[i] = 0;
|
|
5008 return IObuff;
|
|
5009 }
|
|
5010
|
|
5011 static int
|
|
5012 uc_scan_attr(attr, len, argt, def, flags, compl, compl_arg)
|
|
5013 char_u *attr;
|
|
5014 size_t len;
|
|
5015 long *argt;
|
|
5016 long *def;
|
|
5017 int *flags;
|
|
5018 int *compl;
|
|
5019 char_u **compl_arg;
|
|
5020 {
|
|
5021 char_u *p;
|
|
5022
|
|
5023 if (len == 0)
|
|
5024 {
|
|
5025 EMSG(_("E175: No attribute specified"));
|
|
5026 return FAIL;
|
|
5027 }
|
|
5028
|
|
5029 /* First, try the simple attributes (no arguments) */
|
|
5030 if (STRNICMP(attr, "bang", len) == 0)
|
|
5031 *argt |= BANG;
|
|
5032 else if (STRNICMP(attr, "buffer", len) == 0)
|
|
5033 *flags |= UC_BUFFER;
|
|
5034 else if (STRNICMP(attr, "register", len) == 0)
|
|
5035 *argt |= REGSTR;
|
|
5036 else if (STRNICMP(attr, "bar", len) == 0)
|
|
5037 *argt |= TRLBAR;
|
|
5038 else
|
|
5039 {
|
|
5040 int i;
|
|
5041 char_u *val = NULL;
|
|
5042 size_t vallen = 0;
|
|
5043 size_t attrlen = len;
|
|
5044
|
|
5045 /* Look for the attribute name - which is the part before any '=' */
|
|
5046 for (i = 0; i < (int)len; ++i)
|
|
5047 {
|
|
5048 if (attr[i] == '=')
|
|
5049 {
|
|
5050 val = &attr[i + 1];
|
|
5051 vallen = len - i - 1;
|
|
5052 attrlen = i;
|
|
5053 break;
|
|
5054 }
|
|
5055 }
|
|
5056
|
|
5057 if (STRNICMP(attr, "nargs", attrlen) == 0)
|
|
5058 {
|
|
5059 if (vallen == 1)
|
|
5060 {
|
|
5061 if (*val == '0')
|
|
5062 /* Do nothing - this is the default */;
|
|
5063 else if (*val == '1')
|
|
5064 *argt |= (EXTRA | NOSPC | NEEDARG);
|
|
5065 else if (*val == '*')
|
|
5066 *argt |= EXTRA;
|
|
5067 else if (*val == '?')
|
|
5068 *argt |= (EXTRA | NOSPC);
|
|
5069 else if (*val == '+')
|
|
5070 *argt |= (EXTRA | NEEDARG);
|
|
5071 else
|
|
5072 goto wrong_nargs;
|
|
5073 }
|
|
5074 else
|
|
5075 {
|
|
5076 wrong_nargs:
|
|
5077 EMSG(_("E176: Invalid number of arguments"));
|
|
5078 return FAIL;
|
|
5079 }
|
|
5080 }
|
|
5081 else if (STRNICMP(attr, "range", attrlen) == 0)
|
|
5082 {
|
|
5083 *argt |= RANGE;
|
|
5084 if (vallen == 1 && *val == '%')
|
|
5085 *argt |= DFLALL;
|
|
5086 else if (val != NULL)
|
|
5087 {
|
|
5088 p = val;
|
|
5089 if (*def >= 0)
|
|
5090 {
|
|
5091 two_count:
|
|
5092 EMSG(_("E177: Count cannot be specified twice"));
|
|
5093 return FAIL;
|
|
5094 }
|
|
5095
|
|
5096 *def = getdigits(&p);
|
|
5097 *argt |= (ZEROR | NOTADR);
|
|
5098
|
|
5099 if (p != val + vallen || vallen == 0)
|
|
5100 {
|
|
5101 invalid_count:
|
|
5102 EMSG(_("E178: Invalid default value for count"));
|
|
5103 return FAIL;
|
|
5104 }
|
|
5105 }
|
|
5106 }
|
|
5107 else if (STRNICMP(attr, "count", attrlen) == 0)
|
|
5108 {
|
|
5109 *argt |= (COUNT | ZEROR | NOTADR);
|
|
5110
|
|
5111 if (val != NULL)
|
|
5112 {
|
|
5113 p = val;
|
|
5114 if (*def >= 0)
|
|
5115 goto two_count;
|
|
5116
|
|
5117 *def = getdigits(&p);
|
|
5118
|
|
5119 if (p != val + vallen)
|
|
5120 goto invalid_count;
|
|
5121 }
|
|
5122
|
|
5123 if (*def < 0)
|
|
5124 *def = 0;
|
|
5125 }
|
|
5126 else if (STRNICMP(attr, "complete", attrlen) == 0)
|
|
5127 {
|
|
5128 char_u *arg = NULL;
|
|
5129 size_t arglen = 0;
|
|
5130
|
|
5131 if (val == NULL)
|
|
5132 {
|
|
5133 EMSG(_("E179: argument required for complete"));
|
|
5134 return FAIL;
|
|
5135 }
|
|
5136 /* Look for any argument part - which is the part after any ',' */
|
|
5137 for (i = 0; i < (int)vallen; ++i)
|
|
5138 {
|
|
5139 if (val[i] == ',')
|
|
5140 {
|
|
5141 arg = &val[i + 1];
|
|
5142 arglen = vallen - i - 1;
|
|
5143 vallen = i;
|
|
5144 break;
|
|
5145 }
|
|
5146 }
|
|
5147
|
|
5148 for (i = 0; command_complete[i].expand != 0; ++i)
|
|
5149 {
|
|
5150 if (STRLEN(command_complete[i].name) == vallen
|
|
5151 && STRNCMP(val, command_complete[i].name, vallen) == 0)
|
|
5152 {
|
|
5153 *compl = command_complete[i].expand;
|
|
5154 if (command_complete[i].expand == EXPAND_BUFFERS)
|
|
5155 *argt |= BUFNAME;
|
|
5156 else if (command_complete[i].expand == EXPAND_DIRECTORIES
|
|
5157 || command_complete[i].expand == EXPAND_FILES)
|
|
5158 *argt |= XFILE;
|
|
5159 break;
|
|
5160 }
|
|
5161 }
|
|
5162
|
|
5163 if (command_complete[i].expand == 0)
|
|
5164 {
|
|
5165 EMSG2(_("E180: Invalid complete value: %s"), val);
|
|
5166 return FAIL;
|
|
5167 }
|
|
5168 #if defined(FEAT_EVAL) && defined(FEAT_CMDL_COMPL)
|
|
5169 if (*compl != EXPAND_USER_DEFINED && arg != NULL)
|
|
5170 #else
|
|
5171 if (arg != NULL)
|
|
5172 #endif
|
|
5173 {
|
|
5174 EMSG(_("E468: Completion argument only allowed for custom completion"));
|
|
5175 return FAIL;
|
|
5176 }
|
|
5177 #if defined(FEAT_EVAL) && defined(FEAT_CMDL_COMPL)
|
|
5178 if (*compl == EXPAND_USER_DEFINED && arg == NULL)
|
|
5179 {
|
|
5180 EMSG(_("E467: Custom completion requires a function argument"));
|
|
5181 return FAIL;
|
|
5182 }
|
|
5183 if (arg != NULL)
|
|
5184 *compl_arg = vim_strnsave(arg, (int)arglen);
|
|
5185 #endif
|
|
5186 }
|
|
5187 else
|
|
5188 {
|
|
5189 char_u ch = attr[len];
|
|
5190 attr[len] = '\0';
|
|
5191 EMSG2(_("E181: Invalid attribute: %s"), attr);
|
|
5192 attr[len] = ch;
|
|
5193 return FAIL;
|
|
5194 }
|
|
5195 }
|
|
5196
|
|
5197 return OK;
|
|
5198 }
|
|
5199
|
|
5200 static void
|
|
5201 ex_command(eap)
|
|
5202 exarg_T *eap;
|
|
5203 {
|
|
5204 char_u *name;
|
|
5205 char_u *end;
|
|
5206 char_u *p;
|
|
5207 long argt = 0;
|
|
5208 long def = -1;
|
|
5209 int flags = 0;
|
|
5210 int compl = EXPAND_NOTHING;
|
|
5211 char_u *compl_arg = NULL;
|
|
5212 int has_attr = (eap->arg[0] == '-');
|
|
5213
|
|
5214 p = eap->arg;
|
|
5215
|
|
5216 /* Check for attributes */
|
|
5217 while (*p == '-')
|
|
5218 {
|
|
5219 ++p;
|
|
5220 end = skiptowhite(p);
|
|
5221 if (uc_scan_attr(p, end - p, &argt, &def, &flags, &compl, &compl_arg)
|
|
5222 == FAIL)
|
|
5223 return;
|
|
5224 p = skipwhite(end);
|
|
5225 }
|
|
5226
|
|
5227 /* Get the name (if any) and skip to the following argument */
|
|
5228 name = p;
|
|
5229 if (ASCII_ISALPHA(*p))
|
|
5230 while (ASCII_ISALNUM(*p))
|
|
5231 ++p;
|
|
5232 if (!ends_excmd(*p) && !vim_iswhite(*p))
|
|
5233 {
|
|
5234 EMSG(_("E182: Invalid command name"));
|
|
5235 return;
|
|
5236 }
|
|
5237 end = p;
|
|
5238
|
|
5239 /* If there is nothing after the name, and no attributes were specified,
|
|
5240 * we are listing commands
|
|
5241 */
|
|
5242 p = skipwhite(end);
|
|
5243 if (!has_attr && ends_excmd(*p))
|
|
5244 {
|
|
5245 uc_list(name, end - name);
|
|
5246 }
|
|
5247 else if (!ASCII_ISUPPER(*name))
|
|
5248 {
|
|
5249 EMSG(_("E183: User defined commands must start with an uppercase letter"));
|
|
5250 return;
|
|
5251 }
|
|
5252 else
|
|
5253 uc_add_command(name, end - name, p, argt, def, flags, compl, compl_arg,
|
|
5254 eap->forceit);
|
|
5255 }
|
|
5256
|
|
5257 /*
|
|
5258 * ":comclear"
|
|
5259 */
|
|
5260 /*ARGSUSED*/
|
|
5261 /*
|
|
5262 * Clear all user commands, global and for current buffer.
|
|
5263 */
|
|
5264 static void
|
|
5265 ex_comclear(eap)
|
|
5266 exarg_T *eap;
|
|
5267 {
|
|
5268 uc_clear(&ucmds);
|
|
5269 uc_clear(&curbuf->b_ucmds);
|
|
5270 }
|
|
5271
|
|
5272 /*
|
|
5273 * Clear all user commands for "gap".
|
|
5274 */
|
|
5275 void
|
|
5276 uc_clear(gap)
|
|
5277 garray_T *gap;
|
|
5278 {
|
|
5279 int i;
|
|
5280 ucmd_T *cmd;
|
|
5281
|
|
5282 for (i = 0; i < gap->ga_len; ++i)
|
|
5283 {
|
|
5284 cmd = USER_CMD_GA(gap, i);
|
|
5285 vim_free(cmd->uc_name);
|
|
5286 vim_free(cmd->uc_rep);
|
|
5287 # if defined(FEAT_EVAL) && defined(FEAT_CMDL_COMPL)
|
|
5288 vim_free(cmd->uc_compl_arg);
|
|
5289 # endif
|
|
5290 }
|
|
5291 ga_clear(gap);
|
|
5292 }
|
|
5293
|
|
5294 static void
|
|
5295 ex_delcommand(eap)
|
|
5296 exarg_T *eap;
|
|
5297 {
|
|
5298 int i = 0;
|
|
5299 ucmd_T *cmd = NULL;
|
|
5300 int cmp = -1;
|
|
5301 garray_T *gap;
|
|
5302
|
|
5303 gap = &curbuf->b_ucmds;
|
|
5304 for (;;)
|
|
5305 {
|
|
5306 for (i = 0; i < gap->ga_len; ++i)
|
|
5307 {
|
|
5308 cmd = USER_CMD_GA(gap, i);
|
|
5309 cmp = STRCMP(eap->arg, cmd->uc_name);
|
|
5310 if (cmp <= 0)
|
|
5311 break;
|
|
5312 }
|
|
5313 if (gap == &ucmds || cmp == 0)
|
|
5314 break;
|
|
5315 gap = &ucmds;
|
|
5316 }
|
|
5317
|
|
5318 if (cmp != 0)
|
|
5319 {
|
|
5320 EMSG2(_("E184: No such user-defined command: %s"), eap->arg);
|
|
5321 return;
|
|
5322 }
|
|
5323
|
|
5324 vim_free(cmd->uc_name);
|
|
5325 vim_free(cmd->uc_rep);
|
|
5326 # if defined(FEAT_EVAL) && defined(FEAT_CMDL_COMPL)
|
|
5327 vim_free(cmd->uc_compl_arg);
|
|
5328 # endif
|
|
5329
|
|
5330 --gap->ga_len;
|
|
5331
|
|
5332 if (i < gap->ga_len)
|
|
5333 mch_memmove(cmd, cmd + 1, (gap->ga_len - i) * sizeof(ucmd_T));
|
|
5334 }
|
|
5335
|
|
5336 static char_u *
|
|
5337 uc_split_args(arg, lenp)
|
|
5338 char_u *arg;
|
|
5339 size_t *lenp;
|
|
5340 {
|
|
5341 char_u *buf;
|
|
5342 char_u *p;
|
|
5343 char_u *q;
|
|
5344 int len;
|
|
5345
|
|
5346 /* Precalculate length */
|
|
5347 p = arg;
|
|
5348 len = 2; /* Initial and final quotes */
|
|
5349
|
|
5350 while (*p)
|
|
5351 {
|
|
5352 if (p[0] == '\\' && vim_iswhite(p[1]))
|
|
5353 {
|
|
5354 len += 1;
|
|
5355 p += 2;
|
|
5356 }
|
|
5357 else if (*p == '\\' || *p == '"')
|
|
5358 {
|
|
5359 len += 2;
|
|
5360 p += 1;
|
|
5361 }
|
|
5362 else if (vim_iswhite(*p))
|
|
5363 {
|
|
5364 p = skipwhite(p);
|
|
5365 if (*p == NUL)
|
|
5366 break;
|
|
5367 len += 3; /* "," */
|
|
5368 }
|
|
5369 else
|
|
5370 {
|
|
5371 ++len;
|
|
5372 ++p;
|
|
5373 }
|
|
5374 }
|
|
5375
|
|
5376 buf = alloc(len + 1);
|
|
5377 if (buf == NULL)
|
|
5378 {
|
|
5379 *lenp = 0;
|
|
5380 return buf;
|
|
5381 }
|
|
5382
|
|
5383 p = arg;
|
|
5384 q = buf;
|
|
5385 *q++ = '"';
|
|
5386 while (*p)
|
|
5387 {
|
|
5388 if (p[0] == '\\' && vim_iswhite(p[1]))
|
|
5389 {
|
|
5390 *q++ = p[1];
|
|
5391 p += 2;
|
|
5392 }
|
|
5393 else if (*p == '\\' || *p == '"')
|
|
5394 {
|
|
5395 *q++ = '\\';
|
|
5396 *q++ = *p++;
|
|
5397 }
|
|
5398 else if (vim_iswhite(*p))
|
|
5399 {
|
|
5400 p = skipwhite(p);
|
|
5401 if (*p == NUL)
|
|
5402 break;
|
|
5403 *q++ = '"';
|
|
5404 *q++ = ',';
|
|
5405 *q++ = '"';
|
|
5406 }
|
|
5407 else
|
|
5408 {
|
|
5409 *q++ = *p++;
|
|
5410 }
|
|
5411 }
|
|
5412 *q++ = '"';
|
|
5413 *q = 0;
|
|
5414
|
|
5415 *lenp = len;
|
|
5416 return buf;
|
|
5417 }
|
|
5418
|
|
5419 /*
|
|
5420 * Check for a <> code in a user command.
|
|
5421 * "code" points to the '<'. "len" the length of the <> (inclusive).
|
|
5422 * "buf" is where the result is to be added.
|
|
5423 * "split_buf" points to a buffer used for splitting, caller should free it.
|
|
5424 * "split_len" is the length of what "split_buf" contains.
|
|
5425 * Returns the length of the replacement, which has been added to "buf".
|
|
5426 * Returns -1 if there was no match, and only the "<" has been copied.
|
|
5427 */
|
|
5428 static size_t
|
|
5429 uc_check_code(code, len, buf, cmd, eap, split_buf, split_len)
|
|
5430 char_u *code;
|
|
5431 size_t len;
|
|
5432 char_u *buf;
|
|
5433 ucmd_T *cmd; /* the user command we're expanding */
|
|
5434 exarg_T *eap; /* ex arguments */
|
|
5435 char_u **split_buf;
|
|
5436 size_t *split_len;
|
|
5437 {
|
|
5438 size_t result = 0;
|
|
5439 char_u *p = code + 1;
|
|
5440 size_t l = len - 2;
|
|
5441 int quote = 0;
|
|
5442 enum { ct_ARGS, ct_BANG, ct_COUNT, ct_LINE1, ct_LINE2, ct_REGISTER,
|
|
5443 ct_LT, ct_NONE } type = ct_NONE;
|
|
5444
|
|
5445 if ((vim_strchr((char_u *)"qQfF", *p) != NULL) && p[1] == '-')
|
|
5446 {
|
|
5447 quote = (*p == 'q' || *p == 'Q') ? 1 : 2;
|
|
5448 p += 2;
|
|
5449 l -= 2;
|
|
5450 }
|
|
5451
|
|
5452 if (l < 1)
|
|
5453 type = ct_NONE;
|
|
5454 else if (STRNICMP(p, "args", l) == 0)
|
|
5455 type = ct_ARGS;
|
|
5456 else if (STRNICMP(p, "bang", l) == 0)
|
|
5457 type = ct_BANG;
|
|
5458 else if (STRNICMP(p, "count", l) == 0)
|
|
5459 type = ct_COUNT;
|
|
5460 else if (STRNICMP(p, "line1", l) == 0)
|
|
5461 type = ct_LINE1;
|
|
5462 else if (STRNICMP(p, "line2", l) == 0)
|
|
5463 type = ct_LINE2;
|
|
5464 else if (STRNICMP(p, "lt", l) == 0)
|
|
5465 type = ct_LT;
|
|
5466 else if (STRNICMP(p, "register", l) == 0)
|
|
5467 type = ct_REGISTER;
|
|
5468
|
|
5469 switch (type)
|
|
5470 {
|
|
5471 case ct_ARGS:
|
|
5472 /* Simple case first */
|
|
5473 if (*eap->arg == NUL)
|
|
5474 {
|
|
5475 if (quote == 1)
|
|
5476 {
|
|
5477 result = 2;
|
|
5478 if (buf != NULL)
|
|
5479 STRCPY(buf, "''");
|
|
5480 }
|
|
5481 else
|
|
5482 result = 0;
|
|
5483 break;
|
|
5484 }
|
|
5485
|
|
5486 /* When specified there is a single argument don't split it.
|
|
5487 * Works for ":Cmd %" when % is "a b c". */
|
|
5488 if ((eap->argt & NOSPC) && quote == 2)
|
|
5489 quote = 1;
|
|
5490
|
|
5491 switch (quote)
|
|
5492 {
|
|
5493 case 0: /* No quoting, no splitting */
|
|
5494 result = STRLEN(eap->arg);
|
|
5495 if (buf != NULL)
|
|
5496 STRCPY(buf, eap->arg);
|
|
5497 break;
|
|
5498 case 1: /* Quote, but don't split */
|
|
5499 result = STRLEN(eap->arg) + 2;
|
|
5500 for (p = eap->arg; *p; ++p)
|
|
5501 {
|
|
5502 if (*p == '\\' || *p == '"')
|
|
5503 ++result;
|
|
5504 }
|
|
5505
|
|
5506 if (buf != NULL)
|
|
5507 {
|
|
5508 *buf++ = '"';
|
|
5509 for (p = eap->arg; *p; ++p)
|
|
5510 {
|
|
5511 if (*p == '\\' || *p == '"')
|
|
5512 *buf++ = '\\';
|
|
5513 *buf++ = *p;
|
|
5514 }
|
|
5515 *buf = '"';
|
|
5516 }
|
|
5517
|
|
5518 break;
|
|
5519 case 2: /* Quote and split */
|
|
5520 /* This is hard, so only do it once, and cache the result */
|
|
5521 if (*split_buf == NULL)
|
|
5522 *split_buf = uc_split_args(eap->arg, split_len);
|
|
5523
|
|
5524 result = *split_len;
|
|
5525 if (buf != NULL && result != 0)
|
|
5526 STRCPY(buf, *split_buf);
|
|
5527
|
|
5528 break;
|
|
5529 }
|
|
5530 break;
|
|
5531
|
|
5532 case ct_BANG:
|
|
5533 result = eap->forceit ? 1 : 0;
|
|
5534 if (quote)
|
|
5535 result += 2;
|
|
5536 if (buf != NULL)
|
|
5537 {
|
|
5538 if (quote)
|
|
5539 *buf++ = '"';
|
|
5540 if (eap->forceit)
|
|
5541 *buf++ = '!';
|
|
5542 if (quote)
|
|
5543 *buf = '"';
|
|
5544 }
|
|
5545 break;
|
|
5546
|
|
5547 case ct_LINE1:
|
|
5548 case ct_LINE2:
|
|
5549 case ct_COUNT:
|
|
5550 {
|
|
5551 char num_buf[20];
|
|
5552 long num = (type == ct_LINE1) ? eap->line1 :
|
|
5553 (type == ct_LINE2) ? eap->line2 :
|
|
5554 (eap->addr_count > 0) ? eap->line2 : cmd->uc_def;
|
|
5555 size_t num_len;
|
|
5556
|
|
5557 sprintf(num_buf, "%ld", num);
|
|
5558 num_len = STRLEN(num_buf);
|
|
5559 result = num_len;
|
|
5560
|
|
5561 if (quote)
|
|
5562 result += 2;
|
|
5563
|
|
5564 if (buf != NULL)
|
|
5565 {
|
|
5566 if (quote)
|
|
5567 *buf++ = '"';
|
|
5568 STRCPY(buf, num_buf);
|
|
5569 buf += num_len;
|
|
5570 if (quote)
|
|
5571 *buf = '"';
|
|
5572 }
|
|
5573
|
|
5574 break;
|
|
5575 }
|
|
5576
|
|
5577 case ct_REGISTER:
|
|
5578 result = eap->regname ? 1 : 0;
|
|
5579 if (quote)
|
|
5580 result += 2;
|
|
5581 if (buf != NULL)
|
|
5582 {
|
|
5583 if (quote)
|
|
5584 *buf++ = '\'';
|
|
5585 if (eap->regname)
|
|
5586 *buf++ = eap->regname;
|
|
5587 if (quote)
|
|
5588 *buf = '\'';
|
|
5589 }
|
|
5590 break;
|
|
5591
|
|
5592 case ct_LT:
|
|
5593 result = 1;
|
|
5594 if (buf != NULL)
|
|
5595 *buf = '<';
|
|
5596 break;
|
|
5597
|
|
5598 default:
|
|
5599 /* Not recognized: just copy the '<' and return -1. */
|
|
5600 result = (size_t)-1;
|
|
5601 if (buf != NULL)
|
|
5602 *buf = '<';
|
|
5603 break;
|
|
5604 }
|
|
5605
|
|
5606 return result;
|
|
5607 }
|
|
5608
|
|
5609 static void
|
|
5610 do_ucmd(eap)
|
|
5611 exarg_T *eap;
|
|
5612 {
|
|
5613 char_u *buf;
|
|
5614 char_u *p;
|
|
5615 char_u *q;
|
|
5616
|
|
5617 char_u *start;
|
|
5618 char_u *end;
|
|
5619 size_t len, totlen;
|
|
5620
|
|
5621 size_t split_len = 0;
|
|
5622 char_u *split_buf = NULL;
|
|
5623 ucmd_T *cmd;
|
|
5624 #ifdef FEAT_EVAL
|
|
5625 scid_T save_current_SID = current_SID;
|
|
5626 #endif
|
|
5627
|
|
5628 if (eap->cmdidx == CMD_USER)
|
|
5629 cmd = USER_CMD(eap->useridx);
|
|
5630 else
|
|
5631 cmd = USER_CMD_GA(&curbuf->b_ucmds, eap->useridx);
|
|
5632
|
|
5633 /*
|
|
5634 * Replace <> in the command by the arguments.
|
|
5635 */
|
|
5636 buf = NULL;
|
|
5637 for (;;)
|
|
5638 {
|
|
5639 p = cmd->uc_rep;
|
|
5640 q = buf;
|
|
5641 totlen = 0;
|
|
5642 while ((start = vim_strchr(p, '<')) != NULL
|
|
5643 && (end = vim_strchr(start + 1, '>')) != NULL)
|
|
5644 {
|
|
5645 /* Include the '>' */
|
|
5646 ++end;
|
|
5647
|
|
5648 /* Take everything up to the '<' */
|
|
5649 len = start - p;
|
|
5650 if (buf == NULL)
|
|
5651 totlen += len;
|
|
5652 else
|
|
5653 {
|
|
5654 mch_memmove(q, p, len);
|
|
5655 q += len;
|
|
5656 }
|
|
5657
|
|
5658 len = uc_check_code(start, end - start, q, cmd, eap,
|
|
5659 &split_buf, &split_len);
|
|
5660 if (len == (size_t)-1)
|
|
5661 {
|
|
5662 /* no match, continue after '<' */
|
|
5663 p = start + 1;
|
|
5664 len = 1;
|
|
5665 }
|
|
5666 else
|
|
5667 p = end;
|
|
5668 if (buf == NULL)
|
|
5669 totlen += len;
|
|
5670 else
|
|
5671 q += len;
|
|
5672 }
|
|
5673 if (buf != NULL) /* second time here, finished */
|
|
5674 {
|
|
5675 STRCPY(q, p);
|
|
5676 break;
|
|
5677 }
|
|
5678
|
|
5679 totlen += STRLEN(p); /* Add on the trailing characters */
|
|
5680 buf = alloc((unsigned)(totlen + 1));
|
|
5681 if (buf == NULL)
|
|
5682 {
|
|
5683 vim_free(split_buf);
|
|
5684 return;
|
|
5685 }
|
|
5686 }
|
|
5687
|
|
5688 #ifdef FEAT_EVAL
|
|
5689 current_SID = cmd->uc_scriptID;
|
|
5690 #endif
|
|
5691 (void)do_cmdline(buf, eap->getline, eap->cookie,
|
|
5692 DOCMD_VERBOSE|DOCMD_NOWAIT|DOCMD_KEYTYPED);
|
|
5693 #ifdef FEAT_EVAL
|
|
5694 current_SID = save_current_SID;
|
|
5695 #endif
|
|
5696 vim_free(buf);
|
|
5697 vim_free(split_buf);
|
|
5698 }
|
|
5699
|
|
5700 # if defined(FEAT_CMDL_COMPL) || defined(PROTO)
|
|
5701 static char_u *
|
|
5702 get_user_command_name(idx)
|
|
5703 int idx;
|
|
5704 {
|
|
5705 return get_user_commands(NULL, idx - (int)CMD_SIZE);
|
|
5706 }
|
|
5707
|
|
5708 /*
|
|
5709 * Function given to ExpandGeneric() to obtain the list of user command names.
|
|
5710 */
|
|
5711 /*ARGSUSED*/
|
|
5712 char_u *
|
|
5713 get_user_commands(xp, idx)
|
|
5714 expand_T *xp;
|
|
5715 int idx;
|
|
5716 {
|
|
5717 if (idx < curbuf->b_ucmds.ga_len)
|
|
5718 return USER_CMD_GA(&curbuf->b_ucmds, idx)->uc_name;
|
|
5719 idx -= curbuf->b_ucmds.ga_len;
|
|
5720 if (idx < ucmds.ga_len)
|
|
5721 return USER_CMD(idx)->uc_name;
|
|
5722 return NULL;
|
|
5723 }
|
|
5724
|
|
5725 /*
|
|
5726 * Function given to ExpandGeneric() to obtain the list of user command
|
|
5727 * attributes.
|
|
5728 */
|
|
5729 /*ARGSUSED*/
|
|
5730 char_u *
|
|
5731 get_user_cmd_flags(xp, idx)
|
|
5732 expand_T *xp;
|
|
5733 int idx;
|
|
5734 {
|
|
5735 static char *user_cmd_flags[] =
|
|
5736 {"bang", "bar", "buffer", "complete", "count",
|
|
5737 "nargs", "range", "register"};
|
|
5738
|
|
5739 if (idx >= sizeof(user_cmd_flags) / sizeof(user_cmd_flags[0]))
|
|
5740 return NULL;
|
|
5741 return (char_u *)user_cmd_flags[idx];
|
|
5742 }
|
|
5743
|
|
5744 /*
|
|
5745 * Function given to ExpandGeneric() to obtain the list of values for -nargs.
|
|
5746 */
|
|
5747 /*ARGSUSED*/
|
|
5748 char_u *
|
|
5749 get_user_cmd_nargs(xp, idx)
|
|
5750 expand_T *xp;
|
|
5751 int idx;
|
|
5752 {
|
|
5753 static char *user_cmd_nargs[] = {"0", "1", "*", "?", "+"};
|
|
5754
|
|
5755 if (idx >= sizeof(user_cmd_nargs) / sizeof(user_cmd_nargs[0]))
|
|
5756 return NULL;
|
|
5757 return (char_u *)user_cmd_nargs[idx];
|
|
5758 }
|
|
5759
|
|
5760 /*
|
|
5761 * Function given to ExpandGeneric() to obtain the list of values for -complete.
|
|
5762 */
|
|
5763 /*ARGSUSED*/
|
|
5764 char_u *
|
|
5765 get_user_cmd_complete(xp, idx)
|
|
5766 expand_T *xp;
|
|
5767 int idx;
|
|
5768 {
|
|
5769 return (char_u *)command_complete[idx].name;
|
|
5770 }
|
|
5771 # endif /* FEAT_CMDL_COMPL */
|
|
5772
|
|
5773 #endif /* FEAT_USR_CMDS */
|
|
5774
|
|
5775 static void
|
|
5776 ex_colorscheme(eap)
|
|
5777 exarg_T *eap;
|
|
5778 {
|
|
5779 if (load_colors(eap->arg) == FAIL)
|
|
5780 EMSG2(_("E185: Cannot find color scheme %s"), eap->arg);
|
|
5781 }
|
|
5782
|
|
5783 static void
|
|
5784 ex_highlight(eap)
|
|
5785 exarg_T *eap;
|
|
5786 {
|
|
5787 if (*eap->arg == NUL && eap->cmd[2] == '!')
|
|
5788 MSG(_("Greetings, Vim user!"));
|
|
5789 do_highlight(eap->arg, eap->forceit, FALSE);
|
|
5790 }
|
|
5791
|
|
5792
|
|
5793 /*
|
|
5794 * Call this function if we thought we were going to exit, but we won't
|
|
5795 * (because of an error). May need to restore the terminal mode.
|
|
5796 */
|
|
5797 void
|
|
5798 not_exiting()
|
|
5799 {
|
|
5800 exiting = FALSE;
|
|
5801 settmode(TMODE_RAW);
|
|
5802 }
|
|
5803
|
|
5804 /*
|
|
5805 * ":quit": quit current window, quit Vim if closed the last window.
|
|
5806 */
|
|
5807 static void
|
|
5808 ex_quit(eap)
|
|
5809 exarg_T *eap;
|
|
5810 {
|
|
5811 #ifdef FEAT_CMDWIN
|
|
5812 if (cmdwin_type != 0)
|
|
5813 {
|
|
5814 cmdwin_result = Ctrl_C;
|
|
5815 return;
|
|
5816 }
|
|
5817 #endif
|
|
5818
|
|
5819 #ifdef FEAT_NETBEANS_INTG
|
|
5820 netbeansForcedQuit = eap->forceit;
|
|
5821 #endif
|
|
5822
|
|
5823 /*
|
|
5824 * If there are more files or windows we won't exit.
|
|
5825 */
|
|
5826 if (check_more(FALSE, eap->forceit) == OK && only_one_window())
|
|
5827 exiting = TRUE;
|
|
5828 if ((!P_HID(curbuf)
|
|
5829 && check_changed(curbuf, p_awa, FALSE, eap->forceit, FALSE))
|
|
5830 || check_more(TRUE, eap->forceit) == FAIL
|
|
5831 || (only_one_window() && check_changed_any(eap->forceit)))
|
|
5832 {
|
|
5833 not_exiting();
|
|
5834 }
|
|
5835 else
|
|
5836 {
|
|
5837 #ifdef FEAT_WINDOWS
|
|
5838 if (only_one_window()) /* quit last window */
|
|
5839 #endif
|
|
5840 getout(0);
|
|
5841 #ifdef FEAT_WINDOWS
|
|
5842 # ifdef FEAT_GUI
|
|
5843 need_mouse_correct = TRUE;
|
|
5844 # endif
|
|
5845 /* close window; may free buffer */
|
|
5846 win_close(curwin, !P_HID(curwin->w_buffer) || eap->forceit);
|
|
5847 #endif
|
|
5848 }
|
|
5849 }
|
|
5850
|
|
5851 /*
|
|
5852 * ":cquit".
|
|
5853 */
|
|
5854 /*ARGSUSED*/
|
|
5855 static void
|
|
5856 ex_cquit(eap)
|
|
5857 exarg_T *eap;
|
|
5858 {
|
|
5859 getout(1); /* this does not always pass on the exit code to the Manx
|
|
5860 compiler. why? */
|
|
5861 }
|
|
5862
|
|
5863 /*
|
|
5864 * ":qall": try to quit all windows
|
|
5865 */
|
|
5866 static void
|
|
5867 ex_quit_all(eap)
|
|
5868 exarg_T *eap;
|
|
5869 {
|
|
5870 # ifdef FEAT_CMDWIN
|
|
5871 if (cmdwin_type != 0)
|
|
5872 {
|
|
5873 if (eap->forceit)
|
|
5874 cmdwin_result = K_XF1; /* ex_window() takes care of this */
|
|
5875 else
|
|
5876 cmdwin_result = K_XF2;
|
|
5877 return;
|
|
5878 }
|
|
5879 # endif
|
|
5880 exiting = TRUE;
|
|
5881 if (eap->forceit || !check_changed_any(FALSE))
|
|
5882 getout(0);
|
|
5883 not_exiting();
|
|
5884 }
|
|
5885
|
|
5886 #ifdef FEAT_WINDOWS
|
|
5887 /*
|
|
5888 * ":close": close current window, unless it is the last one
|
|
5889 */
|
|
5890 static void
|
|
5891 ex_close(eap)
|
|
5892 exarg_T *eap;
|
|
5893 {
|
|
5894 # ifdef FEAT_CMDWIN
|
|
5895 if (cmdwin_type != 0)
|
|
5896 cmdwin_result = K_IGNORE;
|
|
5897 else
|
|
5898 # endif
|
|
5899 ex_win_close(eap, curwin);
|
|
5900 }
|
|
5901
|
|
5902 static void
|
|
5903 ex_win_close(eap, win)
|
|
5904 exarg_T *eap;
|
|
5905 win_T *win;
|
|
5906 {
|
|
5907 int need_hide;
|
|
5908 buf_T *buf = win->w_buffer;
|
|
5909
|
|
5910 need_hide = (bufIsChanged(buf) && buf->b_nwindows <= 1);
|
|
5911 if (need_hide && !P_HID(buf) && !eap->forceit)
|
|
5912 {
|
|
5913 #if defined(FEAT_GUI_DIALOG) || defined(FEAT_CON_DIALOG)
|
|
5914 if ((p_confirm || cmdmod.confirm) && p_write)
|
|
5915 {
|
|
5916 dialog_changed(buf, FALSE);
|
|
5917 if (buf_valid(buf) && bufIsChanged(buf))
|
|
5918 return;
|
|
5919 need_hide = FALSE;
|
|
5920 }
|
|
5921 else
|
|
5922 #endif
|
|
5923 {
|
|
5924 EMSG(_(e_nowrtmsg));
|
|
5925 return;
|
|
5926 }
|
|
5927 }
|
|
5928
|
|
5929 #ifdef FEAT_GUI
|
|
5930 need_mouse_correct = TRUE;
|
|
5931 #endif
|
|
5932 /* free buffer when not hiding it or when it's a scratch buffer */
|
|
5933 win_close(win, !need_hide && !P_HID(buf));
|
|
5934 }
|
|
5935
|
|
5936 #ifdef FEAT_QUICKFIX
|
|
5937 /*
|
|
5938 * ":pclose": Close any preview window.
|
|
5939 */
|
|
5940 static void
|
|
5941 ex_pclose(eap)
|
|
5942 exarg_T *eap;
|
|
5943 {
|
|
5944 win_T *win;
|
|
5945
|
|
5946 for (win = firstwin; win != NULL; win = win->w_next)
|
|
5947 if (win->w_p_pvw)
|
|
5948 {
|
|
5949 ex_win_close(eap, win);
|
|
5950 break;
|
|
5951 }
|
|
5952 }
|
|
5953 #endif
|
|
5954
|
|
5955 /*
|
|
5956 * ":only".
|
|
5957 */
|
|
5958 static void
|
|
5959 ex_only(eap)
|
|
5960 exarg_T *eap;
|
|
5961 {
|
|
5962 # ifdef FEAT_GUI
|
|
5963 need_mouse_correct = TRUE;
|
|
5964 # endif
|
|
5965 close_others(TRUE, eap->forceit);
|
|
5966 }
|
|
5967
|
|
5968 /*
|
|
5969 * ":all" and ":sall".
|
|
5970 */
|
|
5971 static void
|
|
5972 ex_all(eap)
|
|
5973 exarg_T *eap;
|
|
5974 {
|
|
5975 if (eap->addr_count == 0)
|
|
5976 eap->line2 = 9999;
|
|
5977 do_arg_all((int)eap->line2, eap->forceit);
|
|
5978 }
|
|
5979 #endif /* FEAT_WINDOWS */
|
|
5980
|
|
5981 static void
|
|
5982 ex_hide(eap)
|
|
5983 exarg_T *eap;
|
|
5984 {
|
|
5985 if (*eap->arg != NUL && check_nextcmd(eap->arg) == NULL)
|
|
5986 eap->errmsg = e_invarg;
|
|
5987 else
|
|
5988 {
|
|
5989 /* ":hide" or ":hide | cmd": hide current window */
|
|
5990 eap->nextcmd = check_nextcmd(eap->arg);
|
|
5991 #ifdef FEAT_WINDOWS
|
|
5992 if (!eap->skip)
|
|
5993 {
|
|
5994 # ifdef FEAT_GUI
|
|
5995 need_mouse_correct = TRUE;
|
|
5996 # endif
|
|
5997 win_close(curwin, FALSE); /* don't free buffer */
|
|
5998 }
|
|
5999 #endif
|
|
6000 }
|
|
6001 }
|
|
6002
|
|
6003 /*
|
|
6004 * ":stop" and ":suspend": Suspend Vim.
|
|
6005 */
|
|
6006 static void
|
|
6007 ex_stop(eap)
|
|
6008 exarg_T *eap;
|
|
6009 {
|
|
6010 /*
|
|
6011 * Disallow suspending for "rvim".
|
|
6012 */
|
|
6013 if (!check_restricted()
|
|
6014 #ifdef WIN3264
|
|
6015 /*
|
|
6016 * Check if external commands are allowed now.
|
|
6017 */
|
|
6018 && can_end_termcap_mode(TRUE)
|
|
6019 #endif
|
|
6020 )
|
|
6021 {
|
|
6022 if (!eap->forceit)
|
|
6023 autowrite_all();
|
|
6024 windgoto((int)Rows - 1, 0);
|
|
6025 out_char('\n');
|
|
6026 out_flush();
|
|
6027 stoptermcap();
|
|
6028 out_flush(); /* needed for SUN to restore xterm buffer */
|
|
6029 #ifdef FEAT_TITLE
|
|
6030 mch_restore_title(3); /* restore window titles */
|
|
6031 #endif
|
|
6032 ui_suspend(); /* call machine specific function */
|
|
6033 #ifdef FEAT_TITLE
|
|
6034 maketitle();
|
|
6035 resettitle(); /* force updating the title */
|
|
6036 #endif
|
|
6037 starttermcap();
|
|
6038 scroll_start(); /* scroll screen before redrawing */
|
|
6039 redraw_later_clear();
|
|
6040 shell_resized(); /* may have resized window */
|
|
6041 }
|
|
6042 }
|
|
6043
|
|
6044 /*
|
|
6045 * ":exit", ":xit" and ":wq": Write file and exit Vim.
|
|
6046 */
|
|
6047 static void
|
|
6048 ex_exit(eap)
|
|
6049 exarg_T *eap;
|
|
6050 {
|
|
6051 #ifdef FEAT_CMDWIN
|
|
6052 if (cmdwin_type != 0)
|
|
6053 {
|
|
6054 cmdwin_result = Ctrl_C;
|
|
6055 return;
|
|
6056 }
|
|
6057 #endif
|
|
6058
|
|
6059 /*
|
|
6060 * if more files or windows we won't exit
|
|
6061 */
|
|
6062 if (check_more(FALSE, eap->forceit) == OK && only_one_window())
|
|
6063 exiting = TRUE;
|
|
6064 if ( ((eap->cmdidx == CMD_wq
|
|
6065 || curbufIsChanged())
|
|
6066 && do_write(eap) == FAIL)
|
|
6067 || check_more(TRUE, eap->forceit) == FAIL
|
|
6068 || (only_one_window() && check_changed_any(eap->forceit)))
|
|
6069 {
|
|
6070 not_exiting();
|
|
6071 }
|
|
6072 else
|
|
6073 {
|
|
6074 #ifdef FEAT_WINDOWS
|
|
6075 if (only_one_window()) /* quit last window, exit Vim */
|
|
6076 #endif
|
|
6077 getout(0);
|
|
6078 #ifdef FEAT_WINDOWS
|
|
6079 # ifdef FEAT_GUI
|
|
6080 need_mouse_correct = TRUE;
|
|
6081 # endif
|
|
6082 /* quit current window, may free buffer */
|
|
6083 win_close(curwin, !P_HID(curwin->w_buffer));
|
|
6084 #endif
|
|
6085 }
|
|
6086 }
|
|
6087
|
|
6088 /*
|
|
6089 * ":print", ":list", ":number".
|
|
6090 */
|
|
6091 static void
|
|
6092 ex_print(eap)
|
|
6093 exarg_T *eap;
|
|
6094 {
|
|
6095 int save_list = 0; /* init for GCC */
|
|
6096
|
|
6097 if (eap->cmdidx == CMD_list)
|
|
6098 {
|
|
6099 save_list = curwin->w_p_list;
|
|
6100 curwin->w_p_list = 1;
|
|
6101 }
|
|
6102
|
|
6103 for ( ;!got_int; ui_breakcheck())
|
|
6104 {
|
|
6105 print_line(eap->line1,
|
|
6106 (eap->cmdidx == CMD_number || eap->cmdidx == CMD_pound));
|
|
6107 if (++eap->line1 > eap->line2)
|
|
6108 break;
|
|
6109 out_flush(); /* show one line at a time */
|
|
6110 }
|
|
6111 setpcmark();
|
|
6112 /* put cursor at last line */
|
|
6113 curwin->w_cursor.lnum = eap->line2;
|
|
6114 beginline(BL_SOL | BL_FIX);
|
|
6115
|
|
6116 ex_no_reprint = TRUE;
|
|
6117
|
|
6118 if (eap->cmdidx == CMD_list)
|
|
6119 curwin->w_p_list = save_list;
|
|
6120 }
|
|
6121
|
|
6122 #ifdef FEAT_BYTEOFF
|
|
6123 static void
|
|
6124 ex_goto(eap)
|
|
6125 exarg_T *eap;
|
|
6126 {
|
|
6127 goto_byte(eap->line2);
|
|
6128 }
|
|
6129 #endif
|
|
6130
|
|
6131 /*
|
|
6132 * ":shell".
|
|
6133 */
|
|
6134 /*ARGSUSED*/
|
|
6135 static void
|
|
6136 ex_shell(eap)
|
|
6137 exarg_T *eap;
|
|
6138 {
|
|
6139 do_shell(NULL, 0);
|
|
6140 }
|
|
6141
|
|
6142 #if (defined(FEAT_WINDOWS) && defined(HAVE_DROP_FILE)) \
|
|
6143 || (defined(FEAT_GUI_GTK) && defined(FEAT_DND)) \
|
|
6144 || defined(PROTO)
|
|
6145
|
|
6146 /*
|
|
6147 * Handle a file drop. The code is here because a drop is *nearly* like an
|
|
6148 * :args command, but not quite (we have a list of exact filenames, so we
|
|
6149 * don't want to (a) parse a command line, or (b) expand wildcards. So the
|
|
6150 * code is very similar to :args and hence needs access to a lot of the static
|
|
6151 * functions in this file.
|
|
6152 *
|
|
6153 * The list should be allocated using alloc(), as should each item in the
|
|
6154 * list. This function takes over responsibility for freeing the list.
|
|
6155 *
|
|
6156 * XXX The list is made into the arggument list. This is freed using
|
|
6157 * FreeWild(), which does a series of vim_free() calls, unless the two defines
|
|
6158 * __EMX__ and __ALWAYS_HAS_TRAILING_NUL_POINTER are set. In this case, a
|
|
6159 * routine _fnexplodefree() is used. This may cause problems, but as the drop
|
|
6160 * file functionality is (currently) not in EMX this is not presently a
|
|
6161 * problem.
|
|
6162 */
|
|
6163 void
|
|
6164 handle_drop(filec, filev, split)
|
|
6165 int filec; /* the number of files dropped */
|
|
6166 char_u **filev; /* the list of files dropped */
|
|
6167 int split; /* force splitting the window */
|
|
6168 {
|
|
6169 exarg_T ea;
|
|
6170 int save_msg_scroll = msg_scroll;
|
|
6171
|
|
6172 # ifdef FEAT_CMDWIN
|
|
6173 if (cmdwin_type != 0)
|
|
6174 return;
|
|
6175 # endif
|
|
6176
|
|
6177 /* Check whether the current buffer is changed. If so, we will need
|
|
6178 * to split the current window or data could be lost.
|
|
6179 * We don't need to check if the 'hidden' option is set, as in this
|
|
6180 * case the buffer won't be lost.
|
|
6181 */
|
|
6182 if (!P_HID(curbuf) && !split)
|
|
6183 {
|
|
6184 ++emsg_off;
|
|
6185 split = check_changed(curbuf, TRUE, FALSE, FALSE, FALSE);
|
|
6186 --emsg_off;
|
|
6187 }
|
|
6188 if (split)
|
|
6189 {
|
|
6190 # ifdef FEAT_WINDOWS
|
|
6191 if (win_split(0, 0) == FAIL)
|
|
6192 return;
|
|
6193 # ifdef FEAT_SCROLLBIND
|
|
6194 curwin->w_p_scb = FALSE;
|
|
6195 # endif
|
|
6196
|
|
6197 /* When splitting the window, create a new alist. Otherwise the
|
|
6198 * existing one is overwritten. */
|
|
6199 alist_unlink(curwin->w_alist);
|
|
6200 alist_new();
|
|
6201 # else
|
|
6202 return; /* can't split, always fail */
|
|
6203 # endif
|
|
6204 }
|
|
6205
|
|
6206 /*
|
|
6207 * Set up the new argument list.
|
|
6208 */
|
41
|
6209 alist_set(ALIST(curwin), filec, filev, FALSE, NULL, 0);
|
7
|
6210
|
|
6211 /*
|
|
6212 * Move to the first file.
|
|
6213 */
|
|
6214 /* Fake up a minimal "next" command for do_argfile() */
|
|
6215 vim_memset(&ea, 0, sizeof(ea));
|
|
6216 ea.cmd = (char_u *)"next";
|
|
6217 do_argfile(&ea, 0);
|
|
6218
|
|
6219 /* do_ecmd() may set need_start_insertmode, but since we never left Insert
|
|
6220 * mode that is not needed here. */
|
|
6221 need_start_insertmode = FALSE;
|
|
6222
|
|
6223 /* Restore msg_scroll, otherwise a following command may cause scrolling
|
|
6224 * unexpectedly. The screen will be redrawn by the caller, thus
|
|
6225 * msg_scroll being set by displaying a message is irrelevant. */
|
|
6226 msg_scroll = save_msg_scroll;
|
|
6227 }
|
|
6228 #endif
|
|
6229
|
|
6230 /*
|
|
6231 * Clear an argument list: free all file names and reset it to zero entries.
|
|
6232 */
|
23
|
6233 void
|
7
|
6234 alist_clear(al)
|
|
6235 alist_T *al;
|
|
6236 {
|
|
6237 while (--al->al_ga.ga_len >= 0)
|
|
6238 vim_free(AARGLIST(al)[al->al_ga.ga_len].ae_fname);
|
|
6239 ga_clear(&al->al_ga);
|
|
6240 }
|
|
6241
|
|
6242 /*
|
|
6243 * Init an argument list.
|
|
6244 */
|
|
6245 void
|
|
6246 alist_init(al)
|
|
6247 alist_T *al;
|
|
6248 {
|
|
6249 ga_init2(&al->al_ga, (int)sizeof(aentry_T), 5);
|
|
6250 }
|
|
6251
|
|
6252 #if defined(FEAT_WINDOWS) || defined(PROTO)
|
|
6253
|
|
6254 /*
|
|
6255 * Remove a reference from an argument list.
|
|
6256 * Ignored when the argument list is the global one.
|
|
6257 * If the argument list is no longer used by any window, free it.
|
|
6258 */
|
|
6259 void
|
|
6260 alist_unlink(al)
|
|
6261 alist_T *al;
|
|
6262 {
|
|
6263 if (al != &global_alist && --al->al_refcount <= 0)
|
|
6264 {
|
|
6265 alist_clear(al);
|
|
6266 vim_free(al);
|
|
6267 }
|
|
6268 }
|
|
6269
|
|
6270 # if defined(FEAT_LISTCMDS) || defined(HAVE_DROP_FILE) || defined(PROTO)
|
|
6271 /*
|
|
6272 * Create a new argument list and use it for the current window.
|
|
6273 */
|
|
6274 void
|
|
6275 alist_new()
|
|
6276 {
|
|
6277 curwin->w_alist = (alist_T *)alloc((unsigned)sizeof(alist_T));
|
|
6278 if (curwin->w_alist == NULL)
|
|
6279 {
|
|
6280 curwin->w_alist = &global_alist;
|
|
6281 ++global_alist.al_refcount;
|
|
6282 }
|
|
6283 else
|
|
6284 {
|
|
6285 curwin->w_alist->al_refcount = 1;
|
|
6286 alist_init(curwin->w_alist);
|
|
6287 }
|
|
6288 }
|
|
6289 # endif
|
|
6290 #endif
|
|
6291
|
|
6292 #if (!defined(UNIX) && !defined(__EMX__)) || defined(ARCHIE) || defined(PROTO)
|
|
6293 /*
|
|
6294 * Expand the file names in the global argument list.
|
41
|
6295 * If "fnum_list" is not NULL, use "fnum_list[fnum_len]" as a list of buffer
|
|
6296 * numbers to be re-used.
|
7
|
6297 */
|
|
6298 void
|
41
|
6299 alist_expand(fnum_list, fnum_len)
|
|
6300 int *fnum_list;
|
|
6301 int fnum_len;
|
7
|
6302 {
|
|
6303 char_u **old_arg_files;
|
41
|
6304 int old_arg_count;
|
7
|
6305 char_u **new_arg_files;
|
|
6306 int new_arg_file_count;
|
|
6307 char_u *save_p_su = p_su;
|
|
6308 int i;
|
|
6309
|
|
6310 /* Don't use 'suffixes' here. This should work like the shell did the
|
|
6311 * expansion. Also, the vimrc file isn't read yet, thus the user
|
|
6312 * can't set the options. */
|
|
6313 p_su = empty_option;
|
|
6314 old_arg_files = (char_u **)alloc((unsigned)(sizeof(char_u *) * GARGCOUNT));
|
|
6315 if (old_arg_files != NULL)
|
|
6316 {
|
|
6317 for (i = 0; i < GARGCOUNT; ++i)
|
41
|
6318 old_arg_files[i] = vim_strsave(GARGLIST[i].ae_fname);
|
|
6319 old_arg_count = GARGCOUNT;
|
|
6320 if (expand_wildcards(old_arg_count, old_arg_files,
|
7
|
6321 &new_arg_file_count, &new_arg_files,
|
|
6322 EW_FILE|EW_NOTFOUND|EW_ADDSLASH) == OK
|
|
6323 && new_arg_file_count > 0)
|
|
6324 {
|
41
|
6325 alist_set(&global_alist, new_arg_file_count, new_arg_files,
|
|
6326 TRUE, fnum_list, fnum_len);
|
|
6327 FreeWild(old_arg_count, old_arg_files);
|
23
|
6328 }
|
7
|
6329 }
|
|
6330 p_su = save_p_su;
|
|
6331 }
|
|
6332 #endif
|
|
6333
|
|
6334 /*
|
|
6335 * Set the argument list for the current window.
|
|
6336 * Takes over the allocated files[] and the allocated fnames in it.
|
|
6337 */
|
|
6338 void
|
41
|
6339 alist_set(al, count, files, use_curbuf, fnum_list, fnum_len)
|
7
|
6340 alist_T *al;
|
|
6341 int count;
|
|
6342 char_u **files;
|
|
6343 int use_curbuf;
|
41
|
6344 int *fnum_list;
|
|
6345 int fnum_len;
|
7
|
6346 {
|
|
6347 int i;
|
|
6348
|
|
6349 alist_clear(al);
|
|
6350 if (ga_grow(&al->al_ga, count) == OK)
|
|
6351 {
|
|
6352 for (i = 0; i < count; ++i)
|
23
|
6353 {
|
|
6354 if (got_int)
|
|
6355 {
|
|
6356 /* When adding many buffers this can take a long time. Allow
|
|
6357 * interrupting here. */
|
|
6358 while (i < count)
|
|
6359 vim_free(files[i++]);
|
|
6360 break;
|
|
6361 }
|
41
|
6362
|
|
6363 /* May set buffer name of a buffer previously used for the
|
|
6364 * argument list, so that it's re-used by alist_add. */
|
|
6365 if (fnum_list != NULL && i < fnum_len)
|
|
6366 buf_set_name(fnum_list[i], files[i]);
|
|
6367
|
7
|
6368 alist_add(al, files[i], use_curbuf ? 2 : 1);
|
23
|
6369 ui_breakcheck();
|
|
6370 }
|
7
|
6371 vim_free(files);
|
|
6372 }
|
|
6373 else
|
|
6374 FreeWild(count, files);
|
|
6375 #ifdef FEAT_WINDOWS
|
|
6376 if (al == &global_alist)
|
|
6377 #endif
|
|
6378 arg_had_last = FALSE;
|
|
6379 }
|
|
6380
|
|
6381 /*
|
|
6382 * Add file "fname" to argument list "al".
|
|
6383 * "fname" must have been allocated and "al" must have been checked for room.
|
|
6384 */
|
|
6385 void
|
|
6386 alist_add(al, fname, set_fnum)
|
|
6387 alist_T *al;
|
|
6388 char_u *fname;
|
|
6389 int set_fnum; /* 1: set buffer number; 2: re-use curbuf */
|
|
6390 {
|
|
6391 if (fname == NULL) /* don't add NULL file names */
|
|
6392 return;
|
|
6393 #ifdef BACKSLASH_IN_FILENAME
|
|
6394 slash_adjust(fname);
|
|
6395 #endif
|
|
6396 AARGLIST(al)[al->al_ga.ga_len].ae_fname = fname;
|
|
6397 if (set_fnum > 0)
|
|
6398 AARGLIST(al)[al->al_ga.ga_len].ae_fnum =
|
|
6399 buflist_add(fname, BLN_LISTED | (set_fnum == 2 ? BLN_CURBUF : 0));
|
|
6400 ++al->al_ga.ga_len;
|
|
6401 }
|
|
6402
|
|
6403 #if defined(BACKSLASH_IN_FILENAME) || defined(PROTO)
|
|
6404 /*
|
|
6405 * Adjust slashes in file names. Called after 'shellslash' was set.
|
|
6406 */
|
|
6407 void
|
|
6408 alist_slash_adjust()
|
|
6409 {
|
|
6410 int i;
|
|
6411 # ifdef FEAT_WINDOWS
|
|
6412 win_T *wp;
|
|
6413 # endif
|
|
6414
|
|
6415 for (i = 0; i < GARGCOUNT; ++i)
|
|
6416 if (GARGLIST[i].ae_fname != NULL)
|
|
6417 slash_adjust(GARGLIST[i].ae_fname);
|
|
6418 # ifdef FEAT_WINDOWS
|
|
6419 for (wp = firstwin; wp != NULL; wp = wp->w_next)
|
|
6420 if (wp->w_alist != &global_alist)
|
|
6421 for (i = 0; i < WARGCOUNT(wp); ++i)
|
|
6422 if (WARGLIST(wp)[i].ae_fname != NULL)
|
|
6423 slash_adjust(WARGLIST(wp)[i].ae_fname);
|
|
6424 # endif
|
|
6425 }
|
|
6426 #endif
|
|
6427
|
|
6428 /*
|
|
6429 * ":preserve".
|
|
6430 */
|
|
6431 /*ARGSUSED*/
|
|
6432 static void
|
|
6433 ex_preserve(eap)
|
|
6434 exarg_T *eap;
|
|
6435 {
|
|
6436 ml_preserve(curbuf, TRUE);
|
|
6437 }
|
|
6438
|
|
6439 /*
|
|
6440 * ":recover".
|
|
6441 */
|
|
6442 static void
|
|
6443 ex_recover(eap)
|
|
6444 exarg_T *eap;
|
|
6445 {
|
|
6446 /* Set recoverymode right away to avoid the ATTENTION prompt. */
|
|
6447 recoverymode = TRUE;
|
|
6448 if (!check_changed(curbuf, p_awa, TRUE, eap->forceit, FALSE)
|
|
6449 && (*eap->arg == NUL
|
|
6450 || setfname(curbuf, eap->arg, NULL, TRUE) == OK))
|
|
6451 ml_recover();
|
|
6452 recoverymode = FALSE;
|
|
6453 }
|
|
6454
|
|
6455 /*
|
|
6456 * Command modifier used in a wrong way.
|
|
6457 */
|
|
6458 static void
|
|
6459 ex_wrongmodifier(eap)
|
|
6460 exarg_T *eap;
|
|
6461 {
|
|
6462 eap->errmsg = e_invcmd;
|
|
6463 }
|
|
6464
|
|
6465 #ifdef FEAT_WINDOWS
|
|
6466 /*
|
|
6467 * :sview [+command] file split window with new file, read-only
|
|
6468 * :split [[+command] file] split window with current or new file
|
|
6469 * :vsplit [[+command] file] split window vertically with current or new file
|
|
6470 * :new [[+command] file] split window with no or new file
|
|
6471 * :vnew [[+command] file] split vertically window with no or new file
|
|
6472 * :sfind [+command] file split window with file in 'path'
|
|
6473 */
|
|
6474 void
|
|
6475 ex_splitview(eap)
|
|
6476 exarg_T *eap;
|
|
6477 {
|
|
6478 win_T *old_curwin;
|
|
6479 #if defined(FEAT_SEARCHPATH) || defined(FEAT_BROWSE)
|
|
6480 char_u *fname = NULL;
|
|
6481 #endif
|
|
6482 #ifdef FEAT_BROWSE
|
|
6483 int browse_flag = cmdmod.browse;
|
|
6484 #endif
|
|
6485
|
|
6486 #ifndef FEAT_VERTSPLIT
|
|
6487 if (eap->cmdidx == CMD_vsplit || eap->cmdidx == CMD_vnew)
|
|
6488 {
|
|
6489 ex_ni(eap);
|
|
6490 return;
|
|
6491 }
|
|
6492 #endif
|
|
6493
|
|
6494 old_curwin = curwin;
|
|
6495 #ifdef FEAT_GUI
|
|
6496 need_mouse_correct = TRUE;
|
|
6497 #endif
|
|
6498
|
|
6499 #ifdef FEAT_QUICKFIX
|
|
6500 /* A ":split" in the quickfix window works like ":new". Don't want two
|
|
6501 * quickfix windows. */
|
|
6502 if (bt_quickfix(curbuf))
|
|
6503 {
|
|
6504 if (eap->cmdidx == CMD_split)
|
|
6505 eap->cmdidx = CMD_new;
|
|
6506 # ifdef FEAT_VERTSPLIT
|
|
6507 if (eap->cmdidx == CMD_vsplit)
|
|
6508 eap->cmdidx = CMD_vnew;
|
|
6509 # endif
|
|
6510 }
|
|
6511 #endif
|
|
6512
|
|
6513 #ifdef FEAT_SEARCHPATH
|
|
6514 if (eap->cmdidx == CMD_sfind)
|
|
6515 {
|
|
6516 fname = find_file_in_path(eap->arg, (int)STRLEN(eap->arg),
|
|
6517 FNAME_MESS, TRUE, curbuf->b_ffname);
|
|
6518 if (fname == NULL)
|
|
6519 goto theend;
|
|
6520 eap->arg = fname;
|
|
6521 }
|
|
6522 # ifdef FEAT_BROWSE
|
|
6523 else
|
|
6524 # endif
|
|
6525 #endif
|
|
6526 #ifdef FEAT_BROWSE
|
|
6527 if (cmdmod.browse
|
|
6528 # ifdef FEAT_VERTSPLIT
|
|
6529 && eap->cmdidx != CMD_vnew
|
|
6530 #endif
|
|
6531 && eap->cmdidx != CMD_new)
|
|
6532 {
|
28
|
6533 fname = do_browse(0, (char_u *)_("Edit File in new window"),
|
7
|
6534 eap->arg, NULL, NULL, NULL, curbuf);
|
|
6535 if (fname == NULL)
|
|
6536 goto theend;
|
|
6537 eap->arg = fname;
|
|
6538 }
|
|
6539 cmdmod.browse = FALSE; /* Don't browse again in do_ecmd(). */
|
|
6540 #endif
|
|
6541
|
|
6542 if (win_split(eap->addr_count > 0 ? (int)eap->line2 : 0,
|
|
6543 *eap->cmd == 'v' ? WSP_VERT : 0) != FAIL)
|
|
6544 {
|
|
6545 #ifdef FEAT_SCROLLBIND
|
|
6546 /* Reset 'scrollbind' when editing another file, but keep it when
|
|
6547 * doing ":split" without arguments. */
|
|
6548 if (*eap->arg != NUL
|
|
6549 #ifdef FEAT_BROWSE
|
|
6550 || cmdmod.browse
|
|
6551 #endif
|
|
6552 )
|
|
6553 curwin->w_p_scb = FALSE;
|
|
6554 else
|
|
6555 do_check_scrollbind(FALSE);
|
|
6556 #endif
|
|
6557 do_exedit(eap, old_curwin);
|
|
6558 }
|
|
6559
|
|
6560 #ifdef FEAT_BROWSE
|
|
6561 cmdmod.browse = browse_flag;
|
|
6562 #endif
|
|
6563
|
|
6564 #if defined(FEAT_SEARCHPATH) || defined(FEAT_BROWSE)
|
|
6565 theend:
|
|
6566 vim_free(fname);
|
|
6567 #endif
|
|
6568 }
|
|
6569 #endif
|
|
6570
|
|
6571 /*
|
|
6572 * ":mode": Set screen mode.
|
|
6573 * If no argument given, just get the screen size and redraw.
|
|
6574 */
|
|
6575 static void
|
|
6576 ex_mode(eap)
|
|
6577 exarg_T *eap;
|
|
6578 {
|
|
6579 if (*eap->arg == NUL)
|
|
6580 shell_resized();
|
|
6581 else
|
|
6582 mch_screenmode(eap->arg);
|
|
6583 }
|
|
6584
|
|
6585 #ifdef FEAT_WINDOWS
|
|
6586 /*
|
|
6587 * ":resize".
|
|
6588 * set, increment or decrement current window height
|
|
6589 */
|
|
6590 static void
|
|
6591 ex_resize(eap)
|
|
6592 exarg_T *eap;
|
|
6593 {
|
|
6594 int n;
|
|
6595 win_T *wp = curwin;
|
|
6596
|
|
6597 if (eap->addr_count > 0)
|
|
6598 {
|
|
6599 n = eap->line2;
|
|
6600 for (wp = firstwin; wp->w_next != NULL && --n > 0; wp = wp->w_next)
|
|
6601 ;
|
|
6602 }
|
|
6603
|
|
6604 #ifdef FEAT_GUI
|
|
6605 need_mouse_correct = TRUE;
|
|
6606 #endif
|
|
6607 n = atol((char *)eap->arg);
|
|
6608 #ifdef FEAT_VERTSPLIT
|
|
6609 if (cmdmod.split & WSP_VERT)
|
|
6610 {
|
|
6611 if (*eap->arg == '-' || *eap->arg == '+')
|
|
6612 n += W_WIDTH(curwin);
|
|
6613 else if (n == 0 && eap->arg[0] == NUL) /* default is very wide */
|
|
6614 n = 9999;
|
|
6615 win_setwidth_win((int)n, wp);
|
|
6616 }
|
|
6617 else
|
|
6618 #endif
|
|
6619 {
|
|
6620 if (*eap->arg == '-' || *eap->arg == '+')
|
|
6621 n += curwin->w_height;
|
|
6622 else if (n == 0 && eap->arg[0] == NUL) /* default is very wide */
|
|
6623 n = 9999;
|
|
6624 win_setheight_win((int)n, wp);
|
|
6625 }
|
|
6626 }
|
|
6627 #endif
|
|
6628
|
|
6629 /*
|
|
6630 * ":find [+command] <file>" command.
|
|
6631 */
|
|
6632 static void
|
|
6633 ex_find(eap)
|
|
6634 exarg_T *eap;
|
|
6635 {
|
|
6636 #ifdef FEAT_SEARCHPATH
|
|
6637 char_u *fname;
|
|
6638 int count;
|
|
6639
|
|
6640 fname = find_file_in_path(eap->arg, (int)STRLEN(eap->arg), FNAME_MESS,
|
|
6641 TRUE, curbuf->b_ffname);
|
|
6642 if (eap->addr_count > 0)
|
|
6643 {
|
|
6644 /* Repeat finding the file "count" times. This matters when it
|
|
6645 * appears several times in the path. */
|
|
6646 count = eap->line2;
|
|
6647 while (fname != NULL && --count > 0)
|
|
6648 {
|
|
6649 vim_free(fname);
|
|
6650 fname = find_file_in_path(NULL, 0, FNAME_MESS,
|
|
6651 FALSE, curbuf->b_ffname);
|
|
6652 }
|
|
6653 }
|
|
6654
|
|
6655 if (fname != NULL)
|
|
6656 {
|
|
6657 eap->arg = fname;
|
|
6658 #endif
|
|
6659 do_exedit(eap, NULL);
|
|
6660 #ifdef FEAT_SEARCHPATH
|
|
6661 vim_free(fname);
|
|
6662 }
|
|
6663 #endif
|
|
6664 }
|
|
6665
|
|
6666 /*
|
|
6667 * ":edit", ":badd".
|
|
6668 */
|
|
6669 static void
|
|
6670 ex_edit(eap)
|
|
6671 exarg_T *eap;
|
|
6672 {
|
|
6673 do_exedit(eap, NULL);
|
|
6674 }
|
|
6675
|
|
6676 /*
|
|
6677 * ":edit <file>" command and alikes.
|
|
6678 */
|
|
6679 /*ARGSUSED*/
|
|
6680 void
|
|
6681 do_exedit(eap, old_curwin)
|
|
6682 exarg_T *eap;
|
|
6683 win_T *old_curwin; /* curwin before doing a split or NULL */
|
|
6684 {
|
|
6685 int n;
|
|
6686 #ifdef FEAT_WINDOWS
|
|
6687 int need_hide;
|
|
6688 #endif
|
|
6689
|
|
6690 /*
|
|
6691 * ":vi" command ends Ex mode.
|
|
6692 */
|
|
6693 if (exmode_active && (eap->cmdidx == CMD_visual
|
|
6694 || eap->cmdidx == CMD_view))
|
|
6695 {
|
|
6696 exmode_active = FALSE;
|
|
6697 if (*eap->arg == NUL)
|
|
6698 return;
|
|
6699 }
|
|
6700
|
|
6701 if ((eap->cmdidx == CMD_new
|
|
6702 #ifdef FEAT_VERTSPLIT
|
|
6703 || eap->cmdidx == CMD_vnew
|
|
6704 #endif
|
|
6705 ) && *eap->arg == NUL)
|
|
6706 {
|
|
6707 /* ":new" without argument: edit an new empty buffer */
|
|
6708 setpcmark();
|
|
6709 (void)do_ecmd(0, NULL, NULL, eap, ECMD_ONE,
|
|
6710 ECMD_HIDE + (eap->forceit ? ECMD_FORCEIT : 0));
|
|
6711 }
|
|
6712 else if ((eap->cmdidx != CMD_split
|
|
6713 #ifdef FEAT_VERTSPLIT
|
|
6714 && eap->cmdidx != CMD_vsplit
|
|
6715 #endif
|
|
6716 )
|
|
6717 || *eap->arg != NUL
|
|
6718 #ifdef FEAT_BROWSE
|
|
6719 || cmdmod.browse
|
|
6720 #endif
|
|
6721 )
|
|
6722 {
|
|
6723 n = readonlymode;
|
|
6724 if (eap->cmdidx == CMD_view || eap->cmdidx == CMD_sview)
|
|
6725 readonlymode = TRUE;
|
|
6726 else if (eap->cmdidx == CMD_enew)
|
|
6727 readonlymode = FALSE; /* 'readonly' doesn't make sense in an
|
|
6728 empty buffer */
|
|
6729 setpcmark();
|
|
6730 if (do_ecmd(0, (eap->cmdidx == CMD_enew ? NULL : eap->arg),
|
|
6731 NULL, eap,
|
|
6732 /* ":edit" goes to first line if Vi compatible */
|
|
6733 (*eap->arg == NUL && eap->do_ecmd_lnum == 0
|
|
6734 && vim_strchr(p_cpo, CPO_GOTO1) != NULL)
|
|
6735 ? ECMD_ONE : eap->do_ecmd_lnum,
|
|
6736 (P_HID(curbuf) ? ECMD_HIDE : 0)
|
|
6737 + (eap->forceit ? ECMD_FORCEIT : 0)
|
|
6738 #ifdef FEAT_LISTCMDS
|
|
6739 + (eap->cmdidx == CMD_badd ? ECMD_ADDBUF : 0 )
|
|
6740 #endif
|
|
6741 ) == FAIL)
|
|
6742 {
|
|
6743 /* Editing the file failed. If the window was split, close it. */
|
|
6744 #ifdef FEAT_WINDOWS
|
|
6745 if (old_curwin != NULL)
|
|
6746 {
|
|
6747 need_hide = (curbufIsChanged() && curbuf->b_nwindows <= 1);
|
|
6748 if (!need_hide || P_HID(curbuf))
|
|
6749 {
|
24
|
6750 # if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
|
|
6751 cleanup_T cs;
|
|
6752
|
|
6753 /* Reset the error/interrupt/exception state here so that
|
|
6754 * aborting() returns FALSE when closing a window. */
|
|
6755 enter_cleanup(&cs);
|
|
6756 # endif
|
7
|
6757 # ifdef FEAT_GUI
|
|
6758 need_mouse_correct = TRUE;
|
|
6759 # endif
|
|
6760 win_close(curwin, !need_hide && !P_HID(curbuf));
|
24
|
6761
|
|
6762 # if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
|
|
6763 /* Restore the error/interrupt/exception state if not
|
|
6764 * discarded by a new aborting error, interrupt, or
|
|
6765 * uncaught exception. */
|
|
6766 leave_cleanup(&cs);
|
|
6767 # endif
|
7
|
6768 }
|
|
6769 }
|
|
6770 #endif
|
|
6771 }
|
|
6772 else if (readonlymode && curbuf->b_nwindows == 1)
|
|
6773 {
|
|
6774 /* When editing an already visited buffer, 'readonly' won't be set
|
|
6775 * but the previous value is kept. With ":view" and ":sview" we
|
|
6776 * want the file to be readonly, except when another window is
|
|
6777 * editing the same buffer. */
|
|
6778 curbuf->b_p_ro = TRUE;
|
|
6779 }
|
|
6780 readonlymode = n;
|
|
6781 }
|
|
6782 else
|
|
6783 {
|
|
6784 if (eap->do_ecmd_cmd != NULL)
|
|
6785 do_cmdline_cmd(eap->do_ecmd_cmd);
|
|
6786 #ifdef FEAT_TITLE
|
|
6787 n = curwin->w_arg_idx_invalid;
|
|
6788 #endif
|
|
6789 check_arg_idx(curwin);
|
|
6790 #ifdef FEAT_TITLE
|
|
6791 if (n != curwin->w_arg_idx_invalid)
|
|
6792 maketitle();
|
|
6793 #endif
|
|
6794 }
|
|
6795
|
|
6796 #ifdef FEAT_WINDOWS
|
|
6797 /*
|
|
6798 * if ":split file" worked, set alternate file name in old window to new
|
|
6799 * file
|
|
6800 */
|
|
6801 if (old_curwin != NULL
|
|
6802 && *eap->arg != NUL
|
|
6803 && curwin != old_curwin
|
|
6804 && win_valid(old_curwin)
|
22
|
6805 && old_curwin->w_buffer != curbuf
|
|
6806 && !cmdmod.keepalt)
|
7
|
6807 old_curwin->w_alt_fnum = curbuf->b_fnum;
|
|
6808 #endif
|
|
6809
|
|
6810 ex_no_reprint = TRUE;
|
|
6811 }
|
|
6812
|
|
6813 #ifndef FEAT_GUI
|
|
6814 /*
|
|
6815 * ":gui" and ":gvim" when there is no GUI.
|
|
6816 */
|
|
6817 static void
|
|
6818 ex_nogui(eap)
|
|
6819 exarg_T *eap;
|
|
6820 {
|
|
6821 eap->errmsg = e_nogvim;
|
|
6822 }
|
|
6823 #endif
|
|
6824
|
|
6825 #if defined(FEAT_GUI_W32) && defined(FEAT_MENU) && defined(FEAT_TEAROFF)
|
|
6826 static void
|
|
6827 ex_tearoff(eap)
|
|
6828 exarg_T *eap;
|
|
6829 {
|
|
6830 gui_make_tearoff(eap->arg);
|
|
6831 }
|
|
6832 #endif
|
|
6833
|
11
|
6834 #if (defined(FEAT_GUI_MSWIN) || defined(FEAT_GUI_KDE) || defined(FEAT_GUI_GTK)) && defined(FEAT_MENU)
|
7
|
6835 static void
|
|
6836 ex_popup(eap)
|
|
6837 exarg_T *eap;
|
|
6838 {
|
|
6839 gui_make_popup(eap->arg);
|
|
6840 }
|
|
6841 #endif
|
|
6842
|
|
6843 /*ARGSUSED*/
|
|
6844 static void
|
|
6845 ex_swapname(eap)
|
|
6846 exarg_T *eap;
|
|
6847 {
|
|
6848 if (curbuf->b_ml.ml_mfp == NULL || curbuf->b_ml.ml_mfp->mf_fname == NULL)
|
|
6849 MSG(_("No swap file"));
|
|
6850 else
|
|
6851 msg(curbuf->b_ml.ml_mfp->mf_fname);
|
|
6852 }
|
|
6853
|
|
6854 /*
|
|
6855 * ":syncbind" forces all 'scrollbind' windows to have the same relative
|
|
6856 * offset.
|
|
6857 * (1998-11-02 16:21:01 R. Edward Ralston <eralston@computer.org>)
|
|
6858 */
|
|
6859 /*ARGSUSED*/
|
|
6860 static void
|
|
6861 ex_syncbind(eap)
|
|
6862 exarg_T *eap;
|
|
6863 {
|
|
6864 #ifdef FEAT_SCROLLBIND
|
|
6865 win_T *wp;
|
|
6866 long topline;
|
|
6867 long y;
|
|
6868 linenr_T old_linenr = curwin->w_cursor.lnum;
|
|
6869
|
|
6870 setpcmark();
|
|
6871
|
|
6872 /*
|
|
6873 * determine max topline
|
|
6874 */
|
|
6875 if (curwin->w_p_scb)
|
|
6876 {
|
|
6877 topline = curwin->w_topline;
|
|
6878 for (wp = firstwin; wp; wp = wp->w_next)
|
|
6879 {
|
|
6880 if (wp->w_p_scb && wp->w_buffer)
|
|
6881 {
|
|
6882 y = wp->w_buffer->b_ml.ml_line_count - p_so;
|
|
6883 if (topline > y)
|
|
6884 topline = y;
|
|
6885 }
|
|
6886 }
|
|
6887 if (topline < 1)
|
|
6888 topline = 1;
|
|
6889 }
|
|
6890 else
|
|
6891 {
|
|
6892 topline = 1;
|
|
6893 }
|
|
6894
|
|
6895
|
|
6896 /*
|
|
6897 * set all scrollbind windows to the same topline
|
|
6898 */
|
|
6899 wp = curwin;
|
|
6900 for (curwin = firstwin; curwin; curwin = curwin->w_next)
|
|
6901 {
|
|
6902 if (curwin->w_p_scb)
|
|
6903 {
|
|
6904 y = topline - curwin->w_topline;
|
|
6905 if (y > 0)
|
|
6906 scrollup(y, TRUE);
|
|
6907 else
|
|
6908 scrolldown(-y, TRUE);
|
|
6909 curwin->w_scbind_pos = topline;
|
|
6910 redraw_later(VALID);
|
|
6911 cursor_correct();
|
|
6912 #ifdef FEAT_WINDOWS
|
|
6913 curwin->w_redr_status = TRUE;
|
|
6914 #endif
|
|
6915 }
|
|
6916 }
|
|
6917 curwin = wp;
|
|
6918 if (curwin->w_p_scb)
|
|
6919 {
|
|
6920 did_syncbind = TRUE;
|
|
6921 checkpcmark();
|
|
6922 if (old_linenr != curwin->w_cursor.lnum)
|
|
6923 {
|
|
6924 char_u ctrl_o[2];
|
|
6925
|
|
6926 ctrl_o[0] = Ctrl_O;
|
|
6927 ctrl_o[1] = 0;
|
|
6928 ins_typebuf(ctrl_o, REMAP_NONE, 0, TRUE, FALSE);
|
|
6929 }
|
|
6930 }
|
|
6931 #endif
|
|
6932 }
|
|
6933
|
|
6934
|
|
6935 static void
|
|
6936 ex_read(eap)
|
|
6937 exarg_T *eap;
|
|
6938 {
|
|
6939 int i;
|
|
6940
|
|
6941 if (eap->usefilter) /* :r!cmd */
|
|
6942 do_bang(1, eap, FALSE, FALSE, TRUE);
|
|
6943 else
|
|
6944 {
|
|
6945 if (u_save(eap->line2, (linenr_T)(eap->line2 + 1)) == FAIL)
|
|
6946 return;
|
|
6947
|
|
6948 #ifdef FEAT_BROWSE
|
|
6949 if (cmdmod.browse)
|
|
6950 {
|
|
6951 char_u *browseFile;
|
|
6952
|
28
|
6953 browseFile = do_browse(0, (char_u *)_("Append File"), eap->arg,
|
7
|
6954 NULL, NULL, NULL, curbuf);
|
|
6955 if (browseFile != NULL)
|
|
6956 {
|
|
6957 i = readfile(browseFile, NULL,
|
|
6958 eap->line2, (linenr_T)0, (linenr_T)MAXLNUM, eap, 0);
|
|
6959 vim_free(browseFile);
|
|
6960 }
|
|
6961 else
|
|
6962 i = OK;
|
|
6963 }
|
|
6964 else
|
|
6965 #endif
|
|
6966 if (*eap->arg == NUL)
|
|
6967 {
|
|
6968 if (check_fname() == FAIL) /* check for no file name */
|
|
6969 return;
|
|
6970 i = readfile(curbuf->b_ffname, curbuf->b_fname,
|
|
6971 eap->line2, (linenr_T)0, (linenr_T)MAXLNUM, eap, 0);
|
|
6972 }
|
|
6973 else
|
|
6974 {
|
|
6975 if (vim_strchr(p_cpo, CPO_ALTREAD) != NULL)
|
|
6976 (void)setaltfname(eap->arg, eap->arg, (linenr_T)1);
|
|
6977 i = readfile(eap->arg, NULL,
|
|
6978 eap->line2, (linenr_T)0, (linenr_T)MAXLNUM, eap, 0);
|
|
6979
|
|
6980 }
|
|
6981 if (i == FAIL)
|
|
6982 {
|
|
6983 #if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
|
|
6984 if (!aborting())
|
|
6985 #endif
|
|
6986 EMSG2(_(e_notopen), eap->arg);
|
|
6987 }
|
|
6988 else
|
|
6989 redraw_curbuf_later(VALID);
|
|
6990 }
|
|
6991 }
|
|
6992
|
|
6993 /*
|
|
6994 * ":cd", ":lcd", ":chdir" and ":lchdir".
|
|
6995 */
|
|
6996 static void
|
|
6997 ex_cd(eap)
|
|
6998 exarg_T *eap;
|
|
6999 {
|
|
7000 static char_u *prev_dir = NULL;
|
|
7001 char_u *new_dir;
|
|
7002 char_u *tofree;
|
|
7003
|
|
7004 new_dir = eap->arg;
|
|
7005 #if !defined(UNIX) && !defined(VMS)
|
|
7006 /* for non-UNIX ":cd" means: print current directory */
|
|
7007 if (*new_dir == NUL)
|
|
7008 ex_pwd(NULL);
|
|
7009 else
|
|
7010 #endif
|
|
7011 {
|
|
7012 /* ":cd -": Change to previous directory */
|
|
7013 if (STRCMP(new_dir, "-") == 0)
|
|
7014 {
|
|
7015 if (prev_dir == NULL)
|
|
7016 {
|
|
7017 EMSG(_("E186: No previous directory"));
|
|
7018 return;
|
|
7019 }
|
|
7020 new_dir = prev_dir;
|
|
7021 }
|
|
7022
|
|
7023 /* Save current directory for next ":cd -" */
|
|
7024 tofree = prev_dir;
|
|
7025 if (mch_dirname(NameBuff, MAXPATHL) == OK)
|
|
7026 prev_dir = vim_strsave(NameBuff);
|
|
7027 else
|
|
7028 prev_dir = NULL;
|
|
7029
|
|
7030 #if defined(UNIX) || defined(VMS)
|
|
7031 /* for UNIX ":cd" means: go to home directory */
|
|
7032 if (*new_dir == NUL)
|
|
7033 {
|
|
7034 /* use NameBuff for home directory name */
|
|
7035 # ifdef VMS
|
|
7036 char_u *p;
|
|
7037
|
|
7038 p = mch_getenv((char_u *)"SYS$LOGIN");
|
|
7039 if (p == NULL || *p == NUL) /* empty is the same as not set */
|
|
7040 NameBuff[0] = NUL;
|
|
7041 else
|
|
7042 STRNCPY(NameBuff, p, MAXPATHL);
|
|
7043 # else
|
|
7044 expand_env((char_u *)"$HOME", NameBuff, MAXPATHL);
|
|
7045 # endif
|
|
7046 new_dir = NameBuff;
|
|
7047 }
|
|
7048 #endif
|
|
7049 if (new_dir == NULL || vim_chdir(new_dir))
|
|
7050 EMSG(_(e_failed));
|
|
7051 else
|
|
7052 {
|
|
7053 vim_free(curwin->w_localdir);
|
|
7054 if (eap->cmdidx == CMD_lcd || eap->cmdidx == CMD_lchdir)
|
|
7055 {
|
|
7056 /* If still in global directory, need to remember current
|
|
7057 * directory as global directory. */
|
|
7058 if (globaldir == NULL && prev_dir != NULL)
|
|
7059 globaldir = vim_strsave(prev_dir);
|
|
7060 /* Remember this local directory for the window. */
|
|
7061 if (mch_dirname(NameBuff, MAXPATHL) == OK)
|
|
7062 curwin->w_localdir = vim_strsave(NameBuff);
|
|
7063 }
|
|
7064 else
|
|
7065 {
|
|
7066 /* We are now in the global directory, no need to remember its
|
|
7067 * name. */
|
|
7068 vim_free(globaldir);
|
|
7069 globaldir = NULL;
|
|
7070 curwin->w_localdir = NULL;
|
|
7071 }
|
|
7072
|
|
7073 shorten_fnames(TRUE);
|
|
7074
|
|
7075 /* Echo the new current directory if the command was typed. */
|
|
7076 if (KeyTyped)
|
|
7077 ex_pwd(eap);
|
|
7078 }
|
|
7079 vim_free(tofree);
|
|
7080 }
|
|
7081 }
|
|
7082
|
|
7083 /*
|
|
7084 * ":pwd".
|
|
7085 */
|
|
7086 /*ARGSUSED*/
|
|
7087 static void
|
|
7088 ex_pwd(eap)
|
|
7089 exarg_T *eap;
|
|
7090 {
|
|
7091 if (mch_dirname(NameBuff, MAXPATHL) == OK)
|
|
7092 {
|
|
7093 #ifdef BACKSLASH_IN_FILENAME
|
|
7094 slash_adjust(NameBuff);
|
|
7095 #endif
|
|
7096 msg(NameBuff);
|
|
7097 }
|
|
7098 else
|
|
7099 EMSG(_("E187: Unknown"));
|
|
7100 }
|
|
7101
|
|
7102 /*
|
|
7103 * ":=".
|
|
7104 */
|
|
7105 static void
|
|
7106 ex_equal(eap)
|
|
7107 exarg_T *eap;
|
|
7108 {
|
|
7109 smsg((char_u *)"%ld", (long)eap->line2);
|
|
7110 }
|
|
7111
|
|
7112 static void
|
|
7113 ex_sleep(eap)
|
|
7114 exarg_T *eap;
|
|
7115 {
|
|
7116 int n;
|
|
7117
|
|
7118 if (cursor_valid())
|
|
7119 {
|
|
7120 n = W_WINROW(curwin) + curwin->w_wrow - msg_scrolled;
|
|
7121 if (n >= 0)
|
|
7122 windgoto((int)n, curwin->w_wcol);
|
|
7123 }
|
|
7124 do_sleep(eap->line2 * (*eap->arg == 'm' ? 1L : 1000L));
|
|
7125 }
|
|
7126
|
|
7127 /*
|
|
7128 * Sleep for "msec" milliseconds, but keep checking for a CTRL-C every second.
|
|
7129 */
|
|
7130 void
|
|
7131 do_sleep(msec)
|
|
7132 long msec;
|
|
7133 {
|
|
7134 long done;
|
|
7135
|
|
7136 cursor_on();
|
|
7137 out_flush();
|
|
7138 for (done = 0; !got_int && done < msec; done += 1000L)
|
|
7139 {
|
|
7140 ui_delay(msec - done > 1000L ? 1000L : msec - done, TRUE);
|
|
7141 ui_breakcheck();
|
|
7142 }
|
|
7143 }
|
|
7144
|
|
7145 static void
|
|
7146 do_exmap(eap, isabbrev)
|
|
7147 exarg_T *eap;
|
|
7148 int isabbrev;
|
|
7149 {
|
|
7150 int mode;
|
|
7151 char_u *cmdp;
|
|
7152
|
|
7153 cmdp = eap->cmd;
|
|
7154 mode = get_map_mode(&cmdp, eap->forceit || isabbrev);
|
|
7155
|
|
7156 switch (do_map((*cmdp == 'n') ? 2 : (*cmdp == 'u'),
|
|
7157 eap->arg, mode, isabbrev))
|
|
7158 {
|
|
7159 case 1: EMSG(_(e_invarg));
|
|
7160 break;
|
|
7161 case 2: EMSG(isabbrev ? _(e_noabbr) : _(e_nomap));
|
|
7162 break;
|
|
7163 }
|
|
7164 }
|
|
7165
|
|
7166 /*
|
|
7167 * ":winsize" command (obsolete).
|
|
7168 */
|
|
7169 static void
|
|
7170 ex_winsize(eap)
|
|
7171 exarg_T *eap;
|
|
7172 {
|
|
7173 int w, h;
|
|
7174 char_u *arg = eap->arg;
|
|
7175 char_u *p;
|
|
7176
|
|
7177 w = getdigits(&arg);
|
|
7178 arg = skipwhite(arg);
|
|
7179 p = arg;
|
|
7180 h = getdigits(&arg);
|
|
7181 if (*p != NUL && *arg == NUL)
|
|
7182 set_shellsize(w, h, TRUE);
|
|
7183 else
|
|
7184 EMSG(_("E465: :winsize requires two number arguments"));
|
|
7185 }
|
|
7186
|
|
7187 #ifdef FEAT_WINDOWS
|
|
7188 static void
|
|
7189 ex_wincmd(eap)
|
|
7190 exarg_T *eap;
|
|
7191 {
|
|
7192 int xchar = NUL;
|
|
7193 char_u *p;
|
|
7194
|
|
7195 if (*eap->arg == 'g' || *eap->arg == Ctrl_G)
|
|
7196 {
|
|
7197 /* CTRL-W g and CTRL-W CTRL-G have an extra command character */
|
|
7198 if (eap->arg[1] == NUL)
|
|
7199 {
|
|
7200 EMSG(_(e_invarg));
|
|
7201 return;
|
|
7202 }
|
|
7203 xchar = eap->arg[1];
|
|
7204 p = eap->arg + 2;
|
|
7205 }
|
|
7206 else
|
|
7207 p = eap->arg + 1;
|
|
7208
|
|
7209 eap->nextcmd = check_nextcmd(p);
|
|
7210 p = skipwhite(p);
|
|
7211 if (*p != NUL && *p != '"' && eap->nextcmd == NULL)
|
|
7212 EMSG(_(e_invarg));
|
|
7213 else
|
|
7214 {
|
|
7215 /* Pass flags on for ":vertical wincmd ]". */
|
|
7216 postponed_split_flags = cmdmod.split;
|
|
7217 do_window(*eap->arg, eap->addr_count > 0 ? eap->line2 : 0L, xchar);
|
|
7218 postponed_split_flags = 0;
|
|
7219 }
|
|
7220 }
|
|
7221 #endif
|
|
7222
|
11
|
7223 #if defined(FEAT_GUI) || defined(UNIX) || defined(VMS) || defined(MSWIN)
|
7
|
7224 /*
|
|
7225 * ":winpos".
|
|
7226 */
|
|
7227 static void
|
|
7228 ex_winpos(eap)
|
|
7229 exarg_T *eap;
|
|
7230 {
|
|
7231 int x, y;
|
|
7232 char_u *arg = eap->arg;
|
|
7233 char_u *p;
|
|
7234
|
|
7235 if (*arg == NUL)
|
|
7236 {
|
11
|
7237 # if defined(FEAT_GUI) || defined(MSWIN)
|
|
7238 # ifdef FEAT_GUI
|
7
|
7239 if (gui.in_use && gui_mch_get_winpos(&x, &y) != FAIL)
|
11
|
7240 # else
|
|
7241 if (mch_get_winpos(&x, &y) != FAIL)
|
|
7242 # endif
|
7
|
7243 {
|
|
7244 sprintf((char *)IObuff, _("Window position: X %d, Y %d"), x, y);
|
|
7245 msg(IObuff);
|
|
7246 }
|
|
7247 else
|
|
7248 # endif
|
|
7249 EMSG(_("E188: Obtaining window position not implemented for this platform"));
|
|
7250 }
|
|
7251 else
|
|
7252 {
|
|
7253 x = getdigits(&arg);
|
|
7254 arg = skipwhite(arg);
|
|
7255 p = arg;
|
|
7256 y = getdigits(&arg);
|
|
7257 if (*p == NUL || *arg != NUL)
|
|
7258 {
|
|
7259 EMSG(_("E466: :winpos requires two number arguments"));
|
|
7260 return;
|
|
7261 }
|
|
7262 # ifdef FEAT_GUI
|
|
7263 if (gui.in_use)
|
|
7264 gui_mch_set_winpos(x, y);
|
|
7265 else if (gui.starting)
|
|
7266 {
|
|
7267 /* Remember the coordinates for when the window is opened. */
|
|
7268 gui_win_x = x;
|
|
7269 gui_win_y = y;
|
|
7270 }
|
|
7271 # ifdef HAVE_TGETENT
|
|
7272 else
|
|
7273 # endif
|
11
|
7274 # else
|
|
7275 # ifdef MSWIN
|
|
7276 mch_set_winpos(x, y);
|
|
7277 # endif
|
7
|
7278 # endif
|
|
7279 # ifdef HAVE_TGETENT
|
|
7280 if (*T_CWP)
|
|
7281 term_set_winpos(x, y);
|
|
7282 # endif
|
|
7283 }
|
|
7284 }
|
|
7285 #endif
|
|
7286
|
|
7287 /*
|
|
7288 * Handle command that work like operators: ":delete", ":yank", ":>" and ":<".
|
|
7289 */
|
|
7290 static void
|
|
7291 ex_operators(eap)
|
|
7292 exarg_T *eap;
|
|
7293 {
|
|
7294 oparg_T oa;
|
|
7295
|
|
7296 clear_oparg(&oa);
|
|
7297 oa.regname = eap->regname;
|
|
7298 oa.start.lnum = eap->line1;
|
|
7299 oa.end.lnum = eap->line2;
|
|
7300 oa.line_count = eap->line2 - eap->line1 + 1;
|
|
7301 oa.motion_type = MLINE;
|
|
7302 #ifdef FEAT_VIRTUALEDIT
|
|
7303 virtual_op = FALSE;
|
|
7304 #endif
|
|
7305 if (eap->cmdidx != CMD_yank) /* position cursor for undo */
|
|
7306 {
|
|
7307 setpcmark();
|
|
7308 curwin->w_cursor.lnum = eap->line1;
|
|
7309 beginline(BL_SOL | BL_FIX);
|
|
7310 }
|
|
7311
|
|
7312 switch (eap->cmdidx)
|
|
7313 {
|
|
7314 case CMD_delete:
|
|
7315 oa.op_type = OP_DELETE;
|
|
7316 op_delete(&oa);
|
|
7317 break;
|
|
7318
|
|
7319 case CMD_yank:
|
|
7320 oa.op_type = OP_YANK;
|
|
7321 (void)op_yank(&oa, FALSE, TRUE);
|
|
7322 break;
|
|
7323
|
|
7324 default: /* CMD_rshift or CMD_lshift */
|
|
7325 if ((eap->cmdidx == CMD_rshift)
|
|
7326 #ifdef FEAT_RIGHTLEFT
|
|
7327 ^ curwin->w_p_rl
|
|
7328 #endif
|
|
7329 )
|
|
7330 oa.op_type = OP_RSHIFT;
|
|
7331 else
|
|
7332 oa.op_type = OP_LSHIFT;
|
|
7333 op_shift(&oa, FALSE, eap->amount);
|
|
7334 break;
|
|
7335 }
|
|
7336 #ifdef FEAT_VIRTUALEDIT
|
|
7337 virtual_op = MAYBE;
|
|
7338 #endif
|
|
7339 }
|
|
7340
|
|
7341 /*
|
|
7342 * ":put".
|
|
7343 */
|
|
7344 static void
|
|
7345 ex_put(eap)
|
|
7346 exarg_T *eap;
|
|
7347 {
|
|
7348 /* ":0put" works like ":1put!". */
|
|
7349 if (eap->line2 == 0)
|
|
7350 {
|
|
7351 eap->line2 = 1;
|
|
7352 eap->forceit = TRUE;
|
|
7353 }
|
|
7354 curwin->w_cursor.lnum = eap->line2;
|
|
7355 do_put(eap->regname, eap->forceit ? BACKWARD : FORWARD, 1L, PUT_LINE);
|
|
7356 }
|
|
7357
|
|
7358 /*
|
|
7359 * Handle ":copy" and ":move".
|
|
7360 */
|
|
7361 static void
|
|
7362 ex_copymove(eap)
|
|
7363 exarg_T *eap;
|
|
7364 {
|
|
7365 long n;
|
|
7366
|
|
7367 n = get_address(&eap->arg, FALSE, FALSE);
|
|
7368 if (eap->arg == NULL) /* error detected */
|
|
7369 {
|
|
7370 eap->nextcmd = NULL;
|
|
7371 return;
|
|
7372 }
|
|
7373
|
|
7374 /*
|
|
7375 * move or copy lines from 'eap->line1'-'eap->line2' to below line 'n'
|
|
7376 */
|
|
7377 if (n == MAXLNUM || n < 0 || n > curbuf->b_ml.ml_line_count)
|
|
7378 {
|
|
7379 EMSG(_(e_invaddr));
|
|
7380 return;
|
|
7381 }
|
|
7382
|
|
7383 if (eap->cmdidx == CMD_move)
|
|
7384 {
|
|
7385 if (do_move(eap->line1, eap->line2, n) == FAIL)
|
|
7386 return;
|
|
7387 }
|
|
7388 else
|
|
7389 ex_copy(eap->line1, eap->line2, n);
|
|
7390 u_clearline();
|
|
7391 beginline(BL_SOL | BL_FIX);
|
|
7392 }
|
|
7393
|
|
7394 /*
|
|
7395 * ":smagic" and ":snomagic".
|
|
7396 */
|
|
7397 static void
|
|
7398 ex_submagic(eap)
|
|
7399 exarg_T *eap;
|
|
7400 {
|
|
7401 int magic_save = p_magic;
|
|
7402
|
|
7403 p_magic = (eap->cmdidx == CMD_smagic);
|
|
7404 do_sub(eap);
|
|
7405 p_magic = magic_save;
|
|
7406 }
|
|
7407
|
|
7408 /*
|
|
7409 * ":join".
|
|
7410 */
|
|
7411 static void
|
|
7412 ex_join(eap)
|
|
7413 exarg_T *eap;
|
|
7414 {
|
|
7415 curwin->w_cursor.lnum = eap->line1;
|
|
7416 if (eap->line1 == eap->line2)
|
|
7417 {
|
|
7418 if (eap->addr_count >= 2) /* :2,2join does nothing */
|
|
7419 return;
|
|
7420 if (eap->line2 == curbuf->b_ml.ml_line_count)
|
|
7421 {
|
|
7422 beep_flush();
|
|
7423 return;
|
|
7424 }
|
|
7425 ++eap->line2;
|
|
7426 }
|
|
7427 do_do_join(eap->line2 - eap->line1 + 1, !eap->forceit);
|
|
7428 beginline(BL_WHITE | BL_FIX);
|
|
7429 }
|
|
7430
|
|
7431 /*
|
|
7432 * ":[addr]@r" or ":[addr]*r": execute register
|
|
7433 */
|
|
7434 static void
|
|
7435 ex_at(eap)
|
|
7436 exarg_T *eap;
|
|
7437 {
|
|
7438 int c;
|
|
7439
|
|
7440 curwin->w_cursor.lnum = eap->line2;
|
|
7441
|
|
7442 #ifdef USE_ON_FLY_SCROLL
|
|
7443 dont_scroll = TRUE; /* disallow scrolling here */
|
|
7444 #endif
|
|
7445
|
|
7446 /* get the register name. No name means to use the previous one */
|
|
7447 c = *eap->arg;
|
|
7448 if (c == NUL || (c == '*' && *eap->cmd == '*'))
|
|
7449 c = '@';
|
|
7450 /* put the register in mapbuf */
|
|
7451 if (do_execreg(c, TRUE, vim_strchr(p_cpo, CPO_EXECBUF) != NULL) == FAIL)
|
|
7452 beep_flush();
|
|
7453 else
|
|
7454 {
|
|
7455 int save_efr = exec_from_reg;
|
|
7456
|
|
7457 exec_from_reg = TRUE;
|
|
7458
|
|
7459 /*
|
|
7460 * Execute from the typeahead buffer.
|
|
7461 * Originally this didn't check for the typeahead buffer to be empty,
|
|
7462 * thus could read more Ex commands from stdin. It's not clear why,
|
|
7463 * it is certainly unexpected.
|
|
7464 */
|
|
7465 while ((!stuff_empty() || typebuf.tb_len > 0) && vpeekc() == ':')
|
|
7466 (void)do_cmdline(NULL, getexline, NULL, DOCMD_NOWAIT|DOCMD_VERBOSE);
|
|
7467
|
|
7468 exec_from_reg = save_efr;
|
|
7469 }
|
|
7470 }
|
|
7471
|
|
7472 /*
|
|
7473 * ":!".
|
|
7474 */
|
|
7475 static void
|
|
7476 ex_bang(eap)
|
|
7477 exarg_T *eap;
|
|
7478 {
|
|
7479 do_bang(eap->addr_count, eap, eap->forceit, TRUE, TRUE);
|
|
7480 }
|
|
7481
|
|
7482 /*
|
|
7483 * ":undo".
|
|
7484 */
|
|
7485 /*ARGSUSED*/
|
|
7486 static void
|
|
7487 ex_undo(eap)
|
|
7488 exarg_T *eap;
|
|
7489 {
|
|
7490 u_undo(1);
|
|
7491 }
|
|
7492
|
|
7493 /*
|
|
7494 * ":redo".
|
|
7495 */
|
|
7496 /*ARGSUSED*/
|
|
7497 static void
|
|
7498 ex_redo(eap)
|
|
7499 exarg_T *eap;
|
|
7500 {
|
|
7501 u_redo(1);
|
|
7502 }
|
|
7503
|
|
7504 /*
|
|
7505 * ":redir": start/stop redirection.
|
|
7506 */
|
|
7507 static void
|
|
7508 ex_redir(eap)
|
|
7509 exarg_T *eap;
|
|
7510 {
|
|
7511 char *mode;
|
|
7512 char_u *fname;
|
|
7513
|
|
7514 if (STRICMP(eap->arg, "END") == 0)
|
|
7515 close_redir();
|
|
7516 else
|
|
7517 {
|
|
7518 if (*eap->arg == '>')
|
|
7519 {
|
|
7520 ++eap->arg;
|
|
7521 if (*eap->arg == '>')
|
|
7522 {
|
|
7523 ++eap->arg;
|
|
7524 mode = "a";
|
|
7525 }
|
|
7526 else
|
|
7527 mode = "w";
|
|
7528 eap->arg = skipwhite(eap->arg);
|
|
7529
|
|
7530 close_redir();
|
|
7531
|
|
7532 /* Expand environment variables and "~/". */
|
|
7533 fname = expand_env_save(eap->arg);
|
|
7534 if (fname == NULL)
|
|
7535 return;
|
|
7536 #ifdef FEAT_BROWSE
|
|
7537 if (cmdmod.browse)
|
|
7538 {
|
|
7539 char_u *browseFile;
|
|
7540
|
28
|
7541 browseFile = do_browse(BROWSE_SAVE,
|
|
7542 (char_u *)_("Save Redirection"),
|
|
7543 fname, NULL, NULL, BROWSE_FILTER_ALL_FILES, curbuf);
|
7
|
7544 if (browseFile == NULL)
|
|
7545 return; /* operation cancelled */
|
|
7546 vim_free(fname);
|
|
7547 fname = browseFile;
|
|
7548 eap->forceit = TRUE; /* since dialog already asked */
|
|
7549 }
|
|
7550 #endif
|
|
7551
|
|
7552 redir_fd = open_exfile(fname, eap->forceit, mode);
|
|
7553 vim_free(fname);
|
|
7554 }
|
|
7555 #ifdef FEAT_EVAL
|
|
7556 else if (*eap->arg == '@')
|
|
7557 {
|
|
7558 /* redirect to a register a-z (resp. A-Z for appending) */
|
|
7559 close_redir();
|
|
7560 ++eap->arg;
|
|
7561 if (ASCII_ISALPHA(*eap->arg)
|
|
7562 # ifdef FEAT_CLIPBOARD
|
|
7563 || *eap->arg == '*'
|
|
7564 # endif
|
|
7565 || *eap->arg == '"')
|
|
7566 {
|
|
7567 redir_reg = *eap->arg;
|
|
7568 if (islower(redir_reg)
|
|
7569 # ifdef FEAT_CLIPBOARD
|
|
7570 || redir_reg == '*'
|
|
7571 # endif
|
|
7572 || redir_reg == '"')
|
|
7573 {
|
|
7574 /* make register empty */
|
|
7575 write_reg_contents(redir_reg, (char_u *)"", -1, FALSE);
|
|
7576 }
|
|
7577 }
|
|
7578 else
|
|
7579 EMSG(_(e_invarg));
|
|
7580 }
|
|
7581 #endif
|
|
7582
|
|
7583 /* TODO: redirect to a buffer */
|
|
7584
|
|
7585 /* TODO: redirect to an internal variable */
|
|
7586
|
|
7587 else
|
|
7588 EMSG(_(e_invarg));
|
|
7589 }
|
|
7590 }
|
|
7591
|
|
7592 /*
|
|
7593 * ":redraw": force redraw
|
|
7594 */
|
|
7595 static void
|
|
7596 ex_redraw(eap)
|
|
7597 exarg_T *eap;
|
|
7598 {
|
|
7599 int r = RedrawingDisabled;
|
|
7600 int p = p_lz;
|
|
7601
|
|
7602 RedrawingDisabled = 0;
|
|
7603 p_lz = FALSE;
|
|
7604 update_topline();
|
|
7605 update_screen(eap->forceit ? CLEAR :
|
|
7606 #ifdef FEAT_VISUAL
|
|
7607 VIsual_active ? INVERTED :
|
|
7608 #endif
|
|
7609 0);
|
|
7610 #ifdef FEAT_TITLE
|
|
7611 if (need_maketitle)
|
|
7612 maketitle();
|
|
7613 #endif
|
|
7614 RedrawingDisabled = r;
|
|
7615 p_lz = p;
|
|
7616
|
|
7617 /* Reset msg_didout, so that a message that's there is overwritten. */
|
|
7618 msg_didout = FALSE;
|
|
7619 msg_col = 0;
|
|
7620
|
|
7621 out_flush();
|
|
7622 }
|
|
7623
|
|
7624 /*
|
|
7625 * ":redrawstatus": force redraw of status line(s)
|
|
7626 */
|
|
7627 /*ARGSUSED*/
|
|
7628 static void
|
|
7629 ex_redrawstatus(eap)
|
|
7630 exarg_T *eap;
|
|
7631 {
|
|
7632 #if defined(FEAT_WINDOWS)
|
|
7633 int r = RedrawingDisabled;
|
|
7634 int p = p_lz;
|
|
7635
|
|
7636 RedrawingDisabled = 0;
|
|
7637 p_lz = FALSE;
|
|
7638 if (eap->forceit)
|
|
7639 status_redraw_all();
|
|
7640 else
|
|
7641 status_redraw_curbuf();
|
|
7642 update_screen(
|
|
7643 # ifdef FEAT_VISUAL
|
|
7644 VIsual_active ? INVERTED :
|
|
7645 # endif
|
|
7646 0);
|
|
7647 RedrawingDisabled = r;
|
|
7648 p_lz = p;
|
|
7649 out_flush();
|
|
7650 #endif
|
|
7651 }
|
|
7652
|
|
7653 static void
|
|
7654 close_redir()
|
|
7655 {
|
|
7656 if (redir_fd != NULL)
|
|
7657 {
|
|
7658 fclose(redir_fd);
|
|
7659 redir_fd = NULL;
|
|
7660 }
|
|
7661 #ifdef FEAT_EVAL
|
|
7662 redir_reg = 0;
|
|
7663 #endif
|
|
7664 }
|
|
7665
|
|
7666 #if defined(FEAT_SESSION) && defined(USE_CRNL)
|
|
7667 # define MKSESSION_NL
|
|
7668 static int mksession_nl = FALSE; /* use NL only in put_eol() */
|
|
7669 #endif
|
|
7670
|
|
7671 /*
|
|
7672 * ":mkexrc", ":mkvimrc", ":mkview" and ":mksession".
|
|
7673 */
|
|
7674 static void
|
|
7675 ex_mkrc(eap)
|
|
7676 exarg_T *eap;
|
|
7677 {
|
|
7678 FILE *fd;
|
|
7679 int failed = FALSE;
|
|
7680 char_u *fname;
|
|
7681 #ifdef FEAT_BROWSE
|
|
7682 char_u *browseFile = NULL;
|
|
7683 #endif
|
|
7684 #ifdef FEAT_SESSION
|
|
7685 int view_session = FALSE;
|
|
7686 int using_vdir = FALSE; /* using 'viewdir'? */
|
|
7687 char_u *viewFile = NULL;
|
|
7688 unsigned *flagp;
|
|
7689 #endif
|
|
7690
|
|
7691 if (eap->cmdidx == CMD_mksession || eap->cmdidx == CMD_mkview)
|
|
7692 {
|
|
7693 #ifdef FEAT_SESSION
|
|
7694 view_session = TRUE;
|
|
7695 #else
|
|
7696 ex_ni(eap);
|
|
7697 return;
|
|
7698 #endif
|
|
7699 }
|
|
7700
|
|
7701 #ifdef FEAT_SESSION
|
|
7702 /* ":mkview" or ":mkview 9": generate file name with 'viewdir' */
|
|
7703 if (eap->cmdidx == CMD_mkview
|
|
7704 && (*eap->arg == NUL
|
|
7705 || (vim_isdigit(*eap->arg) && eap->arg[1] == NUL)))
|
|
7706 {
|
|
7707 eap->forceit = TRUE;
|
|
7708 fname = get_view_file(*eap->arg);
|
|
7709 if (fname == NULL)
|
|
7710 return;
|
|
7711 viewFile = fname;
|
|
7712 using_vdir = TRUE;
|
|
7713 }
|
|
7714 else
|
|
7715 #endif
|
|
7716 if (*eap->arg != NUL)
|
|
7717 fname = eap->arg;
|
|
7718 else if (eap->cmdidx == CMD_mkvimrc)
|
|
7719 fname = (char_u *)VIMRC_FILE;
|
|
7720 #ifdef FEAT_SESSION
|
|
7721 else if (eap->cmdidx == CMD_mksession)
|
|
7722 fname = (char_u *)SESSION_FILE;
|
|
7723 #endif
|
|
7724 else
|
|
7725 fname = (char_u *)EXRC_FILE;
|
|
7726
|
|
7727 #ifdef FEAT_BROWSE
|
|
7728 if (cmdmod.browse)
|
|
7729 {
|
28
|
7730 browseFile = do_browse(BROWSE_SAVE,
|
7
|
7731 # ifdef FEAT_SESSION
|
|
7732 eap->cmdidx == CMD_mkview ? (char_u *)_("Save View") :
|
|
7733 eap->cmdidx == CMD_mksession ? (char_u *)_("Save Session") :
|
|
7734 # endif
|
|
7735 (char_u *)_("Save Setup"),
|
|
7736 fname, (char_u *)"vim", NULL, BROWSE_FILTER_MACROS, NULL);
|
|
7737 if (browseFile == NULL)
|
|
7738 goto theend;
|
|
7739 fname = browseFile;
|
|
7740 eap->forceit = TRUE; /* since dialog already asked */
|
|
7741 }
|
|
7742 #endif
|
|
7743
|
|
7744 #if defined(FEAT_SESSION) && defined(vim_mkdir)
|
|
7745 /* When using 'viewdir' may have to create the directory. */
|
|
7746 if (using_vdir && !mch_isdir(p_vdir))
|
|
7747 vim_mkdir(p_vdir, 0755); /* ignore errors, open_exfile() will fail */
|
|
7748 #endif
|
|
7749
|
|
7750 fd = open_exfile(fname, eap->forceit, WRITEBIN);
|
|
7751 if (fd != NULL)
|
|
7752 {
|
|
7753 #ifdef FEAT_SESSION
|
|
7754 if (eap->cmdidx == CMD_mkview)
|
|
7755 flagp = &vop_flags;
|
|
7756 else
|
|
7757 flagp = &ssop_flags;
|
|
7758 #endif
|
|
7759
|
|
7760 #ifdef MKSESSION_NL
|
|
7761 /* "unix" in 'sessionoptions': use NL line separator */
|
|
7762 if (view_session && (*flagp & SSOP_UNIX))
|
|
7763 mksession_nl = TRUE;
|
|
7764 #endif
|
|
7765
|
|
7766 /* Write the version command for :mkvimrc */
|
|
7767 if (eap->cmdidx == CMD_mkvimrc)
|
|
7768 (void)put_line(fd, "version 6.0");
|
|
7769
|
|
7770 #ifdef FEAT_SESSION
|
|
7771 if (eap->cmdidx != CMD_mkview)
|
|
7772 #endif
|
|
7773 {
|
|
7774 /* Write setting 'compatible' first, because it has side effects.
|
|
7775 * For that same reason only do it when needed. */
|
|
7776 if (p_cp)
|
|
7777 (void)put_line(fd, "if !&cp | set cp | endif");
|
|
7778 else
|
|
7779 (void)put_line(fd, "if &cp | set nocp | endif");
|
|
7780 }
|
|
7781
|
|
7782 #ifdef FEAT_SESSION
|
|
7783 if (!view_session
|
|
7784 || (eap->cmdidx == CMD_mksession
|
|
7785 && (*flagp & SSOP_OPTIONS)))
|
|
7786 #endif
|
|
7787 failed |= (makemap(fd, NULL) == FAIL
|
|
7788 || makeset(fd, OPT_GLOBAL, FALSE) == FAIL);
|
|
7789
|
|
7790 #ifdef FEAT_SESSION
|
|
7791 if (!failed && view_session)
|
|
7792 {
|
|
7793 if (put_line(fd, "let s:so_save = &so | let s:siso_save = &siso | set so=0 siso=0") == FAIL)
|
|
7794 failed = TRUE;
|
|
7795 if (eap->cmdidx == CMD_mksession)
|
|
7796 {
|
|
7797 char_u dirnow[MAXPATHL]; /* current directory */
|
|
7798
|
|
7799 /*
|
|
7800 * Change to session file's dir.
|
|
7801 */
|
|
7802 if (mch_dirname(dirnow, MAXPATHL) == FAIL
|
|
7803 || mch_chdir((char *)dirnow) != 0)
|
|
7804 *dirnow = NUL;
|
|
7805 if (*dirnow != NUL && (ssop_flags & SSOP_SESDIR))
|
|
7806 {
|
|
7807 if (vim_chdirfile(fname) == OK)
|
|
7808 shorten_fnames(TRUE);
|
|
7809 }
|
|
7810 else if (*dirnow != NUL
|
|
7811 && (ssop_flags & SSOP_CURDIR) && globaldir != NULL)
|
|
7812 {
|
|
7813 (void)mch_chdir((char *)globaldir);
|
|
7814 shorten_fnames(TRUE);
|
|
7815 }
|
|
7816
|
|
7817 failed |= (makeopens(fd, dirnow) == FAIL);
|
|
7818
|
|
7819 /* restore original dir */
|
|
7820 if (*dirnow != NUL && ((ssop_flags & SSOP_SESDIR)
|
|
7821 || ((ssop_flags & SSOP_CURDIR) && globaldir != NULL)))
|
|
7822 {
|
|
7823 if (mch_chdir((char *)dirnow) != 0)
|
|
7824 EMSG(_(e_prev_dir));
|
|
7825 shorten_fnames(TRUE);
|
|
7826 }
|
|
7827 }
|
|
7828 else
|
|
7829 {
|
|
7830 failed |= (put_view(fd, curwin, !using_vdir, flagp) == FAIL);
|
|
7831 }
|
|
7832 if (put_line(fd, "let &so = s:so_save | let &siso = s:siso_save")
|
|
7833 == FAIL)
|
|
7834 failed = TRUE;
|
|
7835 }
|
|
7836 #endif
|
|
7837 failed |= fclose(fd);
|
|
7838
|
|
7839 if (failed)
|
|
7840 EMSG(_(e_write));
|
|
7841 #if defined(FEAT_EVAL) && defined(FEAT_SESSION)
|
|
7842 else if (eap->cmdidx == CMD_mksession)
|
|
7843 {
|
|
7844 /* successful session write - set this_session var */
|
|
7845 char_u tbuf[MAXPATHL];
|
|
7846
|
|
7847 if (vim_FullName(fname, tbuf, MAXPATHL, FALSE) == OK)
|
|
7848 set_vim_var_string(VV_THIS_SESSION, tbuf, -1);
|
|
7849 }
|
|
7850 #endif
|
|
7851 #ifdef MKSESSION_NL
|
|
7852 mksession_nl = FALSE;
|
|
7853 #endif
|
|
7854 }
|
|
7855
|
|
7856 #ifdef FEAT_BROWSE
|
|
7857 theend:
|
|
7858 vim_free(browseFile);
|
|
7859 #endif
|
|
7860 #ifdef FEAT_SESSION
|
|
7861 vim_free(viewFile);
|
|
7862 #endif
|
|
7863 }
|
|
7864
|
|
7865 /*
|
|
7866 * Open a file for writing for an Ex command, with some checks.
|
|
7867 * Return file descriptor, or NULL on failure.
|
|
7868 */
|
|
7869 FILE *
|
|
7870 open_exfile(fname, forceit, mode)
|
|
7871 char_u *fname;
|
|
7872 int forceit;
|
|
7873 char *mode; /* "w" for create new file or "a" for append */
|
|
7874 {
|
|
7875 FILE *fd;
|
|
7876
|
|
7877 #ifdef UNIX
|
|
7878 /* with Unix it is possible to open a directory */
|
|
7879 if (mch_isdir(fname))
|
|
7880 {
|
|
7881 EMSG2(_(e_isadir2), fname);
|
|
7882 return NULL;
|
|
7883 }
|
|
7884 #endif
|
|
7885 if (!forceit && *mode != 'a' && vim_fexists(fname))
|
|
7886 {
|
|
7887 EMSG2(_("E189: \"%s\" exists (add ! to override)"), fname);
|
|
7888 return NULL;
|
|
7889 }
|
|
7890
|
|
7891 if ((fd = mch_fopen((char *)fname, mode)) == NULL)
|
|
7892 EMSG2(_("E190: Cannot open \"%s\" for writing"), fname);
|
|
7893
|
|
7894 return fd;
|
|
7895 }
|
|
7896
|
|
7897 /*
|
|
7898 * ":mark" and ":k".
|
|
7899 */
|
|
7900 static void
|
|
7901 ex_mark(eap)
|
|
7902 exarg_T *eap;
|
|
7903 {
|
|
7904 pos_T pos;
|
|
7905
|
|
7906 if (*eap->arg == NUL) /* No argument? */
|
|
7907 EMSG(_(e_argreq));
|
|
7908 else if (eap->arg[1] != NUL) /* more than one character? */
|
|
7909 EMSG(_(e_trailing));
|
|
7910 else
|
|
7911 {
|
|
7912 pos = curwin->w_cursor; /* save curwin->w_cursor */
|
|
7913 curwin->w_cursor.lnum = eap->line2;
|
|
7914 beginline(BL_WHITE | BL_FIX);
|
|
7915 if (setmark(*eap->arg) == FAIL) /* set mark */
|
|
7916 EMSG(_("E191: Argument must be a letter or forward/backward quote"));
|
|
7917 curwin->w_cursor = pos; /* restore curwin->w_cursor */
|
|
7918 }
|
|
7919 }
|
|
7920
|
|
7921 /*
|
|
7922 * Update w_topline, w_leftcol and the cursor position.
|
|
7923 */
|
|
7924 void
|
|
7925 update_topline_cursor()
|
|
7926 {
|
|
7927 check_cursor(); /* put cursor on valid line */
|
|
7928 update_topline();
|
|
7929 if (!curwin->w_p_wrap)
|
|
7930 validate_cursor();
|
|
7931 update_curswant();
|
|
7932 }
|
|
7933
|
|
7934 #ifdef FEAT_EX_EXTRA
|
|
7935 /*
|
|
7936 * ":normal[!] {commands}": Execute normal mode commands.
|
|
7937 */
|
|
7938 static void
|
|
7939 ex_normal(eap)
|
|
7940 exarg_T *eap;
|
|
7941 {
|
|
7942 int save_msg_scroll = msg_scroll;
|
|
7943 int save_restart_edit = restart_edit;
|
|
7944 int save_msg_didout = msg_didout;
|
|
7945 int save_State = State;
|
|
7946 tasave_T tabuf;
|
|
7947 int save_insertmode = p_im;
|
|
7948 int save_finish_op = finish_op;
|
|
7949 #ifdef FEAT_MBYTE
|
|
7950 char_u *arg = NULL;
|
|
7951 int l;
|
|
7952 char_u *p;
|
|
7953 #endif
|
|
7954
|
|
7955 if (ex_normal_busy >= p_mmd)
|
|
7956 {
|
|
7957 EMSG(_("E192: Recursive use of :normal too deep"));
|
|
7958 return;
|
|
7959 }
|
|
7960 ++ex_normal_busy;
|
|
7961
|
|
7962 msg_scroll = FALSE; /* no msg scrolling in Normal mode */
|
|
7963 restart_edit = 0; /* don't go to Insert mode */
|
|
7964 p_im = FALSE; /* don't use 'insertmode' */
|
|
7965
|
|
7966 #ifdef FEAT_MBYTE
|
|
7967 /*
|
|
7968 * vgetc() expects a CSI and K_SPECIAL to have been escaped. Don't do
|
|
7969 * this for the K_SPECIAL leading byte, otherwise special keys will not
|
|
7970 * work.
|
|
7971 */
|
|
7972 if (has_mbyte)
|
|
7973 {
|
|
7974 int len = 0;
|
|
7975
|
|
7976 /* Count the number of characters to be escaped. */
|
|
7977 for (p = eap->arg; *p != NUL; ++p)
|
|
7978 {
|
|
7979 # ifdef FEAT_GUI
|
|
7980 if (*p == CSI) /* leadbyte CSI */
|
|
7981 len += 2;
|
|
7982 # endif
|
|
7983 for (l = (*mb_ptr2len_check)(p) - 1; l > 0; --l)
|
|
7984 if (*++p == K_SPECIAL /* trailbyte K_SPECIAL or CSI */
|
|
7985 # ifdef FEAT_GUI
|
|
7986 || *p == CSI
|
|
7987 # endif
|
|
7988 )
|
|
7989 len += 2;
|
|
7990 }
|
|
7991 if (len > 0)
|
|
7992 {
|
|
7993 arg = alloc((unsigned)(STRLEN(eap->arg) + len + 1));
|
|
7994 if (arg != NULL)
|
|
7995 {
|
|
7996 len = 0;
|
|
7997 for (p = eap->arg; *p != NUL; ++p)
|
|
7998 {
|
|
7999 arg[len++] = *p;
|
|
8000 # ifdef FEAT_GUI
|
|
8001 if (*p == CSI)
|
|
8002 {
|
|
8003 arg[len++] = KS_EXTRA;
|
|
8004 arg[len++] = (int)KE_CSI;
|
|
8005 }
|
|
8006 # endif
|
|
8007 for (l = (*mb_ptr2len_check)(p) - 1; l > 0; --l)
|
|
8008 {
|
|
8009 arg[len++] = *++p;
|
|
8010 if (*p == K_SPECIAL)
|
|
8011 {
|
|
8012 arg[len++] = KS_SPECIAL;
|
|
8013 arg[len++] = KE_FILLER;
|
|
8014 }
|
|
8015 # ifdef FEAT_GUI
|
|
8016 else if (*p == CSI)
|
|
8017 {
|
|
8018 arg[len++] = KS_EXTRA;
|
|
8019 arg[len++] = (int)KE_CSI;
|
|
8020 }
|
|
8021 # endif
|
|
8022 }
|
|
8023 arg[len] = NUL;
|
|
8024 }
|
|
8025 }
|
|
8026 }
|
|
8027 }
|
|
8028 #endif
|
|
8029
|
|
8030 /*
|
|
8031 * Save the current typeahead. This is required to allow using ":normal"
|
|
8032 * from an event handler and makes sure we don't hang when the argument
|
|
8033 * ends with half a command.
|
|
8034 */
|
|
8035 save_typeahead(&tabuf);
|
|
8036 if (tabuf.typebuf_valid)
|
|
8037 {
|
|
8038 /*
|
|
8039 * Repeat the :normal command for each line in the range. When no
|
|
8040 * range given, execute it just once, without positioning the cursor
|
|
8041 * first.
|
|
8042 */
|
|
8043 do
|
|
8044 {
|
|
8045 if (eap->addr_count != 0)
|
|
8046 {
|
|
8047 curwin->w_cursor.lnum = eap->line1++;
|
|
8048 curwin->w_cursor.col = 0;
|
|
8049 }
|
|
8050
|
36
|
8051 exec_normal_cmd(
|
7
|
8052 #ifdef FEAT_MBYTE
|
|
8053 arg != NULL ? arg :
|
|
8054 #endif
|
36
|
8055 eap->arg, eap->forceit ? REMAP_NONE : REMAP_YES, FALSE);
|
7
|
8056 }
|
|
8057 while (eap->addr_count > 0 && eap->line1 <= eap->line2 && !got_int);
|
|
8058 }
|
|
8059
|
|
8060 /* Might not return to the main loop when in an event handler. */
|
|
8061 update_topline_cursor();
|
|
8062
|
|
8063 /* Restore the previous typeahead. */
|
|
8064 restore_typeahead(&tabuf);
|
|
8065
|
|
8066 --ex_normal_busy;
|
|
8067 msg_scroll = save_msg_scroll;
|
|
8068 restart_edit = save_restart_edit;
|
|
8069 p_im = save_insertmode;
|
|
8070 finish_op = save_finish_op;
|
|
8071 msg_didout |= save_msg_didout; /* don't reset msg_didout now */
|
|
8072
|
|
8073 /* Restore the state (needed when called from a function executed for
|
|
8074 * 'indentexpr'). */
|
|
8075 State = save_State;
|
|
8076 #ifdef FEAT_MBYTE
|
|
8077 vim_free(arg);
|
|
8078 #endif
|
|
8079 }
|
|
8080
|
|
8081 /*
|
14
|
8082 * ":startinsert" and ":startreplace"
|
7
|
8083 */
|
|
8084 static void
|
|
8085 ex_startinsert(eap)
|
|
8086 exarg_T *eap;
|
|
8087 {
|
|
8088 if (eap->forceit)
|
|
8089 {
|
|
8090 coladvance((colnr_T)MAXCOL);
|
|
8091 curwin->w_curswant = MAXCOL;
|
|
8092 curwin->w_set_curswant = FALSE;
|
14
|
8093 if (eap->cmdidx == CMD_startinsert)
|
|
8094 restart_edit = 'a';
|
|
8095 else
|
|
8096 restart_edit = 'R';
|
7
|
8097 }
|
|
8098 else
|
|
8099 {
|
14
|
8100 if (eap->cmdidx == CMD_startinsert)
|
|
8101 restart_edit = 'i';
|
|
8102 else
|
|
8103 restart_edit = 'R';
|
7
|
8104 curwin->w_curswant = 0; /* avoid MAXCOL */
|
|
8105 }
|
|
8106 }
|
|
8107
|
|
8108 /*
|
|
8109 * ":stopinsert"
|
|
8110 */
|
|
8111 /*ARGSUSED*/
|
|
8112 static void
|
|
8113 ex_stopinsert(eap)
|
|
8114 exarg_T *eap;
|
|
8115 {
|
|
8116 restart_edit = 0;
|
|
8117 stop_insert_mode = TRUE;
|
|
8118 }
|
|
8119 #endif
|
|
8120
|
36
|
8121 #if defined(FEAT_EX_EXTRA) || defined(FEAT_MENU) || defined(PROTO)
|
|
8122 /*
|
|
8123 * Execute normal mode command "cmd".
|
|
8124 * "remap" can be REMAP_NONE or REMAP_YES.
|
|
8125 */
|
|
8126 void
|
|
8127 exec_normal_cmd(cmd, remap, silent)
|
|
8128 char_u *cmd;
|
|
8129 int remap;
|
|
8130 int silent;
|
|
8131 {
|
|
8132 oparg_T oa;
|
|
8133
|
|
8134 /*
|
|
8135 * Stuff the argument into the typeahead buffer.
|
|
8136 * Execute normal_cmd() until there is no typeahead left.
|
|
8137 */
|
|
8138 clear_oparg(&oa);
|
|
8139 finish_op = FALSE;
|
|
8140 ins_typebuf(cmd, remap, 0, TRUE, silent);
|
|
8141 while ((!stuff_empty() || (!typebuf_typed() && typebuf.tb_len > 0))
|
|
8142 && !got_int)
|
|
8143 {
|
|
8144 update_topline_cursor();
|
|
8145 normal_cmd(&oa, FALSE); /* execute a Normal mode cmd */
|
|
8146 }
|
|
8147 }
|
|
8148 #endif
|
|
8149
|
7
|
8150 #ifdef FEAT_FIND_ID
|
|
8151 static void
|
|
8152 ex_checkpath(eap)
|
|
8153 exarg_T *eap;
|
|
8154 {
|
|
8155 find_pattern_in_path(NULL, 0, 0, FALSE, FALSE, CHECK_PATH, 1L,
|
|
8156 eap->forceit ? ACTION_SHOW_ALL : ACTION_SHOW,
|
|
8157 (linenr_T)1, (linenr_T)MAXLNUM);
|
|
8158 }
|
|
8159
|
|
8160 #if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
|
|
8161 /*
|
|
8162 * ":psearch"
|
|
8163 */
|
|
8164 static void
|
|
8165 ex_psearch(eap)
|
|
8166 exarg_T *eap;
|
|
8167 {
|
|
8168 g_do_tagpreview = p_pvh;
|
|
8169 ex_findpat(eap);
|
|
8170 g_do_tagpreview = 0;
|
|
8171 }
|
|
8172 #endif
|
|
8173
|
|
8174 static void
|
|
8175 ex_findpat(eap)
|
|
8176 exarg_T *eap;
|
|
8177 {
|
|
8178 int whole = TRUE;
|
|
8179 long n;
|
|
8180 char_u *p;
|
|
8181 int action;
|
|
8182
|
|
8183 switch (cmdnames[eap->cmdidx].cmd_name[2])
|
|
8184 {
|
|
8185 case 'e': /* ":psearch", ":isearch" and ":dsearch" */
|
|
8186 if (cmdnames[eap->cmdidx].cmd_name[0] == 'p')
|
|
8187 action = ACTION_GOTO;
|
|
8188 else
|
|
8189 action = ACTION_SHOW;
|
|
8190 break;
|
|
8191 case 'i': /* ":ilist" and ":dlist" */
|
|
8192 action = ACTION_SHOW_ALL;
|
|
8193 break;
|
|
8194 case 'u': /* ":ijump" and ":djump" */
|
|
8195 action = ACTION_GOTO;
|
|
8196 break;
|
|
8197 default: /* ":isplit" and ":dsplit" */
|
|
8198 action = ACTION_SPLIT;
|
|
8199 break;
|
|
8200 }
|
|
8201
|
|
8202 n = 1;
|
|
8203 if (vim_isdigit(*eap->arg)) /* get count */
|
|
8204 {
|
|
8205 n = getdigits(&eap->arg);
|
|
8206 eap->arg = skipwhite(eap->arg);
|
|
8207 }
|
|
8208 if (*eap->arg == '/') /* Match regexp, not just whole words */
|
|
8209 {
|
|
8210 whole = FALSE;
|
|
8211 ++eap->arg;
|
|
8212 p = skip_regexp(eap->arg, '/', p_magic, NULL);
|
|
8213 if (*p)
|
|
8214 {
|
|
8215 *p++ = NUL;
|
|
8216 p = skipwhite(p);
|
|
8217
|
|
8218 /* Check for trailing illegal characters */
|
|
8219 if (!ends_excmd(*p))
|
|
8220 eap->errmsg = e_trailing;
|
|
8221 else
|
|
8222 eap->nextcmd = check_nextcmd(p);
|
|
8223 }
|
|
8224 }
|
|
8225 if (!eap->skip)
|
|
8226 find_pattern_in_path(eap->arg, 0, (int)STRLEN(eap->arg),
|
|
8227 whole, !eap->forceit,
|
|
8228 *eap->cmd == 'd' ? FIND_DEFINE : FIND_ANY,
|
|
8229 n, action, eap->line1, eap->line2);
|
|
8230 }
|
|
8231 #endif
|
|
8232
|
|
8233 #ifdef FEAT_WINDOWS
|
|
8234
|
|
8235 # ifdef FEAT_QUICKFIX
|
|
8236 /*
|
|
8237 * ":ptag", ":ptselect", ":ptjump", ":ptnext", etc.
|
|
8238 */
|
|
8239 static void
|
|
8240 ex_ptag(eap)
|
|
8241 exarg_T *eap;
|
|
8242 {
|
|
8243 g_do_tagpreview = p_pvh;
|
|
8244 ex_tag_cmd(eap, cmdnames[eap->cmdidx].cmd_name + 1);
|
|
8245 }
|
|
8246
|
|
8247 /*
|
|
8248 * ":pedit"
|
|
8249 */
|
|
8250 static void
|
|
8251 ex_pedit(eap)
|
|
8252 exarg_T *eap;
|
|
8253 {
|
|
8254 win_T *curwin_save = curwin;
|
|
8255
|
|
8256 g_do_tagpreview = p_pvh;
|
|
8257 prepare_tagpreview();
|
|
8258 keep_help_flag = curwin_save->w_buffer->b_help;
|
|
8259 do_exedit(eap, NULL);
|
|
8260 keep_help_flag = FALSE;
|
|
8261 if (curwin != curwin_save && win_valid(curwin_save))
|
|
8262 {
|
|
8263 /* Return cursor to where we were */
|
|
8264 validate_cursor();
|
|
8265 redraw_later(VALID);
|
|
8266 win_enter(curwin_save, TRUE);
|
|
8267 }
|
|
8268 g_do_tagpreview = 0;
|
|
8269 }
|
|
8270 # endif
|
|
8271
|
|
8272 /*
|
|
8273 * ":stag", ":stselect" and ":stjump".
|
|
8274 */
|
|
8275 static void
|
|
8276 ex_stag(eap)
|
|
8277 exarg_T *eap;
|
|
8278 {
|
|
8279 postponed_split = -1;
|
|
8280 postponed_split_flags = cmdmod.split;
|
|
8281 ex_tag_cmd(eap, cmdnames[eap->cmdidx].cmd_name + 1);
|
|
8282 postponed_split_flags = 0;
|
|
8283 }
|
|
8284 #endif
|
|
8285
|
|
8286 /*
|
|
8287 * ":tag", ":tselect", ":tjump", ":tnext", etc.
|
|
8288 */
|
|
8289 static void
|
|
8290 ex_tag(eap)
|
|
8291 exarg_T *eap;
|
|
8292 {
|
|
8293 ex_tag_cmd(eap, cmdnames[eap->cmdidx].cmd_name);
|
|
8294 }
|
|
8295
|
|
8296 static void
|
|
8297 ex_tag_cmd(eap, name)
|
|
8298 exarg_T *eap;
|
|
8299 char_u *name;
|
|
8300 {
|
|
8301 int cmd;
|
|
8302
|
|
8303 switch (name[1])
|
|
8304 {
|
|
8305 case 'j': cmd = DT_JUMP; /* ":tjump" */
|
|
8306 break;
|
|
8307 case 's': cmd = DT_SELECT; /* ":tselect" */
|
|
8308 break;
|
|
8309 case 'p': cmd = DT_PREV; /* ":tprevious" */
|
|
8310 break;
|
|
8311 case 'N': cmd = DT_PREV; /* ":tNext" */
|
|
8312 break;
|
|
8313 case 'n': cmd = DT_NEXT; /* ":tnext" */
|
|
8314 break;
|
|
8315 case 'o': cmd = DT_POP; /* ":pop" */
|
|
8316 break;
|
|
8317 case 'f': /* ":tfirst" */
|
|
8318 case 'r': cmd = DT_FIRST; /* ":trewind" */
|
|
8319 break;
|
|
8320 case 'l': cmd = DT_LAST; /* ":tlast" */
|
|
8321 break;
|
|
8322 default: /* ":tag" */
|
|
8323 #ifdef FEAT_CSCOPE
|
|
8324 if (p_cst)
|
|
8325 {
|
|
8326 do_cstag(eap);
|
|
8327 return;
|
|
8328 }
|
|
8329 #endif
|
|
8330 cmd = DT_TAG;
|
|
8331 break;
|
|
8332 }
|
|
8333
|
|
8334 do_tag(eap->arg, cmd, eap->addr_count > 0 ? (int)eap->line2 : 1,
|
|
8335 eap->forceit, TRUE);
|
|
8336 }
|
|
8337
|
|
8338 /*
|
|
8339 * Evaluate cmdline variables.
|
|
8340 *
|
|
8341 * change '%' to curbuf->b_ffname
|
|
8342 * '#' to curwin->w_altfile
|
|
8343 * '<cword>' to word under the cursor
|
|
8344 * '<cWORD>' to WORD under the cursor
|
|
8345 * '<cfile>' to path name under the cursor
|
|
8346 * '<sfile>' to sourced file name
|
|
8347 * '<afile>' to file name for autocommand
|
|
8348 * '<abuf>' to buffer number for autocommand
|
|
8349 * '<amatch>' to matching name for autocommand
|
|
8350 *
|
|
8351 * When an error is detected, "errormsg" is set to a non-NULL pointer (may be
|
|
8352 * "" for error without a message) and NULL is returned.
|
|
8353 * Returns an allocated string if a valid match was found.
|
|
8354 * Returns NULL if no match was found. "usedlen" then still contains the
|
|
8355 * number of characters to skip.
|
|
8356 */
|
|
8357 char_u *
|
|
8358 eval_vars(src, usedlen, lnump, errormsg, srcstart)
|
|
8359 char_u *src; /* pointer into commandline */
|
|
8360 int *usedlen; /* characters after src that are used */
|
|
8361 linenr_T *lnump; /* line number for :e command, or NULL */
|
|
8362 char_u **errormsg; /* pointer to error message */
|
|
8363 char_u *srcstart; /* beginning of valid memory for src */
|
|
8364 {
|
|
8365 int i;
|
|
8366 char_u *s;
|
|
8367 char_u *result;
|
|
8368 char_u *resultbuf = NULL;
|
|
8369 int resultlen;
|
|
8370 buf_T *buf;
|
|
8371 int valid = VALID_HEAD + VALID_PATH; /* assume valid result */
|
|
8372 int spec_idx;
|
|
8373 #ifdef FEAT_MODIFY_FNAME
|
|
8374 int skip_mod = FALSE;
|
|
8375 #endif
|
|
8376 static char *(spec_str[]) =
|
|
8377 {
|
|
8378 "%",
|
|
8379 #define SPEC_PERC 0
|
|
8380 "#",
|
|
8381 #define SPEC_HASH 1
|
|
8382 "<cword>", /* cursor word */
|
|
8383 #define SPEC_CWORD 2
|
|
8384 "<cWORD>", /* cursor WORD */
|
|
8385 #define SPEC_CCWORD 3
|
|
8386 "<cfile>", /* cursor path name */
|
|
8387 #define SPEC_CFILE 4
|
|
8388 "<sfile>", /* ":so" file name */
|
|
8389 #define SPEC_SFILE 5
|
|
8390 #ifdef FEAT_AUTOCMD
|
|
8391 "<afile>", /* autocommand file name */
|
|
8392 # define SPEC_AFILE 6
|
|
8393 "<abuf>", /* autocommand buffer number */
|
|
8394 # define SPEC_ABUF 7
|
|
8395 "<amatch>", /* autocommand match name */
|
|
8396 # define SPEC_AMATCH 8
|
|
8397 #endif
|
|
8398 #ifdef FEAT_CLIENTSERVER
|
|
8399 "<client>"
|
|
8400 # define SPEC_CLIENT 9
|
|
8401 #endif
|
|
8402 };
|
|
8403 #define SPEC_COUNT (sizeof(spec_str) / sizeof(char *))
|
|
8404
|
|
8405 #if defined(FEAT_AUTOCMD) || defined(FEAT_CLIENTSERVER)
|
|
8406 char_u strbuf[30];
|
|
8407 #endif
|
|
8408
|
|
8409 *errormsg = NULL;
|
|
8410
|
|
8411 /*
|
|
8412 * Check if there is something to do.
|
|
8413 */
|
|
8414 for (spec_idx = 0; spec_idx < SPEC_COUNT; ++spec_idx)
|
|
8415 {
|
|
8416 *usedlen = (int)STRLEN(spec_str[spec_idx]);
|
|
8417 if (STRNCMP(src, spec_str[spec_idx], *usedlen) == 0)
|
|
8418 break;
|
|
8419 }
|
|
8420 if (spec_idx == SPEC_COUNT) /* no match */
|
|
8421 {
|
|
8422 *usedlen = 1;
|
|
8423 return NULL;
|
|
8424 }
|
|
8425
|
|
8426 /*
|
|
8427 * Skip when preceded with a backslash "\%" and "\#".
|
|
8428 * Note: In "\\%" the % is also not recognized!
|
|
8429 */
|
|
8430 if (src > srcstart && src[-1] == '\\')
|
|
8431 {
|
|
8432 *usedlen = 0;
|
|
8433 STRCPY(src - 1, src); /* remove backslash */
|
|
8434 return NULL;
|
|
8435 }
|
|
8436
|
|
8437 /*
|
|
8438 * word or WORD under cursor
|
|
8439 */
|
|
8440 if (spec_idx == SPEC_CWORD || spec_idx == SPEC_CCWORD)
|
|
8441 {
|
|
8442 resultlen = find_ident_under_cursor(&result, spec_idx == SPEC_CWORD ?
|
|
8443 (FIND_IDENT|FIND_STRING) : FIND_STRING);
|
|
8444 if (resultlen == 0)
|
|
8445 {
|
|
8446 *errormsg = (char_u *)"";
|
|
8447 return NULL;
|
|
8448 }
|
|
8449 }
|
|
8450
|
|
8451 /*
|
|
8452 * '#': Alternate file name
|
|
8453 * '%': Current file name
|
|
8454 * File name under the cursor
|
|
8455 * File name for autocommand
|
|
8456 * and following modifiers
|
|
8457 */
|
|
8458 else
|
|
8459 {
|
|
8460 switch (spec_idx)
|
|
8461 {
|
|
8462 case SPEC_PERC: /* '%': current file */
|
|
8463 if (curbuf->b_fname == NULL)
|
|
8464 {
|
|
8465 result = (char_u *)"";
|
|
8466 valid = 0; /* Must have ":p:h" to be valid */
|
|
8467 }
|
|
8468 else
|
|
8469 #ifdef RISCOS
|
|
8470 /* Always use the full path for RISC OS if possible. */
|
|
8471 result = curbuf->b_ffname;
|
|
8472 if (result == NULL)
|
|
8473 result = curbuf->b_fname;
|
|
8474 #else
|
|
8475 result = curbuf->b_fname;
|
|
8476 #endif
|
|
8477 break;
|
|
8478
|
|
8479 case SPEC_HASH: /* '#' or "#99": alternate file */
|
|
8480 if (src[1] == '#') /* "##": the argument list */
|
|
8481 {
|
|
8482 result = arg_all();
|
|
8483 resultbuf = result;
|
|
8484 *usedlen = 2;
|
|
8485 #ifdef FEAT_MODIFY_FNAME
|
|
8486 skip_mod = TRUE;
|
|
8487 #endif
|
|
8488 break;
|
|
8489 }
|
|
8490 s = src + 1;
|
|
8491 i = (int)getdigits(&s);
|
|
8492 *usedlen = (int)(s - src); /* length of what we expand */
|
|
8493
|
|
8494 buf = buflist_findnr(i);
|
|
8495 if (buf == NULL)
|
|
8496 {
|
|
8497 *errormsg = (char_u *)_("E194: No alternate file name to substitute for '#'");
|
|
8498 return NULL;
|
|
8499 }
|
|
8500 if (lnump != NULL)
|
|
8501 *lnump = ECMD_LAST;
|
|
8502 if (buf->b_fname == NULL)
|
|
8503 {
|
|
8504 result = (char_u *)"";
|
|
8505 valid = 0; /* Must have ":p:h" to be valid */
|
|
8506 }
|
|
8507 else
|
|
8508 result = buf->b_fname;
|
|
8509 break;
|
|
8510
|
|
8511 #ifdef FEAT_SEARCHPATH
|
|
8512 case SPEC_CFILE: /* file name under cursor */
|
|
8513 result = file_name_at_cursor(FNAME_MESS|FNAME_HYP, 1L);
|
|
8514 if (result == NULL)
|
|
8515 {
|
|
8516 *errormsg = (char_u *)"";
|
|
8517 return NULL;
|
|
8518 }
|
|
8519 resultbuf = result; /* remember allocated string */
|
|
8520 break;
|
|
8521 #endif
|
|
8522
|
|
8523 #ifdef FEAT_AUTOCMD
|
|
8524 case SPEC_AFILE: /* file name for autocommand */
|
|
8525 result = autocmd_fname;
|
|
8526 if (result == NULL)
|
|
8527 {
|
|
8528 *errormsg = (char_u *)_("E495: no autocommand file name to substitute for \"<afile>\"");
|
|
8529 return NULL;
|
|
8530 }
|
|
8531 break;
|
|
8532
|
|
8533 case SPEC_ABUF: /* buffer number for autocommand */
|
|
8534 if (autocmd_bufnr <= 0)
|
|
8535 {
|
|
8536 *errormsg = (char_u *)_("E496: no autocommand buffer number to substitute for \"<abuf>\"");
|
|
8537 return NULL;
|
|
8538 }
|
|
8539 sprintf((char *)strbuf, "%d", autocmd_bufnr);
|
|
8540 result = strbuf;
|
|
8541 break;
|
|
8542
|
|
8543 case SPEC_AMATCH: /* match name for autocommand */
|
|
8544 result = autocmd_match;
|
|
8545 if (result == NULL)
|
|
8546 {
|
|
8547 *errormsg = (char_u *)_("E497: no autocommand match name to substitute for \"<amatch>\"");
|
|
8548 return NULL;
|
|
8549 }
|
|
8550 break;
|
|
8551
|
|
8552 #endif
|
|
8553 case SPEC_SFILE: /* file name for ":so" command */
|
|
8554 result = sourcing_name;
|
|
8555 if (result == NULL)
|
|
8556 {
|
|
8557 *errormsg = (char_u *)_("E498: no :source file name to substitute for \"<sfile>\"");
|
|
8558 return NULL;
|
|
8559 }
|
|
8560 break;
|
|
8561 #if defined(FEAT_CLIENTSERVER)
|
|
8562 case SPEC_CLIENT: /* Source of last submitted input */
|
|
8563 sprintf((char *)strbuf, "0x%x", (unsigned int)clientWindow);
|
|
8564 result = strbuf;
|
|
8565 break;
|
|
8566 #endif
|
|
8567 }
|
|
8568
|
|
8569 resultlen = (int)STRLEN(result); /* length of new string */
|
|
8570 if (src[*usedlen] == '<') /* remove the file name extension */
|
|
8571 {
|
|
8572 ++*usedlen;
|
|
8573 #ifdef RISCOS
|
|
8574 if ((s = vim_strrchr(result, '/')) != NULL && s >= gettail(result))
|
|
8575 #else
|
|
8576 if ((s = vim_strrchr(result, '.')) != NULL && s >= gettail(result))
|
|
8577 #endif
|
|
8578 resultlen = (int)(s - result);
|
|
8579 }
|
|
8580 #ifdef FEAT_MODIFY_FNAME
|
|
8581 else if (!skip_mod)
|
|
8582 {
|
|
8583 valid |= modify_fname(src, usedlen, &result, &resultbuf,
|
|
8584 &resultlen);
|
|
8585 if (result == NULL)
|
|
8586 {
|
|
8587 *errormsg = (char_u *)"";
|
|
8588 return NULL;
|
|
8589 }
|
|
8590 }
|
|
8591 #endif
|
|
8592 }
|
|
8593
|
|
8594 if (resultlen == 0 || valid != VALID_HEAD + VALID_PATH)
|
|
8595 {
|
|
8596 if (valid != VALID_HEAD + VALID_PATH)
|
|
8597 /* xgettext:no-c-format */
|
|
8598 *errormsg = (char_u *)_("E499: Empty file name for '%' or '#', only works with \":p:h\"");
|
|
8599 else
|
|
8600 *errormsg = (char_u *)_("E500: Evaluates to an empty string");
|
|
8601 result = NULL;
|
|
8602 }
|
|
8603 else
|
|
8604 result = vim_strnsave(result, resultlen);
|
|
8605 vim_free(resultbuf);
|
|
8606 return result;
|
|
8607 }
|
|
8608
|
|
8609 /*
|
|
8610 * Concatenate all files in the argument list, separated by spaces, and return
|
|
8611 * it in one allocated string.
|
|
8612 * Spaces and backslashes in the file names are escaped with a backslash.
|
|
8613 * Returns NULL when out of memory.
|
|
8614 */
|
|
8615 static char_u *
|
|
8616 arg_all()
|
|
8617 {
|
|
8618 int len;
|
|
8619 int idx;
|
|
8620 char_u *retval = NULL;
|
|
8621 char_u *p;
|
|
8622
|
|
8623 /*
|
|
8624 * Do this loop two times:
|
|
8625 * first time: compute the total length
|
|
8626 * second time: concatenate the names
|
|
8627 */
|
|
8628 for (;;)
|
|
8629 {
|
|
8630 len = 0;
|
|
8631 for (idx = 0; idx < ARGCOUNT; ++idx)
|
|
8632 {
|
|
8633 p = alist_name(&ARGLIST[idx]);
|
|
8634 if (p != NULL)
|
|
8635 {
|
|
8636 if (len > 0)
|
|
8637 {
|
|
8638 /* insert a space in between names */
|
|
8639 if (retval != NULL)
|
|
8640 retval[len] = ' ';
|
|
8641 ++len;
|
|
8642 }
|
|
8643 for ( ; *p != NUL; ++p)
|
|
8644 {
|
|
8645 if (*p == ' ' || *p == '\\')
|
|
8646 {
|
|
8647 /* insert a backslash */
|
|
8648 if (retval != NULL)
|
|
8649 retval[len] = '\\';
|
|
8650 ++len;
|
|
8651 }
|
|
8652 if (retval != NULL)
|
|
8653 retval[len] = *p;
|
|
8654 ++len;
|
|
8655 }
|
|
8656 }
|
|
8657 }
|
|
8658
|
|
8659 /* second time: break here */
|
|
8660 if (retval != NULL)
|
|
8661 {
|
|
8662 retval[len] = NUL;
|
|
8663 break;
|
|
8664 }
|
|
8665
|
|
8666 /* allocate memory */
|
|
8667 retval = alloc(len + 1);
|
|
8668 if (retval == NULL)
|
|
8669 break;
|
|
8670 }
|
|
8671
|
|
8672 return retval;
|
|
8673 }
|
|
8674
|
|
8675 #if defined(FEAT_AUTOCMD) || defined(PROTO)
|
|
8676 /*
|
|
8677 * Expand the <sfile> string in "arg".
|
|
8678 *
|
|
8679 * Returns an allocated string, or NULL for any error.
|
|
8680 */
|
|
8681 char_u *
|
|
8682 expand_sfile(arg)
|
|
8683 char_u *arg;
|
|
8684 {
|
|
8685 char_u *errormsg;
|
|
8686 int len;
|
|
8687 char_u *result;
|
|
8688 char_u *newres;
|
|
8689 char_u *repl;
|
|
8690 int srclen;
|
|
8691 char_u *p;
|
|
8692
|
|
8693 result = vim_strsave(arg);
|
|
8694 if (result == NULL)
|
|
8695 return NULL;
|
|
8696
|
|
8697 for (p = result; *p; )
|
|
8698 {
|
|
8699 if (STRNCMP(p, "<sfile>", 7) != 0)
|
|
8700 ++p;
|
|
8701 else
|
|
8702 {
|
|
8703 /* replace "<sfile>" with the sourced file name, and do ":" stuff */
|
|
8704 repl = eval_vars(p, &srclen, NULL, &errormsg, result);
|
|
8705 if (errormsg != NULL)
|
|
8706 {
|
|
8707 if (*errormsg)
|
|
8708 emsg(errormsg);
|
|
8709 vim_free(result);
|
|
8710 return NULL;
|
|
8711 }
|
|
8712 if (repl == NULL) /* no match (cannot happen) */
|
|
8713 {
|
|
8714 p += srclen;
|
|
8715 continue;
|
|
8716 }
|
|
8717 len = (int)STRLEN(result) - srclen + (int)STRLEN(repl) + 1;
|
|
8718 newres = alloc(len);
|
|
8719 if (newres == NULL)
|
|
8720 {
|
|
8721 vim_free(repl);
|
|
8722 vim_free(result);
|
|
8723 return NULL;
|
|
8724 }
|
|
8725 mch_memmove(newres, result, (size_t)(p - result));
|
|
8726 STRCPY(newres + (p - result), repl);
|
|
8727 len = (int)STRLEN(newres);
|
|
8728 STRCAT(newres, p + srclen);
|
|
8729 vim_free(repl);
|
|
8730 vim_free(result);
|
|
8731 result = newres;
|
|
8732 p = newres + len; /* continue after the match */
|
|
8733 }
|
|
8734 }
|
|
8735
|
|
8736 return result;
|
|
8737 }
|
|
8738 #endif
|
|
8739
|
|
8740 #ifdef FEAT_SESSION
|
|
8741 static int ses_winsizes __ARGS((FILE *fd, int restore_size));
|
|
8742 static int ses_win_rec __ARGS((FILE *fd, frame_T *fr));
|
|
8743 static frame_T *ses_skipframe __ARGS((frame_T *fr));
|
|
8744 static int ses_do_frame __ARGS((frame_T *fr));
|
|
8745 static int ses_do_win __ARGS((win_T *wp));
|
|
8746 static int ses_arglist __ARGS((FILE *fd, char *cmd, garray_T *gap, int fullname, unsigned *flagp));
|
|
8747 static int ses_put_fname __ARGS((FILE *fd, char_u *name, unsigned *flagp));
|
|
8748 static int ses_fname __ARGS((FILE *fd, buf_T *buf, unsigned *flagp));
|
|
8749
|
|
8750 /*
|
|
8751 * Write openfile commands for the current buffers to an .exrc file.
|
|
8752 * Return FAIL on error, OK otherwise.
|
|
8753 */
|
|
8754 static int
|
|
8755 makeopens(fd, dirnow)
|
|
8756 FILE *fd;
|
|
8757 char_u *dirnow; /* Current directory name */
|
|
8758 {
|
|
8759 buf_T *buf;
|
|
8760 int only_save_windows = TRUE;
|
|
8761 int nr;
|
|
8762 int cnr = 1;
|
|
8763 int restore_size = TRUE;
|
|
8764 win_T *wp;
|
|
8765 char_u *sname;
|
|
8766 win_T *edited_win = NULL;
|
|
8767
|
|
8768 if (ssop_flags & SSOP_BUFFERS)
|
|
8769 only_save_windows = FALSE; /* Save ALL buffers */
|
|
8770
|
|
8771 /*
|
|
8772 * Begin by setting the this_session variable, and then other
|
|
8773 * sessionable variables.
|
|
8774 */
|
|
8775 #ifdef FEAT_EVAL
|
|
8776 if (put_line(fd, "let v:this_session=expand(\"<sfile>:p\")") == FAIL)
|
|
8777 return FAIL;
|
|
8778 if (ssop_flags & SSOP_GLOBALS)
|
|
8779 if (store_session_globals(fd) == FAIL)
|
|
8780 return FAIL;
|
|
8781 #endif
|
|
8782
|
|
8783 /*
|
|
8784 * Close all windows but one.
|
|
8785 */
|
|
8786 if (put_line(fd, "silent only") == FAIL)
|
|
8787 return FAIL;
|
|
8788
|
|
8789 /*
|
|
8790 * Now a :cd command to the session directory or the current directory
|
|
8791 */
|
|
8792 if (ssop_flags & SSOP_SESDIR)
|
|
8793 {
|
|
8794 if (put_line(fd, "exe \"cd \" . expand(\"<sfile>:p:h\")") == FAIL)
|
|
8795 return FAIL;
|
|
8796 }
|
|
8797 else if (ssop_flags & SSOP_CURDIR)
|
|
8798 {
|
|
8799 sname = home_replace_save(NULL, globaldir != NULL ? globaldir : dirnow);
|
|
8800 if (sname == NULL
|
|
8801 || fprintf(fd, "cd %s", sname) < 0 || put_eol(fd) == FAIL)
|
|
8802 return FAIL;
|
|
8803 vim_free(sname);
|
|
8804 }
|
|
8805
|
|
8806 /*
|
36
|
8807 * If there is an empty, unnamed buffer we will wipe it out later.
|
|
8808 * Remember the buffer number.
|
|
8809 */
|
|
8810 if (put_line(fd, "if expand('%') == '' && !&modified && line('$') <= 1 && getline(1) == ''") == FAIL)
|
|
8811 return FAIL;
|
|
8812 if (put_line(fd, " let s:wipebuf = bufnr('%')") == FAIL)
|
|
8813 return FAIL;
|
|
8814 if (put_line(fd, "endif") == FAIL)
|
|
8815 return FAIL;
|
|
8816
|
|
8817 /*
|
7
|
8818 * Now save the current files, current buffer first.
|
|
8819 */
|
|
8820 if (put_line(fd, "set shortmess=aoO") == FAIL)
|
|
8821 return FAIL;
|
|
8822
|
|
8823 /* Now put the other buffers into the buffer list */
|
|
8824 for (buf = firstbuf; buf != NULL; buf = buf->b_next)
|
|
8825 {
|
|
8826 if (!(only_save_windows && buf->b_nwindows == 0)
|
|
8827 && !(buf->b_help && !(ssop_flags & SSOP_HELP))
|
|
8828 && buf->b_fname != NULL
|
|
8829 && buf->b_p_bl)
|
|
8830 {
|
|
8831 if (fprintf(fd, "badd +%ld ", buf->b_wininfo == NULL ? 1L
|
|
8832 : buf->b_wininfo->wi_fpos.lnum) < 0
|
|
8833 || ses_fname(fd, buf, &ssop_flags) == FAIL)
|
|
8834 return FAIL;
|
|
8835 }
|
|
8836 }
|
|
8837
|
|
8838 /* the global argument list */
|
|
8839 if (ses_arglist(fd, "args", &global_alist.al_ga,
|
|
8840 !(ssop_flags & SSOP_CURDIR), &ssop_flags) == FAIL)
|
|
8841 return FAIL;
|
|
8842
|
|
8843 if (ssop_flags & SSOP_RESIZE)
|
|
8844 {
|
|
8845 /* Note: after the restore we still check it worked!*/
|
|
8846 if (fprintf(fd, "set lines=%ld columns=%ld" , Rows, Columns) < 0
|
|
8847 || put_eol(fd) == FAIL)
|
|
8848 return FAIL;
|
|
8849 }
|
|
8850
|
|
8851 #ifdef FEAT_GUI
|
|
8852 if (gui.in_use && (ssop_flags & SSOP_WINPOS))
|
|
8853 {
|
|
8854 int x, y;
|
|
8855
|
|
8856 if (gui_mch_get_winpos(&x, &y) == OK)
|
|
8857 {
|
|
8858 /* Note: after the restore we still check it worked!*/
|
|
8859 if (fprintf(fd, "winpos %d %d", x, y) < 0 || put_eol(fd) == FAIL)
|
|
8860 return FAIL;
|
|
8861 }
|
|
8862 }
|
|
8863 #endif
|
|
8864
|
|
8865 /*
|
|
8866 * Before creating the window layout, try loading one file. If this is
|
|
8867 * aborted we don't end up with a number of useless windows.
|
|
8868 * This may have side effects! (e.g., compressed or network file).
|
|
8869 */
|
|
8870 for (wp = firstwin; wp != NULL; wp = wp->w_next)
|
|
8871 {
|
|
8872 if (ses_do_win(wp)
|
|
8873 && wp->w_buffer->b_ffname != NULL
|
|
8874 && !wp->w_buffer->b_help
|
|
8875 #ifdef FEAT_QUICKFIX
|
|
8876 && !bt_nofile(wp->w_buffer)
|
|
8877 #endif
|
|
8878 )
|
|
8879 {
|
|
8880 if (fputs("edit ", fd) < 0
|
|
8881 || ses_fname(fd, wp->w_buffer, &ssop_flags) == FAIL)
|
|
8882 return FAIL;
|
|
8883 if (!wp->w_arg_idx_invalid)
|
|
8884 edited_win = wp;
|
|
8885 break;
|
|
8886 }
|
|
8887 }
|
|
8888
|
|
8889 /*
|
|
8890 * Save current window layout.
|
|
8891 */
|
|
8892 if (put_line(fd, "set splitbelow splitright") == FAIL)
|
|
8893 return FAIL;
|
|
8894 if (ses_win_rec(fd, topframe) == FAIL)
|
|
8895 return FAIL;
|
|
8896 if (!p_sb && put_line(fd, "set nosplitbelow") == FAIL)
|
|
8897 return FAIL;
|
|
8898 if (!p_spr && put_line(fd, "set nosplitright") == FAIL)
|
|
8899 return FAIL;
|
|
8900
|
|
8901 /*
|
|
8902 * Check if window sizes can be restored (no windows omitted).
|
|
8903 * Remember the window number of the current window after restoring.
|
|
8904 */
|
|
8905 nr = 0;
|
|
8906 for (wp = firstwin; wp != NULL; wp = W_NEXT(wp))
|
|
8907 {
|
|
8908 if (ses_do_win(wp))
|
|
8909 ++nr;
|
|
8910 else
|
|
8911 restore_size = FALSE;
|
|
8912 if (curwin == wp)
|
|
8913 cnr = nr;
|
|
8914 }
|
|
8915
|
|
8916 /* Go to the first window. */
|
|
8917 if (put_line(fd, "wincmd t") == FAIL)
|
|
8918 return FAIL;
|
|
8919
|
|
8920 /*
|
|
8921 * If more than one window, see if sizes can be restored.
|
|
8922 * First set 'winheight' and 'winwidth' to 1 to avoid the windows being
|
|
8923 * resized when moving between windows.
|
|
8924 * Do this before restoring the view, so that the topline and the cursor
|
|
8925 * can be set. This is done again below.
|
|
8926 */
|
|
8927 if (put_line(fd, "set winheight=1 winwidth=1") == FAIL)
|
|
8928 return FAIL;
|
|
8929 if (nr > 1 && ses_winsizes(fd, restore_size) == FAIL)
|
|
8930 return FAIL;
|
|
8931
|
|
8932 /*
|
|
8933 * Restore the view of the window (options, file, cursor, etc.).
|
|
8934 */
|
|
8935 for (wp = firstwin; wp != NULL; wp = wp->w_next)
|
|
8936 {
|
|
8937 if (!ses_do_win(wp))
|
|
8938 continue;
|
|
8939 if (put_view(fd, wp, wp != edited_win, &ssop_flags) == FAIL)
|
|
8940 return FAIL;
|
|
8941 if (nr > 1 && put_line(fd, "wincmd w") == FAIL)
|
|
8942 return FAIL;
|
|
8943 }
|
|
8944
|
|
8945 /*
|
|
8946 * Restore cursor to the current window if it's not the first one.
|
|
8947 */
|
|
8948 if (cnr > 1 && (fprintf(fd, "%dwincmd w", cnr) < 0 || put_eol(fd) == FAIL))
|
|
8949 return FAIL;
|
|
8950
|
|
8951 /*
|
36
|
8952 * Wipe out an empty unnamed buffer we started in.
|
|
8953 */
|
|
8954 if (put_line(fd, "if exists('s:wipebuf')") == FAIL)
|
|
8955 return FAIL;
|
|
8956 if (put_line(fd, " exe 'bwipe ' . s:wipebuf") == FAIL)
|
|
8957 return FAIL;
|
|
8958 if (put_line(fd, "endif") == FAIL)
|
|
8959 return FAIL;
|
|
8960 if (put_line(fd, "unlet! s:wipebuf") == FAIL)
|
|
8961 return FAIL;
|
|
8962
|
|
8963 /*
|
7
|
8964 * Restore window sizes again after jumping around in windows, because the
|
|
8965 * current window has a minimum size while others may not.
|
|
8966 */
|
|
8967 if (nr > 1 && ses_winsizes(fd, restore_size) == FAIL)
|
|
8968 return FAIL;
|
|
8969
|
|
8970 /* Re-apply 'winheight', 'winwidth' and 'shortmess'. */
|
|
8971 if (fprintf(fd, "set winheight=%ld winwidth=%ld shortmess=%s",
|
|
8972 p_wh, p_wiw, p_shm) < 0 || put_eol(fd) == FAIL)
|
|
8973 return FAIL;
|
|
8974
|
|
8975 /*
|
|
8976 * Lastly, execute the x.vim file if it exists.
|
|
8977 */
|
|
8978 if (put_line(fd, "let s:sx = expand(\"<sfile>:p:r\").\"x.vim\"") == FAIL
|
|
8979 || put_line(fd, "if file_readable(s:sx)") == FAIL
|
|
8980 || put_line(fd, " exe \"source \" . s:sx") == FAIL
|
|
8981 || put_line(fd, "endif") == FAIL)
|
|
8982 return FAIL;
|
|
8983
|
|
8984 return OK;
|
|
8985 }
|
|
8986
|
|
8987 static int
|
|
8988 ses_winsizes(fd, restore_size)
|
|
8989 FILE *fd;
|
|
8990 int restore_size;
|
|
8991 {
|
|
8992 int n = 0;
|
|
8993 win_T *wp;
|
|
8994
|
|
8995 if (restore_size && (ssop_flags & SSOP_WINSIZE))
|
|
8996 {
|
|
8997 for (wp = firstwin; wp != NULL; wp = wp->w_next)
|
|
8998 {
|
|
8999 if (!ses_do_win(wp))
|
|
9000 continue;
|
|
9001 ++n;
|
|
9002
|
|
9003 /* restore height when not full height */
|
|
9004 if (wp->w_height + wp->w_status_height < topframe->fr_height
|
|
9005 && (fprintf(fd,
|
|
9006 "exe '%dresize ' . ((&lines * %ld + %ld) / %ld)",
|
|
9007 n, (long)wp->w_height, Rows / 2, Rows) < 0
|
|
9008 || put_eol(fd) == FAIL))
|
|
9009 return FAIL;
|
|
9010
|
|
9011 /* restore width when not full width */
|
|
9012 if (wp->w_width < Columns && (fprintf(fd,
|
|
9013 "exe 'vert %dresize ' . ((&columns * %ld + %ld) / %ld)",
|
|
9014 n, (long)wp->w_width, Columns / 2, Columns) < 0
|
|
9015 || put_eol(fd) == FAIL))
|
|
9016 return FAIL;
|
|
9017 }
|
|
9018 }
|
|
9019 else
|
|
9020 {
|
|
9021 /* Just equalise window sizes */
|
|
9022 if (put_line(fd, "wincmd =") == FAIL)
|
|
9023 return FAIL;
|
|
9024 }
|
|
9025 return OK;
|
|
9026 }
|
|
9027
|
|
9028 /*
|
|
9029 * Write commands to "fd" to recursively create windows for frame "fr",
|
|
9030 * horizontally and vertically split.
|
|
9031 * After the commands the last window in the frame is the current window.
|
|
9032 * Returns FAIL when writing the commands to "fd" fails.
|
|
9033 */
|
|
9034 static int
|
|
9035 ses_win_rec(fd, fr)
|
|
9036 FILE *fd;
|
|
9037 frame_T *fr;
|
|
9038 {
|
|
9039 frame_T *frc;
|
|
9040 int count = 0;
|
|
9041
|
|
9042 if (fr->fr_layout != FR_LEAF)
|
|
9043 {
|
|
9044 /* Find first frame that's not skipped and then create a window for
|
|
9045 * each following one (first frame is already there). */
|
|
9046 frc = ses_skipframe(fr->fr_child);
|
|
9047 if (frc != NULL)
|
|
9048 while ((frc = ses_skipframe(frc->fr_next)) != NULL)
|
|
9049 {
|
|
9050 /* Make window as big as possible so that we have lots of room
|
|
9051 * to split. */
|
|
9052 if (put_line(fd, "wincmd _ | wincmd |") == FAIL
|
|
9053 || put_line(fd, fr->fr_layout == FR_COL
|
|
9054 ? "split" : "vsplit") == FAIL)
|
|
9055 return FAIL;
|
|
9056 ++count;
|
|
9057 }
|
|
9058
|
|
9059 /* Go back to the first window. */
|
|
9060 if (count > 0 && (fprintf(fd, fr->fr_layout == FR_COL
|
|
9061 ? "%dwincmd k" : "%dwincmd h", count) < 0
|
|
9062 || put_eol(fd) == FAIL))
|
|
9063 return FAIL;
|
|
9064
|
|
9065 /* Recursively create frames/windows in each window of this column or
|
|
9066 * row. */
|
|
9067 frc = ses_skipframe(fr->fr_child);
|
|
9068 while (frc != NULL)
|
|
9069 {
|
|
9070 ses_win_rec(fd, frc);
|
|
9071 frc = ses_skipframe(frc->fr_next);
|
|
9072 /* Go to next window. */
|
|
9073 if (frc != NULL && put_line(fd, "wincmd w") == FAIL)
|
|
9074 return FAIL;
|
|
9075 }
|
|
9076 }
|
|
9077 return OK;
|
|
9078 }
|
|
9079
|
|
9080 /*
|
|
9081 * Skip frames that don't contain windows we want to save in the Session.
|
|
9082 * Returns NULL when there none.
|
|
9083 */
|
|
9084 static frame_T *
|
|
9085 ses_skipframe(fr)
|
|
9086 frame_T *fr;
|
|
9087 {
|
|
9088 frame_T *frc;
|
|
9089
|
|
9090 for (frc = fr; frc != NULL; frc = frc->fr_next)
|
|
9091 if (ses_do_frame(frc))
|
|
9092 break;
|
|
9093 return frc;
|
|
9094 }
|
|
9095
|
|
9096 /*
|
|
9097 * Return TRUE if frame "fr" has a window somewhere that we want to save in
|
|
9098 * the Session.
|
|
9099 */
|
|
9100 static int
|
|
9101 ses_do_frame(fr)
|
|
9102 frame_T *fr;
|
|
9103 {
|
|
9104 frame_T *frc;
|
|
9105
|
|
9106 if (fr->fr_layout == FR_LEAF)
|
|
9107 return ses_do_win(fr->fr_win);
|
|
9108 for (frc = fr->fr_child; frc != NULL; frc = frc->fr_next)
|
|
9109 if (ses_do_frame(frc))
|
|
9110 return TRUE;
|
|
9111 return FALSE;
|
|
9112 }
|
|
9113
|
|
9114 /*
|
|
9115 * Return non-zero if window "wp" is to be stored in the Session.
|
|
9116 */
|
|
9117 static int
|
|
9118 ses_do_win(wp)
|
|
9119 win_T *wp;
|
|
9120 {
|
|
9121 if (wp->w_buffer->b_fname == NULL
|
|
9122 #ifdef FEAT_QUICKFIX
|
|
9123 /* When 'buftype' is "nofile" can't restore the window contents. */
|
|
9124 || bt_nofile(wp->w_buffer)
|
|
9125 #endif
|
|
9126 )
|
|
9127 return (ssop_flags & SSOP_BLANK);
|
|
9128 if (wp->w_buffer->b_help)
|
|
9129 return (ssop_flags & SSOP_HELP);
|
|
9130 return TRUE;
|
|
9131 }
|
|
9132
|
|
9133 /*
|
|
9134 * Write commands to "fd" to restore the view of a window.
|
|
9135 * Caller must make sure 'scrolloff' is zero.
|
|
9136 */
|
|
9137 static int
|
|
9138 put_view(fd, wp, add_edit, flagp)
|
|
9139 FILE *fd;
|
|
9140 win_T *wp;
|
|
9141 int add_edit; /* add ":edit" command to view */
|
|
9142 unsigned *flagp; /* vop_flags or ssop_flags */
|
|
9143 {
|
|
9144 win_T *save_curwin;
|
|
9145 int f;
|
|
9146 int do_cursor;
|
|
9147
|
|
9148 /* Always restore cursor position for ":mksession". For ":mkview" only
|
|
9149 * when 'viewoptions' contains "cursor". */
|
|
9150 do_cursor = (flagp == &ssop_flags || *flagp & SSOP_CURSOR);
|
|
9151
|
|
9152 /*
|
|
9153 * Local argument list.
|
|
9154 */
|
|
9155 if (wp->w_alist == &global_alist)
|
|
9156 {
|
|
9157 if (put_line(fd, "argglobal") == FAIL)
|
|
9158 return FAIL;
|
|
9159 }
|
|
9160 else
|
|
9161 {
|
|
9162 if (ses_arglist(fd, "arglocal", &wp->w_alist->al_ga,
|
|
9163 flagp == &vop_flags
|
|
9164 || !(*flagp & SSOP_CURDIR)
|
|
9165 || wp->w_localdir != NULL, flagp) == FAIL)
|
|
9166 return FAIL;
|
|
9167 }
|
|
9168
|
|
9169 /* Only when part of a session: restore the argument index. */
|
|
9170 if (wp->w_arg_idx != 0 && flagp == &ssop_flags)
|
|
9171 {
|
|
9172 if (fprintf(fd, "%ldnext", (long)wp->w_arg_idx) < 0
|
|
9173 || put_eol(fd) == FAIL)
|
|
9174 return FAIL;
|
|
9175 }
|
|
9176
|
|
9177 /* Edit the file. Skip this when ":next" already did it. */
|
|
9178 if (add_edit && (wp->w_arg_idx == 0 || flagp != &ssop_flags
|
|
9179 || wp->w_arg_idx_invalid))
|
|
9180 {
|
|
9181 /*
|
|
9182 * Load the file.
|
|
9183 */
|
|
9184 if (wp->w_buffer->b_ffname != NULL
|
|
9185 #ifdef FEAT_QUICKFIX
|
|
9186 && !bt_nofile(wp->w_buffer)
|
|
9187 #endif
|
|
9188 )
|
|
9189 {
|
|
9190 /*
|
|
9191 * Editing a file in this buffer: use ":edit file".
|
|
9192 * This may have side effects! (e.g., compressed or network file).
|
|
9193 */
|
|
9194 if (fputs("edit ", fd) < 0
|
|
9195 || ses_fname(fd, wp->w_buffer, flagp) == FAIL)
|
|
9196 return FAIL;
|
|
9197 }
|
|
9198 else
|
|
9199 {
|
|
9200 /* No file in this buffer, just make it empty. */
|
|
9201 if (put_line(fd, "enew") == FAIL)
|
|
9202 return FAIL;
|
|
9203 #ifdef FEAT_QUICKFIX
|
|
9204 if (wp->w_buffer->b_ffname != NULL)
|
|
9205 {
|
|
9206 /* The buffer does have a name, but it's not a file name. */
|
|
9207 if (fputs("file ", fd) < 0
|
|
9208 || ses_fname(fd, wp->w_buffer, flagp) == FAIL)
|
|
9209 return FAIL;
|
|
9210 }
|
|
9211 #endif
|
|
9212 do_cursor = FALSE;
|
|
9213 }
|
|
9214 }
|
|
9215
|
|
9216 /*
|
|
9217 * Local mappings and abbreviations.
|
|
9218 */
|
|
9219 if ((*flagp & (SSOP_OPTIONS | SSOP_LOCALOPTIONS))
|
|
9220 && makemap(fd, wp->w_buffer) == FAIL)
|
|
9221 return FAIL;
|
|
9222
|
|
9223 /*
|
|
9224 * Local options. Need to go to the window temporarily.
|
|
9225 * Store only local values when using ":mkview" and when ":mksession" is
|
|
9226 * used and 'sessionoptions' doesn't include "options".
|
|
9227 * Some folding options are always stored when "folds" is included,
|
|
9228 * otherwise the folds would not be restored correctly.
|
|
9229 */
|
|
9230 save_curwin = curwin;
|
|
9231 curwin = wp;
|
|
9232 curbuf = curwin->w_buffer;
|
|
9233 if (*flagp & (SSOP_OPTIONS | SSOP_LOCALOPTIONS))
|
|
9234 f = makeset(fd, OPT_LOCAL,
|
|
9235 flagp == &vop_flags || !(*flagp & SSOP_OPTIONS));
|
|
9236 #ifdef FEAT_FOLDING
|
|
9237 else if (*flagp & SSOP_FOLDS)
|
|
9238 f = makefoldset(fd);
|
|
9239 #endif
|
|
9240 else
|
|
9241 f = OK;
|
|
9242 curwin = save_curwin;
|
|
9243 curbuf = curwin->w_buffer;
|
|
9244 if (f == FAIL)
|
|
9245 return FAIL;
|
|
9246
|
|
9247 #ifdef FEAT_FOLDING
|
|
9248 /*
|
|
9249 * Save Folds when 'buftype' is empty and for help files.
|
|
9250 */
|
|
9251 if ((*flagp & SSOP_FOLDS)
|
|
9252 && wp->w_buffer->b_ffname != NULL
|
|
9253 && (*wp->w_buffer->b_p_bt == NUL || wp->w_buffer->b_help))
|
|
9254 {
|
|
9255 if (put_folds(fd, wp) == FAIL)
|
|
9256 return FAIL;
|
|
9257 }
|
|
9258 #endif
|
|
9259
|
|
9260 /*
|
|
9261 * Set the cursor after creating folds, since that moves the cursor.
|
|
9262 */
|
|
9263 if (do_cursor)
|
|
9264 {
|
|
9265
|
|
9266 /* Restore the cursor line in the file and relatively in the
|
|
9267 * window. Don't use "G", it changes the jumplist. */
|
|
9268 if (fprintf(fd, "let s:l = %ld - ((%ld * winheight(0) + %ld) / %ld)",
|
|
9269 (long)wp->w_cursor.lnum,
|
|
9270 (long)(wp->w_cursor.lnum - wp->w_topline),
|
|
9271 (long)wp->w_height / 2, (long)wp->w_height) < 0
|
|
9272 || put_eol(fd) == FAIL
|
|
9273 || put_line(fd, "if s:l < 1 | let s:l = 1 | endif") == FAIL
|
|
9274 || put_line(fd, "exe s:l") == FAIL
|
|
9275 || put_line(fd, "normal! zt") == FAIL
|
|
9276 || fprintf(fd, "%ld", (long)wp->w_cursor.lnum) < 0
|
|
9277 || put_eol(fd) == FAIL)
|
|
9278 return FAIL;
|
|
9279 /* Restore the cursor column and left offset when not wrapping. */
|
|
9280 if (wp->w_cursor.col == 0)
|
|
9281 {
|
|
9282 if (put_line(fd, "normal! 0") == FAIL)
|
|
9283 return FAIL;
|
|
9284 }
|
|
9285 else
|
|
9286 {
|
|
9287 if (!wp->w_p_wrap && wp->w_leftcol > 0 && wp->w_width > 0)
|
|
9288 {
|
|
9289 if (fprintf(fd,
|
|
9290 "let s:c = %ld - ((%ld * winwidth(0) + %ld) / %ld)",
|
|
9291 (long)wp->w_cursor.col,
|
|
9292 (long)(wp->w_cursor.col - wp->w_leftcol),
|
|
9293 (long)wp->w_width / 2, (long)wp->w_width) < 0
|
|
9294 || put_eol(fd) == FAIL
|
|
9295 || put_line(fd, "if s:c > 0") == FAIL
|
|
9296 || fprintf(fd,
|
|
9297 " exe 'normal! 0' . s:c . 'lzs' . (%ld - s:c) . 'l'",
|
|
9298 (long)wp->w_cursor.col) < 0
|
|
9299 || put_eol(fd) == FAIL
|
|
9300 || put_line(fd, "else") == FAIL
|
|
9301 || fprintf(fd, " normal! 0%dl", wp->w_cursor.col) < 0
|
|
9302 || put_eol(fd) == FAIL
|
|
9303 || put_line(fd, "endif") == FAIL)
|
|
9304 return FAIL;
|
|
9305 }
|
|
9306 else
|
|
9307 {
|
|
9308 if (fprintf(fd, "normal! 0%dl", wp->w_cursor.col) < 0
|
|
9309 || put_eol(fd) == FAIL)
|
|
9310 return FAIL;
|
|
9311 }
|
|
9312 }
|
|
9313 }
|
|
9314
|
|
9315 /*
|
|
9316 * Local directory.
|
|
9317 */
|
|
9318 if (wp->w_localdir != NULL)
|
|
9319 {
|
|
9320 if (fputs("lcd ", fd) < 0
|
|
9321 || ses_put_fname(fd, wp->w_localdir, flagp) == FAIL
|
|
9322 || put_eol(fd) == FAIL)
|
|
9323 return FAIL;
|
|
9324 }
|
|
9325
|
|
9326 return OK;
|
|
9327 }
|
|
9328
|
|
9329 /*
|
|
9330 * Write an argument list to the session file.
|
|
9331 * Returns FAIL if writing fails.
|
|
9332 */
|
|
9333 static int
|
|
9334 ses_arglist(fd, cmd, gap, fullname, flagp)
|
|
9335 FILE *fd;
|
|
9336 char *cmd;
|
|
9337 garray_T *gap;
|
|
9338 int fullname; /* TRUE: use full path name */
|
|
9339 unsigned *flagp;
|
|
9340 {
|
|
9341 int i;
|
|
9342 char_u buf[MAXPATHL];
|
|
9343 char_u *s;
|
|
9344
|
|
9345 if (gap->ga_len == 0)
|
|
9346 return put_line(fd, "silent! argdel *");
|
|
9347 if (fputs(cmd, fd) < 0)
|
|
9348 return FAIL;
|
|
9349 for (i = 0; i < gap->ga_len; ++i)
|
|
9350 {
|
|
9351 /* NULL file names are skipped (only happens when out of memory). */
|
|
9352 s = alist_name(&((aentry_T *)gap->ga_data)[i]);
|
|
9353 if (s != NULL)
|
|
9354 {
|
|
9355 if (fullname)
|
|
9356 {
|
|
9357 (void)vim_FullName(s, buf, MAXPATHL, FALSE);
|
|
9358 s = buf;
|
|
9359 }
|
|
9360 if (fputs(" ", fd) < 0 || ses_put_fname(fd, s, flagp) == FAIL)
|
|
9361 return FAIL;
|
|
9362 }
|
|
9363 }
|
|
9364 return put_eol(fd);
|
|
9365 }
|
|
9366
|
|
9367 /*
|
|
9368 * Write a buffer name to the session file.
|
|
9369 * Also ends the line.
|
|
9370 * Returns FAIL if writing fails.
|
|
9371 */
|
|
9372 static int
|
|
9373 ses_fname(fd, buf, flagp)
|
|
9374 FILE *fd;
|
|
9375 buf_T *buf;
|
|
9376 unsigned *flagp;
|
|
9377 {
|
|
9378 char_u *name;
|
|
9379
|
|
9380 /* Use the short file name if the current directory is known at the time
|
|
9381 * the session file will be sourced. Don't do this for ":mkview", we
|
|
9382 * don't know the current directory. */
|
|
9383 if (buf->b_sfname != NULL
|
|
9384 && flagp == &ssop_flags
|
|
9385 && (ssop_flags & (SSOP_CURDIR | SSOP_SESDIR)))
|
|
9386 name = buf->b_sfname;
|
|
9387 else
|
|
9388 name = buf->b_ffname;
|
|
9389 if (ses_put_fname(fd, name, flagp) == FAIL || put_eol(fd) == FAIL)
|
|
9390 return FAIL;
|
|
9391 return OK;
|
|
9392 }
|
|
9393
|
|
9394 /*
|
|
9395 * Write a file name to the session file.
|
|
9396 * Takes care of the "slash" option in 'sessionoptions' and escapes special
|
|
9397 * characters.
|
|
9398 * Returns FAIL if writing fails.
|
|
9399 */
|
|
9400 static int
|
|
9401 ses_put_fname(fd, name, flagp)
|
|
9402 FILE *fd;
|
|
9403 char_u *name;
|
|
9404 unsigned *flagp;
|
|
9405 {
|
|
9406 char_u *sname;
|
|
9407 int retval = OK;
|
|
9408 int c;
|
|
9409
|
|
9410 sname = home_replace_save(NULL, name);
|
|
9411 if (sname != NULL)
|
|
9412 name = sname;
|
|
9413 while (*name != NUL)
|
|
9414 {
|
|
9415 #ifdef FEAT_MBYTE
|
|
9416 {
|
|
9417 int l;
|
|
9418
|
|
9419 if (has_mbyte && (l = (*mb_ptr2len_check)(name)) > 1)
|
|
9420 {
|
|
9421 /* copy a multibyte char */
|
|
9422 while (--l >= 0)
|
|
9423 {
|
|
9424 if (putc(*name, fd) != *name)
|
|
9425 retval = FAIL;
|
|
9426 ++name;
|
|
9427 }
|
|
9428 continue;
|
|
9429 }
|
|
9430 }
|
|
9431 #endif
|
|
9432 c = *name++;
|
|
9433 if (c == '\\' && (*flagp & SSOP_SLASH))
|
|
9434 /* change a backslash to a forward slash */
|
|
9435 c = '/';
|
|
9436 else if ((vim_strchr(escape_chars, c) != NULL
|
|
9437 #ifdef BACKSLASH_IN_FILENAME
|
|
9438 && c != '\\'
|
|
9439 #endif
|
|
9440 ) || c == '#' || c == '%')
|
|
9441 {
|
|
9442 /* escape a special character with a backslash */
|
|
9443 if (putc('\\', fd) != '\\')
|
|
9444 retval = FAIL;
|
|
9445 }
|
|
9446 if (putc(c, fd) != c)
|
|
9447 retval = FAIL;
|
|
9448 }
|
|
9449 vim_free(sname);
|
|
9450 return retval;
|
|
9451 }
|
|
9452
|
|
9453 /*
|
|
9454 * ":loadview [nr]"
|
|
9455 */
|
|
9456 static void
|
|
9457 ex_loadview(eap)
|
|
9458 exarg_T *eap;
|
|
9459 {
|
|
9460 char_u *fname;
|
|
9461
|
|
9462 fname = get_view_file(*eap->arg);
|
|
9463 if (fname != NULL)
|
|
9464 {
|
|
9465 do_source(fname, FALSE, FALSE);
|
|
9466 vim_free(fname);
|
|
9467 }
|
|
9468 }
|
|
9469
|
|
9470 /*
|
|
9471 * Get the name of the view file for the current buffer.
|
|
9472 */
|
|
9473 static char_u *
|
|
9474 get_view_file(c)
|
|
9475 int c;
|
|
9476 {
|
|
9477 int len = 0;
|
|
9478 char_u *p, *s;
|
|
9479 char_u *retval;
|
|
9480 char_u *sname;
|
|
9481
|
|
9482 if (curbuf->b_ffname == NULL)
|
|
9483 {
|
|
9484 EMSG(_(e_noname));
|
|
9485 return NULL;
|
|
9486 }
|
|
9487 sname = home_replace_save(NULL, curbuf->b_ffname);
|
|
9488 if (sname == NULL)
|
|
9489 return NULL;
|
|
9490
|
|
9491 /*
|
|
9492 * We want a file name without separators, because we're not going to make
|
|
9493 * a directory.
|
|
9494 * "normal" path separator -> "=+"
|
|
9495 * "=" -> "=="
|
|
9496 * ":" path separator -> "=-"
|
|
9497 */
|
|
9498 for (p = sname; *p; ++p)
|
|
9499 if (*p == '=' || vim_ispathsep(*p))
|
|
9500 ++len;
|
|
9501 retval = alloc((unsigned)(STRLEN(sname) + len + STRLEN(p_vdir) + 9));
|
|
9502 if (retval != NULL)
|
|
9503 {
|
|
9504 STRCPY(retval, p_vdir);
|
|
9505 add_pathsep(retval);
|
|
9506 s = retval + STRLEN(retval);
|
|
9507 for (p = sname; *p; ++p)
|
|
9508 {
|
|
9509 if (*p == '=')
|
|
9510 {
|
|
9511 *s++ = '=';
|
|
9512 *s++ = '=';
|
|
9513 }
|
|
9514 else if (vim_ispathsep(*p))
|
|
9515 {
|
|
9516 *s++ = '=';
|
|
9517 #ifdef MACOS_CLASSIC /* TODO: Is it also needed for MACOS_X? (Dany) */
|
|
9518 *s++ = '+';
|
|
9519 #else
|
|
9520 # if defined(BACKSLASH_IN_FILENAME) || defined(AMIGA) || defined(RISCOS) \
|
|
9521 || defined(VMS)
|
|
9522 if (*p == ':')
|
|
9523 *s++ = '-';
|
|
9524 else
|
|
9525 # endif
|
|
9526 *s++ = '+';
|
|
9527 #endif
|
|
9528 }
|
|
9529 else
|
|
9530 *s++ = *p;
|
|
9531 }
|
|
9532 *s++ = '=';
|
|
9533 *s++ = c;
|
|
9534 STRCPY(s, ".vim");
|
|
9535 }
|
|
9536
|
|
9537 vim_free(sname);
|
|
9538 return retval;
|
|
9539 }
|
|
9540
|
|
9541 #endif /* FEAT_SESSION */
|
|
9542
|
|
9543 /*
|
|
9544 * Write end-of-line character(s) for ":mkexrc", ":mkvimrc" and ":mksession".
|
|
9545 * Return FAIL for a write error.
|
|
9546 */
|
|
9547 int
|
|
9548 put_eol(fd)
|
|
9549 FILE *fd;
|
|
9550 {
|
|
9551 if (
|
|
9552 #ifdef USE_CRNL
|
|
9553 (
|
|
9554 # ifdef MKSESSION_NL
|
|
9555 !mksession_nl &&
|
|
9556 # endif
|
|
9557 (putc('\r', fd) < 0)) ||
|
|
9558 #endif
|
|
9559 (putc('\n', fd) < 0))
|
|
9560 return FAIL;
|
|
9561 return OK;
|
|
9562 }
|
|
9563
|
|
9564 /*
|
|
9565 * Write a line to "fd".
|
|
9566 * Return FAIL for a write error.
|
|
9567 */
|
|
9568 int
|
|
9569 put_line(fd, s)
|
|
9570 FILE *fd;
|
|
9571 char *s;
|
|
9572 {
|
|
9573 if (fputs(s, fd) < 0 || put_eol(fd) == FAIL)
|
|
9574 return FAIL;
|
|
9575 return OK;
|
|
9576 }
|
|
9577
|
|
9578 #ifdef FEAT_VIMINFO
|
|
9579 /*
|
|
9580 * ":rviminfo" and ":wviminfo".
|
|
9581 */
|
|
9582 static void
|
|
9583 ex_viminfo(eap)
|
|
9584 exarg_T *eap;
|
|
9585 {
|
|
9586 char_u *save_viminfo;
|
|
9587
|
|
9588 save_viminfo = p_viminfo;
|
|
9589 if (*p_viminfo == NUL)
|
|
9590 p_viminfo = (char_u *)"'100";
|
|
9591 if (eap->cmdidx == CMD_rviminfo)
|
|
9592 {
|
|
9593 if (read_viminfo(eap->arg, TRUE, TRUE, eap->forceit) == FAIL)
|
|
9594 EMSG(_("E195: Cannot open viminfo file for reading"));
|
|
9595 }
|
|
9596 else
|
|
9597 write_viminfo(eap->arg, eap->forceit);
|
|
9598 p_viminfo = save_viminfo;
|
|
9599 }
|
|
9600 #endif
|
|
9601
|
|
9602 #if defined(FEAT_GUI_DIALOG) || defined(FEAT_CON_DIALOG) || defined(PROTO)
|
|
9603 void
|
|
9604 dialog_msg(buff, format, fname)
|
|
9605 char_u *buff;
|
|
9606 char *format;
|
|
9607 char_u *fname;
|
|
9608 {
|
|
9609 int len;
|
|
9610
|
|
9611 if (fname == NULL)
|
|
9612 fname = (char_u *)_("Untitled");
|
|
9613 len = (int)STRLEN(format) + (int)STRLEN(fname);
|
|
9614 if (len >= IOSIZE)
|
|
9615 sprintf((char *)buff, format, (int)(IOSIZE - STRLEN(format)), fname);
|
|
9616 else
|
|
9617 sprintf((char *)buff, format, (int)STRLEN(fname), fname);
|
|
9618 }
|
|
9619 #endif
|
|
9620
|
|
9621 /*
|
|
9622 * ":behave {mswin,xterm}"
|
|
9623 */
|
|
9624 static void
|
|
9625 ex_behave(eap)
|
|
9626 exarg_T *eap;
|
|
9627 {
|
|
9628 if (STRCMP(eap->arg, "mswin") == 0)
|
|
9629 {
|
|
9630 set_option_value((char_u *)"selection", 0L, (char_u *)"exclusive", 0);
|
|
9631 set_option_value((char_u *)"selectmode", 0L, (char_u *)"mouse,key", 0);
|
|
9632 set_option_value((char_u *)"mousemodel", 0L, (char_u *)"popup", 0);
|
|
9633 set_option_value((char_u *)"keymodel", 0L,
|
|
9634 (char_u *)"startsel,stopsel", 0);
|
|
9635 }
|
|
9636 else if (STRCMP(eap->arg, "xterm") == 0)
|
|
9637 {
|
|
9638 set_option_value((char_u *)"selection", 0L, (char_u *)"inclusive", 0);
|
|
9639 set_option_value((char_u *)"selectmode", 0L, (char_u *)"", 0);
|
|
9640 set_option_value((char_u *)"mousemodel", 0L, (char_u *)"extend", 0);
|
|
9641 set_option_value((char_u *)"keymodel", 0L, (char_u *)"", 0);
|
|
9642 }
|
|
9643 else
|
|
9644 EMSG2(_(e_invarg2), eap->arg);
|
|
9645 }
|
|
9646
|
|
9647 #ifdef FEAT_AUTOCMD
|
|
9648 static int filetype_detect = FALSE;
|
|
9649 static int filetype_plugin = FALSE;
|
|
9650 static int filetype_indent = FALSE;
|
|
9651
|
|
9652 /*
|
|
9653 * ":filetype [plugin] [indent] {on,off,detect}"
|
|
9654 * on: Load the filetype.vim file to install autocommands for file types.
|
|
9655 * off: Load the ftoff.vim file to remove all autocommands for file types.
|
|
9656 * plugin on: load filetype.vim and ftplugin.vim
|
|
9657 * plugin off: load ftplugof.vim
|
|
9658 * indent on: load filetype.vim and indent.vim
|
|
9659 * indent off: load indoff.vim
|
|
9660 */
|
|
9661 static void
|
|
9662 ex_filetype(eap)
|
|
9663 exarg_T *eap;
|
|
9664 {
|
|
9665 char_u *arg = eap->arg;
|
|
9666 int plugin = FALSE;
|
|
9667 int indent = FALSE;
|
|
9668
|
|
9669 if (*eap->arg == NUL)
|
|
9670 {
|
|
9671 /* Print current status. */
|
|
9672 smsg((char_u *)"filetype detection:%s plugin:%s indent:%s",
|
|
9673 filetype_detect ? "ON" : "OFF",
|
|
9674 filetype_plugin ? (filetype_detect ? "ON" : "(on)") : "OFF",
|
|
9675 filetype_indent ? (filetype_detect ? "ON" : "(on)") : "OFF");
|
|
9676 return;
|
|
9677 }
|
|
9678
|
|
9679 /* Accept "plugin" and "indent" in any order. */
|
|
9680 for (;;)
|
|
9681 {
|
|
9682 if (STRNCMP(arg, "plugin", 6) == 0)
|
|
9683 {
|
|
9684 plugin = TRUE;
|
|
9685 arg = skipwhite(arg + 6);
|
|
9686 continue;
|
|
9687 }
|
|
9688 if (STRNCMP(arg, "indent", 6) == 0)
|
|
9689 {
|
|
9690 indent = TRUE;
|
|
9691 arg = skipwhite(arg + 6);
|
|
9692 continue;
|
|
9693 }
|
|
9694 break;
|
|
9695 }
|
|
9696 if (STRCMP(arg, "on") == 0 || STRCMP(arg, "detect") == 0)
|
|
9697 {
|
|
9698 if (*arg == 'o' || !filetype_detect)
|
|
9699 {
|
|
9700 cmd_runtime((char_u *)FILETYPE_FILE, TRUE);
|
|
9701 filetype_detect = TRUE;
|
|
9702 if (plugin)
|
|
9703 {
|
|
9704 cmd_runtime((char_u *)FTPLUGIN_FILE, TRUE);
|
|
9705 filetype_plugin = TRUE;
|
|
9706 }
|
|
9707 if (indent)
|
|
9708 {
|
|
9709 cmd_runtime((char_u *)INDENT_FILE, TRUE);
|
|
9710 filetype_indent = TRUE;
|
|
9711 }
|
|
9712 }
|
|
9713 if (*arg == 'd')
|
|
9714 {
|
|
9715 (void)do_doautocmd((char_u *)"filetypedetect BufRead", TRUE);
|
23
|
9716 do_modelines(FALSE);
|
7
|
9717 }
|
|
9718 }
|
|
9719 else if (STRCMP(arg, "off") == 0)
|
|
9720 {
|
|
9721 if (plugin || indent)
|
|
9722 {
|
|
9723 if (plugin)
|
|
9724 {
|
|
9725 cmd_runtime((char_u *)FTPLUGOF_FILE, TRUE);
|
|
9726 filetype_plugin = FALSE;
|
|
9727 }
|
|
9728 if (indent)
|
|
9729 {
|
|
9730 cmd_runtime((char_u *)INDOFF_FILE, TRUE);
|
|
9731 filetype_indent = FALSE;
|
|
9732 }
|
|
9733 }
|
|
9734 else
|
|
9735 {
|
|
9736 cmd_runtime((char_u *)FTOFF_FILE, TRUE);
|
|
9737 filetype_detect = FALSE;
|
|
9738 }
|
|
9739 }
|
|
9740 else
|
|
9741 EMSG2(_(e_invarg2), arg);
|
|
9742 }
|
|
9743
|
|
9744 /*
|
|
9745 * ":setfiletype {name}"
|
|
9746 */
|
|
9747 static void
|
|
9748 ex_setfiletype(eap)
|
|
9749 exarg_T *eap;
|
|
9750 {
|
|
9751 if (!did_filetype)
|
|
9752 set_option_value((char_u *)"filetype", 0L, eap->arg, OPT_LOCAL);
|
|
9753 }
|
|
9754 #endif
|
|
9755
|
|
9756 /*ARGSUSED*/
|
|
9757 static void
|
|
9758 ex_digraphs(eap)
|
|
9759 exarg_T *eap;
|
|
9760 {
|
|
9761 #ifdef FEAT_DIGRAPHS
|
|
9762 if (*eap->arg != NUL)
|
|
9763 putdigraph(eap->arg);
|
|
9764 else
|
|
9765 listdigraphs();
|
|
9766 #else
|
|
9767 EMSG(_("E196: No digraphs in this version"));
|
|
9768 #endif
|
|
9769 }
|
|
9770
|
|
9771 static void
|
|
9772 ex_set(eap)
|
|
9773 exarg_T *eap;
|
|
9774 {
|
|
9775 int flags = 0;
|
|
9776
|
|
9777 if (eap->cmdidx == CMD_setlocal)
|
|
9778 flags = OPT_LOCAL;
|
|
9779 else if (eap->cmdidx == CMD_setglobal)
|
|
9780 flags = OPT_GLOBAL;
|
|
9781 #if defined(FEAT_EVAL) && defined(FEAT_AUTOCMD) && defined(FEAT_BROWSE)
|
|
9782 if (cmdmod.browse && flags == 0)
|
|
9783 ex_options(eap);
|
|
9784 else
|
|
9785 #endif
|
|
9786 (void)do_set(eap->arg, flags);
|
|
9787 }
|
|
9788
|
|
9789 #ifdef FEAT_SEARCH_EXTRA
|
|
9790 /*
|
|
9791 * ":nohlsearch"
|
|
9792 */
|
|
9793 /*ARGSUSED*/
|
|
9794 static void
|
|
9795 ex_nohlsearch(eap)
|
|
9796 exarg_T *eap;
|
|
9797 {
|
|
9798 no_hlsearch = TRUE;
|
|
9799 redraw_all_later(NOT_VALID);
|
|
9800 }
|
|
9801
|
|
9802 /*
|
|
9803 * ":match {group} {pattern}"
|
|
9804 * Sets nextcmd to the start of the next command, if any. Also called when
|
|
9805 * skipping commands to find the next command.
|
|
9806 */
|
|
9807 static void
|
|
9808 ex_match(eap)
|
|
9809 exarg_T *eap;
|
|
9810 {
|
|
9811 char_u *p;
|
|
9812 char_u *end;
|
|
9813 int c;
|
|
9814
|
|
9815 /* First clear any old pattern. */
|
|
9816 if (!eap->skip)
|
|
9817 {
|
|
9818 vim_free(curwin->w_match.regprog);
|
|
9819 curwin->w_match.regprog = NULL;
|
|
9820 redraw_later(NOT_VALID); /* always need a redraw */
|
|
9821 }
|
|
9822
|
|
9823 if (ends_excmd(*eap->arg))
|
|
9824 end = eap->arg;
|
|
9825 else if ((STRNICMP(eap->arg, "none", 4) == 0
|
|
9826 && (vim_iswhite(eap->arg[4]) || ends_excmd(eap->arg[4]))))
|
|
9827 end = eap->arg + 4;
|
|
9828 else
|
|
9829 {
|
|
9830 p = skiptowhite(eap->arg);
|
|
9831 if (!eap->skip)
|
|
9832 {
|
|
9833 curwin->w_match_id = syn_namen2id(eap->arg, (int)(p - eap->arg));
|
|
9834 if (curwin->w_match_id == 0)
|
|
9835 {
|
|
9836 EMSG2(_(e_nogroup), eap->arg);
|
|
9837 return;
|
|
9838 }
|
|
9839 }
|
|
9840 p = skipwhite(p);
|
|
9841 if (*p == NUL)
|
|
9842 {
|
|
9843 /* There must be two arguments. */
|
|
9844 EMSG2(_(e_invarg2), eap->arg);
|
|
9845 return;
|
|
9846 }
|
|
9847 end = skip_regexp(p + 1, *p, TRUE, NULL);
|
|
9848 if (!eap->skip)
|
|
9849 {
|
|
9850 if (*end != NUL && !ends_excmd(*skipwhite(end + 1)))
|
|
9851 {
|
|
9852 eap->errmsg = e_trailing;
|
|
9853 return;
|
|
9854 }
|
|
9855
|
|
9856 c = *end;
|
|
9857 *end = NUL;
|
|
9858 curwin->w_match.regprog = vim_regcomp(p + 1, RE_MAGIC);
|
|
9859 *end = c;
|
|
9860 if (curwin->w_match.regprog == NULL)
|
|
9861 {
|
|
9862 EMSG2(_(e_invarg2), p);
|
|
9863 return;
|
|
9864 }
|
|
9865 }
|
|
9866 }
|
|
9867 eap->nextcmd = find_nextcmd(end);
|
|
9868 }
|
|
9869 #endif
|
|
9870
|
|
9871 #ifdef FEAT_CRYPT
|
|
9872 /*
|
|
9873 * ":X": Get crypt key
|
|
9874 */
|
|
9875 /*ARGSUSED*/
|
|
9876 static void
|
|
9877 ex_X(eap)
|
|
9878 exarg_T *eap;
|
|
9879 {
|
|
9880 (void)get_crypt_key(TRUE, TRUE);
|
|
9881 }
|
|
9882 #endif
|
|
9883
|
|
9884 #ifdef FEAT_FOLDING
|
|
9885 static void
|
|
9886 ex_fold(eap)
|
|
9887 exarg_T *eap;
|
|
9888 {
|
|
9889 if (foldManualAllowed(TRUE))
|
|
9890 foldCreate(eap->line1, eap->line2);
|
|
9891 }
|
|
9892
|
|
9893 static void
|
|
9894 ex_foldopen(eap)
|
|
9895 exarg_T *eap;
|
|
9896 {
|
|
9897 opFoldRange(eap->line1, eap->line2, eap->cmdidx == CMD_foldopen,
|
|
9898 eap->forceit, FALSE);
|
|
9899 }
|
|
9900
|
|
9901 static void
|
|
9902 ex_folddo(eap)
|
|
9903 exarg_T *eap;
|
|
9904 {
|
|
9905 linenr_T lnum;
|
|
9906
|
|
9907 /* First set the marks for all lines closed/open. */
|
|
9908 for (lnum = eap->line1; lnum <= eap->line2; ++lnum)
|
|
9909 if (hasFolding(lnum, NULL, NULL) == (eap->cmdidx == CMD_folddoclosed))
|
|
9910 ml_setmarked(lnum);
|
|
9911
|
|
9912 /* Execute the command on the marked lines. */
|
|
9913 global_exe(eap->arg);
|
|
9914 ml_clearmarked(); /* clear rest of the marks */
|
|
9915 }
|
|
9916 #endif
|