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