aboutsummaryrefslogtreecommitdiff
path: root/plugins/pdfview.lua
blob: 743c6ec9f2fecf7f7bb563f975f016127640799e (plain)
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
-- mod-version:1 -- lite-xl 1.16
local core = require "core"
local command = require "core.command"
local keymap = require "core.keymap"

command.add("core.docview", {
  ["pdfview:show-preview"] = function()
    local av = core.active_view

-- User's home directory
    local homedir = ""

    if PLATFORM == "Windows" then
        homedir = os.getenv("USERPROFILE")
    else
        homedir = os.getenv("HOME")
    end

-- The current (La)TeX file
    local texfile = av:get_filename()
    texfile = string.gsub(texfile, '~', homedir)
-- Construct the PDF file name out of the (La)Tex filename
    local pdffile = "\"" .. string.gsub(texfile, ".tex", ".pdf") .. "\""
-- PDF viewer - is there any provided by the environment
    local pdfcmd = os.getenv("LITE_PDF_VIEWER")

    core.log("Opening pdf preview for \"%s\"", texfile)

    if pdfcmd ~= nil then
        system.exec(pdfcmd .. " " .. pdffile)
    elseif PLATFORM == "Windows" then
        system.exec("start " .. pdffile)
    else
        system.exec(string.format("xdg-open %q", pdffile))
    end

--    core.add_thread(function()
--      coroutine.yield(5)
--      os.remove(htmlfile)
--    end)
  end
})


keymap.add { ["ctrl+shift+v"] = "pdfview:show-preview" }