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