aboutsummaryrefslogtreecommitdiff
path: root/plugins
diff options
context:
space:
mode:
authorFrancesco <francesco.bbt@gmail.com>2021-06-15 22:58:31 +0200
committerGitHub <noreply@github.com>2021-06-15 22:58:31 +0200
commitdc4448f9e3ca44ed175d0dabbc20486c9b7d92a8 (patch)
tree58e59bee047b9c6eeabd99fe7a17c59e2d2d768a /plugins
parent32b8d620b8b2aa07304ed76a2855d353faaa9ca0 (diff)
parent3d3c48f3215c1d663abafefd78a0ca595565df0e (diff)
downloadlite-xl-plugins-dc4448f9e3ca44ed175d0dabbc20486c9b7d92a8.tar.gz
lite-xl-plugins-dc4448f9e3ca44ed175d0dabbc20486c9b7d92a8.zip
Merge pull request #35 from ajalexei/master
Added syntax highlighting for BibTeX files, PDF preview for LaTeX files, compilation of LaTeX files into PDF
Diffstat (limited to 'plugins')
-rw-r--r--plugins/language_bib.lua22
-rw-r--r--plugins/pdfview.lua45
-rw-r--r--plugins/texcompile.lua44
3 files changed, 111 insertions, 0 deletions
diff --git a/plugins/language_bib.lua b/plugins/language_bib.lua
new file mode 100644
index 0000000..08a5662
--- /dev/null
+++ b/plugins/language_bib.lua
@@ -0,0 +1,22 @@
+-- mod-version:1 -- lite-xl 1.16
+local syntax = require "core.syntax"
+
+syntax.add {
+ files = { "%.bib$" },
+ comment = "%%",
+ patterns = {
+ { pattern = {"%%", "\n"}, type = "comment" },
+ { pattern = "@%a+", type = "keyword" },
+ { pattern = "%a+%s=", type = "keyword2" },
+ },
+ symbols = {
+ ["author"] = "keyword",
+ ["doi"] = "keyword",
+ ["issue"] = "keyword",
+ ["journal"] = "keyword",
+ ["month"] = "keyword",
+ ["numpages"] = "keyword",
+ ["pages"] = "keyword",
+ ["publisher"] = "keyword",
+ }
+}
diff --git a/plugins/pdfview.lua b/plugins/pdfview.lua
new file mode 100644
index 0000000..41e8ad0
--- /dev/null
+++ b/plugins/pdfview.lua
@@ -0,0 +1,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" }
diff --git a/plugins/texcompile.lua b/plugins/texcompile.lua
new file mode 100644
index 0000000..7a5fd6e
--- /dev/null
+++ b/plugins/texcompile.lua
@@ -0,0 +1,44 @@
+-- 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", {
+ ["texcompile:tex-compile"] = 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 and path
+ local texname = av:get_name()
+ local texpath = av:get_filename()
+ texpath = string.gsub(texpath, '~', homedir)
+ texpath = string.gsub(texpath, texname, '')
+
+-- LaTeX compiler - is there any provided by the environment
+ local texcmd = os.getenv("LITE_LATEX_COMPILER")
+
+ if texcmd == nil then
+ core.log("No LaTeX compiler found")
+ else
+ core.log("LaTeX compiler is %s, compiling %s", texcmd, texname)
+
+ system.exec(string.format("cd %q && %q %q", texpath, texcmd, texname))
+ end
+
+-- core.add_thread(function()
+-- coroutine.yield(5)
+-- os.remove(htmlfile)
+-- end)
+ end
+})
+
+
+keymap.add { ["ctrl+shift+t"] = "texcompile:tex-compile" }