Mercurial > vim
changeset 11666:5cd9ba96561d v8.0.0716
patch 8.0.0716: not easy to start Vim cleanly
commit https://github.com/vim/vim/commit/c4da113ef98dcfd6f2a088b1693c0317dcb5bf42
Author: Bram Moolenaar <Bram@vim.org>
Date: Sat Jul 15 19:39:43 2017 +0200
patch 8.0.0716: not easy to start Vim cleanly
Problem: Not easy to start Vim cleanly without changing the viminfo file.
Not possible to know whether the -i command line flag was used.
Solution: Add the --clean command line argument. Add the 'viminfofile'
option. Add "-u DEFAULTS".
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Sat, 15 Jul 2017 19:45:03 +0200 |
parents | d7fe6dc88ea4 |
children | 88d6ae605f3f |
files | runtime/doc/debug.txt runtime/doc/options.txt runtime/doc/starting.txt runtime/doc/usr_01.txt src/channel.c src/ex_cmds.c src/globals.h src/main.c src/option.c src/option.h src/testdir/test_channel.vim src/testdir/test_channel_write.py src/version.c |
diffstat | 13 files changed, 154 insertions(+), 44 deletions(-) [+] |
line wrap: on
line diff
--- a/runtime/doc/debug.txt +++ b/runtime/doc/debug.txt @@ -1,4 +1,4 @@ -*debug.txt* For Vim version 8.0. Last change: 2012 Feb 11 +*debug.txt* For Vim version 8.0. Last change: 2017 Jul 15 VIM REFERENCE MANUAL by Bram Moolenaar @@ -53,7 +53,7 @@ Use this command to start Vim: valgrind --log-file=valgrind.log --leak-check=full ./vim Note: Vim will run much slower. If your .vimrc is big or you have several -plugins you need to be patient for startup, or run with the "-u NONE" +plugins you need to be patient for startup, or run with the "--clean" argument. There are often a few leaks from libraries, such as getpwuid() and
--- a/runtime/doc/options.txt +++ b/runtime/doc/options.txt @@ -4966,8 +4966,8 @@ A jump table for the options with a shor When on the plugin scripts are loaded when starting up |load-plugins|. This option can be reset in your |vimrc| file to disable the loading of plugins. - Note that using the "-u NONE" and "--noplugin" command line arguments - reset this option. |-u| |--noplugin| + Note that using the "-u NONE", "-u DEFAULTS" and "--noplugin" command + line arguments reset this option. See |-u| and |--noplugin|. *'luadll'* 'luadll' string (default depends on the build) @@ -7330,7 +7330,7 @@ A jump table for the options with a shor Watch out for errors in expressions. They may render Vim unusable! If you are stuck, hold down ':' or 'Q' to get a prompt, then quit and - edit your .vimrc or whatever with "vim -u NONE" to get it right. + edit your .vimrc or whatever with "vim --clean" to get it right. Examples: Emulate standard status line with 'ruler' set > @@ -7755,7 +7755,7 @@ A jump table for the options with a shor NOTE: This option is reset when 'compatible' is set. *'termkey'* *'tk'* -'termkey' 'tk' string (default "CTRL-W") +'termkey' 'tk' string (default "CTRL-W") local to window {not in Vi} The key that precedes a Vim command in a terminal window. Other keys @@ -8333,13 +8333,14 @@ A jump table for the options with a shor {not available when compiled without the |+viminfo| feature} When non-empty, the viminfo file is read upon startup and written - when exiting Vim (see |viminfo-file|). The string should be a comma - separated list of parameters, each consisting of a single character - identifying the particular parameter, followed by a number or string - which specifies the value of that parameter. If a particular - character is left out, then the default value is used for that - parameter. The following is a list of the identifying characters and - the effect of their value. + when exiting Vim (see |viminfo-file|). Except when 'viminfofile' is + "NONE". + The string should be a comma separated list of parameters, each + consisting of a single character identifying the particular parameter, + followed by a number or string which specifies the value of that + parameter. If a particular character is left out, then the default + value is used for that parameter. The following is a list of the + identifying characters and the effect of their value. CHAR VALUE ~ *viminfo-!* ! When included, save and restore global variables that start @@ -8399,9 +8400,9 @@ A jump table for the options with a shor has been used since the last search command. *viminfo-n* n Name of the viminfo file. The name must immediately follow - the 'n'. Must be at the end of the option! If the "-i" - argument was given when starting Vim, that file name overrides - the one given here with 'viminfo'. Environment variables are + the 'n'. Must be at the end of the option! If the + 'viminfofile' option is set, that file name overrides the one + given here with 'viminfo'. Environment variables are expanded when opening the file, not when setting the option. *viminfo-r* r Removable media. The argument is a string (up to the next @@ -8442,6 +8443,17 @@ A jump table for the options with a shor NOTE: This option is set to the Vim default value when 'compatible' is reset. + *'viminfofile'* *'vif'* +'viminfofile' 'vif' string (default: "") + global + {not in Vi} + {not available when compiled without the |+viminfo| + feature} + When non-empty, overrides the file name used for viminfo. + When equal to "NONE" no viminfo file will be read or written. + This option can be set with the |-i| command line flag. The |--clean| + command line flag sets it to "NONE". + *'virtualedit'* *'ve'* 'virtualedit' 've' string (default "") global
--- a/runtime/doc/starting.txt +++ b/runtime/doc/starting.txt @@ -1,4 +1,4 @@ -*starting.txt* For Vim version 8.0. Last change: 2017 Jan 15 +*starting.txt* For Vim version 8.0. Last change: 2017 Jul 15 VIM REFERENCE MANUAL by Bram Moolenaar @@ -140,11 +140,12 @@ a slash. Thus "-R" means recovery and " --noplugin Skip loading plugins. Resets the 'loadplugins' option. {not in Vi} Note that the |-u| argument may also disable loading plugins: - argument load vimrc files load plugins ~ - (nothing) yes yes - -u NONE no no - -u NORC no yes - --noplugin yes no + argument load: vimrc files plugins defaults.vim ~ + (nothing) yes yes yes + -u NONE no no no + -u DEFAULTS no no yes + -u NORC no yes no + --noplugin yes no yes --startuptime {fname} *--startuptime* During startup write timing messages to the file {fname}. @@ -465,21 +466,30 @@ a slash. Thus "-R" means recovery and " --nofork GUI: Do not fork. Same as |-f|. *-u* *E282* -u {vimrc} The file {vimrc} is read for initializations. Most other - initializations are skipped; see |initialization|. This can - be used to start Vim in a special mode, with special + initializations are skipped; see |initialization|. + + This can be used to start Vim in a special mode, with special mappings and settings. A shell alias can be used to make this easy to use. For example: > alias vimc vim -u ~/.c_vimrc !* < Also consider using autocommands; see |autocommand|. + When {vimrc} is equal to "NONE" (all uppercase), all initializations from files and environment variables are skipped, including reading the |gvimrc| file when the GUI starts. Loading plugins is also skipped. + When {vimrc} is equal to "NORC" (all uppercase), this has the same effect as "NONE", but loading plugins is not skipped. - Using the "-u" argument has the side effect that the - 'compatible' option will be on by default. This can have - unexpected effects. See |'compatible'|. + + When {vimrc} is equal to "DEFAULTS" (all uppercase), this has + the same effect as "NONE", but the |defaults.vim| script is + loaded, which will also set 'nocompatible'. + + Using the "-u" argument with another argument than DEFAULTS + has the side effect that the 'compatible' option will be on by + default. This can have unexpected effects. See + |'compatible'|. {not in Vi} *-U* *E230* @@ -497,6 +507,13 @@ a slash. Thus "-R" means recovery and " ":rv" or ":wv" are used. See also |viminfo-file|. {not in Vi} + *--clean* +--clean Equal to "-u DEFAULTS -i NONE": + - initializations from files and environment variables is + skipped + - the |defaults.vim| script is loaded, which implies + 'nocompatible': use Vim defaults + - no viminfo file is read or written *-x* -x Use encryption to read/write files. Will prompt for a key, which is then stored in the 'key' option. All writes will @@ -868,6 +885,7 @@ 4. Load the plugin scripts. *load-pl Loading plugins won't be done when: - The 'loadplugins' option was reset in a vimrc file. - The |--noplugin| command line argument is used. + - The |--clean| command line argument is used. - The "-u NONE" command line argument is used |-u|. - When Vim was compiled without the |+eval| feature. Note that using "-c 'set noloadplugins'" doesn't work, because the @@ -990,6 +1008,7 @@ starts its initializations. But as soon - a vimrc file in the current directory, or - the "VIMINIT" environment variable is set, or - the "-N" command line argument is given, or +- the "--clean" command line argument is given, or even when no vimrc file exists. - the |defaults.vim| script is loaded, or - gvimrc file was found,
--- a/runtime/doc/usr_01.txt +++ b/runtime/doc/usr_01.txt @@ -1,4 +1,4 @@ -*usr_01.txt* For Vim version 8.0. Last change: 2010 Nov 03 +*usr_01.txt* For Vim version 8.0. Last change: 2017 Jul 15 VIM USER MANUAL - by Bram Moolenaar @@ -140,19 +140,19 @@ On other systems, you have to do a littl 1. Copy the tutor file. You can do this with Vim (it knows where to find it): > - vim -u NONE -c 'e $VIMRUNTIME/tutor/tutor' -c 'w! TUTORCOPY' -c 'q' + vim --clean -c 'e $VIMRUNTIME/tutor/tutor' -c 'w! TUTORCOPY' -c 'q' < This will write the file "TUTORCOPY" in the current directory. To use a translated version of the tutor, append the two-letter language code to the filename. For French: > - vim -u NONE -c 'e $VIMRUNTIME/tutor/tutor.fr' -c 'w! TUTORCOPY' -c 'q' + vim --clean -c 'e $VIMRUNTIME/tutor/tutor.fr' -c 'w! TUTORCOPY' -c 'q' < 2. Edit the copied file with Vim: > - vim -u NONE -c "set nocp" TUTORCOPY + vim --clean TUTORCOPY < - The extra arguments make sure Vim is started in a good mood. + The --clean argument makes sure Vim is started with nice defaults. 3. Delete the copied file when you are finished with it: >
--- a/src/channel.c +++ b/src/channel.c @@ -1438,6 +1438,7 @@ channel_write_in(channel_T *channel) if (!bufref_valid(&in_part->ch_bufref) || buf->b_ml.ml_mfp == NULL) { /* buffer was wiped out or unloaded */ + ch_log(channel, "input buffer has been wiped out"); in_part->ch_bufref.br_buf = NULL; return; } @@ -2338,7 +2339,7 @@ append_to_buffer(buf_T *buffer, char_u * int save_write_to = buffer->b_write_to_channel; chanpart_T *ch_part = &channel->ch_part[part]; int save_p_ma = buffer->b_p_ma; - int empty = (buffer->b_ml.ml_flags & ML_EMPTY); + int empty = (buffer->b_ml.ml_flags & ML_EMPTY) ? 1 : 0; if (!buffer->b_p_ma && !ch_part->ch_nomodifiable) { @@ -2359,13 +2360,14 @@ append_to_buffer(buf_T *buffer, char_u * } /* Append to the buffer */ - ch_logn(channel, "appending line %d to buffer", (int)lnum + 1); + ch_logn(channel, "appending line %d to buffer", (int)lnum + 1 - empty); buffer->b_p_ma = TRUE; curbuf = buffer; + curwin->w_buffer = curbuf; u_sync(TRUE); /* ignore undo failure, undo is not very useful here */ - ignored = u_save(lnum, lnum + 1 + (empty ? 1 : 0)); + ignored = u_save(lnum - empty, lnum + 1); if (empty) { @@ -2377,6 +2379,7 @@ append_to_buffer(buf_T *buffer, char_u * ml_append(lnum, msg, 0, FALSE); appended_lines_mark(lnum, 1L); curbuf = save_curbuf; + curwin->w_buffer = curbuf; if (ch_part->ch_nomodifiable) buffer->b_p_ma = FALSE; else @@ -2483,9 +2486,11 @@ may_invoke_callback(channel_T *channel, } buffer = ch_part->ch_bufref.br_buf; - if (buffer != NULL && !bufref_valid(&ch_part->ch_bufref)) + if (buffer != NULL && (!bufref_valid(&ch_part->ch_bufref) + || buffer->b_ml.ml_mfp == NULL)) { - /* buffer was wiped out */ + /* buffer was wiped out or unloaded */ + ch_logs(channel, "%s buffer has been wiped out", part_names[part]); ch_part->ch_bufref.br_buf = NULL; buffer = NULL; }
--- a/src/ex_cmds.c +++ b/src/ex_cmds.c @@ -1743,7 +1743,7 @@ static int viminfo_errcnt; no_viminfo(void) { /* "vim -i NONE" does not read or write a viminfo file */ - return (use_viminfo != NULL && STRCMP(use_viminfo, "NONE") == 0); + return STRCMP(p_viminfofile, "NONE") == 0; } /* @@ -2093,8 +2093,8 @@ viminfo_filename(char_u *file) { if (file == NULL || *file == NUL) { - if (use_viminfo != NULL) - file = use_viminfo; + if (*p_viminfofile != NUL) + file = p_viminfofile; else if ((file = find_viminfo_parameter('n')) == NULL || *file == NUL) { #ifdef VIMINFO_FILE2
--- a/src/globals.h +++ b/src/globals.h @@ -1036,7 +1036,6 @@ EXTERN int skip_redraw INIT(= FALSE); / EXTERN int do_redraw INIT(= FALSE); /* extra redraw once */ EXTERN int need_highlight_changed INIT(= TRUE); -EXTERN char_u *use_viminfo INIT(= NULL); /* name of viminfo file to use */ #define NSCRIPT 15 EXTERN FILE *scriptin[NSCRIPT]; /* streams to read script from */
--- a/src/main.c +++ b/src/main.c @@ -433,7 +433,9 @@ vim_main2(void) #ifndef NO_VIM_MAIN /* Reset 'loadplugins' for "-u NONE" before "--cmd" arguments. * Allows for setting 'loadplugins' there. */ - if (params.use_vimrc != NULL && STRCMP(params.use_vimrc, "NONE") == 0) + if (params.use_vimrc != NULL + && (STRCMP(params.use_vimrc, "NONE") == 0 + || STRCMP(params.use_vimrc, "DEFAULTS") == 0)) p_lpl = FALSE; /* Execute --cmd arguments. */ @@ -1869,6 +1871,7 @@ command_line_scan(mparm_T *parmp) case '-': /* "--" don't take any more option arguments */ /* "--help" give help message */ /* "--version" give version message */ + /* "--clean" clean context */ /* "--literal" take files literally */ /* "--nofork" don't fork */ /* "--not-a-term" don't warn for not a term */ @@ -1886,6 +1889,11 @@ command_line_scan(mparm_T *parmp) msg_didout = FALSE; mch_exit(0); } + else if (STRNICMP(argv[0] + argv_idx, "clean", 5) == 0) + { + parmp->use_vimrc = (char_u *)"DEFAULTS"; + set_option_value((char_u *)"vif", 0L, (char_u *)"NONE", 0); + } else if (STRNICMP(argv[0] + argv_idx, "literal", 7) == 0) { #ifdef EXPAND_FILENAMES @@ -2318,7 +2326,7 @@ command_line_scan(mparm_T *parmp) #endif case 'i': /* "-i {viminfo}" use for viminfo */ - use_viminfo = (char_u *)argv[0]; + set_option_value((char_u *)"vif", 0L, (char_u *)argv[0], 0); break; case 's': /* "-s {scriptin}" read from script file */ @@ -2988,7 +2996,9 @@ source_startup_scripts(mparm_T *parmp) */ if (parmp->use_vimrc != NULL) { - if (STRCMP(parmp->use_vimrc, "NONE") == 0 + if (STRCMP(parmp->use_vimrc, "DEFAULTS") == 0) + do_source((char_u *)VIM_DEFAULTS_FILE, FALSE, DOSO_NONE); + else if (STRCMP(parmp->use_vimrc, "NONE") == 0 || STRCMP(parmp->use_vimrc, "NORC") == 0) { #ifdef FEAT_GUI @@ -3383,6 +3393,7 @@ usage(void) #ifdef FEAT_VIMINFO main_msg(_("-i <viminfo>\t\tUse <viminfo> instead of .viminfo")); #endif + main_msg(_("--clean\t\t'nocompatible', Vim defaults, no plugins, no viminfo")); main_msg(_("-h or --help\tPrint Help (this message) and exit")); main_msg(_("--version\t\tPrint version information and exit"));
--- a/src/option.c +++ b/src/option.c @@ -2986,6 +2986,15 @@ static struct vimoption options[] = {(char_u *)0L, (char_u *)0L} #endif SCRIPTID_INIT}, + {"viminfofile", "vif", P_STRING|P_ONECOMMA|P_NODUP|P_SECURE|P_VI_DEF, +#ifdef FEAT_VIMINFO + (char_u *)&p_viminfofile, PV_NONE, + {(char_u *)"", (char_u *)0L} +#else + (char_u *)NULL, PV_NONE, + {(char_u *)0L, (char_u *)0L} +#endif + SCRIPTID_INIT}, {"virtualedit", "ve", P_STRING|P_ONECOMMA|P_NODUP|P_VI_DEF |P_VIM|P_CURSWANT, #ifdef FEAT_VIRTUALEDIT
--- a/src/option.h +++ b/src/option.h @@ -920,6 +920,7 @@ EXTERN char_u *p_fcs; /* 'fillchar' */ #endif #ifdef FEAT_VIMINFO EXTERN char_u *p_viminfo; /* 'viminfo' */ +EXTERN char_u *p_viminfofile; /* 'viminfofile' */ #endif #ifdef FEAT_SESSION EXTERN char_u *p_vdir; /* 'viewdir' */
--- a/src/testdir/test_channel.vim +++ b/src/testdir/test_channel.vim @@ -739,6 +739,38 @@ func Test_pipe_to_buffer_name_nomsg() call Run_test_pipe_to_buffer(1, 0, 1) endfunc +func Test_close_output_buffer() + if !has('job') + return + endif + enew! + let test_lines = ['one', 'two'] + call setline(1, test_lines) + call ch_log('Test_close_output_buffer()') + let options = {'out_io': 'buffer'} + let options['out_name'] = 'buffer-output' + let options['out_msg'] = 0 + split buffer-output + let job = job_start(s:python . " test_channel_write.py", options) + call assert_equal("run", job_status(job)) + try + call WaitFor('line("$") == 3') + call assert_equal(3, line('$')) + quit! + sleep 100m + " Make sure the write didn't happen to the wrong buffer. + call assert_equal(test_lines, getline(1, line('$'))) + call assert_equal(-1, bufwinnr('buffer-output')) + sbuf buffer-output + call assert_notequal(-1, bufwinnr('buffer-output')) + sleep 100m + close " no more writes + bwipe! + finally + call job_stop(job) + endtry +endfunc + func Run_test_pipe_err_to_buffer(use_name, nomod, do_msg) if !has('job') return
new file mode 100644 --- /dev/null +++ b/src/testdir/test_channel_write.py @@ -0,0 +1,18 @@ +#!/usr/bin/python +# +# Program that writes a number to stdout repeatedly +# +# This requires Python 2.6 or later. + +from __future__ import print_function +import sys +import time + +if __name__ == "__main__": + + done = 0 + while done < 10: + done = done + 1 + print(done) + sys.stdout.flush() + time.sleep(0.05) # sleep 50 msec