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