]> granicus.if.org Git - vim/commitdiff
patch 8.0.0716: not easy to start Vim cleanly v8.0.0716
authorBram Moolenaar <Bram@vim.org>
Sat, 15 Jul 2017 17:39:43 +0000 (19:39 +0200)
committerBram Moolenaar <Bram@vim.org>
Sat, 15 Jul 2017 17:39:43 +0000 (19:39 +0200)
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".

13 files changed:
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 [new file with mode: 0644]
src/version.c

index f539acaa9247408d02ae24913c16f53147a6b89d..4547eabe08bcc22a57fd60587dbaeb5a76698b7a 100644 (file)
@@ -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
index b083efc535d248d9139bcac45094ff2f423daa4d..bbf9cf1ba4d82ae0941a32ad412e99d2dbcf8746 100644 (file)
@@ -4966,8 +4966,8 @@ A jump table for the options with a short description can be found at |Q_op|.
        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 short description can be found at |Q_op|.
 
        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 short description can be found at |Q_op|.
        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 short description can be found at |Q_op|.
                        {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 short description can be found at |Q_op|.
                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 short description can be found at |Q_op|.
        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
index eb1fdc89518c95343c8c76249c7ad0bf6d3065b7..0ea6ea284599b47c2c4722a7c6c1d28c6977c75e 100644 (file)
@@ -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 "-/R" readonly.
 --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 "-/R" readonly.
 --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 "-/R" readonly.
                ":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 @@ accordingly.  Vim proceeds in this order:
        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 as:
 - 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,
index c45c156dc2c41606469625665e76b0a35b23c7cc..b450c4e586e380f0908ce5313f0946477b8b1563 100644 (file)
@@ -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 little work:
 
 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:
 >
index ffee334b54aea1e2a14d40482ca18ab4e6fd8f94..c9e5e144d6fb02541b3eb2858283c65b97f59f28 100644 (file)
@@ -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 *msg, channel_T *channel, ch_part_T part)
     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 *msg, channel_T *channel, ch_part_T part)
     }
 
     /* 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 *msg, channel_T *channel, ch_part_T part)
        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, ch_part_T part)
     }
 
     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;
     }
index a69a05268dbd4ef61657fdffd1e5c55d493ac42b..9c84e24b15da627f654810ad72b82cd550f3cbd4 100644 (file)
@@ -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
index 7cf928c16d3c7341371491c47b720238d6785e43..d0938fda64c878a169f321b122cb3a40ac6197b9 100644 (file)
@@ -1036,7 +1036,6 @@ EXTERN int        skip_redraw INIT(= FALSE);  /* skip redraw once */
 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 */
index 67c0a30d420ed1f04e5af1f3918cc1b8f8e5bf62..6e21f73148ce3e7e5c1c21ba4c7f97d9db728a5d 100644 (file)
@@ -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"));
 
index 39aef6eda6e2c6faffec33b412d0d2a9694e793a..8e91fae74ae8d1719f0bfd8f8ed928a9bcafe75d 100644 (file)
@@ -2981,6 +2981,15 @@ static struct vimoption options[] =
                            {(char_u *)"", (char_u *)"'100,<50,s10,h"}
 # endif
 #endif
+#else
+                           (char_u *)NULL, PV_NONE,
+                           {(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}
index c74a89b22e923c1c94d6d03f0aa9c17e29ed886e..7394c7fd92b89f2fdf5dd15f0e7fc1cdafc22c54 100644 (file)
@@ -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' */
index 3694fc24adec5fdf9aa9dd20a2486019c9307819..c988968bb2a43b6f13c0af8d3793878af212eb36 100644 (file)
@@ -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
diff --git a/src/testdir/test_channel_write.py b/src/testdir/test_channel_write.py
new file mode 100644 (file)
index 0000000..9c8813b
--- /dev/null
@@ -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
index c8322cd1fc70829ed77dd27b34f254b8306b4c52..09b3b85605f02d65120aff37d1de0f9cdc694155 100644 (file)
@@ -764,6 +764,10 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    716,
+/**/
+    715,
 /**/
     714,
 /**/