forked from dail8859/LuaScript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathopen_source.lua
More file actions
48 lines (38 loc) · 1.06 KB
/
open_source.lua
File metadata and controls
48 lines (38 loc) · 1.06 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
-- open corresponding header (.h, .hpp) or source (.c, .cpp) file
-- скрипт для Notepad++, открывает соотвтествующий файл заголовка или исх. кода по названию
local function get_index(tbl, val)
for i, v in ipairs(tbl) do
if v == val then
return i
end
end
end
local function split_ext(file_path)
return string.match(file_path, "^(.+)(%..+)$")
end
local function file_exist(file_path)
local f = io.open(file_path, "r")
if f ~= nil then
io.close(f)
return true
else
return false
end
end
-- ======================================================
local KNOWN_EXTENSIONS = {'.h', '.hpp', '.cpp', '.c'}
npp.AddShortcut("Open Source", "", function()
local file_name, file_ext = split_ext(npp:GetFullCurrentPath())
if get_index(KNOWN_EXTENSIONS, file_ext) then
for i, ext in ipairs(KNOWN_EXTENSIONS) do
if ext ~= file_ext then
local tmp_path = file_name .. ext
-- print(tmp_path)
if file_exist(tmp_path) then
npp:DoOpen(tmp_path)
break
end
end
end
end
end)