API: nvim_buf_set_lines: handle 'nomodifiable' #10910

This commit is contained in:
Justin M. Keyes
2019-09-01 22:04:20 -07:00
committed by GitHub
parent 5f23a3dbcf
commit 299331490e
2 changed files with 12 additions and 0 deletions

View File

@@ -453,6 +453,11 @@ void nvim_buf_set_lines(uint64_t channel_id,
aco_save_T aco; aco_save_T aco;
aucmd_prepbuf(&aco, (buf_T *)buf); aucmd_prepbuf(&aco, (buf_T *)buf);
if (!MODIFIABLE(buf)) {
api_set_error(err, kErrorTypeException, "Buffer is not 'modifiable'");
goto end;
}
if (u_save((linenr_T)(start - 1), (linenr_T)end) == FAIL) { if (u_save((linenr_T)(start - 1), (linenr_T)end) == FAIL) {
api_set_error(err, kErrorTypeException, "Failed to save undo information"); api_set_error(err, kErrorTypeException, "Failed to save undo information");
goto end; goto end;

View File

@@ -14,6 +14,7 @@ local meth_pcall = helpers.meth_pcall
local command = helpers.command local command = helpers.command
local bufmeths = helpers.bufmeths local bufmeths = helpers.bufmeths
local feed = helpers.feed local feed = helpers.feed
local expect_err = helpers.expect_err
describe('api/buf', function() describe('api/buf', function()
before_each(clear) before_each(clear)
@@ -197,6 +198,12 @@ describe('api/buf', function()
eq(': ' .. exp_emsg, emsg:sub(-#exp_emsg - 2)) eq(': ' .. exp_emsg, emsg:sub(-#exp_emsg - 2))
end) end)
it("fails if 'nomodifiable'", function()
command('set nomodifiable')
expect_err([[Buffer is not 'modifiable']],
bufmeths.set_lines, 1, 1, 2, false, {'a','b'})
end)
it('has correct line_count when inserting and deleting', function() it('has correct line_count when inserting and deleting', function()
eq(1, line_count()) eq(1, line_count())
set_lines(-1, -1, true, {'line'}) set_lines(-1, -1, true, {'line'})