Mercurial > vim
annotate src/main.c @ 5143:29e57603bf6f v7.3.1314
updated for version 7.3.1314
Problem: Test 87 fails with Python 3.3.
Solution: Filter the error messages. (Taro Muraoka)
author | Bram Moolenaar <bram@vim.org> |
---|---|
date | Sat, 06 Jul 2013 13:54:33 +0200 |
parents | 5e0b6a9282df |
children | 4fe1dfc7014e |
rev | line source |
---|---|
6 | 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 #define EXTERN | |
11 #include "vim.h" | |
12 | |
13 #ifdef SPAWNO | |
242 | 14 # include <spawno.h> /* special MS-DOS swapping library */ |
6 | 15 #endif |
16 | |
17 #ifdef __CYGWIN__ | |
18 # ifndef WIN32 | |
1657 | 19 # include <cygwin/version.h> |
20 # include <sys/cygwin.h> /* for cygwin_conv_to_posix_path() and/or | |
21 * cygwin_conv_path() */ | |
6 | 22 # endif |
23 # include <limits.h> | |
24 #endif | |
25 | |
443 | 26 /* Maximum number of commands from + or -c arguments. */ |
27 #define MAX_ARG_CMDS 10 | |
28 | |
673 | 29 /* values for "window_layout" */ |
30 #define WIN_HOR 1 /* "-o" horizontally split windows */ | |
31 #define WIN_VER 2 /* "-O" vertically split windows */ | |
32 #define WIN_TABS 3 /* "-p" windows on tab pages */ | |
33 | |
440 | 34 /* Struct for various parameters passed between main() and other functions. */ |
35 typedef struct | |
36 { | |
443 | 37 int argc; |
38 char **argv; | |
39 | |
40 int evim_mode; /* started as "evim" */ | |
41 char_u *use_vimrc; /* vimrc from -u argument */ | |
42 | |
43 int n_commands; /* no. of commands from + or -c */ | |
44 char_u *commands[MAX_ARG_CMDS]; /* commands from + or -c arg. */ | |
45 char_u cmds_tofree[MAX_ARG_CMDS]; /* commands that need free() */ | |
46 int n_pre_commands; /* no. of commands from --cmd */ | |
47 char_u *pre_commands[MAX_ARG_CMDS]; /* commands from --cmd argument */ | |
48 | |
49 int edit_type; /* type of editing to do */ | |
50 char_u *tagname; /* tag from -t argument */ | |
51 #ifdef FEAT_QUICKFIX | |
52 char_u *use_ef; /* 'errorfile' from -q argument */ | |
53 #endif | |
54 | |
55 int want_full_screen; | |
56 int stdout_isatty; /* is stdout a terminal? */ | |
57 char_u *term; /* specified terminal name */ | |
58 #ifdef FEAT_CRYPT | |
59 int ask_for_key; /* -x argument */ | |
60 #endif | |
61 int no_swap_file; /* "-n" argument used */ | |
62 #ifdef FEAT_EVAL | |
63 int use_debug_break_level; | |
64 #endif | |
65 #ifdef FEAT_WINDOWS | |
66 int window_count; /* number of windows to use */ | |
673 | 67 int window_layout; /* 0, WIN_HOR, WIN_VER or WIN_TABS */ |
443 | 68 #endif |
69 | |
70 #ifdef FEAT_CLIENTSERVER | |
440 | 71 int serverArg; /* TRUE when argument for a server */ |
72 char_u *serverName_arg; /* cmdline arg for server name */ | |
443 | 73 char_u *serverStr; /* remote server command */ |
74 char_u *serverStrEnc; /* encoding of serverStr */ | |
75 char_u *servername; /* allocated name for our server */ | |
76 #endif | |
77 #if (!defined(UNIX) && !defined(__EMX__)) || defined(ARCHIE) | |
78 int literal; /* don't expand file names */ | |
79 #endif | |
80 #ifdef MSWIN | |
81 int full_path; /* file name argument was full path */ | |
82 #endif | |
83 #ifdef FEAT_DIFF | |
84 int diff_mode; /* start with 'diff' set */ | |
85 #endif | |
440 | 86 } mparm_T; |
87 | |
443 | 88 /* Values for edit_type. */ |
89 #define EDIT_NONE 0 /* no edit type yet */ | |
90 #define EDIT_FILE 1 /* file name argument[s] given, use argument list */ | |
91 #define EDIT_STDIN 2 /* read file from stdin */ | |
92 #define EDIT_TAG 3 /* tag name argument given, use tagname */ | |
93 #define EDIT_QF 4 /* start in quickfix mode */ | |
94 | |
2730 | 95 #if (defined(UNIX) || defined(VMS)) && !defined(NO_VIM_MAIN) |
6 | 96 static int file_owned __ARGS((char *fname)); |
97 #endif | |
98 static void mainerr __ARGS((int, char_u *)); | |
2730 | 99 #ifndef NO_VIM_MAIN |
6 | 100 static void main_msg __ARGS((char *s)); |
101 static void usage __ARGS((void)); | |
102 static int get_number_arg __ARGS((char_u *p, int *idx, int def)); | |
2730 | 103 # if defined(HAVE_LOCALE_H) || defined(X_LOCALE) |
443 | 104 static void init_locale __ARGS((void)); |
2730 | 105 # endif |
443 | 106 static void parse_command_name __ARGS((mparm_T *parmp)); |
107 static void early_arg_scan __ARGS((mparm_T *parmp)); | |
108 static void command_line_scan __ARGS((mparm_T *parmp)); | |
109 static void check_tty __ARGS((mparm_T *parmp)); | |
110 static void read_stdin __ARGS((void)); | |
111 static void create_windows __ARGS((mparm_T *parmp)); | |
2730 | 112 # ifdef FEAT_WINDOWS |
443 | 113 static void edit_buffers __ARGS((mparm_T *parmp)); |
2730 | 114 # endif |
443 | 115 static void exe_pre_commands __ARGS((mparm_T *parmp)); |
116 static void exe_commands __ARGS((mparm_T *parmp)); | |
440 | 117 static void source_startup_scripts __ARGS((mparm_T *parmp)); |
6 | 118 static void main_start_gui __ARGS((void)); |
2730 | 119 # if defined(HAS_SWAP_EXISTS_ACTION) |
6 | 120 static void check_swap_exists_action __ARGS((void)); |
2730 | 121 # endif |
122 # if defined(FEAT_CLIENTSERVER) || defined(PROTO) | |
443 | 123 static void exec_on_server __ARGS((mparm_T *parmp)); |
124 static void prepare_server __ARGS((mparm_T *parmp)); | |
6 | 125 static void cmdsrv_main __ARGS((int *argc, char **argv, char_u *serverName_arg, char_u **serverStr)); |
126 static char_u *serverMakeName __ARGS((char_u *arg, char *cmd)); | |
2730 | 127 # endif |
6 | 128 #endif |
129 | |
130 | |
131 /* | |
132 * Different types of error messages. | |
133 */ | |
134 static char *(main_errors[]) = | |
135 { | |
443 | 136 N_("Unknown option argument"), |
6 | 137 #define ME_UNKNOWN_OPTION 0 |
138 N_("Too many edit arguments"), | |
139 #define ME_TOO_MANY_ARGS 1 | |
140 N_("Argument missing after"), | |
141 #define ME_ARG_MISSING 2 | |
443 | 142 N_("Garbage after option argument"), |
6 | 143 #define ME_GARBAGE 3 |
144 N_("Too many \"+command\", \"-c command\" or \"--cmd command\" arguments"), | |
145 #define ME_EXTRA_CMD 4 | |
146 N_("Invalid argument for"), | |
147 #define ME_INVALID_ARG 5 | |
148 }; | |
149 | |
3955 | 150 #ifndef PROTO /* don't want a prototype for main() */ |
2730 | 151 #ifndef NO_VIM_MAIN /* skip this for unittests */ |
6 | 152 int |
153 # ifdef VIMDLL | |
154 _export | |
155 # endif | |
156 # ifdef FEAT_GUI_MSWIN | |
157 # ifdef __BORLANDC__ | |
158 _cdecl | |
159 # endif | |
160 VimMain | |
161 # else | |
162 main | |
163 # endif | |
164 (argc, argv) | |
165 int argc; | |
166 char **argv; | |
167 { | |
168 char_u *fname = NULL; /* file name from command line */ | |
440 | 169 mparm_T params; /* various parameters passed between |
170 * main() and other functions. */ | |
1972 | 171 #ifdef STARTUPTIME |
172 int i; | |
173 #endif | |
6 | 174 |
175 /* | |
176 * Do any system-specific initialisations. These can NOT use IObuff or | |
177 * NameBuff. Thus emsg2() cannot be called! | |
178 */ | |
179 mch_early_init(); | |
180 | |
443 | 181 /* Many variables are in "params" so that we can pass them to invoked |
182 * functions without a lot of arguments. "argc" and "argv" are also | |
183 * copied, so that they can be changed. */ | |
440 | 184 vim_memset(¶ms, 0, sizeof(params)); |
443 | 185 params.argc = argc; |
186 params.argv = argv; | |
187 params.want_full_screen = TRUE; | |
188 #ifdef FEAT_EVAL | |
189 params.use_debug_break_level = -1; | |
190 #endif | |
191 #ifdef FEAT_WINDOWS | |
192 params.window_count = -1; | |
193 #endif | |
440 | 194 |
4369 | 195 #ifdef FEAT_RUBY |
196 { | |
197 int ruby_stack_start; | |
198 vim_ruby_init((void *)&ruby_stack_start); | |
199 } | |
200 #endif | |
201 | |
6 | 202 #ifdef FEAT_TCL |
443 | 203 vim_tcl_init(params.argv[0]); |
6 | 204 #endif |
205 | |
206 #ifdef MEM_PROFILE | |
207 atexit(vim_mem_profile_dump); | |
208 #endif | |
209 | |
210 #ifdef STARTUPTIME | |
1972 | 211 for (i = 1; i < argc; ++i) |
212 { | |
1989 | 213 if (STRICMP(argv[i], "--startuptime") == 0 && i + 1 < argc) |
1972 | 214 { |
1989 | 215 time_fd = mch_fopen(argv[i + 1], "a"); |
1972 | 216 TIME_MSG("--- VIM STARTING ---"); |
217 break; | |
218 } | |
219 } | |
6 | 220 #endif |
777 | 221 starttime = time(NULL); |
6 | 222 |
223 #ifdef __EMX__ | |
443 | 224 _wildcard(¶ms.argc, ¶ms.argv); |
6 | 225 #endif |
226 | |
227 #ifdef FEAT_MBYTE | |
228 (void)mb_init(); /* init mb_bytelen_tab[] to ones */ | |
229 #endif | |
123 | 230 #ifdef FEAT_EVAL |
231 eval_init(); /* init global variables */ | |
232 #endif | |
6 | 233 |
234 #ifdef __QNXNTO__ | |
235 qnx_init(); /* PhAttach() for clipboard, (and gui) */ | |
236 #endif | |
237 | |
238 #ifdef MAC_OS_CLASSIC | |
443 | 239 /* Prepare for possibly starting GUI sometime */ |
6 | 240 /* Macintosh needs this before any memory is allocated. */ |
443 | 241 gui_prepare(¶ms.argc, params.argv); |
6 | 242 TIME_MSG("GUI prepared"); |
243 #endif | |
244 | |
245 /* Init the table of Normal mode commands. */ | |
246 init_normal_cmds(); | |
247 | |
248 #if defined(HAVE_DATE_TIME) && defined(VMS) && defined(VAXC) | |
440 | 249 make_version(); /* Construct the long version string. */ |
6 | 250 #endif |
251 | |
252 /* | |
253 * Allocate space for the generic buffers (needed for set_init_1() and | |
254 * EMSG2()). | |
255 */ | |
256 if ((IObuff = alloc(IOSIZE)) == NULL | |
257 || (NameBuff = alloc(MAXPATHL)) == NULL) | |
258 mch_exit(0); | |
259 TIME_MSG("Allocated generic buffers"); | |
260 | |
22 | 261 #ifdef NBDEBUG |
262 /* Wait a moment for debugging NetBeans. Must be after allocating | |
263 * NameBuff. */ | |
264 nbdebug_log_init("SPRO_GVIM_DEBUG", "SPRO_GVIM_DLEVEL"); | |
265 nbdebug_wait(WT_ENV | WT_WAIT | WT_STOP, "SPRO_GVIM_WAIT", 20); | |
443 | 266 TIME_MSG("NetBeans debug wait"); |
22 | 267 #endif |
268 | |
6 | 269 #if defined(HAVE_LOCALE_H) || defined(X_LOCALE) |
270 /* | |
271 * Setup to use the current locale (for ctype() and many other things). | |
272 * NOTE: Translated messages with encodings other than latin1 will not | |
273 * work until set_init_1() has been called! | |
274 */ | |
443 | 275 init_locale(); |
6 | 276 TIME_MSG("locale set"); |
277 #endif | |
278 | |
279 #ifdef FEAT_GUI | |
280 gui.dofork = TRUE; /* default is to use fork() */ | |
281 #endif | |
282 | |
283 /* | |
440 | 284 * Do a first scan of the arguments in "argv[]": |
443 | 285 * -display or --display |
440 | 286 * --server... |
287 * --socketid | |
1376 | 288 * --windowid |
6 | 289 */ |
443 | 290 early_arg_scan(¶ms); |
6 | 291 |
292 #ifdef FEAT_SUN_WORKSHOP | |
443 | 293 findYourself(params.argv[0]); |
6 | 294 #endif |
295 #if defined(FEAT_GUI) && !defined(MAC_OS_CLASSIC) | |
443 | 296 /* Prepare for possibly starting GUI sometime */ |
297 gui_prepare(¶ms.argc, params.argv); | |
6 | 298 TIME_MSG("GUI prepared"); |
299 #endif | |
300 | |
301 #ifdef FEAT_CLIPBOARD | |
302 clip_init(FALSE); /* Initialise clipboard stuff */ | |
303 TIME_MSG("clipboard setup"); | |
304 #endif | |
305 | |
306 /* | |
307 * Check if we have an interactive window. | |
308 * On the Amiga: If there is no window, we open one with a newcli command | |
309 * (needed for :! to * work). mch_check_win() will also handle the -d or | |
310 * -dev argument. | |
311 */ | |
443 | 312 params.stdout_isatty = (mch_check_win(params.argc, params.argv) != FAIL); |
6 | 313 TIME_MSG("window checked"); |
314 | |
315 /* | |
667 | 316 * Allocate the first window and buffer. |
317 * Can't do anything without it, exit when it fails. | |
6 | 318 */ |
667 | 319 if (win_alloc_first() == FAIL) |
320 mch_exit(0); | |
6 | 321 |
322 init_yank(); /* init yank buffers */ | |
323 | |
443 | 324 alist_init(&global_alist); /* Init the argument list to empty. */ |
6 | 325 |
326 /* | |
327 * Set the default values for the options. | |
328 * NOTE: Non-latin1 translated messages are working only after this, | |
329 * because this is where "has_mbyte" will be set, which is used by | |
330 * msg_outtrans_len_attr(). | |
331 * First find out the home directory, needed to expand "~" in options. | |
332 */ | |
333 init_homedir(); /* find real value of $HOME */ | |
334 set_init_1(); | |
335 TIME_MSG("inits 1"); | |
336 | |
337 #ifdef FEAT_EVAL | |
338 set_lang_var(); /* set v:lang and v:ctype */ | |
339 #endif | |
340 | |
341 #ifdef FEAT_CLIENTSERVER | |
342 /* | |
343 * Do the client-server stuff, unless "--servername ''" was used. | |
443 | 344 * This may exit Vim if the command was sent to the server. |
6 | 345 */ |
443 | 346 exec_on_server(¶ms); |
6 | 347 #endif |
348 | |
349 /* | |
443 | 350 * Figure out the way to work from the command name argv[0]. |
351 * "vimdiff" starts diff mode, "rvim" sets "restricted", etc. | |
6 | 352 */ |
443 | 353 parse_command_name(¶ms); |
6 | 354 |
355 /* | |
443 | 356 * Process the command line arguments. File names are put in the global |
357 * argument list "global_alist". | |
6 | 358 */ |
443 | 359 command_line_scan(¶ms); |
6 | 360 TIME_MSG("parsing arguments"); |
361 | |
362 /* | |
363 * On some systems, when we compile with the GUI, we always use it. On Mac | |
443 | 364 * there is no terminal version, and on Windows we can't fork one off with |
365 * :gui. | |
6 | 366 */ |
367 #ifdef ALWAYS_USE_GUI | |
368 gui.starting = TRUE; | |
369 #else | |
575 | 370 # if defined(FEAT_GUI_X11) || defined(FEAT_GUI_GTK) |
6 | 371 /* |
372 * Check if the GUI can be started. Reset gui.starting if not. | |
373 * Don't know about other systems, stay on the safe side and don't check. | |
374 */ | |
2021 | 375 if (gui.starting) |
6 | 376 { |
2021 | 377 if (gui_init_check() == FAIL) |
378 { | |
379 gui.starting = FALSE; | |
380 | |
381 /* When running "evim" or "gvim -y" we need the menus, exit if we | |
382 * don't have them. */ | |
383 if (params.evim_mode) | |
384 mch_exit(1); | |
385 } | |
6 | 386 } |
387 # endif | |
388 #endif | |
389 | |
390 if (GARGCOUNT > 0) | |
391 { | |
392 #if (!defined(UNIX) && !defined(__EMX__)) || defined(ARCHIE) | |
393 /* | |
394 * Expand wildcards in file names. | |
395 */ | |
443 | 396 if (!params.literal) |
6 | 397 { |
398 /* Temporarily add '(' and ')' to 'isfname'. These are valid | |
399 * filename characters but are excluded from 'isfname' to make | |
400 * "gf" work on a file name in parenthesis (e.g.: see vim.h). */ | |
401 do_cmdline_cmd((char_u *)":set isf+=(,)"); | |
41 | 402 alist_expand(NULL, 0); |
6 | 403 do_cmdline_cmd((char_u *)":set isf&"); |
404 } | |
405 #endif | |
406 fname = alist_name(&GARGLIST[0]); | |
407 } | |
23 | 408 |
409 #if defined(WIN32) && defined(FEAT_MBYTE) | |
410 { | |
411 extern void set_alist_count(void); | |
412 | |
413 /* Remember the number of entries in the argument list. If it changes | |
414 * we don't react on setting 'encoding'. */ | |
415 set_alist_count(); | |
416 } | |
417 #endif | |
418 | |
6 | 419 #ifdef MSWIN |
443 | 420 if (GARGCOUNT == 1 && params.full_path) |
6 | 421 { |
422 /* | |
423 * If there is one filename, fully qualified, we have very probably | |
424 * been invoked from explorer, so change to the file's directory. | |
425 * Hint: to avoid this when typing a command use a forward slash. | |
426 * If the cd fails, it doesn't matter. | |
427 */ | |
428 (void)vim_chdirfile(fname); | |
429 } | |
430 #endif | |
431 TIME_MSG("expanding arguments"); | |
432 | |
433 #ifdef FEAT_DIFF | |
769 | 434 if (params.diff_mode && params.window_count == -1) |
435 params.window_count = 0; /* open up to 3 windows */ | |
6 | 436 #endif |
437 | |
443 | 438 /* Don't redraw until much later. */ |
6 | 439 ++RedrawingDisabled; |
440 | |
441 /* | |
442 * When listing swap file names, don't do cursor positioning et. al. | |
443 */ | |
444 if (recoverymode && fname == NULL) | |
443 | 445 params.want_full_screen = FALSE; |
6 | 446 |
447 /* | |
448 * When certain to start the GUI, don't check capabilities of terminal. | |
449 * For GTK we can't be sure, but when started from the desktop it doesn't | |
450 * make sense to try using a terminal. | |
451 */ | |
575 | 452 #if defined(ALWAYS_USE_GUI) || defined(FEAT_GUI_X11) || defined(FEAT_GUI_GTK) |
6 | 453 if (gui.starting |
454 # ifdef FEAT_GUI_GTK | |
455 && !isatty(2) | |
456 # endif | |
457 ) | |
443 | 458 params.want_full_screen = FALSE; |
6 | 459 #endif |
460 | |
461 #if defined(FEAT_GUI_MAC) && defined(MACOS_X_UNIX) | |
462 /* When the GUI is started from Finder, need to display messages in a | |
463 * message box. isatty(2) returns TRUE anyway, thus we need to check the | |
464 * name to know we're not started from a terminal. */ | |
465 if (gui.starting && (!isatty(2) || strcmp("/dev/console", ttyname(2)) == 0)) | |
816 | 466 { |
443 | 467 params.want_full_screen = FALSE; |
816 | 468 |
469 /* Avoid always using "/" as the current directory. Note that when | |
470 * started from Finder the arglist will be filled later in | |
471 * HandleODocAE() and "fname" will be NULL. */ | |
472 if (getcwd((char *)NameBuff, MAXPATHL) != NULL | |
473 && STRCMP(NameBuff, "/") == 0) | |
474 { | |
475 if (fname != NULL) | |
476 (void)vim_chdirfile(fname); | |
477 else | |
478 { | |
479 expand_env((char_u *)"$HOME", NameBuff, MAXPATHL); | |
480 vim_chdir(NameBuff); | |
481 } | |
482 } | |
483 } | |
6 | 484 #endif |
485 | |
486 /* | |
487 * mch_init() sets up the terminal (window) for use. This must be | |
488 * done after resetting full_screen, otherwise it may move the cursor | |
489 * (MSDOS). | |
490 * Note that we may use mch_exit() before mch_init()! | |
491 */ | |
492 mch_init(); | |
493 TIME_MSG("shell init"); | |
494 | |
495 #ifdef USE_XSMP | |
496 /* | |
497 * For want of anywhere else to do it, try to connect to xsmp here. | |
498 * Fitting it in after gui_mch_init, but before gui_init (via termcapinit). | |
499 * Hijacking -X 'no X connection' to also disable XSMP connection as that | |
500 * has a similar delay upon failure. | |
501 * Only try if SESSION_MANAGER is set to something non-null. | |
502 */ | |
503 if (!x_no_connect) | |
504 { | |
443 | 505 char *p = getenv("SESSION_MANAGER"); |
506 | |
6 | 507 if (p != NULL && *p != NUL) |
508 { | |
509 xsmp_init(); | |
510 TIME_MSG("xsmp init"); | |
511 } | |
512 } | |
513 #endif | |
514 | |
515 /* | |
516 * Print a warning if stdout is not a terminal. | |
517 */ | |
443 | 518 check_tty(¶ms); |
6 | 519 |
169 | 520 /* This message comes before term inits, but after setting "silent_mode" |
521 * when the input is not a tty. */ | |
522 if (GARGCOUNT > 1 && !silent_mode) | |
523 printf(_("%d files to edit\n"), GARGCOUNT); | |
524 | |
443 | 525 if (params.want_full_screen && !silent_mode) |
6 | 526 { |
443 | 527 termcapinit(params.term); /* set terminal name and get terminal |
6 | 528 capabilities (will set full_screen) */ |
529 screen_start(); /* don't know where cursor is now */ | |
530 TIME_MSG("Termcap init"); | |
531 } | |
532 | |
533 /* | |
534 * Set the default values for the options that use Rows and Columns. | |
535 */ | |
536 ui_get_shellsize(); /* inits Rows and Columns */ | |
667 | 537 win_init_size(); |
6 | 538 #ifdef FEAT_DIFF |
539 /* Set the 'diff' option now, so that it can be checked for in a .vimrc | |
540 * file. There is no buffer yet though. */ | |
443 | 541 if (params.diff_mode) |
6 | 542 diff_win_options(firstwin, FALSE); |
543 #endif | |
544 | |
545 cmdline_row = Rows - p_ch; | |
546 msg_row = cmdline_row; | |
547 screenalloc(FALSE); /* allocate screen buffers */ | |
548 set_init_2(); | |
549 TIME_MSG("inits 2"); | |
550 | |
551 msg_scroll = TRUE; | |
552 no_wait_return = TRUE; | |
553 | |
554 init_mappings(); /* set up initial mappings */ | |
555 | |
556 init_highlight(TRUE, FALSE); /* set the default highlight groups */ | |
557 TIME_MSG("init highlight"); | |
558 | |
559 #ifdef FEAT_EVAL | |
560 /* Set the break level after the terminal is initialized. */ | |
443 | 561 debug_break_level = params.use_debug_break_level; |
6 | 562 #endif |
563 | |
3348 | 564 #ifdef FEAT_MZSCHEME |
565 /* | |
566 * Newer version of MzScheme (Racket) require earlier (trampolined) | |
567 * initialisation via scheme_main_setup. | |
568 * Implement this by initialising it as early as possible | |
569 * and splitting off remaining Vim main into vim_main2 | |
570 */ | |
571 { | |
572 /* Pack up preprocessed command line arguments. | |
573 * It is safe because Scheme does not access argc/argv. */ | |
574 char *args[2]; | |
575 args[0] = (char *)fname; | |
576 args[1] = (char *)¶ms; | |
577 return mzscheme_main(2, args); | |
578 } | |
579 } | |
3955 | 580 #endif |
581 #endif /* NO_VIM_MAIN */ | |
582 | |
583 /* vim_main2() needs to be produced when FEAT_MZSCHEME is defined even when | |
584 * NO_VIM_MAIN is defined. */ | |
585 #ifdef FEAT_MZSCHEME | |
586 int | |
587 vim_main2(int argc UNUSED, char **argv UNUSED) | |
3348 | 588 { |
3955 | 589 # ifndef NO_VIM_MAIN |
3348 | 590 char_u *fname = (char_u *)argv[0]; |
591 mparm_T params; | |
592 | |
593 memcpy(¶ms, argv[1], sizeof(params)); | |
3955 | 594 # else |
595 return 0; | |
596 } | |
597 # endif | |
3348 | 598 #endif |
599 | |
3955 | 600 #ifndef NO_VIM_MAIN |
440 | 601 /* Execute --cmd arguments. */ |
443 | 602 exe_pre_commands(¶ms); |
440 | 603 |
604 /* Source startup scripts. */ | |
605 source_startup_scripts(¶ms); | |
6 | 606 |
607 #ifdef FEAT_EVAL | |
608 /* | |
609 * Read all the plugin files. | |
610 * Only when compiled with +eval, since most plugins need it. | |
611 */ | |
612 if (p_lpl) | |
613 { | |
892 | 614 # ifdef VMS /* Somehow VMS doesn't handle the "**". */ |
615 source_runtime((char_u *)"plugin/*.vim", TRUE); | |
616 # else | |
541 | 617 source_runtime((char_u *)"plugin/**/*.vim", TRUE); |
892 | 618 # endif |
6 | 619 TIME_MSG("loading plugins"); |
620 } | |
621 #endif | |
622 | |
769 | 623 #ifdef FEAT_DIFF |
624 /* Decide about window layout for diff mode after reading vimrc. */ | |
625 if (params.diff_mode && params.window_layout == 0) | |
626 { | |
627 if (diffopt_horizontal()) | |
628 params.window_layout = WIN_HOR; /* use horizontal split */ | |
629 else | |
630 params.window_layout = WIN_VER; /* use vertical split */ | |
631 } | |
632 #endif | |
633 | |
6 | 634 /* |
635 * Recovery mode without a file name: List swap files. | |
636 * This uses the 'dir' option, therefore it must be after the | |
637 * initializations. | |
638 */ | |
639 if (recoverymode && fname == NULL) | |
640 { | |
2267 | 641 recover_names(NULL, TRUE, 0, NULL); |
6 | 642 mch_exit(0); |
643 } | |
644 | |
645 /* | |
646 * Set a few option defaults after reading .vimrc files: | |
647 * 'title' and 'icon', Unix: 'shellpipe' and 'shellredir'. | |
648 */ | |
649 set_init_3(); | |
650 TIME_MSG("inits 3"); | |
651 | |
652 /* | |
653 * "-n" argument: Disable swap file by setting 'updatecount' to 0. | |
654 * Note that this overrides anything from a vimrc file. | |
655 */ | |
443 | 656 if (params.no_swap_file) |
6 | 657 p_uc = 0; |
658 | |
659 #ifdef FEAT_FKMAP | |
660 if (curwin->w_p_rl && p_altkeymap) | |
661 { | |
662 p_hkmap = FALSE; /* Reset the Hebrew keymap mode */ | |
663 # ifdef FEAT_ARABIC | |
664 curwin->w_p_arab = FALSE; /* Reset the Arabic keymap mode */ | |
665 # endif | |
666 p_fkmap = TRUE; /* Set the Farsi keymap mode */ | |
667 } | |
668 #endif | |
669 | |
670 #ifdef FEAT_GUI | |
671 if (gui.starting) | |
672 { | |
673 #if defined(UNIX) || defined(VMS) | |
674 /* When something caused a message from a vimrc script, need to output | |
675 * an extra newline before the shell prompt. */ | |
676 if (did_emsg || msg_didout) | |
677 putchar('\n'); | |
678 #endif | |
679 | |
680 gui_start(); /* will set full_screen to TRUE */ | |
681 TIME_MSG("starting GUI"); | |
682 | |
683 /* When running "evim" or "gvim -y" we need the menus, exit if we | |
684 * don't have them. */ | |
440 | 685 if (!gui.in_use && params.evim_mode) |
6 | 686 mch_exit(1); |
687 } | |
688 #endif | |
689 | |
690 #ifdef SPAWNO /* special MSDOS swapping library */ | |
691 init_SPAWNO("", SWAP_ANY); | |
692 #endif | |
693 | |
694 #ifdef FEAT_VIMINFO | |
695 /* | |
1733 | 696 * Read in registers, history etc, but not marks, from the viminfo file. |
697 * This is where v:oldfiles gets filled. | |
6 | 698 */ |
699 if (*p_viminfo != NUL) | |
700 { | |
1733 | 701 read_viminfo(NULL, VIF_WANT_INFO | VIF_GET_OLDFILES); |
6 | 702 TIME_MSG("reading viminfo"); |
703 } | |
704 #endif | |
705 | |
706 #ifdef FEAT_QUICKFIX | |
707 /* | |
708 * "-q errorfile": Load the error file now. | |
709 * If the error file can't be read, exit before doing anything else. | |
710 */ | |
443 | 711 if (params.edit_type == EDIT_QF) |
6 | 712 { |
443 | 713 if (params.use_ef != NULL) |
714 set_string_option_direct((char_u *)"ef", -1, | |
694 | 715 params.use_ef, OPT_FREE, SID_CARG); |
2411
68e394361ca3
Add "q" item for 'statusline'. Add w:quickfix_title. (Lech Lorens)
Bram Moolenaar <bram@vim.org>
parents:
2394
diff
changeset
|
716 vim_snprintf((char *)IObuff, IOSIZE, "cfile %s", p_ef); |
68e394361ca3
Add "q" item for 'statusline'. Add w:quickfix_title. (Lech Lorens)
Bram Moolenaar <bram@vim.org>
parents:
2394
diff
changeset
|
717 if (qf_init(NULL, p_ef, p_efm, TRUE, IObuff) < 0) |
6 | 718 { |
719 out_char('\n'); | |
720 mch_exit(3); | |
721 } | |
722 TIME_MSG("reading errorfile"); | |
723 } | |
724 #endif | |
725 | |
726 /* | |
727 * Start putting things on the screen. | |
728 * Scroll screen down before drawing over it | |
729 * Clear screen now, so file message will not be cleared. | |
730 */ | |
731 starting = NO_BUFFERS; | |
732 no_wait_return = FALSE; | |
733 if (!exmode_active) | |
734 msg_scroll = FALSE; | |
735 | |
736 #ifdef FEAT_GUI | |
737 /* | |
738 * This seems to be required to make callbacks to be called now, instead | |
739 * of after things have been put on the screen, which then may be deleted | |
740 * when getting a resize callback. | |
741 * For the Mac this handles putting files dropped on the Vim icon to | |
742 * global_alist. | |
743 */ | |
744 if (gui.in_use) | |
745 { | |
746 # ifdef FEAT_SUN_WORKSHOP | |
747 if (!usingSunWorkShop) | |
748 # endif | |
749 gui_wait_for_chars(50L); | |
750 TIME_MSG("GUI delay"); | |
751 } | |
752 #endif | |
753 | |
754 #if defined(FEAT_GUI_PHOTON) && defined(FEAT_CLIPBOARD) | |
755 qnx_clip_init(); | |
756 #endif | |
757 | |
2312
bbd6f5539378
Missing piece for Mac console clipboard support. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2282
diff
changeset
|
758 #if defined(MACOS_X) && defined(FEAT_CLIPBOARD) |
bbd6f5539378
Missing piece for Mac console clipboard support. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2282
diff
changeset
|
759 clip_init(TRUE); |
bbd6f5539378
Missing piece for Mac console clipboard support. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2282
diff
changeset
|
760 #endif |
bbd6f5539378
Missing piece for Mac console clipboard support. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2282
diff
changeset
|
761 |
6 | 762 #ifdef FEAT_XCLIPBOARD |
763 /* Start using the X clipboard, unless the GUI was started. */ | |
764 # ifdef FEAT_GUI | |
765 if (!gui.in_use) | |
766 # endif | |
767 { | |
768 setup_term_clip(); | |
769 TIME_MSG("setup clipboard"); | |
770 } | |
771 #endif | |
772 | |
773 #ifdef FEAT_CLIENTSERVER | |
443 | 774 /* Prepare for being a Vim server. */ |
775 prepare_server(¶ms); | |
6 | 776 #endif |
777 | |
778 /* | |
779 * If "-" argument given: Read file from stdin. | |
780 * Do this before starting Raw mode, because it may change things that the | |
781 * writing end of the pipe doesn't like, e.g., in case stdin and stderr | |
782 * are the same terminal: "cat | vim -". | |
783 * Using autocommands here may cause trouble... | |
784 */ | |
443 | 785 if (params.edit_type == EDIT_STDIN && !recoverymode) |
786 read_stdin(); | |
6 | 787 |
788 #if defined(UNIX) || defined(VMS) | |
789 /* When switching screens and something caused a message from a vimrc | |
790 * script, need to output an extra newline on exit. */ | |
791 if ((did_emsg || msg_didout) && *T_TI != NUL) | |
792 newline_on_exit = TRUE; | |
793 #endif | |
794 | |
795 /* | |
796 * When done something that is not allowed or error message call | |
797 * wait_return. This must be done before starttermcap(), because it may | |
798 * switch to another screen. It must be done after settmode(TMODE_RAW), | |
799 * because we want to react on a single key stroke. | |
800 * Call settmode and starttermcap here, so the T_KS and T_TI may be | |
1226 | 801 * defined by termcapinit and redefined in .exrc. |
6 | 802 */ |
803 settmode(TMODE_RAW); | |
804 TIME_MSG("setting raw mode"); | |
805 | |
806 if (need_wait_return || msg_didany) | |
807 { | |
808 wait_return(TRUE); | |
809 TIME_MSG("waiting for return"); | |
810 } | |
811 | |
812 starttermcap(); /* start termcap if not done by wait_return() */ | |
813 TIME_MSG("start termcap"); | |
4215 | 814 #if defined(FEAT_TERMRESPONSE) && defined(FEAT_MBYTE) |
815 may_req_ambiguous_character_width(); | |
816 #endif | |
6 | 817 |
818 #ifdef FEAT_MOUSE | |
819 setmouse(); /* may start using the mouse */ | |
820 #endif | |
821 if (scroll_region) | |
822 scroll_region_reset(); /* In case Rows changed */ | |
440 | 823 scroll_start(); /* may scroll the screen to the right position */ |
6 | 824 |
825 /* | |
826 * Don't clear the screen when starting in Ex mode, unless using the GUI. | |
827 */ | |
828 if (exmode_active | |
829 #ifdef FEAT_GUI | |
830 && !gui.in_use | |
831 #endif | |
832 ) | |
833 must_redraw = CLEAR; | |
834 else | |
835 { | |
836 screenclear(); /* clear screen */ | |
837 TIME_MSG("clearing screen"); | |
838 } | |
839 | |
840 #ifdef FEAT_CRYPT | |
443 | 841 if (params.ask_for_key) |
6 | 842 { |
2180
f60a0c9cbe6c
Add the blowfish encryption patch from Mohsin Ahmed. Needs more work.
Bram Moolenaar <bram@vim.org>
parents:
2133
diff
changeset
|
843 (void)blowfish_self_test(); |
6 | 844 (void)get_crypt_key(TRUE, TRUE); |
845 TIME_MSG("getting crypt key"); | |
846 } | |
847 #endif | |
848 | |
849 no_wait_return = TRUE; | |
850 | |
851 /* | |
443 | 852 * Create the requested number of windows and edit buffers in them. |
853 * Also does recovery if "recoverymode" set. | |
6 | 854 */ |
443 | 855 create_windows(¶ms); |
6 | 856 TIME_MSG("opening buffers"); |
857 | |
1093 | 858 #ifdef FEAT_EVAL |
859 /* clear v:swapcommand */ | |
860 set_vim_var_string(VV_SWAPCOMMAND, NULL, -1); | |
861 #endif | |
862 | |
6 | 863 /* Ex starts at last line of the file */ |
864 if (exmode_active) | |
865 curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count; | |
866 | |
867 #ifdef FEAT_AUTOCMD | |
868 apply_autocmds(EVENT_BUFENTER, NULL, NULL, FALSE, curbuf); | |
869 TIME_MSG("BufEnter autocommands"); | |
870 #endif | |
871 setpcmark(); | |
872 | |
873 #ifdef FEAT_QUICKFIX | |
874 /* | |
875 * When started with "-q errorfile" jump to first error now. | |
876 */ | |
443 | 877 if (params.edit_type == EDIT_QF) |
6 | 878 { |
644 | 879 qf_jump(NULL, 0, 0, FALSE); |
6 | 880 TIME_MSG("jump to first error"); |
881 } | |
882 #endif | |
883 | |
884 #ifdef FEAT_WINDOWS | |
885 /* | |
886 * If opened more than one window, start editing files in the other | |
443 | 887 * windows. |
6 | 888 */ |
443 | 889 edit_buffers(¶ms); |
890 #endif | |
6 | 891 |
892 #ifdef FEAT_DIFF | |
443 | 893 if (params.diff_mode) |
6 | 894 { |
895 win_T *wp; | |
896 | |
897 /* set options in each window for "vimdiff". */ | |
898 for (wp = firstwin; wp != NULL; wp = wp->w_next) | |
899 diff_win_options(wp, TRUE); | |
900 } | |
901 #endif | |
902 | |
903 /* | |
904 * Shorten any of the filenames, but only when absolute. | |
905 */ | |
906 shorten_fnames(FALSE); | |
907 | |
908 /* | |
909 * Need to jump to the tag before executing the '-c command'. | |
910 * Makes "vim -c '/return' -t main" work. | |
911 */ | |
443 | 912 if (params.tagname != NULL) |
6 | 913 { |
604 | 914 #if defined(HAS_SWAP_EXISTS_ACTION) |
915 swap_exists_did_quit = FALSE; | |
916 #endif | |
917 | |
443 | 918 vim_snprintf((char *)IObuff, IOSIZE, "ta %s", params.tagname); |
6 | 919 do_cmdline_cmd(IObuff); |
920 TIME_MSG("jumping to tag"); | |
604 | 921 |
922 #if defined(HAS_SWAP_EXISTS_ACTION) | |
923 /* If the user doesn't want to edit the file then we quit here. */ | |
924 if (swap_exists_did_quit) | |
925 getout(1); | |
926 #endif | |
6 | 927 } |
928 | |
443 | 929 /* Execute any "+", "-c" and "-S" arguments. */ |
930 if (params.n_commands > 0) | |
931 exe_commands(¶ms); | |
6 | 932 |
933 RedrawingDisabled = 0; | |
934 redraw_all_later(NOT_VALID); | |
935 no_wait_return = FALSE; | |
936 starting = 0; | |
937 | |
626 | 938 #ifdef FEAT_TERMRESPONSE |
939 /* Requesting the termresponse is postponed until here, so that a "-c q" | |
940 * argument doesn't make it appear in the shell Vim was started from. */ | |
941 may_req_termresponse(); | |
942 #endif | |
943 | |
6 | 944 /* start in insert mode */ |
945 if (p_im) | |
946 need_start_insertmode = TRUE; | |
947 | |
948 #ifdef FEAT_AUTOCMD | |
949 apply_autocmds(EVENT_VIMENTER, NULL, NULL, FALSE, curbuf); | |
950 TIME_MSG("VimEnter autocommands"); | |
951 #endif | |
952 | |
3488 | 953 #if defined(FEAT_EVAL) && defined(FEAT_CLIPBOARD) |
954 /* Adjust default register name for "unnamed" in 'clipboard'. Can only be | |
955 * done after the clipboard is available and all initial commands that may | |
956 * modify the 'clipboard' setting have run; i.e. just before entering the | |
957 * main loop. */ | |
958 { | |
959 int default_regname = 0; | |
960 adjust_clip_reg(&default_regname); | |
961 set_reg_var(default_regname); | |
962 } | |
963 #endif | |
964 | |
6 | 965 #if defined(FEAT_DIFF) && defined(FEAT_SCROLLBIND) |
966 /* When a startup script or session file setup for diff'ing and | |
967 * scrollbind, sync the scrollbind now. */ | |
968 if (curwin->w_p_diff && curwin->w_p_scb) | |
969 { | |
970 update_topline(); | |
971 check_scrollbind((linenr_T)0, 0L); | |
972 TIME_MSG("diff scrollbinding"); | |
973 } | |
974 #endif | |
975 | |
976 #if defined(WIN3264) && !defined(FEAT_GUI_W32) | |
977 mch_set_winsize_now(); /* Allow winsize changes from now on */ | |
978 #endif | |
979 | |
685 | 980 #if defined(FEAT_GUI) && defined(FEAT_WINDOWS) |
981 /* When tab pages were created, may need to update the tab pages line and | |
982 * scrollbars. This is skipped while creating them. */ | |
983 if (first_tabpage->tp_next != NULL) | |
984 { | |
985 out_flush(); | |
986 gui_init_which_components(NULL); | |
987 gui_update_scrollbars(TRUE); | |
988 } | |
989 need_mouse_correct = TRUE; | |
990 #endif | |
991 | |
6 | 992 /* If ":startinsert" command used, stuff a dummy command to be able to |
993 * call normal_cmd(), which will then start Insert mode. */ | |
994 if (restart_edit != 0) | |
620 | 995 stuffcharReadbuff(K_NOP); |
6 | 996 |
997 #ifdef FEAT_NETBEANS_INTG | |
2210 | 998 if (netbeansArg != NULL && strncmp("-nb", netbeansArg, 3) == 0) |
2209
d0ddf7ba1630
Included the patch to support netbeans in a terminal.
Bram Moolenaar <bram@vim.org>
parents:
2201
diff
changeset
|
999 { |
d0ddf7ba1630
Included the patch to support netbeans in a terminal.
Bram Moolenaar <bram@vim.org>
parents:
2201
diff
changeset
|
1000 # ifdef FEAT_GUI |
2592 | 1001 # if !defined(FEAT_GUI_X11) && !defined(FEAT_GUI_GTK) \ |
2209
d0ddf7ba1630
Included the patch to support netbeans in a terminal.
Bram Moolenaar <bram@vim.org>
parents:
2201
diff
changeset
|
1002 && !defined(FEAT_GUI_W32) |
d0ddf7ba1630
Included the patch to support netbeans in a terminal.
Bram Moolenaar <bram@vim.org>
parents:
2201
diff
changeset
|
1003 if (gui.in_use) |
d0ddf7ba1630
Included the patch to support netbeans in a terminal.
Bram Moolenaar <bram@vim.org>
parents:
2201
diff
changeset
|
1004 { |
d0ddf7ba1630
Included the patch to support netbeans in a terminal.
Bram Moolenaar <bram@vim.org>
parents:
2201
diff
changeset
|
1005 mch_errmsg(_("netbeans is not supported with this GUI\n")); |
d0ddf7ba1630
Included the patch to support netbeans in a terminal.
Bram Moolenaar <bram@vim.org>
parents:
2201
diff
changeset
|
1006 mch_exit(2); |
d0ddf7ba1630
Included the patch to support netbeans in a terminal.
Bram Moolenaar <bram@vim.org>
parents:
2201
diff
changeset
|
1007 } |
d0ddf7ba1630
Included the patch to support netbeans in a terminal.
Bram Moolenaar <bram@vim.org>
parents:
2201
diff
changeset
|
1008 # endif |
d0ddf7ba1630
Included the patch to support netbeans in a terminal.
Bram Moolenaar <bram@vim.org>
parents:
2201
diff
changeset
|
1009 # endif |
6 | 1010 /* Tell the client that it can start sending commands. */ |
2210 | 1011 netbeans_open(netbeansArg + 3, TRUE); |
2209
d0ddf7ba1630
Included the patch to support netbeans in a terminal.
Bram Moolenaar <bram@vim.org>
parents:
2201
diff
changeset
|
1012 } |
6 | 1013 #endif |
1014 | |
1015 TIME_MSG("before starting main loop"); | |
1016 | |
1017 /* | |
1018 * Call the main command loop. This never returns. | |
3348 | 1019 */ |
169 | 1020 main_loop(FALSE, FALSE); |
6 | 1021 |
1022 return 0; | |
1023 } | |
3955 | 1024 #endif /* NO_VIM_MAIN */ |
6 | 1025 #endif /* PROTO */ |
1026 | |
1027 /* | |
1028 * Main loop: Execute Normal mode commands until exiting Vim. | |
1029 * Also used to handle commands in the command-line window, until the window | |
1030 * is closed. | |
169 | 1031 * Also used to handle ":visual" command after ":global": execute Normal mode |
1032 * commands, return when entering Ex mode. "noexmode" is TRUE then. | |
6 | 1033 */ |
1034 void | |
169 | 1035 main_loop(cmdwin, noexmode) |
1036 int cmdwin; /* TRUE when working in the command-line window */ | |
1037 int noexmode; /* TRUE when return on entering Ex mode */ | |
6 | 1038 { |
1345 | 1039 oparg_T oa; /* operator arguments */ |
1040 int previous_got_int = FALSE; /* "got_int" was TRUE */ | |
2282
a888ed7ba375
Make updating text for conceal mode simpler. A few compiler warning fixes.
Bram Moolenaar <bram@vim.org>
parents:
2275
diff
changeset
|
1041 #ifdef FEAT_CONCEAL |
a888ed7ba375
Make updating text for conceal mode simpler. A few compiler warning fixes.
Bram Moolenaar <bram@vim.org>
parents:
2275
diff
changeset
|
1042 linenr_T conceal_old_cursor_line = 0; |
a888ed7ba375
Make updating text for conceal mode simpler. A few compiler warning fixes.
Bram Moolenaar <bram@vim.org>
parents:
2275
diff
changeset
|
1043 linenr_T conceal_new_cursor_line = 0; |
a888ed7ba375
Make updating text for conceal mode simpler. A few compiler warning fixes.
Bram Moolenaar <bram@vim.org>
parents:
2275
diff
changeset
|
1044 int conceal_update_lines = FALSE; |
a888ed7ba375
Make updating text for conceal mode simpler. A few compiler warning fixes.
Bram Moolenaar <bram@vim.org>
parents:
2275
diff
changeset
|
1045 #endif |
6 | 1046 |
1047 #if defined(FEAT_X11) && defined(FEAT_XCLIPBOARD) | |
1048 /* Setup to catch a terminating error from the X server. Just ignore | |
1049 * it, restore the state and continue. This might not always work | |
1050 * properly, but at least we don't exit unexpectedly when the X server | |
1051 * exists while Vim is running in a console. */ | |
169 | 1052 if (!cmdwin && !noexmode && SETJMP(x_jump_env)) |
6 | 1053 { |
1054 State = NORMAL; | |
1055 # ifdef FEAT_VISUAL | |
1056 VIsual_active = FALSE; | |
1057 # endif | |
1058 got_int = TRUE; | |
1059 need_wait_return = FALSE; | |
1060 global_busy = FALSE; | |
1061 exmode_active = 0; | |
1062 skip_redraw = FALSE; | |
1063 RedrawingDisabled = 0; | |
1064 no_wait_return = 0; | |
3119 | 1065 vgetc_busy = 0; |
6 | 1066 # ifdef FEAT_EVAL |
1067 emsg_skip = 0; | |
1068 # endif | |
1069 emsg_off = 0; | |
1070 # ifdef FEAT_MOUSE | |
1071 setmouse(); | |
1072 # endif | |
1073 settmode(TMODE_RAW); | |
1074 starttermcap(); | |
1075 scroll_start(); | |
1076 redraw_later_clear(); | |
1077 } | |
1078 #endif | |
1079 | |
1080 clear_oparg(&oa); | |
1081 while (!cmdwin | |
1082 #ifdef FEAT_CMDWIN | |
1083 || cmdwin_result == 0 | |
1084 #endif | |
1085 ) | |
1086 { | |
1087 if (stuff_empty()) | |
1088 { | |
1089 did_check_timestamps = FALSE; | |
1090 if (need_check_timestamps) | |
1091 check_timestamps(FALSE); | |
1092 if (need_wait_return) /* if wait_return still needed ... */ | |
1093 wait_return(FALSE); /* ... call it now */ | |
1094 if (need_start_insertmode && goto_im() | |
1095 #ifdef FEAT_VISUAL | |
1096 && !VIsual_active | |
1097 #endif | |
1098 ) | |
1099 { | |
1100 need_start_insertmode = FALSE; | |
1101 stuffReadbuff((char_u *)"i"); /* start insert mode next */ | |
1102 /* skip the fileinfo message now, because it would be shown | |
1103 * after insert mode finishes! */ | |
1104 need_fileinfo = FALSE; | |
1105 } | |
1106 } | |
1345 | 1107 |
1108 /* Reset "got_int" now that we got back to the main loop. Except when | |
1109 * inside a ":g/pat/cmd" command, then the "got_int" needs to abort | |
1110 * the ":g" command. | |
1111 * For ":g/pat/vi" we reset "got_int" when used once. When used | |
1112 * a second time we go back to Ex mode and abort the ":g" command. */ | |
1113 if (got_int) | |
6 | 1114 { |
1345 | 1115 if (noexmode && global_busy && !exmode_active && previous_got_int) |
1116 { | |
1117 /* Typed two CTRL-C in a row: go back to ex mode as if "Q" was | |
1118 * used and keep "got_int" set, so that it aborts ":g". */ | |
1119 exmode_active = EXMODE_NORMAL; | |
1120 State = NORMAL; | |
1121 } | |
1122 else if (!global_busy || !exmode_active) | |
1123 { | |
1124 if (!quit_more) | |
1125 (void)vgetc(); /* flush all buffers */ | |
1126 got_int = FALSE; | |
1127 } | |
1128 previous_got_int = TRUE; | |
6 | 1129 } |
1345 | 1130 else |
1131 previous_got_int = FALSE; | |
1132 | |
6 | 1133 if (!exmode_active) |
1134 msg_scroll = FALSE; | |
1135 quit_more = FALSE; | |
1136 | |
1137 /* | |
1138 * If skip redraw is set (for ":" in wait_return()), don't redraw now. | |
1139 * If there is nothing in the stuff_buffer or do_redraw is TRUE, | |
1140 * update cursor and redraw. | |
1141 */ | |
1142 if (skip_redraw || exmode_active) | |
1143 skip_redraw = FALSE; | |
1144 else if (do_redraw || stuff_empty()) | |
1145 { | |
2282
a888ed7ba375
Make updating text for conceal mode simpler. A few compiler warning fixes.
Bram Moolenaar <bram@vim.org>
parents:
2275
diff
changeset
|
1146 #if defined(FEAT_AUTOCMD) || defined(FEAT_CONCEAL) |
662 | 1147 /* Trigger CursorMoved if the cursor moved. */ |
2282
a888ed7ba375
Make updating text for conceal mode simpler. A few compiler warning fixes.
Bram Moolenaar <bram@vim.org>
parents:
2275
diff
changeset
|
1148 if (!finish_op && ( |
a888ed7ba375
Make updating text for conceal mode simpler. A few compiler warning fixes.
Bram Moolenaar <bram@vim.org>
parents:
2275
diff
changeset
|
1149 # ifdef FEAT_AUTOCMD |
a888ed7ba375
Make updating text for conceal mode simpler. A few compiler warning fixes.
Bram Moolenaar <bram@vim.org>
parents:
2275
diff
changeset
|
1150 has_cursormoved() |
a888ed7ba375
Make updating text for conceal mode simpler. A few compiler warning fixes.
Bram Moolenaar <bram@vim.org>
parents:
2275
diff
changeset
|
1151 # endif |
a888ed7ba375
Make updating text for conceal mode simpler. A few compiler warning fixes.
Bram Moolenaar <bram@vim.org>
parents:
2275
diff
changeset
|
1152 # if defined(FEAT_AUTOCMD) && defined(FEAT_CONCEAL) |
a888ed7ba375
Make updating text for conceal mode simpler. A few compiler warning fixes.
Bram Moolenaar <bram@vim.org>
parents:
2275
diff
changeset
|
1153 || |
a888ed7ba375
Make updating text for conceal mode simpler. A few compiler warning fixes.
Bram Moolenaar <bram@vim.org>
parents:
2275
diff
changeset
|
1154 # endif |
a888ed7ba375
Make updating text for conceal mode simpler. A few compiler warning fixes.
Bram Moolenaar <bram@vim.org>
parents:
2275
diff
changeset
|
1155 # ifdef FEAT_CONCEAL |
2378
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2348
diff
changeset
|
1156 curwin->w_p_cole > 0 |
2282
a888ed7ba375
Make updating text for conceal mode simpler. A few compiler warning fixes.
Bram Moolenaar <bram@vim.org>
parents:
2275
diff
changeset
|
1157 # endif |
a888ed7ba375
Make updating text for conceal mode simpler. A few compiler warning fixes.
Bram Moolenaar <bram@vim.org>
parents:
2275
diff
changeset
|
1158 ) |
a888ed7ba375
Make updating text for conceal mode simpler. A few compiler warning fixes.
Bram Moolenaar <bram@vim.org>
parents:
2275
diff
changeset
|
1159 && !equalpos(last_cursormoved, curwin->w_cursor)) |
662 | 1160 { |
2282
a888ed7ba375
Make updating text for conceal mode simpler. A few compiler warning fixes.
Bram Moolenaar <bram@vim.org>
parents:
2275
diff
changeset
|
1161 # ifdef FEAT_AUTOCMD |
a888ed7ba375
Make updating text for conceal mode simpler. A few compiler warning fixes.
Bram Moolenaar <bram@vim.org>
parents:
2275
diff
changeset
|
1162 if (has_cursormoved()) |
a888ed7ba375
Make updating text for conceal mode simpler. A few compiler warning fixes.
Bram Moolenaar <bram@vim.org>
parents:
2275
diff
changeset
|
1163 apply_autocmds(EVENT_CURSORMOVED, NULL, NULL, |
a888ed7ba375
Make updating text for conceal mode simpler. A few compiler warning fixes.
Bram Moolenaar <bram@vim.org>
parents:
2275
diff
changeset
|
1164 FALSE, curbuf); |
a888ed7ba375
Make updating text for conceal mode simpler. A few compiler warning fixes.
Bram Moolenaar <bram@vim.org>
parents:
2275
diff
changeset
|
1165 # endif |
a888ed7ba375
Make updating text for conceal mode simpler. A few compiler warning fixes.
Bram Moolenaar <bram@vim.org>
parents:
2275
diff
changeset
|
1166 # ifdef FEAT_CONCEAL |
2378
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2348
diff
changeset
|
1167 if (curwin->w_p_cole > 0) |
2282
a888ed7ba375
Make updating text for conceal mode simpler. A few compiler warning fixes.
Bram Moolenaar <bram@vim.org>
parents:
2275
diff
changeset
|
1168 { |
a888ed7ba375
Make updating text for conceal mode simpler. A few compiler warning fixes.
Bram Moolenaar <bram@vim.org>
parents:
2275
diff
changeset
|
1169 conceal_old_cursor_line = last_cursormoved.lnum; |
a888ed7ba375
Make updating text for conceal mode simpler. A few compiler warning fixes.
Bram Moolenaar <bram@vim.org>
parents:
2275
diff
changeset
|
1170 conceal_new_cursor_line = curwin->w_cursor.lnum; |
a888ed7ba375
Make updating text for conceal mode simpler. A few compiler warning fixes.
Bram Moolenaar <bram@vim.org>
parents:
2275
diff
changeset
|
1171 conceal_update_lines = TRUE; |
a888ed7ba375
Make updating text for conceal mode simpler. A few compiler warning fixes.
Bram Moolenaar <bram@vim.org>
parents:
2275
diff
changeset
|
1172 } |
a888ed7ba375
Make updating text for conceal mode simpler. A few compiler warning fixes.
Bram Moolenaar <bram@vim.org>
parents:
2275
diff
changeset
|
1173 # endif |
662 | 1174 last_cursormoved = curwin->w_cursor; |
1175 } | |
1176 #endif | |
1177 | |
4232 | 1178 #ifdef FEAT_AUTOCMD |
1179 /* Trigger TextChanged if b_changedtick differs. */ | |
1180 if (!finish_op && has_textchanged() | |
1181 && last_changedtick != curbuf->b_changedtick) | |
1182 { | |
1183 if (last_changedtick_buf == curbuf) | |
1184 apply_autocmds(EVENT_TEXTCHANGED, NULL, NULL, | |
1185 FALSE, curbuf); | |
1186 last_changedtick_buf = curbuf; | |
1187 last_changedtick = curbuf->b_changedtick; | |
1188 } | |
1189 #endif | |
1190 | |
640 | 1191 #if defined(FEAT_DIFF) && defined(FEAT_SCROLLBIND) |
1192 /* Scroll-binding for diff mode may have been postponed until | |
1193 * here. Avoids doing it for every change. */ | |
1194 if (diff_need_scrollbind) | |
1195 { | |
1196 check_scrollbind((linenr_T)0, 0L); | |
1197 diff_need_scrollbind = FALSE; | |
1198 } | |
1199 #endif | |
6 | 1200 #if defined(FEAT_FOLDING) && defined(FEAT_VISUAL) |
1201 /* Include a closed fold completely in the Visual area. */ | |
1202 foldAdjustVisual(); | |
1203 #endif | |
1204 #ifdef FEAT_FOLDING | |
1205 /* | |
1206 * When 'foldclose' is set, apply 'foldlevel' to folds that don't | |
1207 * contain the cursor. | |
1208 * When 'foldopen' is "all", open the fold(s) under the cursor. | |
1209 * This may mark the window for redrawing. | |
1210 */ | |
1211 if (hasAnyFolding(curwin) && !char_avail()) | |
1212 { | |
1213 foldCheckClose(); | |
1214 if (fdo_flags & FDO_ALL) | |
1215 foldOpenCursor(); | |
1216 } | |
1217 #endif | |
1218 | |
1219 /* | |
1220 * Before redrawing, make sure w_topline is correct, and w_leftcol | |
1221 * if lines don't wrap, and w_skipcol if lines wrap. | |
1222 */ | |
1223 update_topline(); | |
1224 validate_cursor(); | |
1225 | |
1226 #ifdef FEAT_VISUAL | |
1227 if (VIsual_active) | |
1228 update_curbuf(INVERTED);/* update inverted part */ | |
1229 else | |
1230 #endif | |
1231 if (must_redraw) | |
1232 update_screen(0); | |
1233 else if (redraw_cmdline || clear_cmdline) | |
1234 showmode(); | |
1235 #ifdef FEAT_WINDOWS | |
1236 redraw_statuslines(); | |
1237 #endif | |
1238 #ifdef FEAT_TITLE | |
1239 if (need_maketitle) | |
1240 maketitle(); | |
1241 #endif | |
1242 /* display message after redraw */ | |
1243 if (keep_msg != NULL) | |
1244 { | |
1245 char_u *p; | |
1246 | |
1247 /* msg_attr_keep() will set keep_msg to NULL, must free the | |
1248 * string here. */ | |
1249 p = keep_msg; | |
680 | 1250 keep_msg = NULL; |
6 | 1251 msg_attr(p, keep_msg_attr); |
1252 vim_free(p); | |
1253 } | |
1254 if (need_fileinfo) /* show file info after redraw */ | |
1255 { | |
1256 fileinfo(FALSE, TRUE, FALSE); | |
1257 need_fileinfo = FALSE; | |
1258 } | |
1259 | |
1260 emsg_on_display = FALSE; /* can delete error message now */ | |
1261 did_emsg = FALSE; | |
1262 msg_didany = FALSE; /* reset lines_left in msg_start() */ | |
448 | 1263 may_clear_sb_text(); /* clear scroll-back text on next msg */ |
6 | 1264 showruler(FALSE); |
1265 | |
2282
a888ed7ba375
Make updating text for conceal mode simpler. A few compiler warning fixes.
Bram Moolenaar <bram@vim.org>
parents:
2275
diff
changeset
|
1266 # if defined(FEAT_CONCEAL) |
a888ed7ba375
Make updating text for conceal mode simpler. A few compiler warning fixes.
Bram Moolenaar <bram@vim.org>
parents:
2275
diff
changeset
|
1267 if (conceal_update_lines |
2378
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2348
diff
changeset
|
1268 && (conceal_old_cursor_line != conceal_new_cursor_line |
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2348
diff
changeset
|
1269 || conceal_cursor_line(curwin) |
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2348
diff
changeset
|
1270 || need_cursor_line_redraw)) |
2282
a888ed7ba375
Make updating text for conceal mode simpler. A few compiler warning fixes.
Bram Moolenaar <bram@vim.org>
parents:
2275
diff
changeset
|
1271 { |
2706 | 1272 if (conceal_old_cursor_line != conceal_new_cursor_line |
1273 && conceal_old_cursor_line | |
1274 <= curbuf->b_ml.ml_line_count) | |
2378
85b7dc8da5eb
Add the 'concealcursor' option to decide when the cursor line is to be
Bram Moolenaar <bram@vim.org>
parents:
2348
diff
changeset
|
1275 update_single_line(curwin, conceal_old_cursor_line); |
2282
a888ed7ba375
Make updating text for conceal mode simpler. A few compiler warning fixes.
Bram Moolenaar <bram@vim.org>
parents:
2275
diff
changeset
|
1276 update_single_line(curwin, conceal_new_cursor_line); |
a888ed7ba375
Make updating text for conceal mode simpler. A few compiler warning fixes.
Bram Moolenaar <bram@vim.org>
parents:
2275
diff
changeset
|
1277 curwin->w_valid &= ~VALID_CROW; |
a888ed7ba375
Make updating text for conceal mode simpler. A few compiler warning fixes.
Bram Moolenaar <bram@vim.org>
parents:
2275
diff
changeset
|
1278 } |
a888ed7ba375
Make updating text for conceal mode simpler. A few compiler warning fixes.
Bram Moolenaar <bram@vim.org>
parents:
2275
diff
changeset
|
1279 # endif |
6 | 1280 setcursor(); |
1281 cursor_on(); | |
1282 | |
1283 do_redraw = FALSE; | |
1972 | 1284 |
1285 #ifdef STARTUPTIME | |
1286 /* Now that we have drawn the first screen all the startup stuff | |
1287 * has been done, close any file for startup messages. */ | |
1288 if (time_fd != NULL) | |
1289 { | |
1290 TIME_MSG("first screen update"); | |
1291 TIME_MSG("--- VIM STARTED ---"); | |
1292 fclose(time_fd); | |
1293 time_fd = NULL; | |
1294 } | |
1295 #endif | |
6 | 1296 } |
1297 #ifdef FEAT_GUI | |
1298 if (need_mouse_correct) | |
1299 gui_mouse_correct(); | |
1300 #endif | |
1301 | |
1302 /* | |
1303 * Update w_curswant if w_set_curswant has been set. | |
1304 * Postponed until here to avoid computing w_virtcol too often. | |
1305 */ | |
1306 update_curswant(); | |
1307 | |
958 | 1308 #ifdef FEAT_EVAL |
1309 /* | |
1310 * May perform garbage collection when waiting for a character, but | |
1311 * only at the very toplevel. Otherwise we may be using a List or | |
1312 * Dict internally somewhere. | |
1313 * "may_garbage_collect" is reset in vgetc() which is invoked through | |
1314 * do_exmode() and normal_cmd(). | |
1315 */ | |
1316 may_garbage_collect = (!cmdwin && !noexmode); | |
1317 #endif | |
6 | 1318 /* |
1319 * If we're invoked as ex, do a round of ex commands. | |
1320 * Otherwise, get and execute a normal mode command. | |
1321 */ | |
1322 if (exmode_active) | |
169 | 1323 { |
1324 if (noexmode) /* End of ":global/path/visual" commands */ | |
1325 return; | |
6 | 1326 do_exmode(exmode_active == EXMODE_VIM); |
169 | 1327 } |
6 | 1328 else |
1329 normal_cmd(&oa, TRUE); | |
1330 } | |
1331 } | |
1332 | |
1333 | |
1334 #if defined(USE_XSMP) || defined(FEAT_GUI_MSWIN) || defined(PROTO) | |
1335 /* | |
1336 * Exit, but leave behind swap files for modified buffers. | |
1337 */ | |
1338 void | |
1339 getout_preserve_modified(exitval) | |
1340 int exitval; | |
1341 { | |
39 | 1342 # if defined(SIGHUP) && defined(SIG_IGN) |
1343 /* Ignore SIGHUP, because a dropped connection causes a read error, which | |
1344 * makes Vim exit and then handling SIGHUP causes various reentrance | |
1345 * problems. */ | |
36 | 1346 signal(SIGHUP, SIG_IGN); |
39 | 1347 # endif |
36 | 1348 |
6 | 1349 ml_close_notmod(); /* close all not-modified buffers */ |
1350 ml_sync_all(FALSE, FALSE); /* preserve all swap files */ | |
1351 ml_close_all(FALSE); /* close all memfiles, without deleting */ | |
1352 getout(exitval); /* exit Vim properly */ | |
1353 } | |
1354 #endif | |
1355 | |
1356 | |
1357 /* Exit properly */ | |
1358 void | |
1359 getout(exitval) | |
1360 int exitval; | |
1361 { | |
1362 #ifdef FEAT_AUTOCMD | |
1363 buf_T *buf; | |
1364 win_T *wp; | |
671 | 1365 tabpage_T *tp, *next_tp; |
6 | 1366 #endif |
1367 | |
1368 exiting = TRUE; | |
1369 | |
169 | 1370 /* When running in Ex mode an error causes us to exit with a non-zero exit |
1371 * code. POSIX requires this, although it's not 100% clear from the | |
1372 * standard. */ | |
1373 if (exmode_active) | |
1374 exitval += ex_exitval; | |
1375 | |
6 | 1376 /* Position the cursor on the last screen line, below all the text */ |
1377 #ifdef FEAT_GUI | |
1378 if (!gui.in_use) | |
1379 #endif | |
1380 windgoto((int)Rows - 1, 0); | |
1381 | |
242 | 1382 #if defined(FEAT_EVAL) || defined(FEAT_SYN_HL) |
1383 /* Optionally print hashtable efficiency. */ | |
1384 hash_debug_results(); | |
1385 #endif | |
1386 | |
6 | 1387 #ifdef FEAT_GUI |
1388 msg_didany = FALSE; | |
1389 #endif | |
1390 | |
1391 #ifdef FEAT_AUTOCMD | |
2226
36a9ac99e1ca
Don't execute some autocommands when v:dying is 2 or more.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1392 if (get_vim_var_nr(VV_DYING) <= 1) |
6 | 1393 { |
2226
36a9ac99e1ca
Don't execute some autocommands when v:dying is 2 or more.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1394 /* Trigger BufWinLeave for all windows, but only once per buffer. */ |
36a9ac99e1ca
Don't execute some autocommands when v:dying is 2 or more.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1395 # if defined FEAT_WINDOWS |
36a9ac99e1ca
Don't execute some autocommands when v:dying is 2 or more.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1396 for (tp = first_tabpage; tp != NULL; tp = next_tp) |
6 | 1397 { |
2226
36a9ac99e1ca
Don't execute some autocommands when v:dying is 2 or more.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1398 next_tp = tp->tp_next; |
36a9ac99e1ca
Don't execute some autocommands when v:dying is 2 or more.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1399 for (wp = (tp == curtab) |
36a9ac99e1ca
Don't execute some autocommands when v:dying is 2 or more.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1400 ? firstwin : tp->tp_firstwin; wp != NULL; wp = wp->w_next) |
671 | 1401 { |
4021 | 1402 if (wp->w_buffer == NULL) |
1403 /* Autocmd must have close the buffer already, skip. */ | |
1404 continue; | |
2226
36a9ac99e1ca
Don't execute some autocommands when v:dying is 2 or more.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1405 buf = wp->w_buffer; |
36a9ac99e1ca
Don't execute some autocommands when v:dying is 2 or more.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1406 if (buf->b_changedtick != -1) |
36a9ac99e1ca
Don't execute some autocommands when v:dying is 2 or more.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1407 { |
36a9ac99e1ca
Don't execute some autocommands when v:dying is 2 or more.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1408 apply_autocmds(EVENT_BUFWINLEAVE, buf->b_fname, |
36a9ac99e1ca
Don't execute some autocommands when v:dying is 2 or more.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1409 buf->b_fname, FALSE, buf); |
3488 | 1410 buf->b_changedtick = -1; /* note that we did it already */ |
2226
36a9ac99e1ca
Don't execute some autocommands when v:dying is 2 or more.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1411 /* start all over, autocommands may mess up the lists */ |
36a9ac99e1ca
Don't execute some autocommands when v:dying is 2 or more.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1412 next_tp = first_tabpage; |
36a9ac99e1ca
Don't execute some autocommands when v:dying is 2 or more.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1413 break; |
36a9ac99e1ca
Don't execute some autocommands when v:dying is 2 or more.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1414 } |
671 | 1415 } |
6 | 1416 } |
640 | 1417 # else |
2226
36a9ac99e1ca
Don't execute some autocommands when v:dying is 2 or more.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1418 apply_autocmds(EVENT_BUFWINLEAVE, curbuf, curbuf->b_fname, |
36a9ac99e1ca
Don't execute some autocommands when v:dying is 2 or more.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1419 FALSE, curbuf); |
640 | 1420 # endif |
1421 | |
2226
36a9ac99e1ca
Don't execute some autocommands when v:dying is 2 or more.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1422 /* Trigger BufUnload for buffers that are loaded */ |
36a9ac99e1ca
Don't execute some autocommands when v:dying is 2 or more.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1423 for (buf = firstbuf; buf != NULL; buf = buf->b_next) |
36a9ac99e1ca
Don't execute some autocommands when v:dying is 2 or more.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1424 if (buf->b_ml.ml_mfp != NULL) |
36a9ac99e1ca
Don't execute some autocommands when v:dying is 2 or more.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1425 { |
36a9ac99e1ca
Don't execute some autocommands when v:dying is 2 or more.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1426 apply_autocmds(EVENT_BUFUNLOAD, buf->b_fname, buf->b_fname, |
6 | 1427 FALSE, buf); |
2226
36a9ac99e1ca
Don't execute some autocommands when v:dying is 2 or more.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1428 if (!buf_valid(buf)) /* autocmd may delete the buffer */ |
36a9ac99e1ca
Don't execute some autocommands when v:dying is 2 or more.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1429 break; |
36a9ac99e1ca
Don't execute some autocommands when v:dying is 2 or more.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1430 } |
36a9ac99e1ca
Don't execute some autocommands when v:dying is 2 or more.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1431 apply_autocmds(EVENT_VIMLEAVEPRE, NULL, NULL, FALSE, curbuf); |
36a9ac99e1ca
Don't execute some autocommands when v:dying is 2 or more.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1432 } |
6 | 1433 #endif |
1434 | |
1435 #ifdef FEAT_VIMINFO | |
1436 if (*p_viminfo != NUL) | |
1437 /* Write out the registers, history, marks etc, to the viminfo file */ | |
1438 write_viminfo(NULL, FALSE); | |
1439 #endif | |
1440 | |
1441 #ifdef FEAT_AUTOCMD | |
2226
36a9ac99e1ca
Don't execute some autocommands when v:dying is 2 or more.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1442 if (get_vim_var_nr(VV_DYING) <= 1) |
36a9ac99e1ca
Don't execute some autocommands when v:dying is 2 or more.
Bram Moolenaar <bram@vim.org>
parents:
2215
diff
changeset
|
1443 apply_autocmds(EVENT_VIMLEAVE, NULL, NULL, FALSE, curbuf); |
6 | 1444 #endif |
1445 | |
170 | 1446 #ifdef FEAT_PROFILE |
1447 profile_dump(); | |
1448 #endif | |
1449 | |
6 | 1450 if (did_emsg |
1451 #ifdef FEAT_GUI | |
1452 || (gui.in_use && msg_didany && p_verbose > 0) | |
1453 #endif | |
1454 ) | |
1455 { | |
1456 /* give the user a chance to read the (error) message */ | |
1457 no_wait_return = FALSE; | |
1458 wait_return(FALSE); | |
1459 } | |
1460 | |
1461 #ifdef FEAT_AUTOCMD | |
1462 /* Position the cursor again, the autocommands may have moved it */ | |
1463 # ifdef FEAT_GUI | |
1464 if (!gui.in_use) | |
1465 # endif | |
1466 windgoto((int)Rows - 1, 0); | |
1467 #endif | |
1468 | |
2320
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
2312
diff
changeset
|
1469 #ifdef FEAT_LUA |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
2312
diff
changeset
|
1470 lua_end(); |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
2312
diff
changeset
|
1471 #endif |
14 | 1472 #ifdef FEAT_MZSCHEME |
1473 mzscheme_end(); | |
1474 #endif | |
6 | 1475 #ifdef FEAT_TCL |
1476 tcl_end(); | |
1477 #endif | |
1478 #ifdef FEAT_RUBY | |
1479 ruby_end(); | |
1480 #endif | |
1481 #ifdef FEAT_PYTHON | |
1482 python_end(); | |
1483 #endif | |
2329
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
2320
diff
changeset
|
1484 #ifdef FEAT_PYTHON3 |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
2320
diff
changeset
|
1485 python3_end(); |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
2320
diff
changeset
|
1486 #endif |
6 | 1487 #ifdef FEAT_PERL |
1488 perl_end(); | |
1489 #endif | |
1490 #if defined(USE_ICONV) && defined(DYNAMIC_ICONV) | |
1491 iconv_end(); | |
1492 #endif | |
1493 #ifdef FEAT_NETBEANS_INTG | |
1494 netbeans_end(); | |
1495 #endif | |
1385 | 1496 #ifdef FEAT_CSCOPE |
1497 cs_end(); | |
1498 #endif | |
1405 | 1499 #ifdef FEAT_EVAL |
1500 if (garbage_collect_at_exit) | |
1501 garbage_collect(); | |
1502 #endif | |
6 | 1503 |
1504 mch_exit(exitval); | |
1505 } | |
1506 | |
2730 | 1507 #ifndef NO_VIM_MAIN |
6 | 1508 /* |
1509 * Get a (optional) count for a Vim argument. | |
1510 */ | |
1511 static int | |
1512 get_number_arg(p, idx, def) | |
1513 char_u *p; /* pointer to argument */ | |
1514 int *idx; /* index in argument, is incremented */ | |
1515 int def; /* default value */ | |
1516 { | |
1517 if (vim_isdigit(p[*idx])) | |
1518 { | |
1519 def = atoi((char *)&(p[*idx])); | |
1520 while (vim_isdigit(p[*idx])) | |
1521 *idx = *idx + 1; | |
1522 } | |
1523 return def; | |
1524 } | |
1525 | |
443 | 1526 #if defined(HAVE_LOCALE_H) || defined(X_LOCALE) |
1527 /* | |
1528 * Setup to use the current locale (for ctype() and many other things). | |
1529 */ | |
1530 static void | |
1531 init_locale() | |
1532 { | |
1533 setlocale(LC_ALL, ""); | |
1624 | 1534 |
2201
4c6b4298852f
Other solution for GTK not changing the locale.
Bram Moolenaar <bram@vim.org>
parents:
2180
diff
changeset
|
1535 # ifdef FEAT_GUI_GTK |
4c6b4298852f
Other solution for GTK not changing the locale.
Bram Moolenaar <bram@vim.org>
parents:
2180
diff
changeset
|
1536 /* Tell Gtk not to change our locale settings. */ |
4c6b4298852f
Other solution for GTK not changing the locale.
Bram Moolenaar <bram@vim.org>
parents:
2180
diff
changeset
|
1537 gtk_disable_setlocale(); |
4c6b4298852f
Other solution for GTK not changing the locale.
Bram Moolenaar <bram@vim.org>
parents:
2180
diff
changeset
|
1538 # endif |
1624 | 1539 # if defined(FEAT_FLOAT) && defined(LC_NUMERIC) |
1540 /* Make sure strtod() uses a decimal point, not a comma. */ | |
1541 setlocale(LC_NUMERIC, "C"); | |
1542 # endif | |
1543 | |
534 | 1544 # ifdef WIN32 |
1545 /* Apparently MS-Windows printf() may cause a crash when we give it 8-bit | |
1546 * text while it's expecting text in the current locale. This call avoids | |
1547 * that. */ | |
1548 setlocale(LC_CTYPE, "C"); | |
1549 # endif | |
443 | 1550 |
1551 # ifdef FEAT_GETTEXT | |
1552 { | |
1553 int mustfree = FALSE; | |
1554 char_u *p; | |
1555 | |
1556 # ifdef DYNAMIC_GETTEXT | |
1557 /* Initialize the gettext library */ | |
1558 dyn_libintl_init(NULL); | |
1559 # endif | |
1560 /* expand_env() doesn't work yet, because chartab[] is not initialized | |
1561 * yet, call vim_getenv() directly */ | |
1562 p = vim_getenv((char_u *)"VIMRUNTIME", &mustfree); | |
1563 if (p != NULL && *p != NUL) | |
1564 { | |
1297 | 1565 vim_snprintf((char *)NameBuff, MAXPATHL, "%s/lang", p); |
443 | 1566 bindtextdomain(VIMPACKAGE, (char *)NameBuff); |
1567 } | |
1568 if (mustfree) | |
1569 vim_free(p); | |
1570 textdomain(VIMPACKAGE); | |
1571 } | |
1572 # endif | |
1573 } | |
1574 #endif | |
1575 | |
1576 /* | |
1577 * Check for: [r][e][g][vi|vim|view][diff][ex[im]] | |
1578 * If the executable name starts with "r" we disable shell commands. | |
1579 * If the next character is "e" we run in Easy mode. | |
1580 * If the next character is "g" we run the GUI version. | |
1581 * If the next characters are "view" we start in readonly mode. | |
1582 * If the next characters are "diff" or "vimdiff" we start in diff mode. | |
1583 * If the next characters are "ex" we start in Ex mode. If it's followed | |
1584 * by "im" use improved Ex mode. | |
1585 */ | |
1586 static void | |
1587 parse_command_name(parmp) | |
1588 mparm_T *parmp; | |
1589 { | |
1590 char_u *initstr; | |
1591 | |
1592 initstr = gettail((char_u *)parmp->argv[0]); | |
1593 | |
1594 #ifdef MACOS_X_UNIX | |
1595 /* An issue has been seen when launching Vim in such a way that | |
1596 * $PWD/$ARGV[0] or $ARGV[0] is not the absolute path to the | |
1597 * executable or a symbolic link of it. Until this issue is resolved | |
1598 * we prohibit the GUI from being used. | |
1599 */ | |
1600 if (STRCMP(initstr, parmp->argv[0]) == 0) | |
1601 disallow_gui = TRUE; | |
1602 | |
1603 /* TODO: On MacOS X default to gui if argv[0] ends in: | |
769 | 1604 * /Vim.app/Contents/MacOS/Vim */ |
443 | 1605 #endif |
1606 | |
1607 #ifdef FEAT_EVAL | |
1608 set_vim_var_string(VV_PROGNAME, initstr, -1); | |
1609 #endif | |
1610 | |
1611 if (TOLOWER_ASC(initstr[0]) == 'r') | |
1612 { | |
1613 restricted = TRUE; | |
1614 ++initstr; | |
1615 } | |
1616 | |
2133
2b273c71a14b
updated for version 7.2.415
Bram Moolenaar <bram@zimbu.org>
parents:
2021
diff
changeset
|
1617 /* Use evim mode for "evim" and "egvim", not for "editor". */ |
443 | 1618 if (TOLOWER_ASC(initstr[0]) == 'e' |
1619 && (TOLOWER_ASC(initstr[1]) == 'v' | |
1620 || TOLOWER_ASC(initstr[1]) == 'g')) | |
1621 { | |
1622 #ifdef FEAT_GUI | |
1623 gui.starting = TRUE; | |
1624 #endif | |
1625 parmp->evim_mode = TRUE; | |
1626 ++initstr; | |
1627 } | |
1628 | |
1722 | 1629 /* "gvim" starts the GUI. Also accept "Gvim" for MS-Windows. */ |
1630 if (TOLOWER_ASC(initstr[0]) == 'g') | |
443 | 1631 { |
1632 main_start_gui(); | |
1633 #ifdef FEAT_GUI | |
1634 ++initstr; | |
1635 #endif | |
1636 } | |
1637 | |
1638 if (STRNICMP(initstr, "view", 4) == 0) | |
1639 { | |
1640 readonlymode = TRUE; | |
1641 curbuf->b_p_ro = TRUE; | |
1642 p_uc = 10000; /* don't update very often */ | |
1643 initstr += 4; | |
1644 } | |
1645 else if (STRNICMP(initstr, "vim", 3) == 0) | |
1646 initstr += 3; | |
1647 | |
1648 /* Catch "[r][g]vimdiff" and "[r][g]viewdiff". */ | |
1649 if (STRICMP(initstr, "diff") == 0) | |
1650 { | |
1651 #ifdef FEAT_DIFF | |
1652 parmp->diff_mode = TRUE; | |
1653 #else | |
1654 mch_errmsg(_("This Vim was not compiled with the diff feature.")); | |
1655 mch_errmsg("\n"); | |
1656 mch_exit(2); | |
1657 #endif | |
1658 } | |
1659 | |
1660 if (STRNICMP(initstr, "ex", 2) == 0) | |
1661 { | |
1662 if (STRNICMP(initstr + 2, "im", 2) == 0) | |
1663 exmode_active = EXMODE_VIM; | |
1664 else | |
1665 exmode_active = EXMODE_NORMAL; | |
1666 change_compatible(TRUE); /* set 'compatible' */ | |
1667 } | |
1668 } | |
1669 | |
6 | 1670 /* |
440 | 1671 * Get the name of the display, before gui_prepare() removes it from |
1672 * argv[]. Used for the xterm-clipboard display. | |
1673 * | |
1376 | 1674 * Also find the --server... arguments and --socketid and --windowid |
440 | 1675 */ |
1676 static void | |
443 | 1677 early_arg_scan(parmp) |
1883 | 1678 mparm_T *parmp UNUSED; |
440 | 1679 { |
1750 | 1680 #if defined(FEAT_XCLIPBOARD) || defined(FEAT_CLIENTSERVER) \ |
1681 || !defined(FEAT_NETBEANS_INTG) | |
443 | 1682 int argc = parmp->argc; |
1683 char **argv = parmp->argv; | |
440 | 1684 int i; |
1685 | |
1686 for (i = 1; i < argc; i++) | |
1687 { | |
1688 if (STRCMP(argv[i], "--") == 0) | |
1689 break; | |
1690 # ifdef FEAT_XCLIPBOARD | |
1691 else if (STRICMP(argv[i], "-display") == 0 | |
575 | 1692 # if defined(FEAT_GUI_GTK) |
440 | 1693 || STRICMP(argv[i], "--display") == 0 |
1694 # endif | |
1695 ) | |
1696 { | |
1697 if (i == argc - 1) | |
1698 mainerr_arg_missing((char_u *)argv[i]); | |
1699 xterm_display = argv[++i]; | |
1700 } | |
1701 # endif | |
1702 # ifdef FEAT_CLIENTSERVER | |
1703 else if (STRICMP(argv[i], "--servername") == 0) | |
1704 { | |
1705 if (i == argc - 1) | |
1706 mainerr_arg_missing((char_u *)argv[i]); | |
1707 parmp->serverName_arg = (char_u *)argv[++i]; | |
1708 } | |
734 | 1709 else if (STRICMP(argv[i], "--serverlist") == 0) |
440 | 1710 parmp->serverArg = TRUE; |
734 | 1711 else if (STRNICMP(argv[i], "--remote", 8) == 0) |
440 | 1712 { |
1713 parmp->serverArg = TRUE; | |
734 | 1714 # ifdef FEAT_GUI |
1715 if (strstr(argv[i], "-wait") != 0) | |
1716 /* don't fork() when starting the GUI to edit files ourself */ | |
1717 gui.dofork = FALSE; | |
1718 # endif | |
440 | 1719 } |
1720 # endif | |
1376 | 1721 |
1722 # if defined(FEAT_GUI_GTK) || defined(FEAT_GUI_W32) | |
1723 # ifdef FEAT_GUI_W32 | |
1724 else if (STRICMP(argv[i], "--windowid") == 0) | |
1725 # else | |
440 | 1726 else if (STRICMP(argv[i], "--socketid") == 0) |
1376 | 1727 # endif |
440 | 1728 { |
1570 | 1729 long_u id; |
1730 int count; | |
440 | 1731 |
1732 if (i == argc - 1) | |
1733 mainerr_arg_missing((char_u *)argv[i]); | |
1734 if (STRNICMP(argv[i+1], "0x", 2) == 0) | |
1570 | 1735 count = sscanf(&(argv[i + 1][2]), SCANF_HEX_LONG_U, &id); |
440 | 1736 else |
1570 | 1737 count = sscanf(argv[i + 1], SCANF_DECIMAL_LONG_U, &id); |
440 | 1738 if (count != 1) |
1739 mainerr(ME_INVALID_ARG, (char_u *)argv[i]); | |
1740 else | |
1376 | 1741 # ifdef FEAT_GUI_W32 |
1742 win_socket_id = id; | |
1743 # else | |
1744 gtk_socket_id = id; | |
1745 # endif | |
440 | 1746 i++; |
1747 } | |
1376 | 1748 # endif |
1749 # ifdef FEAT_GUI_GTK | |
440 | 1750 else if (STRICMP(argv[i], "--echo-wid") == 0) |
1751 echo_wid_arg = TRUE; | |
1752 # endif | |
1750 | 1753 # ifndef FEAT_NETBEANS_INTG |
1754 else if (strncmp(argv[i], "-nb", (size_t)3) == 0) | |
2209
d0ddf7ba1630
Included the patch to support netbeans in a terminal.
Bram Moolenaar <bram@vim.org>
parents:
2201
diff
changeset
|
1755 { |
d0ddf7ba1630
Included the patch to support netbeans in a terminal.
Bram Moolenaar <bram@vim.org>
parents:
2201
diff
changeset
|
1756 mch_errmsg(_("'-nb' cannot be used: not enabled at compile time\n")); |
d0ddf7ba1630
Included the patch to support netbeans in a terminal.
Bram Moolenaar <bram@vim.org>
parents:
2201
diff
changeset
|
1757 mch_exit(2); |
d0ddf7ba1630
Included the patch to support netbeans in a terminal.
Bram Moolenaar <bram@vim.org>
parents:
2201
diff
changeset
|
1758 } |
1750 | 1759 # endif |
1760 | |
440 | 1761 } |
1762 #endif | |
1763 } | |
1764 | |
1765 /* | |
443 | 1766 * Scan the command line arguments. |
1767 */ | |
1768 static void | |
1769 command_line_scan(parmp) | |
1770 mparm_T *parmp; | |
1771 { | |
1772 int argc = parmp->argc; | |
1773 char **argv = parmp->argv; | |
1774 int argv_idx; /* index in argv[n][] */ | |
1775 int had_minmin = FALSE; /* found "--" argument */ | |
1776 int want_argument; /* option argument with argument */ | |
1777 int c; | |
445 | 1778 char_u *p = NULL; |
443 | 1779 long n; |
1780 | |
1781 --argc; | |
1782 ++argv; | |
1783 argv_idx = 1; /* active option letter is argv[0][argv_idx] */ | |
1784 while (argc > 0) | |
1785 { | |
1786 /* | |
1787 * "+" or "+{number}" or "+/{pat}" or "+{command}" argument. | |
1788 */ | |
1789 if (argv[0][0] == '+' && !had_minmin) | |
1790 { | |
1791 if (parmp->n_commands >= MAX_ARG_CMDS) | |
1792 mainerr(ME_EXTRA_CMD, NULL); | |
1793 argv_idx = -1; /* skip to next argument */ | |
1794 if (argv[0][1] == NUL) | |
1795 parmp->commands[parmp->n_commands++] = (char_u *)"$"; | |
1796 else | |
1797 parmp->commands[parmp->n_commands++] = (char_u *)&(argv[0][1]); | |
1798 } | |
1799 | |
1800 /* | |
1801 * Optional argument. | |
1802 */ | |
1803 else if (argv[0][0] == '-' && !had_minmin) | |
1804 { | |
1805 want_argument = FALSE; | |
1806 c = argv[0][argv_idx++]; | |
1807 #ifdef VMS | |
1808 /* | |
1809 * VMS only uses upper case command lines. Interpret "-X" as "-x" | |
1810 * and "-/X" as "-X". | |
1811 */ | |
1812 if (c == '/') | |
1813 { | |
1814 c = argv[0][argv_idx++]; | |
1815 c = TOUPPER_ASC(c); | |
1816 } | |
1817 else | |
1818 c = TOLOWER_ASC(c); | |
1819 #endif | |
1820 switch (c) | |
1821 { | |
1822 case NUL: /* "vim -" read from stdin */ | |
1823 /* "ex -" silent mode */ | |
1824 if (exmode_active) | |
1825 silent_mode = TRUE; | |
1826 else | |
1827 { | |
1828 if (parmp->edit_type != EDIT_NONE) | |
1829 mainerr(ME_TOO_MANY_ARGS, (char_u *)argv[0]); | |
1830 parmp->edit_type = EDIT_STDIN; | |
1831 read_cmd_fd = 2; /* read from stderr instead of stdin */ | |
1832 } | |
1833 argv_idx = -1; /* skip to next argument */ | |
1834 break; | |
1835 | |
1836 case '-': /* "--" don't take any more option arguments */ | |
1837 /* "--help" give help message */ | |
1838 /* "--version" give version message */ | |
1839 /* "--literal" take files literally */ | |
1840 /* "--nofork" don't fork */ | |
1841 /* "--noplugin[s]" skip plugins */ | |
1842 /* "--cmd <cmd>" execute cmd before vimrc */ | |
1843 if (STRICMP(argv[0] + argv_idx, "help") == 0) | |
1844 usage(); | |
1845 else if (STRICMP(argv[0] + argv_idx, "version") == 0) | |
1846 { | |
1847 Columns = 80; /* need to init Columns */ | |
1848 info_message = TRUE; /* use mch_msg(), not mch_errmsg() */ | |
1849 list_version(); | |
1850 msg_putchar('\n'); | |
1851 msg_didout = FALSE; | |
1852 mch_exit(0); | |
1853 } | |
1854 else if (STRNICMP(argv[0] + argv_idx, "literal", 7) == 0) | |
1855 { | |
1856 #if (!defined(UNIX) && !defined(__EMX__)) || defined(ARCHIE) | |
1857 parmp->literal = TRUE; | |
1858 #endif | |
1859 } | |
1860 else if (STRNICMP(argv[0] + argv_idx, "nofork", 6) == 0) | |
1861 { | |
1862 #ifdef FEAT_GUI | |
1863 gui.dofork = FALSE; /* don't fork() when starting GUI */ | |
1864 #endif | |
1865 } | |
1866 else if (STRNICMP(argv[0] + argv_idx, "noplugin", 8) == 0) | |
1867 p_lpl = FALSE; | |
1868 else if (STRNICMP(argv[0] + argv_idx, "cmd", 3) == 0) | |
1869 { | |
1870 want_argument = TRUE; | |
1871 argv_idx += 3; | |
1872 } | |
1989 | 1873 else if (STRNICMP(argv[0] + argv_idx, "startuptime", 11) == 0) |
1874 { | |
1875 want_argument = TRUE; | |
1876 argv_idx += 11; | |
1877 } | |
443 | 1878 #ifdef FEAT_CLIENTSERVER |
1879 else if (STRNICMP(argv[0] + argv_idx, "serverlist", 10) == 0) | |
1880 ; /* already processed -- no arg */ | |
1881 else if (STRNICMP(argv[0] + argv_idx, "servername", 10) == 0 | |
1882 || STRNICMP(argv[0] + argv_idx, "serversend", 10) == 0) | |
1883 { | |
1884 /* already processed -- snatch the following arg */ | |
1885 if (argc > 1) | |
1886 { | |
1887 --argc; | |
1888 ++argv; | |
1889 } | |
1890 } | |
1891 #endif | |
1376 | 1892 #if defined(FEAT_GUI_GTK) || defined(FEAT_GUI_W32) |
1893 # ifdef FEAT_GUI_GTK | |
443 | 1894 else if (STRNICMP(argv[0] + argv_idx, "socketid", 8) == 0) |
1376 | 1895 # else |
1896 else if (STRNICMP(argv[0] + argv_idx, "windowid", 8) == 0) | |
1897 # endif | |
443 | 1898 { |
1899 /* already processed -- snatch the following arg */ | |
1900 if (argc > 1) | |
1901 { | |
1902 --argc; | |
1903 ++argv; | |
1904 } | |
1905 } | |
1376 | 1906 #endif |
1907 #ifdef FEAT_GUI_GTK | |
443 | 1908 else if (STRNICMP(argv[0] + argv_idx, "echo-wid", 8) == 0) |
1909 { | |
1910 /* already processed, skip */ | |
1911 } | |
1912 #endif | |
1913 else | |
1914 { | |
1915 if (argv[0][argv_idx]) | |
1916 mainerr(ME_UNKNOWN_OPTION, (char_u *)argv[0]); | |
1917 had_minmin = TRUE; | |
1918 } | |
1919 if (!want_argument) | |
1920 argv_idx = -1; /* skip to next argument */ | |
1921 break; | |
1922 | |
1923 case 'A': /* "-A" start in Arabic mode */ | |
1924 #ifdef FEAT_ARABIC | |
1925 set_option_value((char_u *)"arabic", 1L, NULL, 0); | |
1926 #else | |
1927 mch_errmsg(_(e_noarabic)); | |
1928 mch_exit(2); | |
1929 #endif | |
1930 break; | |
1931 | |
1932 case 'b': /* "-b" binary mode */ | |
445 | 1933 /* Needs to be effective before expanding file names, because |
1934 * for Win32 this makes us edit a shortcut file itself, | |
1935 * instead of the file it links to. */ | |
1936 set_options_bin(curbuf->b_p_bin, 1, 0); | |
1937 curbuf->b_p_bin = 1; /* binary file I/O */ | |
443 | 1938 break; |
1939 | |
1940 case 'C': /* "-C" Compatible */ | |
1941 change_compatible(TRUE); | |
1942 break; | |
1943 | |
1944 case 'e': /* "-e" Ex mode */ | |
1945 exmode_active = EXMODE_NORMAL; | |
1946 break; | |
1947 | |
1948 case 'E': /* "-E" Improved Ex mode */ | |
1949 exmode_active = EXMODE_VIM; | |
1950 break; | |
1951 | |
1952 case 'f': /* "-f" GUI: run in foreground. Amiga: open | |
1953 window directly, not with newcli */ | |
1954 #ifdef FEAT_GUI | |
1955 gui.dofork = FALSE; /* don't fork() when starting GUI */ | |
1956 #endif | |
1957 break; | |
1958 | |
1959 case 'g': /* "-g" start GUI */ | |
1960 main_start_gui(); | |
1961 break; | |
1962 | |
1963 case 'F': /* "-F" start in Farsi mode: rl + fkmap set */ | |
1964 #ifdef FEAT_FKMAP | |
1509 | 1965 p_fkmap = TRUE; |
1966 set_option_value((char_u *)"rl", 1L, NULL, 0); | |
443 | 1967 #else |
1968 mch_errmsg(_(e_nofarsi)); | |
1969 mch_exit(2); | |
1970 #endif | |
1971 break; | |
1972 | |
1973 case 'h': /* "-h" give help message */ | |
1974 #ifdef FEAT_GUI_GNOME | |
1975 /* Tell usage() to exit for "gvim". */ | |
1976 gui.starting = FALSE; | |
1977 #endif | |
1978 usage(); | |
1979 break; | |
1980 | |
1981 case 'H': /* "-H" start in Hebrew mode: rl + hkmap set */ | |
1982 #ifdef FEAT_RIGHTLEFT | |
1509 | 1983 p_hkmap = TRUE; |
1984 set_option_value((char_u *)"rl", 1L, NULL, 0); | |
443 | 1985 #else |
1986 mch_errmsg(_(e_nohebrew)); | |
1987 mch_exit(2); | |
1988 #endif | |
1989 break; | |
1990 | |
1991 case 'l': /* "-l" lisp mode, 'lisp' and 'showmatch' on */ | |
1992 #ifdef FEAT_LISP | |
1993 set_option_value((char_u *)"lisp", 1L, NULL, 0); | |
1994 p_sm = TRUE; | |
1995 #endif | |
1996 break; | |
1997 | |
1998 case 'M': /* "-M" no changes or writing of files */ | |
1999 reset_modifiable(); | |
2000 /* FALLTHROUGH */ | |
2001 | |
2002 case 'm': /* "-m" no writing of files */ | |
2003 p_write = FALSE; | |
2004 break; | |
2005 | |
2006 case 'y': /* "-y" easy mode */ | |
2007 #ifdef FEAT_GUI | |
2008 gui.starting = TRUE; /* start GUI a bit later */ | |
2009 #endif | |
2010 parmp->evim_mode = TRUE; | |
2011 break; | |
2012 | |
2013 case 'N': /* "-N" Nocompatible */ | |
2014 change_compatible(FALSE); | |
2015 break; | |
2016 | |
2017 case 'n': /* "-n" no swap file */ | |
2209
d0ddf7ba1630
Included the patch to support netbeans in a terminal.
Bram Moolenaar <bram@vim.org>
parents:
2201
diff
changeset
|
2018 #ifdef FEAT_NETBEANS_INTG |
d0ddf7ba1630
Included the patch to support netbeans in a terminal.
Bram Moolenaar <bram@vim.org>
parents:
2201
diff
changeset
|
2019 /* checking for "-nb", netbeans parameters */ |
d0ddf7ba1630
Included the patch to support netbeans in a terminal.
Bram Moolenaar <bram@vim.org>
parents:
2201
diff
changeset
|
2020 if (argv[0][argv_idx] == 'b') |
d0ddf7ba1630
Included the patch to support netbeans in a terminal.
Bram Moolenaar <bram@vim.org>
parents:
2201
diff
changeset
|
2021 { |
d0ddf7ba1630
Included the patch to support netbeans in a terminal.
Bram Moolenaar <bram@vim.org>
parents:
2201
diff
changeset
|
2022 netbeansArg = argv[0]; |
d0ddf7ba1630
Included the patch to support netbeans in a terminal.
Bram Moolenaar <bram@vim.org>
parents:
2201
diff
changeset
|
2023 argv_idx = -1; /* skip to next argument */ |
d0ddf7ba1630
Included the patch to support netbeans in a terminal.
Bram Moolenaar <bram@vim.org>
parents:
2201
diff
changeset
|
2024 } |
d0ddf7ba1630
Included the patch to support netbeans in a terminal.
Bram Moolenaar <bram@vim.org>
parents:
2201
diff
changeset
|
2025 else |
d0ddf7ba1630
Included the patch to support netbeans in a terminal.
Bram Moolenaar <bram@vim.org>
parents:
2201
diff
changeset
|
2026 #endif |
443 | 2027 parmp->no_swap_file = TRUE; |
2028 break; | |
2029 | |
673 | 2030 case 'p': /* "-p[N]" open N tab pages */ |
674 | 2031 #ifdef TARGET_API_MAC_OSX |
2032 /* For some reason on MacOS X, an argument like: | |
2033 -psn_0_10223617 is passed in when invoke from Finder | |
2034 or with the 'open' command */ | |
2035 if (argv[0][argv_idx] == 's') | |
2036 { | |
2037 argv_idx = -1; /* bypass full -psn */ | |
2038 main_start_gui(); | |
2039 break; | |
2040 } | |
2041 #endif | |
673 | 2042 #ifdef FEAT_WINDOWS |
2043 /* default is 0: open window for each file */ | |
2044 parmp->window_count = get_number_arg((char_u *)argv[0], | |
2045 &argv_idx, 0); | |
2046 parmp->window_layout = WIN_TABS; | |
2047 #endif | |
2048 break; | |
2049 | |
443 | 2050 case 'o': /* "-o[N]" open N horizontal split windows */ |
2051 #ifdef FEAT_WINDOWS | |
2052 /* default is 0: open window for each file */ | |
445 | 2053 parmp->window_count = get_number_arg((char_u *)argv[0], |
2054 &argv_idx, 0); | |
673 | 2055 parmp->window_layout = WIN_HOR; |
443 | 2056 #endif |
2057 break; | |
2058 | |
2059 case 'O': /* "-O[N]" open N vertical split windows */ | |
2060 #if defined(FEAT_VERTSPLIT) && defined(FEAT_WINDOWS) | |
2061 /* default is 0: open window for each file */ | |
445 | 2062 parmp->window_count = get_number_arg((char_u *)argv[0], |
2063 &argv_idx, 0); | |
673 | 2064 parmp->window_layout = WIN_VER; |
443 | 2065 #endif |
2066 break; | |
2067 | |
2068 #ifdef FEAT_QUICKFIX | |
2069 case 'q': /* "-q" QuickFix mode */ | |
2070 if (parmp->edit_type != EDIT_NONE) | |
2071 mainerr(ME_TOO_MANY_ARGS, (char_u *)argv[0]); | |
2072 parmp->edit_type = EDIT_QF; | |
2073 if (argv[0][argv_idx]) /* "-q{errorfile}" */ | |
2074 { | |
2075 parmp->use_ef = (char_u *)argv[0] + argv_idx; | |
2076 argv_idx = -1; | |
2077 } | |
2078 else if (argc > 1) /* "-q {errorfile}" */ | |
2079 want_argument = TRUE; | |
2080 break; | |
2081 #endif | |
2082 | |
2083 case 'R': /* "-R" readonly mode */ | |
2084 readonlymode = TRUE; | |
2085 curbuf->b_p_ro = TRUE; | |
2086 p_uc = 10000; /* don't update very often */ | |
2087 break; | |
2088 | |
2089 case 'r': /* "-r" recovery mode */ | |
2090 case 'L': /* "-L" recovery mode */ | |
2091 recoverymode = 1; | |
2092 break; | |
2093 | |
2094 case 's': | |
2095 if (exmode_active) /* "-s" silent (batch) mode */ | |
2096 silent_mode = TRUE; | |
2097 else /* "-s {scriptin}" read from script file */ | |
2098 want_argument = TRUE; | |
2099 break; | |
2100 | |
2101 case 't': /* "-t {tag}" or "-t{tag}" jump to tag */ | |
2102 if (parmp->edit_type != EDIT_NONE) | |
2103 mainerr(ME_TOO_MANY_ARGS, (char_u *)argv[0]); | |
2104 parmp->edit_type = EDIT_TAG; | |
2105 if (argv[0][argv_idx]) /* "-t{tag}" */ | |
2106 { | |
2107 parmp->tagname = (char_u *)argv[0] + argv_idx; | |
2108 argv_idx = -1; | |
2109 } | |
2110 else /* "-t {tag}" */ | |
2111 want_argument = TRUE; | |
2112 break; | |
2113 | |
2114 #ifdef FEAT_EVAL | |
2115 case 'D': /* "-D" Debugging */ | |
2116 parmp->use_debug_break_level = 9999; | |
2117 break; | |
2118 #endif | |
2119 #ifdef FEAT_DIFF | |
2120 case 'd': /* "-d" 'diff' */ | |
2121 # ifdef AMIGA | |
2122 /* check for "-dev {device}" */ | |
2123 if (argv[0][argv_idx] == 'e' && argv[0][argv_idx + 1] == 'v') | |
2124 want_argument = TRUE; | |
2125 else | |
2126 # endif | |
2127 parmp->diff_mode = TRUE; | |
2128 break; | |
2129 #endif | |
2130 case 'V': /* "-V{N}" Verbose level */ | |
2131 /* default is 10: a little bit verbose */ | |
2132 p_verbose = get_number_arg((char_u *)argv[0], &argv_idx, 10); | |
2133 if (argv[0][argv_idx] != NUL) | |
2134 { | |
2135 set_option_value((char_u *)"verbosefile", 0L, | |
2136 (char_u *)argv[0] + argv_idx, 0); | |
835 | 2137 argv_idx = (int)STRLEN(argv[0]); |
443 | 2138 } |
2139 break; | |
2140 | |
2141 case 'v': /* "-v" Vi-mode (as if called "vi") */ | |
2142 exmode_active = 0; | |
2143 #ifdef FEAT_GUI | |
2144 gui.starting = FALSE; /* don't start GUI */ | |
2145 #endif | |
2146 break; | |
2147 | |
2148 case 'w': /* "-w{number}" set window height */ | |
2149 /* "-w {scriptout}" write to script */ | |
2150 if (vim_isdigit(((char_u *)argv[0])[argv_idx])) | |
2151 { | |
2152 n = get_number_arg((char_u *)argv[0], &argv_idx, 10); | |
2153 set_option_value((char_u *)"window", n, NULL, 0); | |
2154 break; | |
2155 } | |
2156 want_argument = TRUE; | |
2157 break; | |
2158 | |
2159 #ifdef FEAT_CRYPT | |
2160 case 'x': /* "-x" encrypted reading/writing of files */ | |
2161 parmp->ask_for_key = TRUE; | |
2162 break; | |
2163 #endif | |
2164 | |
2165 case 'X': /* "-X" don't connect to X server */ | |
2166 #if (defined(UNIX) || defined(VMS)) && defined(FEAT_X11) | |
2167 x_no_connect = TRUE; | |
2168 #endif | |
2169 break; | |
2170 | |
2171 case 'Z': /* "-Z" restricted mode */ | |
2172 restricted = TRUE; | |
2173 break; | |
2174 | |
2175 case 'c': /* "-c{command}" or "-c {command}" execute | |
2176 command */ | |
2177 if (argv[0][argv_idx] != NUL) | |
2178 { | |
2179 if (parmp->n_commands >= MAX_ARG_CMDS) | |
2180 mainerr(ME_EXTRA_CMD, NULL); | |
445 | 2181 parmp->commands[parmp->n_commands++] = (char_u *)argv[0] |
2182 + argv_idx; | |
443 | 2183 argv_idx = -1; |
2184 break; | |
2185 } | |
2186 /*FALLTHROUGH*/ | |
2187 case 'S': /* "-S {file}" execute Vim script */ | |
2188 case 'i': /* "-i {viminfo}" use for viminfo */ | |
2189 #ifndef FEAT_DIFF | |
2190 case 'd': /* "-d {device}" device (for Amiga) */ | |
2191 #endif | |
2192 case 'T': /* "-T {terminal}" terminal name */ | |
2193 case 'u': /* "-u {vimrc}" vim inits file */ | |
2194 case 'U': /* "-U {gvimrc}" gvim inits file */ | |
2195 case 'W': /* "-W {scriptout}" overwrite */ | |
2196 #ifdef FEAT_GUI_W32 | |
2197 case 'P': /* "-P {parent title}" MDI parent */ | |
2198 #endif | |
2199 want_argument = TRUE; | |
2200 break; | |
2201 | |
2202 default: | |
2203 mainerr(ME_UNKNOWN_OPTION, (char_u *)argv[0]); | |
2204 } | |
2205 | |
2206 /* | |
2207 * Handle option arguments with argument. | |
2208 */ | |
2209 if (want_argument) | |
2210 { | |
2211 /* | |
2212 * Check for garbage immediately after the option letter. | |
2213 */ | |
2214 if (argv[0][argv_idx] != NUL) | |
2215 mainerr(ME_GARBAGE, (char_u *)argv[0]); | |
2216 | |
2217 --argc; | |
1989 | 2218 if (argc < 1 && c != 'S') /* -S has an optional argument */ |
443 | 2219 mainerr_arg_missing((char_u *)argv[0]); |
2220 ++argv; | |
2221 argv_idx = -1; | |
2222 | |
2223 switch (c) | |
2224 { | |
2225 case 'c': /* "-c {command}" execute command */ | |
2226 case 'S': /* "-S {file}" execute Vim script */ | |
2227 if (parmp->n_commands >= MAX_ARG_CMDS) | |
2228 mainerr(ME_EXTRA_CMD, NULL); | |
2229 if (c == 'S') | |
2230 { | |
2231 char *a; | |
2232 | |
2233 if (argc < 1) | |
2234 /* "-S" without argument: use default session file | |
2235 * name. */ | |
2236 a = SESSION_FILE; | |
2237 else if (argv[0][0] == '-') | |
2238 { | |
2239 /* "-S" followed by another option: use default | |
2240 * session file name. */ | |
2241 a = SESSION_FILE; | |
2242 ++argc; | |
2243 --argv; | |
2244 } | |
2245 else | |
2246 a = argv[0]; | |
2247 p = alloc((unsigned)(STRLEN(a) + 4)); | |
2248 if (p == NULL) | |
2249 mch_exit(2); | |
2250 sprintf((char *)p, "so %s", a); | |
2251 parmp->cmds_tofree[parmp->n_commands] = TRUE; | |
2252 parmp->commands[parmp->n_commands++] = p; | |
2253 } | |
2254 else | |
445 | 2255 parmp->commands[parmp->n_commands++] = |
2256 (char_u *)argv[0]; | |
443 | 2257 break; |
2258 | |
1989 | 2259 case '-': |
2260 if (argv[-1][2] == 'c') | |
2261 { | |
2262 /* "--cmd {command}" execute command */ | |
2263 if (parmp->n_pre_commands >= MAX_ARG_CMDS) | |
2264 mainerr(ME_EXTRA_CMD, NULL); | |
2265 parmp->pre_commands[parmp->n_pre_commands++] = | |
445 | 2266 (char_u *)argv[0]; |
1989 | 2267 } |
2268 /* "--startuptime <file>" already handled */ | |
443 | 2269 break; |
2270 | |
2271 /* case 'd': -d {device} is handled in mch_check_win() for the | |
2272 * Amiga */ | |
2273 | |
2274 #ifdef FEAT_QUICKFIX | |
2275 case 'q': /* "-q {errorfile}" QuickFix mode */ | |
2276 parmp->use_ef = (char_u *)argv[0]; | |
2277 break; | |
2278 #endif | |
2279 | |
2280 case 'i': /* "-i {viminfo}" use for viminfo */ | |
2281 use_viminfo = (char_u *)argv[0]; | |
2282 break; | |
2283 | |
2284 case 's': /* "-s {scriptin}" read from script file */ | |
2285 if (scriptin[0] != NULL) | |
2286 { | |
2287 scripterror: | |
2288 mch_errmsg(_("Attempt to open script file again: \"")); | |
2289 mch_errmsg(argv[-1]); | |
2290 mch_errmsg(" "); | |
2291 mch_errmsg(argv[0]); | |
2292 mch_errmsg("\"\n"); | |
2293 mch_exit(2); | |
2294 } | |
2295 if ((scriptin[0] = mch_fopen(argv[0], READBIN)) == NULL) | |
2296 { | |
2297 mch_errmsg(_("Cannot open for reading: \"")); | |
2298 mch_errmsg(argv[0]); | |
2299 mch_errmsg("\"\n"); | |
2300 mch_exit(2); | |
2301 } | |
2302 if (save_typebuf() == FAIL) | |
2303 mch_exit(2); /* out of memory */ | |
2304 break; | |
2305 | |
2306 case 't': /* "-t {tag}" */ | |
2307 parmp->tagname = (char_u *)argv[0]; | |
2308 break; | |
2309 | |
2310 case 'T': /* "-T {terminal}" terminal name */ | |
2311 /* | |
2312 * The -T term argument is always available and when | |
2313 * HAVE_TERMLIB is supported it overrides the environment | |
2314 * variable TERM. | |
2315 */ | |
2316 #ifdef FEAT_GUI | |
2317 if (term_is_gui((char_u *)argv[0])) | |
2318 gui.starting = TRUE; /* start GUI a bit later */ | |
2319 else | |
2320 #endif | |
2321 parmp->term = (char_u *)argv[0]; | |
2322 break; | |
2323 | |
2324 case 'u': /* "-u {vimrc}" vim inits file */ | |
2325 parmp->use_vimrc = (char_u *)argv[0]; | |
2326 break; | |
2327 | |
2328 case 'U': /* "-U {gvimrc}" gvim inits file */ | |
2329 #ifdef FEAT_GUI | |
2330 use_gvimrc = (char_u *)argv[0]; | |
2331 #endif | |
2332 break; | |
2333 | |
2334 case 'w': /* "-w {nr}" 'window' value */ | |
2335 /* "-w {scriptout}" append to script file */ | |
2336 if (vim_isdigit(*((char_u *)argv[0]))) | |
2337 { | |
2338 argv_idx = 0; | |
2339 n = get_number_arg((char_u *)argv[0], &argv_idx, 10); | |
2340 set_option_value((char_u *)"window", n, NULL, 0); | |
2341 argv_idx = -1; | |
2342 break; | |
2343 } | |
2344 /*FALLTHROUGH*/ | |
2345 case 'W': /* "-W {scriptout}" overwrite script file */ | |
2346 if (scriptout != NULL) | |
2347 goto scripterror; | |
2348 if ((scriptout = mch_fopen(argv[0], | |
2349 c == 'w' ? APPENDBIN : WRITEBIN)) == NULL) | |
2350 { | |
2351 mch_errmsg(_("Cannot open for script output: \"")); | |
2352 mch_errmsg(argv[0]); | |
2353 mch_errmsg("\"\n"); | |
2354 mch_exit(2); | |
2355 } | |
2356 break; | |
2357 | |
2358 #ifdef FEAT_GUI_W32 | |
2359 case 'P': /* "-P {parent title}" MDI parent */ | |
2360 gui_mch_set_parent(argv[0]); | |
2361 break; | |
2362 #endif | |
2363 } | |
2364 } | |
2365 } | |
2366 | |
2367 /* | |
2368 * File name argument. | |
2369 */ | |
2370 else | |
2371 { | |
2372 argv_idx = -1; /* skip to next argument */ | |
2373 | |
2374 /* Check for only one type of editing. */ | |
2375 if (parmp->edit_type != EDIT_NONE && parmp->edit_type != EDIT_FILE) | |
2376 mainerr(ME_TOO_MANY_ARGS, (char_u *)argv[0]); | |
2377 parmp->edit_type = EDIT_FILE; | |
2378 | |
2379 #ifdef MSWIN | |
2380 /* Remember if the argument was a full path before changing | |
2381 * slashes to backslashes. */ | |
2382 if (argv[0][0] != NUL && argv[0][1] == ':' && argv[0][2] == '\\') | |
2383 parmp->full_path = TRUE; | |
2384 #endif | |
2385 | |
2386 /* Add the file to the global argument list. */ | |
2387 if (ga_grow(&global_alist.al_ga, 1) == FAIL | |
2388 || (p = vim_strsave((char_u *)argv[0])) == NULL) | |
2389 mch_exit(2); | |
2390 #ifdef FEAT_DIFF | |
2391 if (parmp->diff_mode && mch_isdir(p) && GARGCOUNT > 0 | |
2392 && !mch_isdir(alist_name(&GARGLIST[0]))) | |
2393 { | |
2394 char_u *r; | |
2395 | |
2396 r = concat_fnames(p, gettail(alist_name(&GARGLIST[0])), TRUE); | |
2397 if (r != NULL) | |
2398 { | |
2399 vim_free(p); | |
2400 p = r; | |
2401 } | |
2402 } | |
2403 #endif | |
2404 #if defined(__CYGWIN32__) && !defined(WIN32) | |
2405 /* | |
2406 * If vim is invoked by non-Cygwin tools, convert away any | |
2407 * DOS paths, so things like .swp files are created correctly. | |
2408 * Look for evidence of non-Cygwin paths before we bother. | |
2409 * This is only for when using the Unix files. | |
2410 */ | |
5037
5e0b6a9282df
updated for version 7.3.1262
Bram Moolenaar <bram@vim.org>
parents:
4912
diff
changeset
|
2411 if (vim_strpbrk(p, "\\:") != NULL && !path_with_url(p)) |
443 | 2412 { |
2413 char posix_path[PATH_MAX]; | |
2414 | |
1657 | 2415 # if CYGWIN_VERSION_DLL_MAJOR >= 1007 |
2416 cygwin_conv_path(CCP_WIN_A_TO_POSIX, p, posix_path, PATH_MAX); | |
2417 # else | |
443 | 2418 cygwin_conv_to_posix_path(p, posix_path); |
1657 | 2419 # endif |
443 | 2420 vim_free(p); |
5037
5e0b6a9282df
updated for version 7.3.1262
Bram Moolenaar <bram@vim.org>
parents:
4912
diff
changeset
|
2421 p = vim_strsave((char_u *)posix_path); |
443 | 2422 if (p == NULL) |
2423 mch_exit(2); | |
2424 } | |
2425 #endif | |
587 | 2426 |
2427 #ifdef USE_FNAME_CASE | |
2428 /* Make the case of the file name match the actual file. */ | |
2429 fname_case(p, 0); | |
2430 #endif | |
2431 | |
443 | 2432 alist_add(&global_alist, p, |
2433 #if (!defined(UNIX) && !defined(__EMX__)) || defined(ARCHIE) | |
445 | 2434 parmp->literal ? 2 : 0 /* add buffer nr after exp. */ |
443 | 2435 #else |
2436 2 /* add buffer number now and use curbuf */ | |
2437 #endif | |
2438 ); | |
2439 | |
2440 #if defined(FEAT_MBYTE) && defined(WIN32) | |
2441 { | |
2442 /* Remember this argument has been added to the argument list. | |
2443 * Needed when 'encoding' is changed. */ | |
819 | 2444 used_file_arg(argv[0], parmp->literal, parmp->full_path, |
1680 | 2445 # ifdef FEAT_DIFF |
2446 parmp->diff_mode | |
2447 # else | |
2448 FALSE | |
2449 # endif | |
2450 ); | |
443 | 2451 } |
2452 #endif | |
2453 } | |
2454 | |
2455 /* | |
2456 * If there are no more letters after the current "-", go to next | |
2457 * argument. argv_idx is set to -1 when the current argument is to be | |
2458 * skipped. | |
2459 */ | |
2460 if (argv_idx <= 0 || argv[0][argv_idx] == NUL) | |
2461 { | |
2462 --argc; | |
2463 ++argv; | |
2464 argv_idx = 1; | |
2465 } | |
2466 } | |
1093 | 2467 |
2468 #ifdef FEAT_EVAL | |
2469 /* If there is a "+123" or "-c" command, set v:swapcommand to the first | |
2470 * one. */ | |
2471 if (parmp->n_commands > 0) | |
2472 { | |
2473 p = alloc((unsigned)STRLEN(parmp->commands[0]) + 3); | |
2474 if (p != NULL) | |
2475 { | |
2476 sprintf((char *)p, ":%s\r", parmp->commands[0]); | |
2477 set_vim_var_string(VV_SWAPCOMMAND, p, -1); | |
2478 vim_free(p); | |
2479 } | |
2480 } | |
2481 #endif | |
443 | 2482 } |
2483 | |
2484 /* | |
2485 * Print a warning if stdout is not a terminal. | |
2486 * When starting in Ex mode and commands come from a file, set Silent mode. | |
2487 */ | |
2488 static void | |
2489 check_tty(parmp) | |
2490 mparm_T *parmp; | |
2491 { | |
2492 int input_isatty; /* is active input a terminal? */ | |
2493 | |
2494 input_isatty = mch_input_isatty(); | |
2495 if (exmode_active) | |
2496 { | |
2497 if (!input_isatty) | |
2498 silent_mode = TRUE; | |
2499 } | |
2500 else if (parmp->want_full_screen && (!parmp->stdout_isatty || !input_isatty) | |
2501 #ifdef FEAT_GUI | |
2502 /* don't want the delay when started from the desktop */ | |
2503 && !gui.starting | |
2504 #endif | |
2505 ) | |
2506 { | |
2507 #ifdef NBDEBUG | |
2508 /* | |
2509 * This shouldn't be necessary. But if I run netbeans with the log | |
2510 * output coming to the console and XOpenDisplay fails, I get vim | |
2511 * trying to start with input/output to my console tty. This fills my | |
2512 * input buffer so fast I can't even kill the process in under 2 | |
1226 | 2513 * minutes (and it beeps continuously the whole time :-) |
443 | 2514 */ |
2210 | 2515 if (netbeans_active() && (!parmp->stdout_isatty || !input_isatty)) |
443 | 2516 { |
2517 mch_errmsg(_("Vim: Error: Failure to start gvim from NetBeans\n")); | |
2518 exit(1); | |
2519 } | |
2520 #endif | |
2521 if (!parmp->stdout_isatty) | |
2522 mch_errmsg(_("Vim: Warning: Output is not to a terminal\n")); | |
2523 if (!input_isatty) | |
2524 mch_errmsg(_("Vim: Warning: Input is not from a terminal\n")); | |
2525 out_flush(); | |
2526 if (scriptin[0] == NULL) | |
2527 ui_delay(2000L, TRUE); | |
2528 TIME_MSG("Warning delay"); | |
2529 } | |
2530 } | |
2531 | |
2532 /* | |
2533 * Read text from stdin. | |
2534 */ | |
2535 static void | |
2536 read_stdin() | |
2537 { | |
2538 int i; | |
2539 | |
580 | 2540 #if defined(HAS_SWAP_EXISTS_ACTION) |
443 | 2541 /* When getting the ATTENTION prompt here, use a dialog */ |
2542 swap_exists_action = SEA_DIALOG; | |
2543 #endif | |
2544 no_wait_return = TRUE; | |
2545 i = msg_didany; | |
2546 set_buflisted(TRUE); | |
2394
a3aca345aafa
Add the 'undoreload' option to be able to undo a file reload.
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
2547 (void)open_buffer(TRUE, NULL, 0); /* create memfile and read file */ |
443 | 2548 no_wait_return = FALSE; |
2549 msg_didany = i; | |
2550 TIME_MSG("reading stdin"); | |
580 | 2551 #if defined(HAS_SWAP_EXISTS_ACTION) |
443 | 2552 check_swap_exists_action(); |
2553 #endif | |
2554 #if !(defined(AMIGA) || defined(MACOS)) | |
2555 /* | |
2556 * Close stdin and dup it from stderr. Required for GPM to work | |
2557 * properly, and for running external commands. | |
2558 * Is there any other system that cannot do this? | |
2559 */ | |
2560 close(0); | |
1757 | 2561 ignored = dup(2); |
443 | 2562 #endif |
2563 } | |
2564 | |
2565 /* | |
2566 * Create the requested number of windows and edit buffers in them. | |
2567 * Also does recovery if "recoverymode" set. | |
2568 */ | |
2569 static void | |
2570 create_windows(parmp) | |
1883 | 2571 mparm_T *parmp UNUSED; |
443 | 2572 { |
2573 #ifdef FEAT_WINDOWS | |
944 | 2574 int dorewind; |
673 | 2575 int done = 0; |
2576 | |
443 | 2577 /* |
2578 * Create the number of windows that was requested. | |
2579 */ | |
2580 if (parmp->window_count == -1) /* was not set */ | |
2581 parmp->window_count = 1; | |
2582 if (parmp->window_count == 0) | |
2583 parmp->window_count = GARGCOUNT; | |
2584 if (parmp->window_count > 1) | |
2585 { | |
2586 /* Don't change the windows if there was a command in .vimrc that | |
2587 * already split some windows */ | |
673 | 2588 if (parmp->window_layout == 0) |
2589 parmp->window_layout = WIN_HOR; | |
2590 if (parmp->window_layout == WIN_TABS) | |
2591 { | |
2592 parmp->window_count = make_tabpages(parmp->window_count); | |
2593 TIME_MSG("making tab pages"); | |
2594 } | |
2595 else if (firstwin->w_next == NULL) | |
443 | 2596 { |
2597 parmp->window_count = make_windows(parmp->window_count, | |
673 | 2598 parmp->window_layout == WIN_VER); |
443 | 2599 TIME_MSG("making windows"); |
2600 } | |
2601 else | |
2602 parmp->window_count = win_count(); | |
2603 } | |
2604 else | |
2605 parmp->window_count = 1; | |
2606 #endif | |
2607 | |
2608 if (recoverymode) /* do recover */ | |
2609 { | |
2610 msg_scroll = TRUE; /* scroll message up */ | |
2611 ml_recover(); | |
2612 if (curbuf->b_ml.ml_mfp == NULL) /* failed */ | |
2613 getout(1); | |
717 | 2614 do_modelines(0); /* do modelines */ |
443 | 2615 } |
2616 else | |
2617 { | |
2618 /* | |
2619 * Open a buffer for windows that don't have one yet. | |
2620 * Commands in the .vimrc might have loaded a file or split the window. | |
2621 * Watch out for autocommands that delete a window. | |
2622 */ | |
2623 #ifdef FEAT_AUTOCMD | |
2624 /* | |
2625 * Don't execute Win/Buf Enter/Leave autocommands here | |
2626 */ | |
2627 ++autocmd_no_enter; | |
2628 ++autocmd_no_leave; | |
2629 #endif | |
2630 #ifdef FEAT_WINDOWS | |
944 | 2631 dorewind = TRUE; |
673 | 2632 while (done++ < 1000) |
2633 { | |
944 | 2634 if (dorewind) |
673 | 2635 { |
2636 if (parmp->window_layout == WIN_TABS) | |
2637 goto_tabpage(1); | |
2638 else | |
2639 curwin = firstwin; | |
2640 } | |
2641 else if (parmp->window_layout == WIN_TABS) | |
2642 { | |
2643 if (curtab->tp_next == NULL) | |
2644 break; | |
2645 goto_tabpage(0); | |
2646 } | |
2647 else | |
2648 { | |
2649 if (curwin->w_next == NULL) | |
2650 break; | |
2651 curwin = curwin->w_next; | |
2652 } | |
944 | 2653 dorewind = FALSE; |
443 | 2654 #endif |
2655 curbuf = curwin->w_buffer; | |
2656 if (curbuf->b_ml.ml_mfp == NULL) | |
2657 { | |
2658 #ifdef FEAT_FOLDING | |
2659 /* Set 'foldlevel' to 'foldlevelstart' if it's not negative. */ | |
2660 if (p_fdls >= 0) | |
2661 curwin->w_p_fdl = p_fdls; | |
2662 #endif | |
580 | 2663 #if defined(HAS_SWAP_EXISTS_ACTION) |
443 | 2664 /* When getting the ATTENTION prompt here, use a dialog */ |
2665 swap_exists_action = SEA_DIALOG; | |
2666 #endif | |
2667 set_buflisted(TRUE); | |
2394
a3aca345aafa
Add the 'undoreload' option to be able to undo a file reload.
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
2668 |
a3aca345aafa
Add the 'undoreload' option to be able to undo a file reload.
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
2669 /* create memfile, read file */ |
a3aca345aafa
Add the 'undoreload' option to be able to undo a file reload.
Bram Moolenaar <bram@vim.org>
parents:
2378
diff
changeset
|
2670 (void)open_buffer(FALSE, NULL, 0); |
443 | 2671 |
580 | 2672 #if defined(HAS_SWAP_EXISTS_ACTION) |
1036 | 2673 if (swap_exists_action == SEA_QUIT) |
2674 { | |
2675 if (got_int || only_one_window()) | |
2676 { | |
2677 /* abort selected or quit and only one window */ | |
2678 did_emsg = FALSE; /* avoid hit-enter prompt */ | |
2679 getout(1); | |
2680 } | |
2681 /* We can't close the window, it would disturb what | |
2682 * happens next. Clear the file name and set the arg | |
2683 * index to -1 to delete it later. */ | |
2684 setfname(curbuf, NULL, NULL, FALSE); | |
2685 curwin->w_arg_idx = -1; | |
2686 swap_exists_action = SEA_NONE; | |
2687 } | |
2688 else | |
2689 handle_swap_exists(NULL); | |
443 | 2690 #endif |
2691 #ifdef FEAT_AUTOCMD | |
944 | 2692 dorewind = TRUE; /* start again */ |
443 | 2693 #endif |
2694 } | |
2695 #ifdef FEAT_WINDOWS | |
2696 ui_breakcheck(); | |
2697 if (got_int) | |
2698 { | |
2699 (void)vgetc(); /* only break the file loading, not the rest */ | |
2700 break; | |
2701 } | |
673 | 2702 } |
443 | 2703 #endif |
673 | 2704 #ifdef FEAT_WINDOWS |
2705 if (parmp->window_layout == WIN_TABS) | |
2706 goto_tabpage(1); | |
2707 else | |
2708 curwin = firstwin; | |
2709 curbuf = curwin->w_buffer; | |
2710 #endif | |
443 | 2711 #ifdef FEAT_AUTOCMD |
2712 --autocmd_no_enter; | |
2713 --autocmd_no_leave; | |
2714 #endif | |
2715 } | |
2716 } | |
2717 | |
2718 #ifdef FEAT_WINDOWS | |
2719 /* | |
2720 * If opened more than one window, start editing files in the other | |
2721 * windows. make_windows() has already opened the windows. | |
2722 */ | |
2723 static void | |
2724 edit_buffers(parmp) | |
2725 mparm_T *parmp; | |
2726 { | |
2727 int arg_idx; /* index in argument list */ | |
2728 int i; | |
1036 | 2729 int advance = TRUE; |
443 | 2730 |
2731 # ifdef FEAT_AUTOCMD | |
2732 /* | |
2733 * Don't execute Win/Buf Enter/Leave autocommands here | |
2734 */ | |
2735 ++autocmd_no_enter; | |
2736 ++autocmd_no_leave; | |
2737 # endif | |
1036 | 2738 |
2739 /* When w_arg_idx is -1 remove the window (see create_windows()). */ | |
2740 if (curwin->w_arg_idx == -1) | |
2741 { | |
2742 win_close(curwin, TRUE); | |
2743 advance = FALSE; | |
2744 } | |
2745 | |
443 | 2746 arg_idx = 1; |
2747 for (i = 1; i < parmp->window_count; ++i) | |
2748 { | |
1036 | 2749 /* When w_arg_idx is -1 remove the window (see create_windows()). */ |
2750 if (curwin->w_arg_idx == -1) | |
673 | 2751 { |
1036 | 2752 ++arg_idx; |
2753 win_close(curwin, TRUE); | |
2754 advance = FALSE; | |
2755 continue; | |
673 | 2756 } |
1036 | 2757 |
2758 if (advance) | |
673 | 2759 { |
1036 | 2760 if (parmp->window_layout == WIN_TABS) |
2761 { | |
2762 if (curtab->tp_next == NULL) /* just checking */ | |
2763 break; | |
2764 goto_tabpage(0); | |
2765 } | |
2766 else | |
2767 { | |
2768 if (curwin->w_next == NULL) /* just checking */ | |
2769 break; | |
2770 win_enter(curwin->w_next, FALSE); | |
2771 } | |
673 | 2772 } |
1036 | 2773 advance = TRUE; |
443 | 2774 |
2775 /* Only open the file if there is no file in this window yet (that can | |
1036 | 2776 * happen when .vimrc contains ":sall"). */ |
443 | 2777 if (curbuf == firstwin->w_buffer || curbuf->b_ffname == NULL) |
2778 { | |
2779 curwin->w_arg_idx = arg_idx; | |
1036 | 2780 /* Edit file from arg list, if there is one. When "Quit" selected |
2781 * at the ATTENTION prompt close the window. */ | |
1684 | 2782 # ifdef HAS_SWAP_EXISTS_ACTION |
2783 swap_exists_did_quit = FALSE; | |
2784 # endif | |
443 | 2785 (void)do_ecmd(0, arg_idx < GARGCOUNT |
2786 ? alist_name(&GARGLIST[arg_idx]) : NULL, | |
1743 | 2787 NULL, NULL, ECMD_LASTL, ECMD_HIDE, curwin); |
1684 | 2788 # ifdef HAS_SWAP_EXISTS_ACTION |
2789 if (swap_exists_did_quit) | |
1036 | 2790 { |
1684 | 2791 /* abort or quit selected */ |
1036 | 2792 if (got_int || only_one_window()) |
2793 { | |
1684 | 2794 /* abort selected and only one window */ |
1036 | 2795 did_emsg = FALSE; /* avoid hit-enter prompt */ |
2796 getout(1); | |
2797 } | |
2798 win_close(curwin, TRUE); | |
2799 advance = FALSE; | |
2800 } | |
1684 | 2801 # endif |
443 | 2802 if (arg_idx == GARGCOUNT - 1) |
2803 arg_had_last = TRUE; | |
2804 ++arg_idx; | |
2805 } | |
2806 ui_breakcheck(); | |
2807 if (got_int) | |
2808 { | |
2809 (void)vgetc(); /* only break the file loading, not the rest */ | |
2810 break; | |
2811 } | |
2812 } | |
673 | 2813 |
2814 if (parmp->window_layout == WIN_TABS) | |
2815 goto_tabpage(1); | |
443 | 2816 # ifdef FEAT_AUTOCMD |
2817 --autocmd_no_enter; | |
2818 # endif | |
4912
d8f65e6238fa
updated for version 7.3.1201
Bram Moolenaar <bram@vim.org>
parents:
4863
diff
changeset
|
2819 #if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX) |
d8f65e6238fa
updated for version 7.3.1201
Bram Moolenaar <bram@vim.org>
parents:
4863
diff
changeset
|
2820 /* |
d8f65e6238fa
updated for version 7.3.1201
Bram Moolenaar <bram@vim.org>
parents:
4863
diff
changeset
|
2821 * Avoid making a preview window the current window. |
d8f65e6238fa
updated for version 7.3.1201
Bram Moolenaar <bram@vim.org>
parents:
4863
diff
changeset
|
2822 */ |
d8f65e6238fa
updated for version 7.3.1201
Bram Moolenaar <bram@vim.org>
parents:
4863
diff
changeset
|
2823 if (firstwin->w_p_pvw) |
d8f65e6238fa
updated for version 7.3.1201
Bram Moolenaar <bram@vim.org>
parents:
4863
diff
changeset
|
2824 { |
d8f65e6238fa
updated for version 7.3.1201
Bram Moolenaar <bram@vim.org>
parents:
4863
diff
changeset
|
2825 win_T *win; |
d8f65e6238fa
updated for version 7.3.1201
Bram Moolenaar <bram@vim.org>
parents:
4863
diff
changeset
|
2826 |
d8f65e6238fa
updated for version 7.3.1201
Bram Moolenaar <bram@vim.org>
parents:
4863
diff
changeset
|
2827 for (win = firstwin; win != NULL; win = win->w_next) |
d8f65e6238fa
updated for version 7.3.1201
Bram Moolenaar <bram@vim.org>
parents:
4863
diff
changeset
|
2828 if (!win->w_p_pvw) |
d8f65e6238fa
updated for version 7.3.1201
Bram Moolenaar <bram@vim.org>
parents:
4863
diff
changeset
|
2829 { |
d8f65e6238fa
updated for version 7.3.1201
Bram Moolenaar <bram@vim.org>
parents:
4863
diff
changeset
|
2830 firstwin = win; |
d8f65e6238fa
updated for version 7.3.1201
Bram Moolenaar <bram@vim.org>
parents:
4863
diff
changeset
|
2831 break; |
d8f65e6238fa
updated for version 7.3.1201
Bram Moolenaar <bram@vim.org>
parents:
4863
diff
changeset
|
2832 } |
d8f65e6238fa
updated for version 7.3.1201
Bram Moolenaar <bram@vim.org>
parents:
4863
diff
changeset
|
2833 } |
d8f65e6238fa
updated for version 7.3.1201
Bram Moolenaar <bram@vim.org>
parents:
4863
diff
changeset
|
2834 #endif |
d8f65e6238fa
updated for version 7.3.1201
Bram Moolenaar <bram@vim.org>
parents:
4863
diff
changeset
|
2835 /* make the first window the current window */ |
d8f65e6238fa
updated for version 7.3.1201
Bram Moolenaar <bram@vim.org>
parents:
4863
diff
changeset
|
2836 win_enter(firstwin, FALSE); |
d8f65e6238fa
updated for version 7.3.1201
Bram Moolenaar <bram@vim.org>
parents:
4863
diff
changeset
|
2837 |
443 | 2838 # ifdef FEAT_AUTOCMD |
2839 --autocmd_no_leave; | |
2840 # endif | |
2841 TIME_MSG("editing files in windows"); | |
673 | 2842 if (parmp->window_count > 1 && parmp->window_layout != WIN_TABS) |
443 | 2843 win_equal(curwin, FALSE, 'b'); /* adjust heights */ |
2844 } | |
2845 #endif /* FEAT_WINDOWS */ | |
2846 | |
2847 /* | |
440 | 2848 * Execute the commands from --cmd arguments "cmds[cnt]". |
2849 */ | |
2850 static void | |
443 | 2851 exe_pre_commands(parmp) |
2852 mparm_T *parmp; | |
440 | 2853 { |
443 | 2854 char_u **cmds = parmp->pre_commands; |
2855 int cnt = parmp->n_pre_commands; | |
440 | 2856 int i; |
2857 | |
2858 if (cnt > 0) | |
2859 { | |
2860 curwin->w_cursor.lnum = 0; /* just in case.. */ | |
2861 sourcing_name = (char_u *)_("pre-vimrc command line"); | |
2862 # ifdef FEAT_EVAL | |
2863 current_SID = SID_CMDARG; | |
2864 # endif | |
2865 for (i = 0; i < cnt; ++i) | |
2866 do_cmdline_cmd(cmds[i]); | |
2867 sourcing_name = NULL; | |
2868 # ifdef FEAT_EVAL | |
2869 current_SID = 0; | |
2870 # endif | |
2871 TIME_MSG("--cmd commands"); | |
2872 } | |
2873 } | |
2874 | |
2875 /* | |
443 | 2876 * Execute "+", "-c" and "-S" arguments. |
2877 */ | |
2878 static void | |
2879 exe_commands(parmp) | |
2880 mparm_T *parmp; | |
2881 { | |
2882 int i; | |
2883 | |
2884 /* | |
2885 * We start commands on line 0, make "vim +/pat file" match a | |
2886 * pattern on line 1. But don't move the cursor when an autocommand | |
2887 * with g`" was used. | |
2888 */ | |
2889 msg_scroll = TRUE; | |
2890 if (parmp->tagname == NULL && curwin->w_cursor.lnum <= 1) | |
2891 curwin->w_cursor.lnum = 0; | |
2892 sourcing_name = (char_u *)"command line"; | |
2893 #ifdef FEAT_EVAL | |
2894 current_SID = SID_CARG; | |
2895 #endif | |
2896 for (i = 0; i < parmp->n_commands; ++i) | |
2897 { | |
2898 do_cmdline_cmd(parmp->commands[i]); | |
2899 if (parmp->cmds_tofree[i]) | |
2900 vim_free(parmp->commands[i]); | |
2901 } | |
2902 sourcing_name = NULL; | |
2903 #ifdef FEAT_EVAL | |
2904 current_SID = 0; | |
2905 #endif | |
2906 if (curwin->w_cursor.lnum == 0) | |
2907 curwin->w_cursor.lnum = 1; | |
2908 | |
2909 if (!exmode_active) | |
2910 msg_scroll = FALSE; | |
2911 | |
2912 #ifdef FEAT_QUICKFIX | |
2913 /* When started with "-q errorfile" jump to first error again. */ | |
2914 if (parmp->edit_type == EDIT_QF) | |
644 | 2915 qf_jump(NULL, 0, 0, FALSE); |
443 | 2916 #endif |
2917 TIME_MSG("executing command arguments"); | |
2918 } | |
2919 | |
2920 /* | |
440 | 2921 * Source startup scripts. |
2922 */ | |
2923 static void | |
2924 source_startup_scripts(parmp) | |
2925 mparm_T *parmp; | |
2926 { | |
2927 int i; | |
2928 | |
2929 /* | |
2930 * For "evim" source evim.vim first of all, so that the user can overrule | |
2931 * any things he doesn't like. | |
2932 */ | |
2933 if (parmp->evim_mode) | |
2934 { | |
819 | 2935 (void)do_source((char_u *)EVIM_FILE, FALSE, DOSO_NONE); |
440 | 2936 TIME_MSG("source evim file"); |
2937 } | |
2938 | |
2939 /* | |
443 | 2940 * If -u argument given, use only the initializations from that file and |
440 | 2941 * nothing else. |
2942 */ | |
2943 if (parmp->use_vimrc != NULL) | |
2944 { | |
445 | 2945 if (STRCMP(parmp->use_vimrc, "NONE") == 0 |
2946 || STRCMP(parmp->use_vimrc, "NORC") == 0) | |
440 | 2947 { |
2948 #ifdef FEAT_GUI | |
2949 if (use_gvimrc == NULL) /* don't load gvimrc either */ | |
2950 use_gvimrc = parmp->use_vimrc; | |
2951 #endif | |
2952 if (parmp->use_vimrc[2] == 'N') | |
2953 p_lpl = FALSE; /* don't load plugins either */ | |
2954 } | |
2955 else | |
2956 { | |
819 | 2957 if (do_source(parmp->use_vimrc, FALSE, DOSO_NONE) != OK) |
440 | 2958 EMSG2(_("E282: Cannot read from \"%s\""), parmp->use_vimrc); |
2959 } | |
2960 } | |
2961 else if (!silent_mode) | |
2962 { | |
2963 #ifdef AMIGA | |
2964 struct Process *proc = (struct Process *)FindTask(0L); | |
2965 APTR save_winptr = proc->pr_WindowPtr; | |
2966 | |
2967 /* Avoid a requester here for a volume that doesn't exist. */ | |
2968 proc->pr_WindowPtr = (APTR)-1L; | |
2969 #endif | |
2970 | |
2971 /* | |
2972 * Get system wide defaults, if the file name is defined. | |
2973 */ | |
2974 #ifdef SYS_VIMRC_FILE | |
819 | 2975 (void)do_source((char_u *)SYS_VIMRC_FILE, FALSE, DOSO_NONE); |
440 | 2976 #endif |
720 | 2977 #ifdef MACOS_X |
819 | 2978 (void)do_source((char_u *)"$VIMRUNTIME/macmap.vim", FALSE, DOSO_NONE); |
720 | 2979 #endif |
440 | 2980 |
2981 /* | |
2982 * Try to read initialization commands from the following places: | |
2983 * - environment variable VIMINIT | |
2984 * - user vimrc file (s:.vimrc for Amiga, ~/.vimrc otherwise) | |
2985 * - second user vimrc file ($VIM/.vimrc for Dos) | |
2986 * - environment variable EXINIT | |
2987 * - user exrc file (s:.exrc for Amiga, ~/.exrc otherwise) | |
2988 * - second user exrc file ($VIM/.exrc for Dos) | |
2989 * The first that exists is used, the rest is ignored. | |
2990 */ | |
2991 if (process_env((char_u *)"VIMINIT", TRUE) != OK) | |
2992 { | |
819 | 2993 if (do_source((char_u *)USR_VIMRC_FILE, TRUE, DOSO_VIMRC) == FAIL |
440 | 2994 #ifdef USR_VIMRC_FILE2 |
819 | 2995 && do_source((char_u *)USR_VIMRC_FILE2, TRUE, |
2996 DOSO_VIMRC) == FAIL | |
440 | 2997 #endif |
2998 #ifdef USR_VIMRC_FILE3 | |
819 | 2999 && do_source((char_u *)USR_VIMRC_FILE3, TRUE, |
3000 DOSO_VIMRC) == FAIL | |
440 | 3001 #endif |
4863
c4d4f0fc12b9
updated for version 7.3.1178
Bram Moolenaar <bram@vim.org>
parents:
4369
diff
changeset
|
3002 #ifdef USR_VIMRC_FILE4 |
c4d4f0fc12b9
updated for version 7.3.1178
Bram Moolenaar <bram@vim.org>
parents:
4369
diff
changeset
|
3003 && do_source((char_u *)USR_VIMRC_FILE4, TRUE, |
c4d4f0fc12b9
updated for version 7.3.1178
Bram Moolenaar <bram@vim.org>
parents:
4369
diff
changeset
|
3004 DOSO_VIMRC) == FAIL |
c4d4f0fc12b9
updated for version 7.3.1178
Bram Moolenaar <bram@vim.org>
parents:
4369
diff
changeset
|
3005 #endif |
440 | 3006 && process_env((char_u *)"EXINIT", FALSE) == FAIL |
819 | 3007 && do_source((char_u *)USR_EXRC_FILE, FALSE, DOSO_NONE) == FAIL) |
440 | 3008 { |
3009 #ifdef USR_EXRC_FILE2 | |
819 | 3010 (void)do_source((char_u *)USR_EXRC_FILE2, FALSE, DOSO_NONE); |
440 | 3011 #endif |
3012 } | |
3013 } | |
3014 | |
3015 /* | |
3016 * Read initialization commands from ".vimrc" or ".exrc" in current | |
3017 * directory. This is only done if the 'exrc' option is set. | |
3018 * Because of security reasons we disallow shell and write commands | |
3019 * now, except for unix if the file is owned by the user or 'secure' | |
3020 * option has been reset in environment of global ".exrc" or ".vimrc". | |
3021 * Only do this if VIMRC_FILE is not the same as USR_VIMRC_FILE or | |
3022 * SYS_VIMRC_FILE. | |
3023 */ | |
3024 if (p_exrc) | |
3025 { | |
3026 #if defined(UNIX) || defined(VMS) | |
3027 /* If ".vimrc" file is not owned by user, set 'secure' mode. */ | |
3028 if (!file_owned(VIMRC_FILE)) | |
3029 #endif | |
3030 secure = p_secure; | |
3031 | |
3032 i = FAIL; | |
3033 if (fullpathcmp((char_u *)USR_VIMRC_FILE, | |
3034 (char_u *)VIMRC_FILE, FALSE) != FPC_SAME | |
3035 #ifdef USR_VIMRC_FILE2 | |
3036 && fullpathcmp((char_u *)USR_VIMRC_FILE2, | |
3037 (char_u *)VIMRC_FILE, FALSE) != FPC_SAME | |
3038 #endif | |
3039 #ifdef USR_VIMRC_FILE3 | |
3040 && fullpathcmp((char_u *)USR_VIMRC_FILE3, | |
3041 (char_u *)VIMRC_FILE, FALSE) != FPC_SAME | |
3042 #endif | |
3043 #ifdef SYS_VIMRC_FILE | |
3044 && fullpathcmp((char_u *)SYS_VIMRC_FILE, | |
3045 (char_u *)VIMRC_FILE, FALSE) != FPC_SAME | |
3046 #endif | |
3047 ) | |
819 | 3048 i = do_source((char_u *)VIMRC_FILE, TRUE, DOSO_VIMRC); |
440 | 3049 |
3050 if (i == FAIL) | |
3051 { | |
3052 #if defined(UNIX) || defined(VMS) | |
3053 /* if ".exrc" is not owned by user set 'secure' mode */ | |
3054 if (!file_owned(EXRC_FILE)) | |
3055 secure = p_secure; | |
3056 else | |
3057 secure = 0; | |
3058 #endif | |
3059 if ( fullpathcmp((char_u *)USR_EXRC_FILE, | |
3060 (char_u *)EXRC_FILE, FALSE) != FPC_SAME | |
3061 #ifdef USR_EXRC_FILE2 | |
3062 && fullpathcmp((char_u *)USR_EXRC_FILE2, | |
3063 (char_u *)EXRC_FILE, FALSE) != FPC_SAME | |
3064 #endif | |
3065 ) | |
819 | 3066 (void)do_source((char_u *)EXRC_FILE, FALSE, DOSO_NONE); |
440 | 3067 } |
3068 } | |
3069 if (secure == 2) | |
3070 need_wait_return = TRUE; | |
3071 secure = 0; | |
3072 #ifdef AMIGA | |
3073 proc->pr_WindowPtr = save_winptr; | |
3074 #endif | |
3075 } | |
3076 TIME_MSG("sourcing vimrc file(s)"); | |
3077 } | |
3078 | |
3079 /* | |
6 | 3080 * Setup to start using the GUI. Exit with an error when not available. |
3081 */ | |
3082 static void | |
3083 main_start_gui() | |
3084 { | |
3085 #ifdef FEAT_GUI | |
3086 gui.starting = TRUE; /* start GUI a bit later */ | |
3087 #else | |
3088 mch_errmsg(_(e_nogvim)); | |
3089 mch_errmsg("\n"); | |
3090 mch_exit(2); | |
3091 #endif | |
3092 } | |
3093 | |
2730 | 3094 #endif /* NO_VIM_MAIN */ |
3095 | |
6 | 3096 /* |
1226 | 3097 * Get an environment variable, and execute it as Ex commands. |
6 | 3098 * Returns FAIL if the environment variable was not executed, OK otherwise. |
3099 */ | |
3100 int | |
3101 process_env(env, is_viminit) | |
3102 char_u *env; | |
3103 int is_viminit; /* when TRUE, called for VIMINIT */ | |
3104 { | |
3105 char_u *initstr; | |
3106 char_u *save_sourcing_name; | |
3107 linenr_T save_sourcing_lnum; | |
3108 #ifdef FEAT_EVAL | |
3109 scid_T save_sid; | |
3110 #endif | |
3111 | |
3112 if ((initstr = mch_getenv(env)) != NULL && *initstr != NUL) | |
3113 { | |
3114 if (is_viminit) | |
819 | 3115 vimrc_found(NULL, NULL); |
6 | 3116 save_sourcing_name = sourcing_name; |
3117 save_sourcing_lnum = sourcing_lnum; | |
3118 sourcing_name = env; | |
3119 sourcing_lnum = 0; | |
3120 #ifdef FEAT_EVAL | |
3121 save_sid = current_SID; | |
3122 current_SID = SID_ENV; | |
3123 #endif | |
3124 do_cmdline_cmd(initstr); | |
3125 sourcing_name = save_sourcing_name; | |
3126 sourcing_lnum = save_sourcing_lnum; | |
3127 #ifdef FEAT_EVAL | |
3128 current_SID = save_sid;; | |
3129 #endif | |
3130 return OK; | |
3131 } | |
3132 return FAIL; | |
3133 } | |
3134 | |
2730 | 3135 #if (defined(UNIX) || defined(VMS)) && !defined(NO_VIM_MAIN) |
6 | 3136 /* |
3137 * Return TRUE if we are certain the user owns the file "fname". | |
3138 * Used for ".vimrc" and ".exrc". | |
3139 * Use both stat() and lstat() for extra security. | |
3140 */ | |
3141 static int | |
3142 file_owned(fname) | |
3143 char *fname; | |
3144 { | |
3145 struct stat s; | |
3146 # ifdef UNIX | |
3147 uid_t uid = getuid(); | |
3148 # else /* VMS */ | |
3149 uid_t uid = ((getgid() << 16) | getuid()); | |
3150 # endif | |
3151 | |
3152 return !(mch_stat(fname, &s) != 0 || s.st_uid != uid | |
3153 # ifdef HAVE_LSTAT | |
3154 || mch_lstat(fname, &s) != 0 || s.st_uid != uid | |
3155 # endif | |
3156 ); | |
3157 } | |
3158 #endif | |
3159 | |
3160 /* | |
3161 * Give an error message main_errors["n"] and exit. | |
3162 */ | |
3163 static void | |
3164 mainerr(n, str) | |
3165 int n; /* one of the ME_ defines */ | |
3166 char_u *str; /* extra argument or NULL */ | |
3167 { | |
3168 #if defined(UNIX) || defined(__EMX__) || defined(VMS) | |
3169 reset_signals(); /* kill us with CTRL-C here, if you like */ | |
3170 #endif | |
3171 | |
3172 mch_errmsg(longVersion); | |
159 | 3173 mch_errmsg("\n"); |
6 | 3174 mch_errmsg(_(main_errors[n])); |
3175 if (str != NULL) | |
3176 { | |
3177 mch_errmsg(": \""); | |
3178 mch_errmsg((char *)str); | |
3179 mch_errmsg("\""); | |
3180 } | |
159 | 3181 mch_errmsg(_("\nMore info with: \"vim -h\"\n")); |
6 | 3182 |
3183 mch_exit(1); | |
3184 } | |
3185 | |
3186 void | |
3187 mainerr_arg_missing(str) | |
3188 char_u *str; | |
3189 { | |
3190 mainerr(ME_ARG_MISSING, str); | |
3191 } | |
3192 | |
2730 | 3193 #ifndef NO_VIM_MAIN |
6 | 3194 /* |
3195 * print a message with three spaces prepended and '\n' appended. | |
3196 */ | |
3197 static void | |
3198 main_msg(s) | |
3199 char *s; | |
3200 { | |
3201 mch_msg(" "); | |
3202 mch_msg(s); | |
3203 mch_msg("\n"); | |
3204 } | |
3205 | |
3206 /* | |
3207 * Print messages for "vim -h" or "vim --help" and exit. | |
3208 */ | |
3209 static void | |
3210 usage() | |
3211 { | |
3212 int i; | |
3213 static char *(use[]) = | |
3214 { | |
3215 N_("[file ..] edit specified file(s)"), | |
3216 N_("- read text from stdin"), | |
3217 N_("-t tag edit file where tag is defined"), | |
3218 #ifdef FEAT_QUICKFIX | |
3219 N_("-q [errorfile] edit file with first error") | |
3220 #endif | |
3221 }; | |
3222 | |
3223 #if defined(UNIX) || defined(__EMX__) || defined(VMS) | |
3224 reset_signals(); /* kill us with CTRL-C here, if you like */ | |
3225 #endif | |
3226 | |
3227 mch_msg(longVersion); | |
3228 mch_msg(_("\n\nusage:")); | |
3229 for (i = 0; ; ++i) | |
3230 { | |
3231 mch_msg(_(" vim [arguments] ")); | |
3232 mch_msg(_(use[i])); | |
3233 if (i == (sizeof(use) / sizeof(char_u *)) - 1) | |
3234 break; | |
3235 mch_msg(_("\n or:")); | |
3236 } | |
22 | 3237 #ifdef VMS |
1164 | 3238 mch_msg(_("\nWhere case is ignored prepend / to make flag upper case")); |
22 | 3239 #endif |
6 | 3240 |
3241 mch_msg(_("\n\nArguments:\n")); | |
3242 main_msg(_("--\t\t\tOnly file names after this")); | |
3243 #if (!defined(UNIX) && !defined(__EMX__)) || defined(ARCHIE) | |
3244 main_msg(_("--literal\t\tDon't expand wildcards")); | |
3245 #endif | |
3246 #ifdef FEAT_OLE | |
3247 main_msg(_("-register\t\tRegister this gvim for OLE")); | |
3248 main_msg(_("-unregister\t\tUnregister gvim for OLE")); | |
3249 #endif | |
3250 #ifdef FEAT_GUI | |
3251 main_msg(_("-g\t\t\tRun using GUI (like \"gvim\")")); | |
3252 main_msg(_("-f or --nofork\tForeground: Don't fork when starting GUI")); | |
3253 #endif | |
3254 main_msg(_("-v\t\t\tVi mode (like \"vi\")")); | |
3255 main_msg(_("-e\t\t\tEx mode (like \"ex\")")); | |
3437 | 3256 main_msg(_("-E\t\t\tImproved Ex mode")); |
6 | 3257 main_msg(_("-s\t\t\tSilent (batch) mode (only for \"ex\")")); |
3258 #ifdef FEAT_DIFF | |
3259 main_msg(_("-d\t\t\tDiff mode (like \"vimdiff\")")); | |
3260 #endif | |
3261 main_msg(_("-y\t\t\tEasy mode (like \"evim\", modeless)")); | |
3262 main_msg(_("-R\t\t\tReadonly mode (like \"view\")")); | |
3263 main_msg(_("-Z\t\t\tRestricted mode (like \"rvim\")")); | |
3264 main_msg(_("-m\t\t\tModifications (writing files) not allowed")); | |
3265 main_msg(_("-M\t\t\tModifications in text not allowed")); | |
3266 main_msg(_("-b\t\t\tBinary mode")); | |
3267 #ifdef FEAT_LISP | |
3268 main_msg(_("-l\t\t\tLisp mode")); | |
3269 #endif | |
3270 main_msg(_("-C\t\t\tCompatible with Vi: 'compatible'")); | |
3271 main_msg(_("-N\t\t\tNot fully Vi compatible: 'nocompatible'")); | |
1164 | 3272 main_msg(_("-V[N][fname]\t\tBe verbose [level N] [log messages to fname]")); |
3273 #ifdef FEAT_EVAL | |
6 | 3274 main_msg(_("-D\t\t\tDebugging mode")); |
1164 | 3275 #endif |
6 | 3276 main_msg(_("-n\t\t\tNo swap file, use memory only")); |
3277 main_msg(_("-r\t\t\tList swap files and exit")); | |
3278 main_msg(_("-r (with file name)\tRecover crashed session")); | |
3279 main_msg(_("-L\t\t\tSame as -r")); | |
3280 #ifdef AMIGA | |
3281 main_msg(_("-f\t\t\tDon't use newcli to open window")); | |
3282 main_msg(_("-dev <device>\t\tUse <device> for I/O")); | |
3283 #endif | |
3284 #ifdef FEAT_ARABIC | |
3285 main_msg(_("-A\t\t\tstart in Arabic mode")); | |
3286 #endif | |
3287 #ifdef FEAT_RIGHTLEFT | |
3288 main_msg(_("-H\t\t\tStart in Hebrew mode")); | |
3289 #endif | |
3290 #ifdef FEAT_FKMAP | |
3291 main_msg(_("-F\t\t\tStart in Farsi mode")); | |
3292 #endif | |
3293 main_msg(_("-T <terminal>\tSet terminal type to <terminal>")); | |
3294 main_msg(_("-u <vimrc>\t\tUse <vimrc> instead of any .vimrc")); | |
3295 #ifdef FEAT_GUI | |
3296 main_msg(_("-U <gvimrc>\t\tUse <gvimrc> instead of any .gvimrc")); | |
3297 #endif | |
3298 main_msg(_("--noplugin\t\tDon't load plugin scripts")); | |
1164 | 3299 #ifdef FEAT_WINDOWS |
673 | 3300 main_msg(_("-p[N]\t\tOpen N tab pages (default: one for each file)")); |
6 | 3301 main_msg(_("-o[N]\t\tOpen N windows (default: one for each file)")); |
3302 main_msg(_("-O[N]\t\tLike -o but split vertically")); | |
1164 | 3303 #endif |
6 | 3304 main_msg(_("+\t\t\tStart at end of file")); |
3305 main_msg(_("+<lnum>\t\tStart at line <lnum>")); | |
3306 main_msg(_("--cmd <command>\tExecute <command> before loading any vimrc file")); | |
3307 main_msg(_("-c <command>\t\tExecute <command> after loading the first file")); | |
3308 main_msg(_("-S <session>\t\tSource file <session> after loading the first file")); | |
3309 main_msg(_("-s <scriptin>\tRead Normal mode commands from file <scriptin>")); | |
3310 main_msg(_("-w <scriptout>\tAppend all typed commands to file <scriptout>")); | |
3311 main_msg(_("-W <scriptout>\tWrite all typed commands to file <scriptout>")); | |
3312 #ifdef FEAT_CRYPT | |
3313 main_msg(_("-x\t\t\tEdit encrypted files")); | |
3314 #endif | |
3315 #if (defined(UNIX) || defined(VMS)) && defined(FEAT_X11) | |
3316 # if defined(FEAT_GUI_X11) && !defined(FEAT_GUI_GTK) | |
3317 main_msg(_("-display <display>\tConnect vim to this particular X-server")); | |
3318 # endif | |
3319 main_msg(_("-X\t\t\tDo not connect to X server")); | |
3320 #endif | |
3321 #ifdef FEAT_CLIENTSERVER | |
3322 main_msg(_("--remote <files>\tEdit <files> in a Vim server if possible")); | |
3323 main_msg(_("--remote-silent <files> Same, don't complain if there is no server")); | |
3324 main_msg(_("--remote-wait <files> As --remote but wait for files to have been edited")); | |
3325 main_msg(_("--remote-wait-silent <files> Same, don't complain if there is no server")); | |
754 | 3326 # ifdef FEAT_WINDOWS |
1501 | 3327 main_msg(_("--remote-tab[-wait][-silent] <files> As --remote but use tab page per file")); |
754 | 3328 # endif |
6 | 3329 main_msg(_("--remote-send <keys>\tSend <keys> to a Vim server and exit")); |
3330 main_msg(_("--remote-expr <expr>\tEvaluate <expr> in a Vim server and print result")); | |
3331 main_msg(_("--serverlist\t\tList available Vim server names and exit")); | |
3332 main_msg(_("--servername <name>\tSend to/become the Vim server <name>")); | |
3333 #endif | |
1989 | 3334 #ifdef STARTUPTIME |
1999 | 3335 main_msg(_("--startuptime <file>\tWrite startup timing messages to <file>")); |
1989 | 3336 #endif |
6 | 3337 #ifdef FEAT_VIMINFO |
3338 main_msg(_("-i <viminfo>\t\tUse <viminfo> instead of .viminfo")); | |
3339 #endif | |
3340 main_msg(_("-h or --help\tPrint Help (this message) and exit")); | |
3341 main_msg(_("--version\t\tPrint version information and exit")); | |
3342 | |
3343 #ifdef FEAT_GUI_X11 | |
3344 # ifdef FEAT_GUI_MOTIF | |
3345 mch_msg(_("\nArguments recognised by gvim (Motif version):\n")); | |
3346 # else | |
3347 # ifdef FEAT_GUI_ATHENA | |
3348 # ifdef FEAT_GUI_NEXTAW | |
3349 mch_msg(_("\nArguments recognised by gvim (neXtaw version):\n")); | |
3350 # else | |
3351 mch_msg(_("\nArguments recognised by gvim (Athena version):\n")); | |
3352 # endif | |
3353 # endif | |
3354 # endif | |
3355 main_msg(_("-display <display>\tRun vim on <display>")); | |
3356 main_msg(_("-iconic\t\tStart vim iconified")); | |
3357 main_msg(_("-background <color>\tUse <color> for the background (also: -bg)")); | |
3358 main_msg(_("-foreground <color>\tUse <color> for normal text (also: -fg)")); | |
3359 main_msg(_("-font <font>\t\tUse <font> for normal text (also: -fn)")); | |
3360 main_msg(_("-boldfont <font>\tUse <font> for bold text")); | |
3361 main_msg(_("-italicfont <font>\tUse <font> for italic text")); | |
3362 main_msg(_("-geometry <geom>\tUse <geom> for initial geometry (also: -geom)")); | |
3363 main_msg(_("-borderwidth <width>\tUse a border width of <width> (also: -bw)")); | |
3364 main_msg(_("-scrollbarwidth <width> Use a scrollbar width of <width> (also: -sw)")); | |
3365 # ifdef FEAT_GUI_ATHENA | |
3366 main_msg(_("-menuheight <height>\tUse a menu bar height of <height> (also: -mh)")); | |
3367 # endif | |
3368 main_msg(_("-reverse\t\tUse reverse video (also: -rv)")); | |
3369 main_msg(_("+reverse\t\tDon't use reverse video (also: +rv)")); | |
3370 main_msg(_("-xrm <resource>\tSet the specified resource")); | |
3371 #endif /* FEAT_GUI_X11 */ | |
3372 #ifdef FEAT_GUI_GTK | |
3373 mch_msg(_("\nArguments recognised by gvim (GTK+ version):\n")); | |
3374 main_msg(_("-font <font>\t\tUse <font> for normal text (also: -fn)")); | |
3375 main_msg(_("-geometry <geom>\tUse <geom> for initial geometry (also: -geom)")); | |
3376 main_msg(_("-reverse\t\tUse reverse video (also: -rv)")); | |
3377 main_msg(_("-display <display>\tRun vim on <display> (also: --display)")); | |
3378 main_msg(_("--role <role>\tSet a unique role to identify the main window")); | |
3379 main_msg(_("--socketid <xid>\tOpen Vim inside another GTK widget")); | |
3437 | 3380 main_msg(_("--echo-wid\t\tMake gvim echo the Window ID on stdout")); |
6 | 3381 #endif |
3382 #ifdef FEAT_GUI_W32 | |
3383 main_msg(_("-P <parent title>\tOpen Vim inside parent application")); | |
1376 | 3384 main_msg(_("--windowid <HWND>\tOpen Vim inside another win32 widget")); |
6 | 3385 #endif |
3386 | |
3387 #ifdef FEAT_GUI_GNOME | |
3388 /* Gnome gives extra messages for --help if we continue, but not for -h. */ | |
3389 if (gui.starting) | |
3198 | 3390 { |
6 | 3391 mch_msg("\n"); |
3198 | 3392 gui.dofork = FALSE; |
3393 } | |
6 | 3394 else |
3395 #endif | |
3396 mch_exit(0); | |
3397 } | |
3398 | |
580 | 3399 #if defined(HAS_SWAP_EXISTS_ACTION) |
6 | 3400 /* |
3401 * Check the result of the ATTENTION dialog: | |
3402 * When "Quit" selected, exit Vim. | |
3403 * When "Recover" selected, recover the file. | |
3404 */ | |
3405 static void | |
3406 check_swap_exists_action() | |
3407 { | |
3408 if (swap_exists_action == SEA_QUIT) | |
3409 getout(1); | |
3410 handle_swap_exists(NULL); | |
3411 } | |
3412 #endif | |
3413 | |
2730 | 3414 #endif |
3415 | |
6 | 3416 #if defined(STARTUPTIME) || defined(PROTO) |
3417 static void time_diff __ARGS((struct timeval *then, struct timeval *now)); | |
3418 | |
3419 static struct timeval prev_timeval; | |
3420 | |
1972 | 3421 # ifdef WIN3264 |
3422 /* | |
3423 * Windows doesn't have gettimeofday(), although it does have struct timeval. | |
3424 */ | |
3425 static int | |
3426 gettimeofday(struct timeval *tv, char *dummy) | |
3427 { | |
3428 long t = clock(); | |
3429 tv->tv_sec = t / CLOCKS_PER_SEC; | |
3430 tv->tv_usec = (t - tv->tv_sec * CLOCKS_PER_SEC) * 1000000 / CLOCKS_PER_SEC; | |
3431 return 0; | |
3432 } | |
3433 # endif | |
3434 | |
6 | 3435 /* |
3436 * Save the previous time before doing something that could nest. | |
3437 * set "*tv_rel" to the time elapsed so far. | |
3438 */ | |
3439 void | |
3440 time_push(tv_rel, tv_start) | |
3441 void *tv_rel, *tv_start; | |
3442 { | |
3443 *((struct timeval *)tv_rel) = prev_timeval; | |
3444 gettimeofday(&prev_timeval, NULL); | |
3445 ((struct timeval *)tv_rel)->tv_usec = prev_timeval.tv_usec | |
3446 - ((struct timeval *)tv_rel)->tv_usec; | |
3447 ((struct timeval *)tv_rel)->tv_sec = prev_timeval.tv_sec | |
3448 - ((struct timeval *)tv_rel)->tv_sec; | |
3449 if (((struct timeval *)tv_rel)->tv_usec < 0) | |
3450 { | |
3451 ((struct timeval *)tv_rel)->tv_usec += 1000000; | |
3452 --((struct timeval *)tv_rel)->tv_sec; | |
3453 } | |
3454 *(struct timeval *)tv_start = prev_timeval; | |
3455 } | |
3456 | |
3457 /* | |
3458 * Compute the previous time after doing something that could nest. | |
3459 * Subtract "*tp" from prev_timeval; | |
3460 * Note: The arguments are (void *) to avoid trouble with systems that don't | |
3461 * have struct timeval. | |
3462 */ | |
3463 void | |
3464 time_pop(tp) | |
3465 void *tp; /* actually (struct timeval *) */ | |
3466 { | |
3467 prev_timeval.tv_usec -= ((struct timeval *)tp)->tv_usec; | |
3468 prev_timeval.tv_sec -= ((struct timeval *)tp)->tv_sec; | |
3469 if (prev_timeval.tv_usec < 0) | |
3470 { | |
3471 prev_timeval.tv_usec += 1000000; | |
3472 --prev_timeval.tv_sec; | |
3473 } | |
3474 } | |
3475 | |
3476 static void | |
3477 time_diff(then, now) | |
3478 struct timeval *then; | |
3479 struct timeval *now; | |
3480 { | |
3481 long usec; | |
3482 long msec; | |
3483 | |
3484 usec = now->tv_usec - then->tv_usec; | |
3485 msec = (now->tv_sec - then->tv_sec) * 1000L + usec / 1000L, | |
3486 usec = usec % 1000L; | |
3487 fprintf(time_fd, "%03ld.%03ld", msec, usec >= 0 ? usec : usec + 1000L); | |
3488 } | |
3489 | |
3490 void | |
2271
2b33a7678e7b
Fix compiler warnings for shadowed variables. Make 'conceal' a long instead
Bram Moolenaar <bram@vim.org>
parents:
2267
diff
changeset
|
3491 time_msg(mesg, tv_start) |
2b33a7678e7b
Fix compiler warnings for shadowed variables. Make 'conceal' a long instead
Bram Moolenaar <bram@vim.org>
parents:
2267
diff
changeset
|
3492 char *mesg; |
6 | 3493 void *tv_start; /* only for do_source: start time; actually |
3494 (struct timeval *) */ | |
3495 { | |
3496 static struct timeval start; | |
3497 struct timeval now; | |
3498 | |
3499 if (time_fd != NULL) | |
3500 { | |
2271
2b33a7678e7b
Fix compiler warnings for shadowed variables. Make 'conceal' a long instead
Bram Moolenaar <bram@vim.org>
parents:
2267
diff
changeset
|
3501 if (strstr(mesg, "STARTING") != NULL) |
6 | 3502 { |
3503 gettimeofday(&start, NULL); | |
3504 prev_timeval = start; | |
3505 fprintf(time_fd, "\n\ntimes in msec\n"); | |
3506 fprintf(time_fd, " clock self+sourced self: sourced script\n"); | |
3507 fprintf(time_fd, " clock elapsed: other lines\n\n"); | |
3508 } | |
3509 gettimeofday(&now, NULL); | |
3510 time_diff(&start, &now); | |
3511 if (((struct timeval *)tv_start) != NULL) | |
3512 { | |
3513 fprintf(time_fd, " "); | |
3514 time_diff(((struct timeval *)tv_start), &now); | |
3515 } | |
3516 fprintf(time_fd, " "); | |
3517 time_diff(&prev_timeval, &now); | |
3518 prev_timeval = now; | |
2271
2b33a7678e7b
Fix compiler warnings for shadowed variables. Make 'conceal' a long instead
Bram Moolenaar <bram@vim.org>
parents:
2267
diff
changeset
|
3519 fprintf(time_fd, ": %s\n", mesg); |
6 | 3520 } |
3521 } | |
3522 | |
3523 #endif | |
3524 | |
2730 | 3525 #if (defined(FEAT_CLIENTSERVER) && !defined(NO_VIM_MAIN)) || defined(PROTO) |
6 | 3526 |
3527 /* | |
3528 * Common code for the X command server and the Win32 command server. | |
3529 */ | |
3530 | |
734 | 3531 static char_u *build_drop_cmd __ARGS((int filec, char **filev, int tabs, int sendReply)); |
6 | 3532 |
443 | 3533 /* |
3534 * Do the client-server stuff, unless "--servername ''" was used. | |
3535 */ | |
3536 static void | |
3537 exec_on_server(parmp) | |
3538 mparm_T *parmp; | |
3539 { | |
3540 if (parmp->serverName_arg == NULL || *parmp->serverName_arg != NUL) | |
3541 { | |
3542 # ifdef WIN32 | |
3543 /* Initialise the client/server messaging infrastructure. */ | |
3544 serverInitMessaging(); | |
3545 # endif | |
3546 | |
3547 /* | |
3548 * When a command server argument was found, execute it. This may | |
3549 * exit Vim when it was successful. Otherwise it's executed further | |
3550 * on. Remember the encoding used here in "serverStrEnc". | |
3551 */ | |
3552 if (parmp->serverArg) | |
3553 { | |
3554 cmdsrv_main(&parmp->argc, parmp->argv, | |
3555 parmp->serverName_arg, &parmp->serverStr); | |
3556 # ifdef FEAT_MBYTE | |
3557 parmp->serverStrEnc = vim_strsave(p_enc); | |
3558 # endif | |
3559 } | |
3560 | |
3561 /* If we're still running, get the name to register ourselves. | |
3562 * On Win32 can register right now, for X11 need to setup the | |
3563 * clipboard first, it's further down. */ | |
3564 parmp->servername = serverMakeName(parmp->serverName_arg, | |
3565 parmp->argv[0]); | |
3566 # ifdef WIN32 | |
3567 if (parmp->servername != NULL) | |
3568 { | |
3569 serverSetName(parmp->servername); | |
3570 vim_free(parmp->servername); | |
3571 } | |
3572 # endif | |
3573 } | |
3574 } | |
3575 | |
3576 /* | |
3577 * Prepare for running as a Vim server. | |
3578 */ | |
3579 static void | |
3580 prepare_server(parmp) | |
3581 mparm_T *parmp; | |
3582 { | |
3583 # if defined(FEAT_X11) | |
3584 /* | |
3585 * Register for remote command execution with :serversend and --remote | |
3586 * unless there was a -X or a --servername '' on the command line. | |
3587 * Only register nongui-vim's with an explicit --servername argument. | |
926 | 3588 * When running as root --servername is also required. |
443 | 3589 */ |
3590 if (X_DISPLAY != NULL && parmp->servername != NULL && ( | |
3591 # ifdef FEAT_GUI | |
926 | 3592 (gui.in_use |
3593 # ifdef UNIX | |
1076 | 3594 && getuid() != ROOT_UID |
926 | 3595 # endif |
3596 ) || | |
443 | 3597 # endif |
3598 parmp->serverName_arg != NULL)) | |
3599 { | |
3600 (void)serverRegisterName(X_DISPLAY, parmp->servername); | |
3601 vim_free(parmp->servername); | |
3602 TIME_MSG("register server name"); | |
3603 } | |
3604 else | |
3605 serverDelayedStartName = parmp->servername; | |
3606 # endif | |
3607 | |
3608 /* | |
3609 * Execute command ourselves if we're here because the send failed (or | |
3610 * else we would have exited above). | |
3611 */ | |
3612 if (parmp->serverStr != NULL) | |
3613 { | |
3614 char_u *p; | |
3615 | |
3616 server_to_input_buf(serverConvert(parmp->serverStrEnc, | |
3617 parmp->serverStr, &p)); | |
3618 vim_free(p); | |
3619 } | |
3620 } | |
3621 | |
6 | 3622 static void |
3623 cmdsrv_main(argc, argv, serverName_arg, serverStr) | |
3624 int *argc; | |
3625 char **argv; | |
3626 char_u *serverName_arg; | |
3627 char_u **serverStr; | |
3628 { | |
3629 char_u *res; | |
3630 int i; | |
3631 char_u *sname; | |
3632 int ret; | |
3633 int didone = FALSE; | |
3634 int exiterr = 0; | |
3635 char **newArgV = argv + 1; | |
3636 int newArgC = 1, | |
3637 Argc = *argc; | |
3638 int argtype; | |
3639 #define ARGTYPE_OTHER 0 | |
3640 #define ARGTYPE_EDIT 1 | |
3641 #define ARGTYPE_EDIT_WAIT 2 | |
3642 #define ARGTYPE_SEND 3 | |
3643 int silent = FALSE; | |
734 | 3644 int tabs = FALSE; |
6 | 3645 # ifndef FEAT_X11 |
3646 HWND srv; | |
3647 # else | |
3648 Window srv; | |
3649 | |
3650 setup_term_clip(); | |
3651 # endif | |
3652 | |
3653 sname = serverMakeName(serverName_arg, argv[0]); | |
3654 if (sname == NULL) | |
3655 return; | |
3656 | |
3657 /* | |
3658 * Execute the command server related arguments and remove them | |
3659 * from the argc/argv array; We may have to return into main() | |
3660 */ | |
3661 for (i = 1; i < Argc; i++) | |
3662 { | |
3663 res = NULL; | |
443 | 3664 if (STRCMP(argv[i], "--") == 0) /* end of option arguments */ |
6 | 3665 { |
3666 for (; i < *argc; i++) | |
3667 { | |
3668 *newArgV++ = argv[i]; | |
3669 newArgC++; | |
3670 } | |
3671 break; | |
3672 } | |
3673 | |
734 | 3674 if (STRICMP(argv[i], "--remote-send") == 0) |
3675 argtype = ARGTYPE_SEND; | |
3676 else if (STRNICMP(argv[i], "--remote", 8) == 0) | |
3677 { | |
3678 char *p = argv[i] + 8; | |
3679 | |
6 | 3680 argtype = ARGTYPE_EDIT; |
734 | 3681 while (*p != NUL) |
3682 { | |
3683 if (STRNICMP(p, "-wait", 5) == 0) | |
3684 { | |
3685 argtype = ARGTYPE_EDIT_WAIT; | |
3686 p += 5; | |
3687 } | |
3688 else if (STRNICMP(p, "-silent", 7) == 0) | |
3689 { | |
3690 silent = TRUE; | |
3691 p += 7; | |
3692 } | |
3693 else if (STRNICMP(p, "-tab", 4) == 0) | |
3694 { | |
3695 tabs = TRUE; | |
3696 p += 4; | |
3697 } | |
3698 else | |
3699 { | |
3700 argtype = ARGTYPE_OTHER; | |
3701 break; | |
3702 } | |
3703 } | |
6 | 3704 } |
3705 else | |
3706 argtype = ARGTYPE_OTHER; | |
734 | 3707 |
6 | 3708 if (argtype != ARGTYPE_OTHER) |
3709 { | |
3710 if (i == *argc - 1) | |
3711 mainerr_arg_missing((char_u *)argv[i]); | |
3712 if (argtype == ARGTYPE_SEND) | |
3713 { | |
3714 *serverStr = (char_u *)argv[i + 1]; | |
3715 i++; | |
3716 } | |
3717 else | |
3718 { | |
3719 *serverStr = build_drop_cmd(*argc - i - 1, argv + i + 1, | |
734 | 3720 tabs, argtype == ARGTYPE_EDIT_WAIT); |
6 | 3721 if (*serverStr == NULL) |
3722 { | |
3723 /* Probably out of memory, exit. */ | |
3724 didone = TRUE; | |
3725 exiterr = 1; | |
3726 break; | |
3727 } | |
3728 Argc = i; | |
3729 } | |
3730 # ifdef FEAT_X11 | |
3731 if (xterm_dpy == NULL) | |
3732 { | |
3733 mch_errmsg(_("No display")); | |
3734 ret = -1; | |
3735 } | |
3736 else | |
3737 ret = serverSendToVim(xterm_dpy, sname, *serverStr, | |
3738 NULL, &srv, 0, 0, silent); | |
3739 # else | |
3740 /* Win32 always works? */ | |
3741 ret = serverSendToVim(sname, *serverStr, NULL, &srv, 0, silent); | |
3742 # endif | |
3743 if (ret < 0) | |
3744 { | |
3745 if (argtype == ARGTYPE_SEND) | |
3746 { | |
3747 /* Failed to send, abort. */ | |
3748 mch_errmsg(_(": Send failed.\n")); | |
3749 didone = TRUE; | |
3750 exiterr = 1; | |
3751 } | |
3752 else if (!silent) | |
3753 /* Let vim start normally. */ | |
3754 mch_errmsg(_(": Send failed. Trying to execute locally\n")); | |
3755 break; | |
3756 } | |
3757 | |
3758 # ifdef FEAT_GUI_W32 | |
3759 /* Guess that when the server name starts with "g" it's a GUI | |
3760 * server, which we can bring to the foreground here. | |
3761 * Foreground() in the server doesn't work very well. */ | |
3762 if (argtype != ARGTYPE_SEND && TOUPPER_ASC(*sname) == 'G') | |
3763 SetForegroundWindow(srv); | |
3764 # endif | |
3765 | |
3766 /* | |
3767 * For --remote-wait: Wait until the server did edit each | |
3768 * file. Also detect that the server no longer runs. | |
3769 */ | |
3770 if (ret >= 0 && argtype == ARGTYPE_EDIT_WAIT) | |
3771 { | |
3772 int numFiles = *argc - i - 1; | |
3773 int j; | |
3774 char_u *done = alloc(numFiles); | |
3775 char_u *p; | |
3776 # ifdef FEAT_GUI_W32 | |
3777 NOTIFYICONDATA ni; | |
3778 int count = 0; | |
3779 extern HWND message_window; | |
3780 # endif | |
3781 | |
3782 if (numFiles > 0 && argv[i + 1][0] == '+') | |
3783 /* Skip "+cmd" argument, don't wait for it to be edited. */ | |
3784 --numFiles; | |
3785 | |
3786 # ifdef FEAT_GUI_W32 | |
3787 ni.cbSize = sizeof(ni); | |
3788 ni.hWnd = message_window; | |
3789 ni.uID = 0; | |
3790 ni.uFlags = NIF_ICON|NIF_TIP; | |
3791 ni.hIcon = LoadIcon((HINSTANCE)GetModuleHandle(0), "IDR_VIM"); | |
3792 sprintf(ni.szTip, _("%d of %d edited"), count, numFiles); | |
3793 Shell_NotifyIcon(NIM_ADD, &ni); | |
3794 # endif | |
3795 | |
3796 /* Wait for all files to unload in remote */ | |
2215
cccb71c2c5c1
Fix uninit memory read in undo code. Fix uint32_t in proto file.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
3797 vim_memset(done, 0, numFiles); |
6 | 3798 while (memchr(done, 0, numFiles) != NULL) |
3799 { | |
3800 # ifdef WIN32 | |
3801 p = serverGetReply(srv, NULL, TRUE, TRUE); | |
3802 if (p == NULL) | |
3803 break; | |
3804 # else | |
3805 if (serverReadReply(xterm_dpy, srv, &p, TRUE) < 0) | |
3806 break; | |
3807 # endif | |
3808 j = atoi((char *)p); | |
3809 if (j >= 0 && j < numFiles) | |
3810 { | |
3811 # ifdef FEAT_GUI_W32 | |
3812 ++count; | |
3813 sprintf(ni.szTip, _("%d of %d edited"), | |
3814 count, numFiles); | |
3815 Shell_NotifyIcon(NIM_MODIFY, &ni); | |
3816 # endif | |
3817 done[j] = 1; | |
3818 } | |
3819 } | |
3820 # ifdef FEAT_GUI_W32 | |
3821 Shell_NotifyIcon(NIM_DELETE, &ni); | |
3822 # endif | |
3823 } | |
3824 } | |
3825 else if (STRICMP(argv[i], "--remote-expr") == 0) | |
3826 { | |
3827 if (i == *argc - 1) | |
3828 mainerr_arg_missing((char_u *)argv[i]); | |
3829 # ifdef WIN32 | |
3830 /* Win32 always works? */ | |
3831 if (serverSendToVim(sname, (char_u *)argv[i + 1], | |
3832 &res, NULL, 1, FALSE) < 0) | |
3833 # else | |
3834 if (xterm_dpy == NULL) | |
3835 mch_errmsg(_("No display: Send expression failed.\n")); | |
3836 else if (serverSendToVim(xterm_dpy, sname, (char_u *)argv[i + 1], | |
3837 &res, NULL, 1, 1, FALSE) < 0) | |
3838 # endif | |
3839 { | |
3840 if (res != NULL && *res != NUL) | |
3841 { | |
3842 /* Output error from remote */ | |
3843 mch_errmsg((char *)res); | |
3844 vim_free(res); | |
3845 res = NULL; | |
3846 } | |
3847 mch_errmsg(_(": Send expression failed.\n")); | |
3848 } | |
3849 } | |
3850 else if (STRICMP(argv[i], "--serverlist") == 0) | |
3851 { | |
3852 # ifdef WIN32 | |
3853 /* Win32 always works? */ | |
3854 res = serverGetVimNames(); | |
3855 # else | |
3856 if (xterm_dpy != NULL) | |
3857 res = serverGetVimNames(xterm_dpy); | |
3858 # endif | |
3859 if (called_emsg) | |
3860 mch_errmsg("\n"); | |
3861 } | |
3862 else if (STRICMP(argv[i], "--servername") == 0) | |
3863 { | |
2021 | 3864 /* Already processed. Take it out of the command line */ |
6 | 3865 i++; |
3866 continue; | |
3867 } | |
3868 else | |
3869 { | |
3870 *newArgV++ = argv[i]; | |
3871 newArgC++; | |
3872 continue; | |
3873 } | |
3874 didone = TRUE; | |
3875 if (res != NULL && *res != NUL) | |
3876 { | |
3877 mch_msg((char *)res); | |
3878 if (res[STRLEN(res) - 1] != '\n') | |
3879 mch_msg("\n"); | |
3880 } | |
3881 vim_free(res); | |
3882 } | |
3883 | |
3884 if (didone) | |
3885 { | |
3886 display_errors(); /* display any collected messages */ | |
3887 exit(exiterr); /* Mission accomplished - get out */ | |
3888 } | |
3889 | |
3890 /* Return back into main() */ | |
3891 *argc = newArgC; | |
3892 vim_free(sname); | |
3893 } | |
3894 | |
3895 /* | |
3896 * Build a ":drop" command to send to a Vim server. | |
3897 */ | |
3898 static char_u * | |
734 | 3899 build_drop_cmd(filec, filev, tabs, sendReply) |
6 | 3900 int filec; |
3901 char **filev; | |
734 | 3902 int tabs; /* Use ":tab drop" instead of ":drop". */ |
6 | 3903 int sendReply; |
3904 { | |
3905 garray_T ga; | |
3906 int i; | |
3907 char_u *inicmd = NULL; | |
3908 char_u *p; | |
2770 | 3909 char_u *cwd; |
6 | 3910 |
3911 if (filec > 0 && filev[0][0] == '+') | |
3912 { | |
3913 inicmd = (char_u *)filev[0] + 1; | |
3914 filev++; | |
3915 filec--; | |
3916 } | |
3917 /* Check if we have at least one argument. */ | |
3918 if (filec <= 0) | |
3919 mainerr_arg_missing((char_u *)filev[-1]); | |
2640 | 3920 |
3921 /* Temporarily cd to the current directory to handle relative file names. */ | |
2770 | 3922 cwd = alloc(MAXPATHL); |
3923 if (cwd == NULL) | |
6 | 3924 return NULL; |
2770 | 3925 if (mch_dirname(cwd, MAXPATHL) != OK) |
3926 { | |
3927 vim_free(cwd); | |
3928 return NULL; | |
3929 } | |
3930 p = vim_strsave_escaped_ext(cwd, | |
1385 | 3931 #ifdef BACKSLASH_IN_FILENAME |
3932 "", /* rem_backslash() will tell what chars to escape */ | |
3933 #else | |
3934 PATH_ESC_CHARS, | |
3935 #endif | |
2770 | 3936 '\\', TRUE); |
3937 vim_free(cwd); | |
3938 if (p == NULL) | |
6 | 3939 return NULL; |
3940 ga_init2(&ga, 1, 100); | |
3941 ga_concat(&ga, (char_u *)"<C-\\><C-N>:cd "); | |
3942 ga_concat(&ga, p); | |
734 | 3943 vim_free(p); |
3944 | |
6 | 3945 /* Call inputsave() so that a prompt for an encryption key works. */ |
734 | 3946 ga_concat(&ga, (char_u *)"<CR>:if exists('*inputsave')|call inputsave()|endif|"); |
3947 if (tabs) | |
3948 ga_concat(&ga, (char_u *)"tab "); | |
3949 ga_concat(&ga, (char_u *)"drop"); | |
6 | 3950 for (i = 0; i < filec; i++) |
3951 { | |
3952 /* On Unix the shell has already expanded the wildcards, don't want to | |
40 | 3953 * do it again in the Vim server. On MS-Windows only escape |
3954 * non-wildcard characters. */ | |
6 | 3955 p = vim_strsave_escaped((char_u *)filev[i], |
3956 #ifdef UNIX | |
3957 PATH_ESC_CHARS | |
3958 #else | |
40 | 3959 (char_u *)" \t%#" |
6 | 3960 #endif |
3961 ); | |
3962 if (p == NULL) | |
3963 { | |
3964 vim_free(ga.ga_data); | |
3965 return NULL; | |
3966 } | |
3967 ga_concat(&ga, (char_u *)" "); | |
3968 ga_concat(&ga, p); | |
3969 vim_free(p); | |
3970 } | |
2640 | 3971 ga_concat(&ga, (char_u *)"|if exists('*inputrestore')|call inputrestore()|endif<CR>"); |
3972 | |
6 | 3973 /* The :drop commands goes to Insert mode when 'insertmode' is set, use |
3974 * CTRL-\ CTRL-N again. */ | |
2640 | 3975 ga_concat(&ga, (char_u *)"<C-\\><C-N>"); |
3976 | |
3977 /* Switch back to the correct current directory (prior to temporary path | |
3978 * switch) unless 'autochdir' is set, in which case it will already be | |
3979 * correct after the :drop command. */ | |
3980 ga_concat(&ga, (char_u *)":if !exists('+acd')||!&acd|cd -|endif<CR>"); | |
3981 | |
6 | 3982 if (sendReply) |
2640 | 3983 ga_concat(&ga, (char_u *)":call SetupRemoteReplies()<CR>"); |
3984 ga_concat(&ga, (char_u *)":"); | |
6 | 3985 if (inicmd != NULL) |
3986 { | |
3987 /* Can't use <CR> after "inicmd", because an "startinsert" would cause | |
3988 * the following commands to be inserted as text. Use a "|", | |
3989 * hopefully "inicmd" does allow this... */ | |
3990 ga_concat(&ga, inicmd); | |
3991 ga_concat(&ga, (char_u *)"|"); | |
3992 } | |
3993 /* Bring the window to the foreground, goto Insert mode when 'im' set and | |
3994 * clear command line. */ | |
46 | 3995 ga_concat(&ga, (char_u *)"cal foreground()|if &im|star|en|redr|f<CR>"); |
6 | 3996 ga_append(&ga, NUL); |
3997 return ga.ga_data; | |
3998 } | |
3999 | |
4000 /* | |
2730 | 4001 * Make our basic server name: use the specified "arg" if given, otherwise use |
4002 * the tail of the command "cmd" we were started with. | |
4003 * Return the name in allocated memory. This doesn't include a serial number. | |
4004 */ | |
4005 static char_u * | |
4006 serverMakeName(arg, cmd) | |
4007 char_u *arg; | |
4008 char *cmd; | |
4009 { | |
4010 char_u *p; | |
4011 | |
4012 if (arg != NULL && *arg != NUL) | |
4013 p = vim_strsave_up(arg); | |
4014 else | |
4015 { | |
4016 p = vim_strsave_up(gettail((char_u *)cmd)); | |
4017 /* Remove .exe or .bat from the name. */ | |
4018 if (p != NULL && vim_strchr(p, '.') != NULL) | |
4019 *vim_strchr(p, '.') = NUL; | |
4020 } | |
4021 return p; | |
4022 } | |
4023 #endif /* FEAT_CLIENTSERVER */ | |
4024 | |
4025 #if defined(FEAT_CLIENTSERVER) || defined(PROTO) | |
4026 /* | |
6 | 4027 * Replace termcodes such as <CR> and insert as key presses if there is room. |
4028 */ | |
4029 void | |
4030 server_to_input_buf(str) | |
4031 char_u *str; | |
4032 { | |
4033 char_u *ptr = NULL; | |
4034 char_u *cpo_save = p_cpo; | |
4035 | |
4036 /* Set 'cpoptions' the way we want it. | |
4037 * B set - backslashes are *not* treated specially | |
4038 * k set - keycodes are *not* reverse-engineered | |
4039 * < unset - <Key> sequences *are* interpreted | |
860 | 4040 * The last but one parameter of replace_termcodes() is TRUE so that the |
4041 * <lt> sequence is recognised - needed for a real backslash. | |
6 | 4042 */ |
4043 p_cpo = (char_u *)"Bk"; | |
860 | 4044 str = replace_termcodes((char_u *)str, &ptr, FALSE, TRUE, FALSE); |
6 | 4045 p_cpo = cpo_save; |
4046 | |
4047 if (*ptr != NUL) /* trailing CTRL-V results in nothing */ | |
4048 { | |
4049 /* | |
4050 * Add the string to the input stream. | |
4051 * Can't use add_to_input_buf() here, we now have K_SPECIAL bytes. | |
4052 * | |
4053 * First clear typed characters from the typeahead buffer, there could | |
4054 * be half a mapping there. Then append to the existing string, so | |
4055 * that multiple commands from a client are concatenated. | |
4056 */ | |
4057 if (typebuf.tb_maplen < typebuf.tb_len) | |
4058 del_typebuf(typebuf.tb_len - typebuf.tb_maplen, typebuf.tb_maplen); | |
4059 (void)ins_typebuf(str, REMAP_NONE, typebuf.tb_len, TRUE, FALSE); | |
4060 | |
4061 /* Let input_available() know we inserted text in the typeahead | |
4062 * buffer. */ | |
841 | 4063 typebuf_was_filled = TRUE; |
6 | 4064 } |
4065 vim_free((char_u *)ptr); | |
4066 } | |
4067 | |
4068 /* | |
4069 * Evaluate an expression that the client sent to a string. | |
4070 */ | |
4071 char_u * | |
4072 eval_client_expr_to_string(expr) | |
4073 char_u *expr; | |
4074 { | |
4075 char_u *res; | |
4076 int save_dbl = debug_break_level; | |
4077 int save_ro = redir_off; | |
4078 | |
4217 | 4079 /* Disable debugging, otherwise Vim hangs, waiting for "cont" to be |
4080 * typed. */ | |
6 | 4081 debug_break_level = -1; |
4082 redir_off = 0; | |
4217 | 4083 /* Do not display error message, otherwise Vim hangs, waiting for "cont" |
4084 * to be typed. Do generate errors so that try/catch works. */ | |
4085 ++emsg_silent; | |
6 | 4086 |
714 | 4087 res = eval_to_string(expr, NULL, TRUE); |
6 | 4088 |
4089 debug_break_level = save_dbl; | |
4090 redir_off = save_ro; | |
4217 | 4091 --emsg_silent; |
4092 if (emsg_silent < 0) | |
4093 emsg_silent = 0; | |
6 | 4094 |
591 | 4095 /* A client can tell us to redraw, but not to display the cursor, so do |
4096 * that here. */ | |
4097 setcursor(); | |
4098 out_flush(); | |
4099 #ifdef FEAT_GUI | |
4100 if (gui.in_use) | |
4101 gui_update_cursor(FALSE, FALSE); | |
4102 #endif | |
4103 | |
6 | 4104 return res; |
4105 } | |
4106 | |
39 | 4107 /* |
4108 * If conversion is needed, convert "data" from "client_enc" to 'encoding' and | |
4109 * return an allocated string. Otherwise return "data". | |
4110 * "*tofree" is set to the result when it needs to be freed later. | |
4111 */ | |
4112 char_u * | |
4113 serverConvert(client_enc, data, tofree) | |
1883 | 4114 char_u *client_enc UNUSED; |
39 | 4115 char_u *data; |
4116 char_u **tofree; | |
4117 { | |
4118 char_u *res = data; | |
4119 | |
4120 *tofree = NULL; | |
4121 # ifdef FEAT_MBYTE | |
4122 if (client_enc != NULL && p_enc != NULL) | |
4123 { | |
4124 vimconv_T vimconv; | |
4125 | |
4126 vimconv.vc_type = CONV_NONE; | |
4127 if (convert_setup(&vimconv, client_enc, p_enc) != FAIL | |
4128 && vimconv.vc_type != CONV_NONE) | |
4129 { | |
4130 res = string_convert(&vimconv, data, NULL); | |
4131 if (res == NULL) | |
4132 res = data; | |
4133 else | |
4134 *tofree = res; | |
4135 } | |
4136 convert_setup(&vimconv, NULL, NULL); | |
4137 } | |
4138 # endif | |
4139 return res; | |
4140 } | |
2730 | 4141 #endif |
6 | 4142 |
4143 /* | |
4144 * When FEAT_FKMAP is defined, also compile the Farsi source code. | |
4145 */ | |
4146 #if defined(FEAT_FKMAP) || defined(PROTO) | |
4147 # include "farsi.c" | |
4148 #endif | |
4149 | |
4150 /* | |
4151 * When FEAT_ARABIC is defined, also compile the Arabic source code. | |
4152 */ | |
4153 #if defined(FEAT_ARABIC) || defined(PROTO) | |
4154 # include "arabic.c" | |
4155 #endif |