On Do, 13 Mär 2014, Bram Moolenaar wrote:
> Tony Mechelynck wrote:
>
> > RFE: I propose a :noswapfile (or something) prefix, working in similar
> > fashion to the :verbose, :vertical, :top, :tab, etc. prefixes in front
> > of another ex-command, and with the meaning: If that _subordinate_
> > ex-command opens a new buffer, we want 'noswapfile' set on that buffer.
> > (If it doesn't, nothing happens, as with e.g. :vert :top or :tab when
> > the subordinate command opens no new window.) Or maybe :0swapfile and
> > :1swapfile prefixes.
> >
> > Rationale: Currently, “:setlocal noswapfile” prior to opening a new
> > buffer would close the swapfile on the current buffer, not the new one;
> > while doing it afterwards opens and closes a swapfile for the new
> > buffer, which is less harmful but still not ideal.
> >
> > In particular, I notice that “directory” windows handled by netrw have
> > swapfiles set on them: IMHO this is wasteful (and after a few crashes
> > you may find yourself with a string of .swp, .swo, .swn, .swm, etc., for
> > something which cannot ever need a recovery).
>
> Makes sense. An alternative would be an argument along the line of ++bin:
> :sp ++buftype=nofile scratch
>
> Perhaps for netrw it would be
> :sp ++buftype=nowrite dirname
Please try out the attached patch.
Best,
Christian
--
Wie man sein Kind nicht nennen sollte:
Marc Stück
--
--
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
---
You received this message because you are subscribed to the Google Groups
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.
diff --git a/runtime/doc/recover.txt b/runtime/doc/recover.txt
--- a/runtime/doc/recover.txt
+++ b/runtime/doc/recover.txt
@@ -83,6 +83,9 @@
The 'swapfile' option can be reset to avoid creating a swapfile.
+:noswap[file] {command} *:noswap* *:noswapfile*
+ Execute {command}. If it contains a command that loads a new
+ buffer, it will be loaded without creating a swapfile.
Detecting an existing swap file ~
diff --git a/src/ex_cmds.h b/src/ex_cmds.h
--- a/src/ex_cmds.h
+++ b/src/ex_cmds.h
@@ -655,6 +655,8 @@
EXTRA|TRLBAR|NOTRLCOM|USECTRLV|CMDWIN),
EX(CMD_noremenu, "noremenu", ex_menu,
RANGE|NOTADR|ZEROR|BANG|EXTRA|TRLBAR|NOTRLCOM|USECTRLV|CMDWIN),
+EX(CMD_noswapfile, "noswapfile", ex_wrongmodifier,
+ NEEDARG|EXTRA|NOTRLCOM),
EX(CMD_normal, "normal", ex_normal,
RANGE|BANG|EXTRA|NEEDARG|NOTRLCOM|USECTRLV|SBOXOK|CMDWIN),
EX(CMD_number, "number", ex_print,
diff --git a/src/ex_docmd.c b/src/ex_docmd.c
--- a/src/ex_docmd.c
+++ b/src/ex_docmd.c
@@ -1876,18 +1876,22 @@
#endif
continue;
- case 'n': if (!checkforcmd(&ea.cmd, "noautocmd", 3))
+ case 'n': if (checkforcmd(&ea.cmd, "noautocmd", 3))
+ {
+#ifdef FEAT_AUTOCMD
+ if (cmdmod.save_ei == NULL)
+ {
+ /* Set 'eventignore' to "all". Restore the
+ * existing option value later. */
+ cmdmod.save_ei = vim_strsave(p_ei);
+ set_string_option_direct((char_u *)"ei", -1,
+ (char_u *)"all", OPT_FREE, SID_NONE);
+ }
+#endif
+ }
+ if (!checkforcmd(&ea.cmd, "noswapfile", 6))
break;
-#ifdef FEAT_AUTOCMD
- if (cmdmod.save_ei == NULL)
- {
- /* Set 'eventignore' to "all". Restore the
- * existing option value later. */
- cmdmod.save_ei = vim_strsave(p_ei);
- set_string_option_direct((char_u *)"ei", -1,
- (char_u *)"all", OPT_FREE, SID_NONE);
- }
-#endif
+ cmdmod.noswapfile = TRUE;
continue;
case 'r': if (!checkforcmd(&ea.cmd, "rightbelow", 6))
@@ -2598,6 +2602,7 @@
case CMD_lua:
case CMD_match:
case CMD_mzscheme:
+ case CMD_noswapfile:
case CMD_perl:
case CMD_psearch:
case CMD_python:
@@ -3101,6 +3106,7 @@
{"leftabove", 5, FALSE},
{"lockmarks", 3, FALSE},
{"noautocmd", 3, FALSE},
+ {"noswapfile", 6, FALSE},
{"rightbelow", 6, FALSE},
{"sandbox", 3, FALSE},
{"silent", 3, FALSE},
@@ -3613,6 +3619,7 @@
case CMD_keeppatterns:
case CMD_leftabove:
case CMD_lockmarks:
+ case CMD_noswapfile:
case CMD_rightbelow:
case CMD_sandbox:
case CMD_silent:
diff --git a/src/memline.c b/src/memline.c
--- a/src/memline.c
+++ b/src/memline.c
@@ -292,6 +292,9 @@
/*
* When 'updatecount' is non-zero swap file may be opened later.
*/
+ if (cmdmod.noswapfile)
+ buf->b_p_swf = FALSE;
+
if (p_uc && buf->b_p_swf)
buf->b_may_swap = TRUE;
else
@@ -606,11 +609,18 @@
* When 'updatecount' is 0 and 'noswapfile' there is no swap file.
* For help files we will make a swap file now.
*/
- if (p_uc != 0)
+ if (p_uc != 0 && !cmdmod.noswapfile)
ml_open_file(buf); /* create a swap file */
return;
}
+ if (cmdmod.noswapfile)
+ {
+ mf_close_file(buf, TRUE);
+ buf->b_p_swf = FALSE;
+ return;
+ }
+
/*
* Try all directories in the 'directory' option.
*/
@@ -719,7 +729,7 @@
char_u *dirp;
mfp = buf->b_ml.ml_mfp;
- if (mfp == NULL || mfp->mf_fd >= 0 || !buf->b_p_swf)
+ if (mfp == NULL || mfp->mf_fd >= 0 || !buf->b_p_swf || cmdmod.noswapfile)
return; /* nothing to do */
#ifdef FEAT_SPELL
diff --git a/src/structs.h b/src/structs.h
--- a/src/structs.h
+++ b/src/structs.h
@@ -547,6 +547,7 @@
int keepjumps; /* TRUE when ":keepjumps" was used */
int lockmarks; /* TRUE when ":lockmarks" was used */
int keeppatterns; /* TRUE when ":keeppatterns" was used */
+ int noswapfile; /* TRUE when ":noswapfile" was used */
# ifdef FEAT_AUTOCMD
char_u *save_ei; /* saved value of 'eventignore' */
# endif