-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmode.lua
More file actions
101 lines (82 loc) · 1.79 KB
/
Copy pathmode.lua
File metadata and controls
101 lines (82 loc) · 1.79 KB
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
101
local micro = import("micro")
local config = import("micro/config")
local plug_path = config.ConfigDir .. "/plug/?.lua"
if not package.path:find(plug_path, 1, true) then
package.path = package.path .. ";" .. plug_path
end
local bell = require("vi/bell")
local combuf = require("vi/combuf")
-- vi modes
local MODE_COMMAND = 0
local MODE_INSERT = 1
local MODE_SEARCH = 2
local MODE_PROMPT = 3
-- states
local mode = MODE_INSERT
local function command()
if mode == MODE_SEARCH then
local cursor = micro.CurPane().Buf:GetActiveCursor()
if cursor:HasSelection() then
local start = cursor.CurSelection[1]
cursor.X = start.X
cursor.Y = start.Y
cursor:ResetSelection()
end
end
mode = MODE_COMMAND
end
local function insert()
mode = MODE_INSERT
end
local function search()
mode = MODE_SEARCH
end
local function prompt()
mode = MODE_PROMPT
end
local function code()
return mode
end
local function is_command()
return mode == MODE_COMMAND
end
local function is_insert()
return mode == MODE_INSERT
end
local function is_search()
return mode == MODE_SEARCH
end
local function is_prompt()
return mode == MODE_PROMPT
end
local function show()
local mode_line
if mode == MODE_COMMAND then
mode_line = "vi command mode"
elseif mode == MODE_INSERT then
mode_line = "vi insert mode"
elseif mode == MODE_SEARCH then
mode_line = "vi search mode"
elseif mode == MODE_PROMPT then
mode_line = "vi prompt mode"
else
bell.program_error("invalid mode == " .. mode)
return
end
bell.info(mode_line .. " [" .. combuf.get() .. "]")
end
-------------
-- Exports --
-------------
local M = {}
M.command = command
M.insert = insert
M.search = search
M.prompt = prompt
M.code = code
M.is_command = is_command
M.is_insert = is_insert
M.is_search = is_search
M.is_prompt = is_prompt
M.show = show
return M