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