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