aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README.md3
-rw-r--r--plugins/force_syntax.lua132
-rw-r--r--plugins/language_julia.lua52
-rw-r--r--plugins/language_scala.lua80
-rw-r--r--plugins/opacity.lua62
-rw-r--r--plugins/open_ext.lua2
6 files changed, 317 insertions, 14 deletions
diff --git a/README.md b/README.md
index a49c21c..7d0176a 100644
--- a/README.md
+++ b/README.md
@@ -36,6 +36,7 @@ Plugin | Description
[`ephemeraldocviews`](plugins/ephemeraldocviews.lua?raw=1) | Preview tabs. Opening a doc will replace the contents of the preview tab. Marks tabs as non-preview on any change.
[`fallbackfonts`](https://github.com/takase1121/lite-fallback-fonts)* | Adds support for fallback fonts *([gif](https://raw.githubusercontent.com/takase1121/lite-fallback-fonts/master/assets/Iw18fI57J0.gif))*
[`fontconfig`](plugins/fontconfig.lua?raw=1) | Allows users to load fonts with [fontconfig](https://www.freedesktop.org/software/fontconfig/fontconfig-user.html).
+*[`force_syntax`](plugins/force_syntax.lua?raw=1)* | Change the syntax used for a file.
[`formatter`](https://github.com/vincens2005/lite-formatters)* | formatters for various languages
[`ghmarkdown`](plugins/ghmarkdown.lua?raw=1) | Opens a preview of the current markdown file in a browser window *([screenshot](https://user-images.githubusercontent.com/3920290/82754898-f7394600-9dc7-11ea-8278-2305363ed372.png))*
*[`gitdiff_highlight`](https://github.com/vincens2005/lite-xl-gitdiff-highlight)** | highlight changed lines from git *([screenshot](https://raw.githubusercontent.com/vincens2005/lite-xl-gitdiff-highlight/master/screenshot.png))*
@@ -91,6 +92,7 @@ Plugin | Description
[`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
[`language sass`](plugins/language_sass.lua?raw=1) | Syntax for the [Sass](https://sass-lang.com/) CSS preprocessor
+[`language scala`](plugins/language_scala.lua?raw=1) | Syntax for the [Scala](https://scala-lang.org/) programming language
[`language_sh`](plugins/language_sh.lua?raw=1) | Syntax for shell scripting language
[`language_ssh_config`](plugins/language_ssh_config.lua?raw=1) | Syntax for ssh & sshd config files
[`language_tcl`](plugins/language_tcl.lua?raw=1) | Syntax for the [Tcl](https://www.tcl.tk/) programming language
@@ -117,6 +119,7 @@ Plugin | Description
[`motiontrail`](plugins/motiontrail.lua?raw=1) | Adds a motion-trail to the caret *([screenshot](https://user-images.githubusercontent.com/3920290/83256814-085ccb00-a1ab-11ea-9e35-e6633cbed1a9.gif))*
~~[`nagbar`](https://github.com/takase1121/lite-nagbar)*~~ | integrated in lite-xl ~~consistent and _beautiful_ confirmation dialogs for lite and lite-xl *([gif](https://raw.githubusercontent.com/takase1121/lite-nagbar/master/assets/preview.gif))*~~
[`navigate`](plugins/navigate.lua?raw=1) | Allows moving back and forward between document positions, reducing the amount of scrolling
+[`opacity`](plugins/opacity.lua?raw=1) | Change the opaqueness/transparency of `lite-xl` using shift+mousewheel or a command.
[`open_ext`](plugins/open_ext.lua?raw=1) | Automatically prompts you if you tried to open a binary file in the editor
[`openfilelocation`](plugins/openfilelocation.lua?raw=1) | Opens the parent directory of the current file in the file manager
[`openselected`](plugins/openselected.lua?raw=1) | Opens the selected filename or url
diff --git a/plugins/force_syntax.lua b/plugins/force_syntax.lua
new file mode 100644
index 0000000..dce4abc
--- /dev/null
+++ b/plugins/force_syntax.lua
@@ -0,0 +1,132 @@
+-- mod-version:2 -- lite-xl 2.0
+local core = require "core"
+local Doc = require "core.doc"
+local syntax = require "core.syntax"
+local command = require "core.command"
+local common = require "core.common"
+local style = require "core.style"
+local StatusView = require "core.statusview"
+local DocView = require "core.docview"
+
+local function doc()
+ if core.active_view and getmetatable(core.active_view) == DocView then return core.active_view.doc end
+ if core.last_active_view and getmetatable(core.last_active_view) == DocView then return core.last_active_view.doc end
+end
+
+-- Force plaintext syntax to have a name
+local plain_text_syntax = syntax.get("", "")
+plain_text_syntax.name = plain_text_syntax.name or "Plain Text"
+
+local doc_reset_syntax = Doc.reset_syntax
+function Doc:reset_syntax()
+ local syntax_get = syntax.get
+ if self.force_syntax then
+ syntax.get = function() return self.force_syntax end
+ end
+ doc_reset_syntax(self)
+ syntax.get = syntax_get
+end
+
+local function get_syntax_name(s)
+ if not s then return "Undefined" end
+ local name = s.name
+ if not name then
+ local exts = type(s.files) == "string" and { s.files } or s.files
+ if exts then
+ name = table.concat(exts, ", ")
+ end
+ end
+ return name or "Undefined"
+end
+
+local statusview_get_items = StatusView.get_items
+function StatusView:get_items()
+ local left, right = statusview_get_items(self)
+
+ local is_dv = core.active_view and getmetatable(core.active_view) == DocView
+ if not is_dv then return left, right end
+
+ local syntax_name = get_syntax_name(doc().syntax)
+
+ local ins = {
+ style.dim,
+ self.separator2,
+ style.text,
+ syntax_name
+ }
+
+ if syntax_name then
+ for _,item in pairs(ins) do
+ table.insert(right, item)
+ end
+ end
+
+ return left, right
+end
+
+local function get_syntax_list()
+ local pt_name = plain_text_syntax.name
+ if doc().syntax == plain_text_syntax then
+ pt_name = "Current: "..pt_name
+ end
+ local list = { ["Auto detect"] = false,
+ [pt_name] = plain_text_syntax }
+ local keylist = { "Auto detect", pt_name }
+
+ for _,s in pairs(syntax.items) do
+ local name = get_syntax_name(s)
+ local fullname = name
+ local i = 1
+ while list[fullname] do
+ i = i + 1
+ fullname = name.." ("..i..")"
+ end
+ if doc().syntax == s then
+ fullname = "Current: "..fullname
+ end
+ list[fullname] = s
+ table.insert(keylist, fullname)
+ end
+
+ return list, keylist
+end
+
+local function sorter(a, b)
+ -- Compare only syntax name
+ a = a:gsub("Current: ", "")
+ b = b:gsub("Current: ", "")
+ return string.upper(a) < string.upper(b)
+end
+
+local function bias_sorter(a, b)
+ -- Bias towards Current and Auto detect syntax
+ if a:match("Current: ") then return true end
+ if b:match("Current: ") then return false end
+ if a:match("Auto detect") then return true end
+ if b:match("Auto detect") then return false end
+ return sorter(a, b)
+end
+
+command.add("core.docview", {
+ ["force-syntax:select-file-syntax"] =
+ function()
+ core.command_view:enter(
+ "Set syntax for this file",
+ function(text, item) -- submit
+ local list, _ = get_syntax_list()
+ doc().force_syntax = list[item.text]
+ doc():reset_syntax()
+ end,
+ function(text) -- suggest
+ local _, keylist = get_syntax_list()
+ local res = common.fuzzy_match(keylist, text)
+ -- Force Current and Auto detect syntax to the bottom
+ -- if the text is empty
+ table.sort(res, #text == 0 and bias_sorter or sorter)
+ return res
+ end,
+ nil, -- cancel
+ nil -- validate
+ )
+ end
+})
diff --git a/plugins/language_julia.lua b/plugins/language_julia.lua
index 65bc1ce..e62a9b2 100644
--- a/plugins/language_julia.lua
+++ b/plugins/language_julia.lua
@@ -1,5 +1,5 @@
-- mod-version:2 -- lite-xl 2.0
--- Support for the Julia programming language:
+-- Support for the Julia programming language:
-- Covers the most used keywords up to Julia version 1.6.4
local syntax = require "core.syntax"
@@ -9,25 +9,37 @@ syntax.add {
files = { "%.jl$" },
comment = "#",
patterns = {
- { pattern = { "#=", "=#" }, type = "comment" },
- { pattern = "#.-\n", type = "comment" },
- { pattern = { '"', '"', '\\' }, type = "string" },
- { pattern = { "`", "`", '\\' }, type = "string" },
+ {pattern = {"#=", "=#"}, type="comment" },
+ {pattern = "#.*$", type="comment" },
+ { pattern = { 'icxx"""', '"""' }, type = "string", syntax = ".cpp" },
+ { pattern = { 'cxx"""', '"""' }, type = "string", syntax = ".cpp" },
+ { pattern = { 'py"""', '"""' }, type = "string", syntax = ".py" },
+ { pattern = { 'js"""', '"""' }, type = "string", syntax = ".js" },
+ { pattern = { 'md"""', '"""' }, type = "string", syntax = ".md" },
+ { pattern = "%d%w*[%.-+*//]", type = "number" },
{ pattern = "0[oO_][0-7]+", type = "number" },
{ pattern = "-?0x[%x_]+", type = "number" },
+ { pattern = "-?0b[%x_]+", type = "number" },
{ pattern = "-?%d+_%d", type = "number" },
{ pattern = "-?%d+[%d%.eE]*f?", type = "number" },
{ pattern = "-?%.?%d+f?", type = "number" },
- { pattern = "[%+%-=/%*%^%%<>!~|&]", type = "operator" },
- { pattern = "[%a_][%w_]*%f[(]", type = "function" },
- { pattern = "[%a_][%w_]*", type = "symbol" },
+ { pattern = "[^%d%g]%:%a*", type = "function" },
+ { pattern = "[%+%-=/%*%^%%<>!~|&%:]",type = "operator"},
+ { pattern = '""".*"""', type = "string" },
+ { pattern = '".*"', type = "string" },
+ { pattern = '[bv]".*"', type = "string" },
+ { pattern = 'r".*$', type = "string" },
+ { pattern = "'\\.*'", type = "string" },
+ { pattern = "'.'", type = "string" },
+ { pattern = "[%a_][%w_]*%f[(]", type = "function" },
+ { pattern = "%g*!", type="function"},
+ { pattern = "[%a_][%w_]*", type = "symbol" },
},
symbols = {
-- keywords
- ["abstract type"] = "keyword",
["baremodule"] = "keyword",
["begin"] = "keyword",
- ["break`"] = "keyword",
+ ["break"] = "keyword",
["catch"] = "keyword",
["const"] = "keyword",
["continue"] = "keyword",
@@ -44,24 +56,31 @@ syntax.add {
["function"] = "keyword",
["global"] = "keyword",
["if"] = "keyword",
+ ["in"] = "keyword",
["import"] = "keyword",
["let"] = "keyword",
["local"] = "keyword",
["macro"] = "keyword",
+ ["type"] = "keyword",
["module"] = "keyword",
+ ["mutable"] = "keyword",
["quote"] = "keyword",
["return"] = "keyword",
["try"] = "keyword",
["typeof"] = "keyword",
["using"] = "keyword",
["while"] = "keyword",
-
+ ["where"] = "keyword",
+
-- types
["struct"] = "keyword2",
- ["mutable struct"] = "keyword2",
+ ["abstract"] = "keyword2",
+ ["primitive"] = "keyword2",
+ ["mutable"] = "keyword2",
["Char"] = "keyword2",
["Bool"] = "keyword2",
["Int"] = "keyword2",
+ ["Integer"] = "keyword2",
["Int8"] = "keyword2",
["UInt8"] = "keyword2",
["Int16"] = "keyword2",
@@ -77,10 +96,17 @@ syntax.add {
["Float64"] = "keyword2",
["Vector"] = "keyword2",
["Matrix"] = "keyword2",
+ ["Ref"] = "keyword2",
+ ["String"] = "keyword2",
+ ["Function"] = "keyword2",
+ ["Number"] = "keyword2",
-- literals
["missing"] = "literal",
["true"] = "literal",
["false"] = "literal",
- },
+ ["nothing"] = "literal",
+ ["Inf"] = "literal",
+ ["NaN"] = "literal",
+ }
}
diff --git a/plugins/language_scala.lua b/plugins/language_scala.lua
new file mode 100644
index 0000000..fddadc7
--- /dev/null
+++ b/plugins/language_scala.lua
@@ -0,0 +1,80 @@
+-- mod-version:2 -- lite-xl 2.0
+local syntax = require "core.syntax"
+
+syntax.add {
+ name = "Scala",
+ files = { "%.sc$", "%.scala$" },
+ comment = "//",
+ patterns = {
+ { pattern = "//.-\n", type = "comment" },
+ { pattern = { "/%*", "%*/" }, type = "comment" },
+ { pattern = { '[ruU]?"', '"', '\\' }, type = "string" },
+ { pattern = { "[ruU]?'", "'", '\\' }, type = "string" },
+ { pattern = "0x[%da-fA-F]+", type = "number" },
+ { pattern = "-?%d+[%d%.eE]*", type = "number" },
+ { pattern = "-?%.?%d+", type = "number" },
+ { pattern = "[%+%-=/%*%^%%<>!~|&]", type = "operator" },
+ { pattern = '[%a_][%w_]*"""*[%a_][%w_]*"""', type = "string" },
+ { pattern = "[%a_][%w_]*%f[(]", type = "function" },
+ { pattern = "[%a_][%w_]*", type = "symbol" },
+ },
+ symbols = {
+ ["abstract"] = "keyword",
+ ["case"] = "keyword",
+ ["catch"] = "keyword",
+ ["class"] = "keyword",
+ ["finally"] = "keyword",
+ ["final"] = "keyword",
+ ["do"] = "keyword",
+ ["extends"] = "keyword",
+ ["forSome"] = "keyword",
+ ["implicit"] = "keyword",
+ ["lazy"] = "keyword",
+ ["match"] = "keyword",
+ ["new"] = "keyword",
+ ["override"] = "keyword",
+ ["package"] = "keyword",
+ ["throw"] = "keyword",
+ ["trait"] = "keyword",
+ ["type"] = "keyword",
+ ["var"] = "keyword",
+ ["val"] = "keyword",
+ ["println"] = "keyword",
+ ["return"] = "keyword",
+ ["for"] = "keyword",
+ ["Try"] = "keyword",
+ ["def"] = "keyword",
+ ["while"] = "keyword",
+ ["with"] = "keyword",
+ ["if"] = "keyword",
+ ["else"] = "keyword",
+ ["import"] = "keyword",
+ ["object"] = "keyword",
+ ["yield"] = "keyword",
+
+ ["private"] = "keyword2",
+ ["protected"] = "keyword2",
+ ["sealed"] = "keyword2",
+ ["super"] = "keyword2",
+ ["this"] = "keyword2",
+ ["Byte"] = "keyword2",
+ ["Short"] = "keyword2",
+ ["Int"] = "keyword2",
+ ["Long"] = "keyword2",
+ ["Float"] = "keyword2",
+ ["Double"] = "keyword2",
+ ["Char"] = "keyword2",
+ ["String"] = "keyword2",
+ ["List"] = "keyword2",
+ ["Array"] = "keyword2",
+ ["Boolean"] = "keyword2",
+
+ ["Null"] = "literal",
+ ["Any"] = "literal",
+ ["AnyRef"] = "literal",
+ ["Nothing"] = "literal",
+ ["Unit"] = "literal",
+ ["true"] = "literal",
+ ["false"] = "literal",
+ }
+}
diff --git a/plugins/opacity.lua b/plugins/opacity.lua
new file mode 100644
index 0000000..8dd0d9a
--- /dev/null
+++ b/plugins/opacity.lua
@@ -0,0 +1,62 @@
+-- mod-version:2 -- lite-xl 2.0
+local common = require "core.common"
+local command = require "core.command"
+local keymap = require "core.keymap"
+local RootView = require "core.rootview"
+
+local opacity_on = true
+local use_mousewheel = true
+local opacity_steps = 0.05
+local default_opacity = 1
+local current_opacity = default_opacity
+
+local function set_opacity(opacity)
+ if not opacity_on then opacity_on = true end
+ current_opacity = common.clamp(opacity, 0.2, 1)
+ system.set_window_opacity(current_opacity)
+end
+
+local on_mouse_wheel = RootView.on_mouse_wheel
+
+function RootView:on_mouse_wheel(d, ...)
+ if keymap.modkeys["shift"] and use_mousewheel then
+ if d < 0 then command.perform "opacity:decrease" end
+ if d > 0 then command.perform "opacity:increase" end
+ else
+ return on_mouse_wheel(self, d, ...)
+ end
+end
+
+local function tog_opacity()
+ opacity_on = not opacity_on
+ if opacity_on then
+ system.set_window_opacity(current_opacity)
+ else
+ system.set_window_opacity(default_opacity)
+ end
+end
+
+local function res_opacity()
+ set_opacity(default_opacity)
+end
+
+local function inc_opacity()
+ set_opacity(current_opacity + opacity_steps)
+end
+
+local function dec_opacity()
+ set_opacity(current_opacity - opacity_steps)
+end
+
+command.add(nil, {
+ ["opacity:toggle" ] = function() tog_opacity() end,
+ ["opacity:reset" ] = function() res_opacity() end,
+ ["opacity:decrease"] = function() dec_opacity() end,
+ ["opacity:increase"] = function() inc_opacity() end,
+ ["opacity:toggle mouse wheel use"] = function() use_mousewheel = not use_mousewheel end,
+})
+
+keymap.add {
+ ["shift+f11"] = "opacity:toggle",
+ ["ctrl+f11"] = "opacity:toggle mouse wheel use",
+}
diff --git a/plugins/open_ext.lua b/plugins/open_ext.lua
index 0c7eff1..8a98516 100644
--- a/plugins/open_ext.lua
+++ b/plugins/open_ext.lua
@@ -143,7 +143,7 @@ local function validate_doc(doc)
if not f then return true end
local str = f:read(128 * 4) -- max bytes for 128 codepoints
f:close()
- return validate_utf8(str, 128)
+ return validate_utf8(str or "", 128)
end