-
Notifications
You must be signed in to change notification settings - Fork 11
/
map.lua
100 lines (87 loc) · 2.85 KB
/
map.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
local M = {}
local command = require "dial.command"
local util = require "dial.util"
---Sandwich input string between <Cmd> and <CR>.
---@param body string
local function cmdcr(body)
local cmd_sequences = "<Cmd>"
local cr_sequences = "<CR>"
return cmd_sequences .. body .. cr_sequences
end
---Output command sequence which provides dial operation.
---@param direction direction
---@param mode mode
---@param group_name? string
---@param count? integer
local function _cmd_sequence(direction, mode, group_name, count)
local select
if group_name == nil then
select = cmdcr([[lua require"dial.command".select_augend_]] .. mode .. "()")
else
select =
cmdcr([[lua require"dial.command".select_augend_]] .. mode .. [[(]] .. vim.fn.string(group_name) .. [[)]])
end
-- command.select_augend_normal(vim.v.count, group_name)
local setopfunc = cmdcr([[let &opfunc="dial#operator#]] .. direction .. "_" .. mode .. [["]])
local textobj =
util.if_expr(mode == "normal" or mode == "gnormal", cmdcr [[lua require("dial.command").textobj()]], "")
if count ~= nil then
if type(count) ~= "number" then
error "count must be a integer."
end
return count .. select .. setopfunc .. "g@" .. textobj
end
return select .. setopfunc .. "g@" .. textobj
end
---Functional interface
---@param direction direction
---@param mode mode
---@param group_name? string
---@param count? integer
function M.manipulate(direction, mode, group_name, count)
if count == nil then
count = vim.v.count1
end
vim.cmd.normal(vim.api.nvim_replace_termcodes(_cmd_sequence(direction, mode, group_name, count), true, true, true))
end
---@param group_name? string
---@return string
function M.inc_normal(group_name)
return _cmd_sequence("increment", "normal", group_name)
end
---@param group_name? string
---@return string
function M.dec_normal(group_name)
return _cmd_sequence("decrement", "normal", group_name)
end
---@param group_name? string
---@return string
function M.inc_gnormal(group_name)
return _cmd_sequence("increment", "gnormal", group_name)
end
---@param group_name? string
---@return string
function M.dec_gnormal(group_name)
return _cmd_sequence("decrement", "gnormal", group_name)
end
---@param group_name? string
---@return string
function M.inc_visual(group_name)
return _cmd_sequence("increment", "visual", group_name)
end
---@param group_name? string
---@return string
function M.dec_visual(group_name)
return _cmd_sequence("decrement", "visual", group_name)
end
---@param group_name? string
---@return string
function M.inc_gvisual(group_name)
return _cmd_sequence("increment", "gvisual", group_name)
end
---@param group_name? string
---@return string
function M.dec_gvisual(group_name)
return _cmd_sequence("decrement", "gvisual", group_name)
end
return M