aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/nvim/api/buffer.c11
-rw-r--r--src/nvim/buffer.c6
-rw-r--r--src/nvim/ex_cmds.c3
-rw-r--r--src/nvim/misc1.c14
-rw-r--r--src/nvim/ops.c8
-rw-r--r--src/nvim/undo.c2
-rw-r--r--test/functional/api/liveupdate_spec.lua85
7 files changed, 63 insertions, 66 deletions
diff --git a/src/nvim/api/buffer.c b/src/nvim/api/buffer.c
index 2c7480a16b..6778227a27 100644
--- a/src/nvim/api/buffer.c
+++ b/src/nvim/api/buffer.c
@@ -85,9 +85,9 @@ String buffer_get_line(Buffer buffer, Integer index, Error *err)
/// @return False when live updates couldn't be enabled because the buffer isn't
/// loaded; otherwise True.
Boolean nvim_buf_live_updates_start(uint64_t channel_id,
- Buffer buffer,
- Boolean send_buffer,
- Error *err)
+ Buffer buffer,
+ Boolean send_buffer,
+ Error *err)
FUNC_API_SINCE(4) FUNC_API_REMOTE_ONLY
{
buf_T *buf = find_buffer_by_handle(buffer, err);
@@ -97,7 +97,6 @@ Boolean nvim_buf_live_updates_start(uint64_t channel_id,
}
return liveupdate_register(buf, channel_id, send_buffer);
-
}
//
/// Deactivate live updates from this buffer to the current channel.
@@ -107,8 +106,8 @@ Boolean nvim_buf_live_updates_start(uint64_t channel_id,
/// @return False when live updates couldn't be disabled because the buffer
/// isn't loaded; otherwise True.
Boolean nvim_buf_live_updates_stop(uint64_t channel_id,
- Buffer buffer,
- Error *err)
+ Buffer buffer,
+ Error *err)
FUNC_API_SINCE(4) FUNC_API_REMOTE_ONLY
{
buf_T *buf = find_buffer_by_handle(buffer, err);
diff --git a/src/nvim/buffer.c b/src/nvim/buffer.c
index 124e479686..e7ff25ce6b 100644
--- a/src/nvim/buffer.c
+++ b/src/nvim/buffer.c
@@ -1738,9 +1738,9 @@ buf_T * buflist_new(char_u *ffname, char_u *sfname, linenr_T lnum, int flags)
if (flags & BLN_DUMMY)
buf->b_flags |= BF_DUMMY;
buf_clear_file(buf);
- clrallmarks(buf); /* clear marks */
- fmarks_check_names(buf); /* check file marks for this file */
- buf->b_p_bl = (flags & BLN_LISTED) ? TRUE : FALSE; /* init 'buflisted' */
+ clrallmarks(buf); // clear marks
+ fmarks_check_names(buf); // check file marks for this file
+ buf->b_p_bl = (flags & BLN_LISTED) ? true : false; // init 'buflisted'
kv_destroy(buf->liveupdate_channels);
kv_init(buf->liveupdate_channels);
if (!(flags & BLN_DUMMY)) {
diff --git a/src/nvim/ex_cmds.c b/src/nvim/ex_cmds.c
index d68dbc8676..e418e0c20e 100644
--- a/src/nvim/ex_cmds.c
+++ b/src/nvim/ex_cmds.c
@@ -745,8 +745,9 @@ void ex_retab(exarg_T *eap)
if (curbuf->b_p_ts != new_ts)
redraw_curbuf_later(NOT_VALID);
- if (first_line != 0)
+ if (first_line != 0) {
changed_lines(first_line, 0, last_line + 1, 0L, true);
+ }
curwin->w_p_list = save_list; /* restore 'list' */
diff --git a/src/nvim/misc1.c b/src/nvim/misc1.c
index a3b2d5e7a4..e2094d7293 100644
--- a/src/nvim/misc1.c
+++ b/src/nvim/misc1.c
@@ -837,7 +837,7 @@ open_line (
if (did_append) {
changed_lines(curwin->w_cursor.lnum, curwin->w_cursor.col,
curwin->w_cursor.lnum + 1, 1L, true);
- did_append = FALSE;
+ did_append = false;
/* Move marks after the line break to the new line. */
if (flags & OPENLINE_MARKFIX)
@@ -1914,12 +1914,12 @@ void deleted_lines_mark(linenr_T lnum, long count)
* Takes care of calling changed() and updating b_mod_*.
* Careful: may trigger autocommands that reload the buffer.
*/
-void
-changed_lines (
- linenr_T lnum, /* first line with change */
- colnr_T col, /* column in first line with change */
- linenr_T lnume, /* line below last changed line */
- long xtra, /* number of extra lines (negative when deleting) */
+void
+changed_lines(
+ linenr_T lnum, // first line with change
+ colnr_T col, // column in first line with change
+ linenr_T lnume, // line below last changed line
+ long xtra, // number of extra lines (negative when deleting)
bool send_liveupdate // some callers like undo/redo call changed_lines()
// and then increment b_changedtick *again*. This flag
// allows these callers to send the LiveUpdate events
diff --git a/src/nvim/ops.c b/src/nvim/ops.c
index 692713af73..c9e8344ac1 100644
--- a/src/nvim/ops.c
+++ b/src/nvim/ops.c
@@ -632,12 +632,13 @@ void op_reindent(oparg_T *oap, Indenter how)
/* Mark changed lines so that they will be redrawn. When Visual
* highlighting was present, need to continue until the last line. When
* there is no change still need to remove the Visual highlighting. */
- if (last_changed != 0)
+ if (last_changed != 0) {
changed_lines(first_changed, 0,
oap->is_VIsual ? start_lnum + oap->line_count :
last_changed + 1, 0L, true);
- else if (oap->is_VIsual)
+ } else if (oap->is_VIsual) {
redraw_curbuf_later(INVERTED);
+ }
if (oap->line_count > p_report) {
i = oap->line_count - (i + 1);
@@ -1856,8 +1857,9 @@ void op_tilde(oparg_T *oap)
did_change |= one_change;
}
- if (did_change)
+ if (did_change) {
changed_lines(oap->start.lnum, 0, oap->end.lnum + 1, 0L, true);
+ }
} else { // not block mode
if (oap->motion_type == kMTLineWise) {
oap->start.col = 0;
diff --git a/src/nvim/undo.c b/src/nvim/undo.c
index 27d745a254..1c14e93211 100644
--- a/src/nvim/undo.c
+++ b/src/nvim/undo.c
@@ -2030,7 +2030,7 @@ void undo_time(long step, int sec, int file, int absolute)
break;
curbuf->b_u_curhead = uhp;
u_undoredo(true, true);
- uhp->uh_walk = nomark; /* don't go back down here */
+ uhp->uh_walk = nomark; // don't go back down here
}
/*
diff --git a/test/functional/api/liveupdate_spec.lua b/test/functional/api/liveupdate_spec.lua
index 9e071ccaa6..ba98aa60c8 100644
--- a/test/functional/api/liveupdate_spec.lua
+++ b/test/functional/api/liveupdate_spec.lua
@@ -10,7 +10,12 @@ local origlines = {"original line 1",
"original line 5",
"original line 6"}
-function sendkeys(keys)
+local function expectn(name, args)
+ -- expect the next message to be the specified notification event
+ eq({'notification', name, args}, next_message())
+end
+
+local function sendkeys(keys)
nvim('input', keys)
-- give neovim some time to process msgpack requests before possibly sending
-- more key presses - otherwise they all pile up in the queue and get
@@ -19,16 +24,7 @@ function sendkeys(keys)
repeat until os.clock() > ntime
end
-function editoriginal(activate, lines)
- if not lines then
- lines = origlines
- end
- -- load up the file with the correct contents
- helpers.clear()
- return open(activate, lines)
-end
-
-function open(activate, lines)
+local function open(activate, lines)
local filename = helpers.tmpname()
helpers.write_file(filename, table.concat(lines, "\n").."\n", true)
command('edit ' .. filename)
@@ -46,24 +42,28 @@ function open(activate, lines)
return b, tick, filename
end
-function reopen(buf, expectedlines)
+local function editoriginal(activate, lines)
+ if not lines then
+ lines = origlines
+ end
+ -- load up the file with the correct contents
+ helpers.clear()
+ return open(activate, lines)
+end
+
+local function reopen(buf, expectedlines)
ok(buffer('live_updates_stop', buf))
expectn('LiveUpdateEnd', {buf})
-- for some reason the :edit! increments tick by 2
command('edit!')
local tick = eval('b:changedtick')
ok(buffer('live_updates_start', buf, true))
- expectn('LiveUpdateStart', {buf, tick, origlines, false})
+ expectn('LiveUpdateStart', {buf, tick, expectedlines, false})
command('normal! gg')
return tick
end
-function expectn(name, args)
- -- expect the next message to be the specified notification event
- eq({'notification', name, args}, next_message())
-end
-
-function reopenwithfolds(b)
+local function reopenwithfolds(b)
-- discard any changes to the buffer
local tick = reopen(b, origlines)
@@ -141,7 +141,7 @@ describe('liveupdate', function()
command('normal! gg4YGp')
command('normal! Gp')
command('normal! Gp')
- firstfour = {'original line 4',
+ local firstfour = {'original line 4',
'original line 5',
'original line 6',
'original line 4'}
@@ -159,8 +159,8 @@ describe('liveupdate', function()
-- add a line at the start of an empty file
command('enew')
- local tick = eval('b:changedtick')
- b2 = nvim('get_current_buf')
+ tick = eval('b:changedtick')
+ local b2 = nvim('get_current_buf')
ok(buffer('live_updates_start', b2, true))
expectn('LiveUpdateStart', {b2, tick, {""}, false})
eval('append(0, ["new line 1"])')
@@ -173,7 +173,7 @@ describe('liveupdate', function()
-- add multiple lines to a blank file
command('enew!')
- b3 = nvim('get_current_buf')
+ local b3 = nvim('get_current_buf')
ok(buffer('live_updates_start', b3, true))
tick = eval('b:changedtick')
expectn('LiveUpdateStart', {b3, tick, {""}, false})
@@ -230,7 +230,6 @@ describe('liveupdate', function()
it('knows when you modify lines of text', function()
local b, tick = editoriginal(true)
- local channel = nvim('get_api_info')[1]
-- some normal text editing
command('normal! A555')
@@ -266,7 +265,7 @@ describe('liveupdate', function()
command('enew!')
tick = 2
expectn('LiveUpdateEnd', {b})
- bnew = nvim('get_current_buf')
+ local bnew = nvim('get_current_buf')
ok(buffer('live_updates_start', bnew, true))
expectn('LiveUpdateStart', {bnew, tick, {''}, false})
sendkeys('i')
@@ -324,7 +323,7 @@ describe('liveupdate', function()
end)
it('sends a sensible event when you use "o"', function()
- b, tick = editoriginal(true, {'AAA', 'BBB'})
+ local b, tick = editoriginal(true, {'AAA', 'BBB'})
command('set noautoindent nosmartindent')
-- use 'o' to start a new line from a line with no indent
@@ -391,14 +390,14 @@ describe('liveupdate', function()
it('allows a channel to watch multiple buffers at once', function()
-- edit 3 buffers, make sure they all have windows visible so that when we
-- move between buffers, none of them are unloaded
- b1, tick1, f1 = editoriginal(true, {'A1', 'A2'})
- b1nr = eval('bufnr("")')
+ local b1, tick1 = editoriginal(true, {'A1', 'A2'})
+ local b1nr = eval('bufnr("")')
command('split')
- b2, tick2, f2 = open(true, {'B1', 'B2'})
- b2nr = eval('bufnr("")')
+ local b2, tick2 = open(true, {'B1', 'B2'})
+ local b2nr = eval('bufnr("")')
command('split')
- b3, tick3, f3 = open(true, {'C1', 'C2'})
- b3nr = eval('bufnr("")')
+ local b3, tick3 = open(true, {'C1', 'C2'})
+ local b3nr = eval('bufnr("")')
-- make a new window for moving between buffers
command('split')
@@ -470,12 +469,12 @@ describe('liveupdate', function()
end
-- create several new sessions, in addition to our main API
- sessions = {}
+ local sessions = {}
sessions[1] = addsession(helpers.tmpname()..'.1')
sessions[2] = addsession(helpers.tmpname()..'.2')
sessions[3] = addsession(helpers.tmpname()..'.3')
- function request(sessionnr, method, ...)
+ local function request(sessionnr, method, ...)
local status, rv = sessions[sessionnr]:request(method, ...)
if not status then
error(rv[2])
@@ -483,7 +482,7 @@ describe('liveupdate', function()
return rv
end
- function wantn(sessionid, name, args)
+ local function wantn(sessionid, name, args)
local session = sessions[sessionid]
eq({'notification', name, args}, session:next_message())
end
@@ -534,7 +533,7 @@ describe('liveupdate', function()
-- make sure there are no other pending LiveUpdate messages going to
-- channel 1
- local channel1 = request(1, 'nvim_get_api_info')[1]
+ channel1 = request(1, 'nvim_get_api_info')[1]
eval('rpcnotify('..channel1..', "Hello Again")')
wantn(1, 'Hello Again', {})
end)
@@ -573,7 +572,6 @@ describe('liveupdate', function()
it('works with :left', function()
local b, tick = editoriginal(true, {" A", " B", "B", "\tB", "\t\tC"})
- local channel = nvim('get_api_info')[1]
command('2,4left')
tick = tick + 1
expectn('LiveUpdate', {b, tick, 1, 3, {"B", "B", "B"}})
@@ -585,7 +583,6 @@ describe('liveupdate', function()
"\t \tBB",
" \tB",
"\t\tC"})
- local channel = nvim('get_api_info')[1]
command('set ts=2 et')
command('2,4retab')
tick = tick + 1
@@ -594,7 +591,6 @@ describe('liveupdate', function()
it('works with :move', function()
local b, tick = editoriginal(true, origlines)
- local channel = nvim('get_api_info')[1]
-- move text down towards the end of the file
command('2,3move 4')
tick = tick + 2
@@ -614,9 +610,8 @@ describe('liveupdate', function()
end)
it('sends sensible events when you manually add/remove folds', function()
- local b, tick = editoriginal(true)
- local channel = nvim('get_api_info')[1]
- tick = reopenwithfolds(b)
+ local b = editoriginal(true)
+ local tick = reopenwithfolds(b)
-- delete the inner fold
command('normal! zR3Gzd')
@@ -683,7 +678,7 @@ describe('liveupdate', function()
eval('rpcnotify('..channel..', "Hello There")')
expectn('Hello There', {})
end)
-
+
-- test what happens when a buffer is hidden
it('keeps updates turned on if the buffer is hidden', function()
local b, tick = editoriginal(true, {'AAA'})
@@ -720,10 +715,10 @@ describe('liveupdate', function()
helpers.clear()
-- need to make a new window with a buffer because :bunload doesn't let you
-- unload the last buffer
- for i, cmd in ipairs({'bunload', 'bdelete', 'bwipeout'}) do
+ for _, cmd in ipairs({'bunload', 'bdelete', 'bwipeout'}) do
command('new')
-- open a brand spanking new file
- local b, filename = open(true, {'AAA'})
+ local b = open(true, {'AAA'})
-- call :bunload or whatever the command is, and then check that we
-- receive a LiveUpdateEnd