aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README.md1
-rw-r--r--plugins/autowrap.lua1
-rw-r--r--plugins/language_R.lua39
-rw-r--r--plugins/texcompile.lua169
4 files changed, 189 insertions, 21 deletions
diff --git a/README.md b/README.md
index 225dffb..ac39ff0 100644
--- a/README.md
+++ b/README.md
@@ -82,6 +82,7 @@ Plugin | Description
[`language_pony`*](https://github.com/MrAnyx/lite-plugin-pony) | Syntax for [Pony](https://www.ponylang.io/) programming language
[`language_powershell`](plugins/language_powershell.lua?raw=1) | Syntax for [PowerShell](https://docs.microsoft.com/en-us/powershell) scripting language
[`language_psql`](plugins/language_psql.lua?raw=1) | Syntax for the postgresql database access language
+[`language_r`](plugins/language_R.lua?raw=1) | Syntax for [R](https://www.r-project.org/) scripting language
[`language_rescript`](plugins/language_rescript.lua?raw=1) | Syntax for the [ReScript](https://rescript-lang.org/) programming language
[`language_rust`](plugins/language_rust.lua?raw=1) | Syntax for the [Rust](https://rust-lang.org/) programming language
[`language_ruby`](plugins/language_ruby.lua?raw=1) | Syntax for the [Ruby](https://www.ruby-lang.org/) programming language
diff --git a/plugins/autowrap.lua b/plugins/autowrap.lua
index 38f8eb3..c9dde6d 100644
--- a/plugins/autowrap.lua
+++ b/plugins/autowrap.lua
@@ -32,5 +32,6 @@ DocView.on_text_input = function(self, ...)
command.perform("reflow:reflow")
command.perform("doc:move-to-next-char")
command.perform("doc:move-to-previous-char")
+ command.perform("doc:move-to-end-of-line")
end
end
diff --git a/plugins/language_R.lua b/plugins/language_R.lua
new file mode 100644
index 0000000..68c3a18
--- /dev/null
+++ b/plugins/language_R.lua
@@ -0,0 +1,39 @@
+-- mod-version:2 -- lite-xl 2.0
+local syntax = require "core.syntax"
+
+syntax.add{
+ files = {"%.r$", "%.rds$", "%.rda$", "%.rdata$", "%.R$"},
+ comment = "#",
+ patterns = {
+ {pattern = {"#", "\n"}, type = "comment"},
+ {pattern = {'"', '"'}, type = "string"},
+ {pattern = {"'", "'"}, type = "string"},
+ {pattern = "[%a_][%w_]*%f[(]", type = "function"},
+ {pattern = "[%a_][%w_]*", type = "symbol"},
+ {pattern = "[%+%-=/%*%^%%<>!|&]", type = "operator"},
+ {pattern = "0x[%da-fA-F]+", type = "number"},
+ {pattern = "-?%d+[%d%.eE]*", type = "number"},
+ {pattern = "-?%.?%d+", type = "number"},
+
+ },
+ symbols = {
+ ["TRUE"] = "literal",
+ ["FALSE"] = "literal",
+ ["NA"] = "literal",
+ ["NULL"] = "literal",
+ ["Inf"] = "literal",
+ ["if"] = "keyword",
+ ["else"] = "keyword",
+ ["while"] = "keyword",
+ ["function"] = "keyword",
+ ["break"] = "keyword",
+ ["next"] = "keyword",
+ ["repeat"] = "keyword",
+ ["in"] = "keyword",
+ ["for"] = "keyword",
+ ["NA_integer"] = "keyword",
+ ["NA_complex"] = "keyword",
+ ["NA_character"] = "keyword",
+ ["NA_real"] = "keyword"
+ }
+}
diff --git a/plugins/texcompile.lua b/plugins/texcompile.lua
index 2f53513..517aa9b 100644
--- a/plugins/texcompile.lua
+++ b/plugins/texcompile.lua
@@ -1,44 +1,171 @@
-- mod-version:2 -- lite-xl 2.0
local core = require "core"
+local config = require "core.config"
local command = require "core.command"
+local common = require "core.common"
local keymap = require "core.keymap"
-command.add("core.docview", {
- ["texcompile:tex-compile"] = function()
- local av = core.active_view
+-- This code use an adaptation of the rxi/console plugin code to
+-- start commands.
+
+local pending_threads = {}
+local thread_active = false
--- User's home directory
- local homedir = ""
+local function push_output(str, opt)
+ -- By default we just ignore the output of a command.
+ -- print(">>OUTPUT:", str)
+end
+
+local function read_file(filename, offset)
+ local fp = io.open(filename, "rb")
+ fp:seek("set", offset or 0)
+ local res = fp:read("*a")
+ fp:close()
+ return res
+end
+
+local function write_file(filename, text)
+ local fp = io.open(filename, "w")
+ fp:write(text)
+ fp:close()
+end
+
+local function init_opt(opt)
+ local res = {
+ command = "",
+ arguments = {},
+ on_complete = function() end,
+ }
+ for k, v in pairs(res) do
+ res[k] = opt[k] or v
+ end
+ return res
+end
+local files = {
+ script = core.temp_filename(PLATFORM == "Windows" and ".bat"),
+ script2 = core.temp_filename(PLATFORM == "Windows" and ".bat"),
+ output = core.temp_filename(),
+ complete = core.temp_filename(),
+}
+
+local function command_run(opt)
+ opt = init_opt(opt)
+
+ local function thread()
+ -- init script file(s)
+ local args_quoted = {}
+ for i, arg in ipairs(opt.arguments) do args_quoted[i] = string.format("%q", arg) end
+ local args_concat = table.concat(args_quoted, " ")
+ local working_dir = opt.working_dir or "."
if PLATFORM == "Windows" then
- homedir = os.getenv("USERPROFILE")
+ write_file(files.script, string.format("%s %s\n", opt.command, args_concat))
+ write_file(files.script2, string.format([[
+ @echo off
+ cd %q
+ call %q >%q 2>&1
+ echo "" >%q
+ exit
+ ]], working_dir, files.script, files.output, files.complete))
+ system.exec(string.format("call %q", files.script2))
+ else
+ write_file(files.script, string.format([[
+ cd %q
+ %s %s
+ touch %q
+ ]], working_dir, opt.command, args_concat, files.complete))
+ system.exec(string.format("bash %q >%q 2>&1", files.script, files.output))
+ end
+
+ -- checks output file for change and reads
+ local last_size = 0
+ local function check_output_file()
+ if PLATFORM == "Windows" then
+ local fp = io.open(files.output)
+ if fp then fp:close() end
+ end
+ local info = system.get_file_info(files.output)
+ if info and info.size > last_size then
+ local text = read_file(files.output, last_size)
+ push_output(text, opt)
+ last_size = info.size
+ end
+ end
+
+ -- read output file until we get a file indicating completion
+ while not system.get_file_info(files.complete) do
+ check_output_file()
+ coroutine.yield(0.1)
+ end
+ check_output_file()
+
+ -- clean up and finish
+ for _, file in pairs(files) do
+ os.remove(file)
+ end
+ opt.on_complete()
+
+ -- handle pending thread
+ local pending = table.remove(pending_threads, 1)
+ if pending then
+ core.add_thread(pending)
else
- homedir = os.getenv("HOME")
+ thread_active = false
end
+ end
+
+ -- push/init thread
+ if thread_active then
+ table.insert(pending_threads, thread)
+ else
+ core.add_thread(thread)
+ thread_active = true
+ end
+end
--- The current (La)TeX file and path
+command.add("core.docview", {
+ ["texcompile:tex-compile"] = function()
+ local av = core.active_view
+
+ -- 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, '')
+ local texpath = common.dirname(av:get_filename())
+
+ -- Add in your user's config file something like:
+ --
+ -- config.texcompile = {
+ -- latex_command = "pdflatex",
+ -- view_command = "evince",
+ -- }
+ --
+ -- On windows you may use the full path for the command like:
+ --
+ -- latex_command = [[c:\miktex\miktex\bin\x64\pdflatex.exe]],
--- LaTeX compiler - is there any provided by the environment
- local texcmd = os.getenv("LITE_LATEX_COMPILER")
+ -- LaTeX compiler - is there any provided by the environment
+ local texcmd = config.texcompile and config.texcompile.latex_command
+ local viewcmd = config.texcompile and config.texcompile.view_command
- if texcmd == nil then
+ if not texcmd 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
+ command_run {
+ command = texcmd,
+ arguments = { texname },
+ working_dir = texpath,
+ on_complete = function() core.log("Tex compiling command terminated.") end
+ }
--- core.add_thread(function()
--- coroutine.yield(5)
--- os.remove(htmlfile)
--- end)
+ local pdfname = texname:gsub("%.tex$", ".pdf")
+ command_run {
+ command = viewcmd,
+ arguments = { pdfname },
+ working_dir = texpath
+ }
+ end
end
})
-
keymap.add { ["ctrl+shift+t"] = "texcompile:tex-compile" }