On Thu, Feb 07, 2008 at 10:20:27PM +0100, Bram Moolenaar wrote: > > James Vega wrote: > > > On Wed, Feb 06, 2008 at 09:43:33PM +0100, Bram Moolenaar wrote: > > > The main reason to do it this way is that when a startup script contains > > > "set nocp" the following lines often depend on this. If one would start > > > "vim -C" and the -C would cause the "set nocp" line to be ignored, the > > > rest of the script would be misinterpreted. Especially for ":map" > > > commands with things like "<C-A>". With 'nocompatible' this means > > > CTRL-A, with 'compatible' this is 5 separate characters. > > > > The initial bug was specifically that "vim -C" with "set nocp" in a > > startup script resulted in a Vim session that didn't have 'compatible' > > set as per the man page. I notice that the help for -C indicates the > > ":set nocompatible" command will override -C so maybe it would be > > sufficient to add this to the man page as well. A similar note should > > be added to the help/man page for -N. > > > > This would be a simpler solution, although I still think that if the > > user is specifically requesting (no)compatible mode at the command line, > > they should be able to deal with side-effects it may have on startup > > scripts. > > Well, a possible solution would be to do "set compatible" after all the > startup stuff is done. I suppose that would work as expected.
In thinking about this patch again, my original patch needs some more work (which I've attached). The changes are as follows: 1) The original behavior of immediately calling change_compatible() when -N/-C are parsed is restored. This allows the startup vimrc files to have conditional behavior based on which compatibility mode Vim will end up in. 2) change_compatible() is again called immediately after the startup vimrc files are sourced (only if -N/-C were given on the command-line) so that the proper compatibility mode is set while loading plugins. 3) If the gui is started, change_compatible() is called one more time (only if -N/-C were given on the command-line) immediately after the gvimrc files are sourced to ensure that any changes they make to 'cp' are overridden to follow the command-line options. -- James GPG Key: 1024D/61326D40 2003-09-02 James Vega <[EMAIL PROTECTED]>
diff --git a/src/main.c b/src/main.c index a9eb460..75ccd4c 100644 --- a/src/main.c +++ b/src/main.c @@ -35,6 +35,9 @@ #define WIN_VER 2 /* "-O" vertically split windows */ #define WIN_TABS 3 /* "-p" windows on tab pages */ +#define SET_CP 1 /* "-C" set compatible */ +#define SET_NOCP 2 /* "-N" set nocompatible */ + /* Struct for various parameters passed between main() and other functions. */ typedef struct { @@ -87,6 +90,7 @@ typedef struct #ifdef FEAT_DIFF int diff_mode; /* start with 'diff' set */ #endif + int option_cp; /* 0, SET_CP, SET_NOCP */ } mparm_T; /* Values for edit_type. */ @@ -556,6 +560,16 @@ main /* Source startup scripts. */ source_startup_scripts(¶ms); + /* + * Now that the startup files are done being sourced, we set 'cp' to the + * value specified on the command-line, if there was one. This ensures + * that the desired value is used while plugins are being loaded. + */ + if (params.option_cp == SET_CP) + change_compatible(TRUE); + else if (params.option_cp == SET_NOCP) + change_compatible(FALSE); + #ifdef FEAT_EVAL /* * Read all the plugin files. @@ -636,6 +650,12 @@ main * don't have them. */ if (!gui.in_use && params.evim_mode) mch_exit(1); + + /* One last time since gvimrc may have changed things on us. */ + if (params.option_cp == SET_CP) + change_compatible(TRUE); + else if (params.option_cp == SET_NOCP) + change_compatible(FALSE); } #endif @@ -1756,6 +1776,7 @@ command_line_scan(parmp) case 'C': /* "-C" Compatible */ change_compatible(TRUE); + parmp->option_cp = SET_CP; break; case 'e': /* "-e" Ex mode */ @@ -1829,6 +1850,7 @@ command_line_scan(parmp) case 'N': /* "-N" Nocompatible */ change_compatible(FALSE); + parmp->option_cp = SET_NOCP; break; case 'n': /* "-n" no swap file */
signature.asc
Description: Digital signature