mirror of
				https://github.com/neovim/neovim.git
				synced 2025-11-04 09:44:31 +00:00 
			
		
		
		
	startup: -es/-Es (silent/batch mode): skip swapfile #8540
To use Nvim as a scripting engine the side-effects of swapfiles and user config should be avoided by default.
This commit is contained in:
		@@ -208,6 +208,7 @@ argument.
 | 
				
			|||||||
			echo foo | nvim -V1 -es
 | 
								echo foo | nvim -V1 -es
 | 
				
			||||||
<
 | 
					<
 | 
				
			||||||
		User |init.vim| is skipped (unless given with |-u|).
 | 
							User |init.vim| is skipped (unless given with |-u|).
 | 
				
			||||||
 | 
							Swap file is skipped (like |-n|).
 | 
				
			||||||
		|$TERM| is not used.
 | 
							|$TERM| is not used.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		If stdin is not a TTY:
 | 
							If stdin is not a TTY:
 | 
				
			||||||
@@ -255,7 +256,7 @@ argument.
 | 
				
			|||||||
		{not available when compiled without the |+eval| feature}
 | 
							{not available when compiled without the |+eval| feature}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
							*-n*
 | 
												*-n*
 | 
				
			||||||
-n		No swap file will be used.  Recovery after a crash will be
 | 
					-n		No |swap-file| will be used.  Recovery after a crash will be
 | 
				
			||||||
		impossible.  Handy if you want to view or edit a file on a
 | 
							impossible.  Handy if you want to view or edit a file on a
 | 
				
			||||||
		very slow medium (e.g., a floppy).
 | 
							very slow medium (e.g., a floppy).
 | 
				
			||||||
		Can also be done with ":set updatecount=0".  You can switch it
 | 
							Can also be done with ":set updatecount=0".  You can switch it
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -346,7 +346,10 @@ Shell:
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
Startup:
 | 
					Startup:
 | 
				
			||||||
  |-e| and |-es| invoke the same "improved Ex mode" as -E and -Es.
 | 
					  |-e| and |-es| invoke the same "improved Ex mode" as -E and -Es.
 | 
				
			||||||
  |-E| and |-Es| reads stdin as text (into buffer 1).
 | 
					  |-E| and |-Es| read stdin as text (into buffer 1).
 | 
				
			||||||
 | 
					  |-es| and |-Es| have improved behavior:
 | 
				
			||||||
 | 
					    - Quits automatically, don't need "-c qa!".
 | 
				
			||||||
 | 
					    - Skips swap-file dialog.
 | 
				
			||||||
  |-s| reads Normal commands from stdin if the script name is "-".
 | 
					  |-s| reads Normal commands from stdin if the script name is "-".
 | 
				
			||||||
  Reading text (instead of commands) from stdin |--|:
 | 
					  Reading text (instead of commands) from stdin |--|:
 | 
				
			||||||
    - works by default: "-" file is optional
 | 
					    - works by default: "-" file is optional
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -114,12 +114,12 @@ typedef struct {
 | 
				
			|||||||
  char *listen_addr;                    // --listen {address}
 | 
					  char *listen_addr;                    // --listen {address}
 | 
				
			||||||
} mparm_T;
 | 
					} mparm_T;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/* Values for edit_type. */
 | 
					// Values for edit_type.
 | 
				
			||||||
#define EDIT_NONE   0       /* no edit type yet */
 | 
					#define EDIT_NONE   0       // no edit type yet
 | 
				
			||||||
#define EDIT_FILE   1       /* file name argument[s] given, use argument list */
 | 
					#define EDIT_FILE   1       // file name argument[s] given, use argument list
 | 
				
			||||||
#define EDIT_STDIN  2       /* read file from stdin */
 | 
					#define EDIT_STDIN  2       // read file from stdin
 | 
				
			||||||
#define EDIT_TAG    3       /* tag name argument given, use tagname */
 | 
					#define EDIT_TAG    3       // tag name argument given, use tagname
 | 
				
			||||||
#define EDIT_QF     4       /* start in quickfix mode */
 | 
					#define EDIT_QF     4       // start in quickfix mode
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#ifdef INCLUDE_GENERATED_DECLARATIONS
 | 
					#ifdef INCLUDE_GENERATED_DECLARATIONS
 | 
				
			||||||
# include "main.c.generated.h"
 | 
					# include "main.c.generated.h"
 | 
				
			||||||
@@ -807,6 +807,7 @@ static void command_line_scan(mparm_T *parmp)
 | 
				
			|||||||
          if (exmode_active) {
 | 
					          if (exmode_active) {
 | 
				
			||||||
            // "nvim -e -" silent mode
 | 
					            // "nvim -e -" silent mode
 | 
				
			||||||
            silent_mode = true;
 | 
					            silent_mode = true;
 | 
				
			||||||
 | 
					            parmp->no_swap_file = true;
 | 
				
			||||||
          } else {
 | 
					          } else {
 | 
				
			||||||
            if (parmp->edit_type != EDIT_NONE
 | 
					            if (parmp->edit_type != EDIT_NONE
 | 
				
			||||||
                && parmp->edit_type != EDIT_FILE
 | 
					                && parmp->edit_type != EDIT_FILE
 | 
				
			||||||
@@ -990,6 +991,7 @@ static void command_line_scan(mparm_T *parmp)
 | 
				
			|||||||
        case 's': {
 | 
					        case 's': {
 | 
				
			||||||
          if (exmode_active) {    // "-es" silent (batch) Ex-mode
 | 
					          if (exmode_active) {    // "-es" silent (batch) Ex-mode
 | 
				
			||||||
            silent_mode = true;
 | 
					            silent_mode = true;
 | 
				
			||||||
 | 
					            parmp->no_swap_file = true;
 | 
				
			||||||
          } else {                // "-s {scriptin}" read from script file
 | 
					          } else {                // "-s {scriptin}" read from script file
 | 
				
			||||||
            want_argument = true;
 | 
					            want_argument = true;
 | 
				
			||||||
          }
 | 
					          }
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -203,6 +203,20 @@ describe('startup', function()
 | 
				
			|||||||
                    { 'set encoding', '' }))
 | 
					                    { 'set encoding', '' }))
 | 
				
			||||||
  end)
 | 
					  end)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  it('-es/-Es disables swapfile, user config #8540', function()
 | 
				
			||||||
 | 
					    for _,arg in ipairs({'-es', '-Es'}) do
 | 
				
			||||||
 | 
					      local out = funcs.system({nvim_prog, arg,
 | 
				
			||||||
 | 
					                                '+set swapfile? updatecount? shada?',
 | 
				
			||||||
 | 
					                                "+put =execute('scriptnames')", '+%print'})
 | 
				
			||||||
 | 
					      local line1 = string.match(out, '^.-\n')
 | 
				
			||||||
 | 
					      -- updatecount=0 means swapfile was disabled.
 | 
				
			||||||
 | 
					      eq("  swapfile  updatecount=0  shada=!,'100,<50,s10,h\n", line1)
 | 
				
			||||||
 | 
					      -- Standard plugins were loaded, but not user config.
 | 
				
			||||||
 | 
					      eq('health.vim', string.match(out, 'health.vim'))
 | 
				
			||||||
 | 
					      eq(nil, string.match(out, 'init.vim'))
 | 
				
			||||||
 | 
					    end
 | 
				
			||||||
 | 
					  end)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  it('does not crash if --embed is given twice', function()
 | 
					  it('does not crash if --embed is given twice', function()
 | 
				
			||||||
    clear{args={'--embed'}}
 | 
					    clear{args={'--embed'}}
 | 
				
			||||||
    eq(2, eval('1+1'))
 | 
					    eq(2, eval('1+1'))
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user