aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJustin M. Keyes <justinkz@gmail.com>2016-11-06 20:48:12 +0100
committerJustin M. Keyes <justinkz@gmail.com>2016-11-08 21:22:24 +0100
commitf3e8ca3bf50c5945ecfd801bf6eb49ffea5bbe0e (patch)
tree3d1b17c40a853cafeca73a29c97261306c3c6811
parentff6ec703d5f5b57a3c18034ba8a110ffcbf41cea (diff)
downloadrneovim-f3e8ca3bf50c5945ecfd801bf6eb49ffea5bbe0e.tar.gz
rneovim-f3e8ca3bf50c5945ecfd801bf6eb49ffea5bbe0e.tar.bz2
rneovim-f3e8ca3bf50c5945ecfd801bf6eb49ffea5bbe0e.zip
'inccommand': preserve 'modified'
During the live preview, the buffer-local 'modified' flag should not be changed.
-rw-r--r--src/nvim/ex_cmds.c10
-rw-r--r--src/nvim/ex_getln.c1
-rw-r--r--test/functional/ui/inccommand_spec.lua26
3 files changed, 32 insertions, 5 deletions
diff --git a/src/nvim/ex_cmds.c b/src/nvim/ex_cmds.c
index 66c4089ec7..6a0b69ae4a 100644
--- a/src/nvim/ex_cmds.c
+++ b/src/nvim/ex_cmds.c
@@ -3142,6 +3142,7 @@ buf_T *do_sub(exarg_T *eap)
pos_T old_cursor = curwin->w_cursor;
int start_nsubs;
int save_ma = 0;
+ int save_b_changed = curbuf->b_changed;
if (!global_busy) {
sub_nsubs = 0;
@@ -3971,6 +3972,8 @@ skip:
}
}
+ curbuf->b_changed = save_b_changed; // preserve 'modified' during preview
+ // set_option_value((char_u *)"modified", 0L, NULL, OPT_LOCAL);
preview_buf = show_sub(pat, sub, eap->line1, eap->line2, &matched_lines);
} else if (*p_icm != NUL && eap->is_live) {
@@ -6014,9 +6017,8 @@ void set_context_in_sign_cmd(expand_T *xp, char_u *arg)
}
}
-/// Shows the effects of the current :substitute command being typed
-/// ('inccommand'). If inccommand=split, shows a preview window then later
-/// restores the layout.
+/// Shows the effects of the :substitute command being typed ('inccommand').
+/// If inccommand=split, shows a preview window and later restores the layout.
static buf_T *show_sub(char_u *pat, char_u *sub, linenr_T line1, linenr_T line2,
MatchedLineVec *matched_lines)
FUNC_ATTR_NONNULL_ALL
@@ -6050,7 +6052,7 @@ static buf_T *show_sub(char_u *pat, char_u *sub, linenr_T line1, linenr_T line2,
buf_open_special(preview_buf ? bufnr : 0, "[Preview]", "incsub");
buf_clear();
preview_buf = curbuf;
- set_option_value((char_u *)"bh", 0L, (char_u *)"hide", OPT_LOCAL);
+ set_option_value((char_u *)"bufhidden", 0L, (char_u *)"hide", OPT_LOCAL);
bufnr = preview_buf->handle;
curbuf->b_p_bl = false;
curbuf->b_p_ma = true;
diff --git a/src/nvim/ex_getln.c b/src/nvim/ex_getln.c
index 04e7d2fbcf..17693ecfc8 100644
--- a/src/nvim/ex_getln.c
+++ b/src/nvim/ex_getln.c
@@ -1594,6 +1594,7 @@ static int command_line_changed(CommandLineState *s)
} else if (s->firstc == ':'
&& KeyTyped // only if interactive
&& *p_icm != NUL // 'inccommand' is set
+ && curbuf->b_p_ma // buffer is modifiable
&& cmdline_star == 0 // not typing a password
&& cmd_is_live(ccline.cmdbuff)) {
// process a "live" command ('inccommand')
diff --git a/test/functional/ui/inccommand_spec.lua b/test/functional/ui/inccommand_spec.lua
index 09c47f1c34..520fadc8e0 100644
--- a/test/functional/ui/inccommand_spec.lua
+++ b/test/functional/ui/inccommand_spec.lua
@@ -610,6 +610,30 @@ describe(":substitute, inccommand=split", function()
screen:detach()
end)
+ it("preserves 'modified' buffer flag", function()
+ execute("set nomodified")
+ feed(":%s/tw")
+ screen:expect([[
+ Inc substitution on |
+ two lines |
+ |
+ {15:~ }|
+ {15:~ }|
+ {11:[No Name] }|
+ |2| two lines |
+ |4| two lines |
+ |
+ {15:~ }|
+ {15:~ }|
+ {15:~ }|
+ {15:~ }|
+ {10:[Preview] }|
+ :%s/tw^ |
+ ]])
+ feed([[<C-\><C-N>]]) -- Cancel the :substitute command.
+ eq(0, eval("&modified"))
+ end)
+
it('shows split window when typing the pattern', function()
feed(":%s/tw")
screen:expect([[
@@ -957,7 +981,7 @@ describe(":substitute, 'inccommand' with a failing expression", function()
common_setup(screen, case, default_text)
end
- it('in the pattern does nothing for', function()
+ it('in the pattern does nothing', function()
for _, case in pairs(cases) do
refresh(case)
execute("set inccommand=" .. case)