File: gvim.lua

package info (click to toggle)
vifm 0.14.3-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 14,252 kB
  • sloc: ansic: 179,567; sh: 5,445; makefile: 723; perl: 347; python: 76; xml: 26
file content (85 lines) | stat: -rw-r--r-- 1,986 bytes parent folder | download | duplicates (2)
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
--[[

Wraps gvim for handling all editor use cases within Vifm.

--]]

local M = {}

M.handlers = {}

M.handlers["open-help"] = function(info)
    vifm.startjob {
        cmd = string.format("gvim %s %s +only",
                            vifm.escape("+set runtimepath+=" .. info.vimdocdir),
                            vifm.escape("+help " .. info.topic))
    }

    return true
end

M.handlers["edit-one"] = function(info)
    local forkarg = info.mustwait and "-f" or ""

    local posarg = ""
    if info.line ~= nil and info.column == nil then
        posarg = '+' .. info.line
    elseif info.line ~= nil and info.column ~= nil then
        posarg = string.format("+call cursor(%d, %d)", info.line, info.column)
    end

    local job = vifm.startjob {
        cmd = string.format("gvim %s %s %s", forkarg, vifm.escape(posarg),
                            vifm.escape(info.path))
    }

    if not info.mustwait then
        return true
    end

    return job:exitcode() == 0
end

function map(table, functor)
    local result = {}
    for key, value in pairs(table) do
        result[key] = functor(value)
    end
    return result
end

M.handlers["edit-many"] = function(info)
    vifm.startjob {
        cmd = string.format("gvim %s",
                            table.concat(map(info.paths, vifm.escape), ' '))
    }

    return true
end

M.handlers["edit-list"] = function(info)
    local cmd
    if info.isquickfix then
        cmd = string.format("gvim +cgetbuffer +bd! +cc%d -", info.current)
    else
        local exec = "exe 'bd!|args' join(map(getline('1','$'),'fnameescape(v:val)'))"
        cmd = string.format("gvim +%s +argument%d -",
                            vifm.escape(exec),
                            info.current)
    end

    local job = vifm.startjob {
        cmd = cmd,
        iomode = 'w'
    }

    local input = table.concat(info.entries, '\n')

    local pipe = job:stdin()
    pipe:write(input)
    pipe:close()

    return true
end

return M