aboutsummaryrefslogtreecommitdiff
path: root/lua
diff options
context:
space:
mode:
authorMarc André Tanner <mat@brain-dump.org>2017-07-12 19:05:03 +0200
committerMarc André Tanner <mat@brain-dump.org>2017-07-14 11:45:15 +0200
commit386eac2063bdda79279bbdea2fffcd7fc0ff682a (patch)
tree73ef16bc7f07ba8848020b98be3cde123f5b0a36 /lua
parent546917d21ca10214c24d3871c92b81265de6958c (diff)
downloadvis-386eac2063bdda79279bbdea2fffcd7fc0ff682a.tar.gz
vis-386eac2063bdda79279bbdea2fffcd7fc0ff682a.tar.xz
vis-lua: make selection first class primitives in Lua API
Diffstat (limited to 'lua')
-rw-r--r--lua/plugins/complete-filename.lua12
-rw-r--r--lua/plugins/complete-word.lua6
-rw-r--r--lua/plugins/number-inc-dec.lua6
-rw-r--r--lua/vis-std.lua12
4 files changed, 18 insertions, 18 deletions
diff --git a/lua/plugins/complete-filename.lua b/lua/plugins/complete-filename.lua
index 3648efe..cb5b361 100644
--- a/lua/plugins/complete-filename.lua
+++ b/lua/plugins/complete-filename.lua
@@ -1,9 +1,9 @@
--- complete file path at primary cursor location using vis-complete(1)
+-- complete file path at primary selection location using vis-complete(1)
vis:map(vis.modes.INSERT, "<C-x><C-f>", function()
local win = vis.win
local file = win.file
- local pos = win.cursor.pos
+ local pos = win.selection.pos
if not pos then return end
-- TODO do something clever here
local range = file:text_object_word(pos > 0 and pos-1 or pos);
@@ -19,15 +19,15 @@ vis:map(vis.modes.INSERT, "<C-x><C-f>", function()
return
end
file:insert(pos, out)
- win.cursor.pos = pos + #out
+ win.selection.pos = pos + #out
end, "Complete file path")
--- complete file path at primary cursor location using vis-open(1)
+-- complete file path at primary selection location using vis-open(1)
vis:map(vis.modes.INSERT, "<C-x><C-o>", function()
local win = vis.win
local file = win.file
- local pos = win.cursor.pos
+ local pos = win.selection.pos
if not pos then return end
local range = file:text_object_word(pos > 0 and pos-1 or pos);
if not range then return end
@@ -48,5 +48,5 @@ vis:map(vis.modes.INSERT, "<C-x><C-o>", function()
out = out:gsub("\n$", "")
file:delete(range)
file:insert(range.start, out)
- win.cursor.pos = range.start + #out
+ win.selection.pos = range.start + #out
end, "Complete file name")
diff --git a/lua/plugins/complete-word.lua b/lua/plugins/complete-word.lua
index 68ce385..41d112c 100644
--- a/lua/plugins/complete-word.lua
+++ b/lua/plugins/complete-word.lua
@@ -1,9 +1,9 @@
--- complete word at primary cursor location using vis-complete(1)
+-- complete word at primary selection location using vis-complete(1)
vis:map(vis.modes.INSERT, "<C-n>", function()
local win = vis.win
local file = win.file
- local pos = win.cursor.pos
+ local pos = win.selection.pos
if not pos then return end
local range = file:text_object_word(pos > 0 and pos-1 or pos);
if not range then return end
@@ -18,5 +18,5 @@ vis:map(vis.modes.INSERT, "<C-n>", function()
return
end
file:insert(pos, out)
- win.cursor.pos = pos + #out
+ win.selection.pos = pos + #out
end, "Complete word in file")
diff --git a/lua/plugins/number-inc-dec.lua b/lua/plugins/number-inc-dec.lua
index e1142ef..26a8825 100644
--- a/lua/plugins/number-inc-dec.lua
+++ b/lua/plugins/number-inc-dec.lua
@@ -15,8 +15,8 @@ local change = function(delta)
if not count then count = 1 end
vis.count = nil -- reset count, otherwise it affects next motion
- for cursor in win:cursors_iterator() do
- local pos = cursor.pos
+ for selection in win:selections_iterator() do
+ local pos = selection.pos
if not pos then goto continue end
local word = file:text_object_word(pos);
if not word then goto continue end
@@ -50,7 +50,7 @@ local change = function(delta)
end
file:delete(s, e - s)
file:insert(s, number)
- cursor.pos = s
+ selection.pos = s
::continue::
end
end
diff --git a/lua/vis-std.lua b/lua/vis-std.lua
index e762d86..5f41b4d 100644
--- a/lua/vis-std.lua
+++ b/lua/vis-std.lua
@@ -81,7 +81,7 @@ vis.events.subscribe(vis.events.WIN_STATUS, function(win)
local left_parts = {}
local right_parts = {}
local file = win.file
- local cursor = win.cursor
+ local selection = win.selection
local mode = modes[vis.mode]
if mode ~= '' and vis.win == win then
@@ -91,18 +91,18 @@ vis.events.subscribe(vis.events.WIN_STATUS, function(win)
table.insert(left_parts, (file.name or '[No Name]') ..
(file.modified and ' [+]' or '') .. (vis.recording and ' @' or ''))
- if #win.cursors > 1 then
- table.insert(right_parts, cursor.number..'/'..#win.cursors)
+ if #win.selections > 1 then
+ table.insert(right_parts, selection.number..'/'..#win.selections)
end
local size = file.size
- local pos = cursor.pos
+ local pos = selection.pos
if not pos then pos = 0 end
table.insert(right_parts, (size == 0 and "0" or math.ceil(pos/size*100)).."%")
if not win.large then
- local col = cursor.col
- table.insert(right_parts, cursor.line..', '..col)
+ local col = selection.col
+ table.insert(right_parts, selection.line..', '..col)
if size > 33554432 or col > 65536 then
win.large = true
end