aboutsummaryrefslogtreecommitdiff
path: root/plugins
diff options
context:
space:
mode:
authorNightwing <94565465+Nightwing13@users.noreply.github.com>2021-12-03 12:35:22 +0900
committerGitHub <noreply@github.com>2021-12-03 12:35:22 +0900
commit15f7af5cfd22b27315e7ed2fc4298c1ee6ab573a (patch)
treea2124a0477506964f8ccba9241cebca33074e68e /plugins
parent4f5d7e9ddfde8feb0d8d9efb91f6cbb47e99137b (diff)
parent7a8cc04b031c4114fa7e85aacea27d21b2f0b331 (diff)
downloadlite-xl-plugins-15f7af5cfd22b27315e7ed2fc4298c1ee6ab573a.tar.gz
lite-xl-plugins-15f7af5cfd22b27315e7ed2fc4298c1ee6ab573a.zip
Merge branch 'lite-xl:master' into dev
Diffstat (limited to 'plugins')
-rw-r--r--plugins/language_scala.lua80
-rw-r--r--plugins/minimap.lua58
-rw-r--r--plugins/open_ext.lua2
-rw-r--r--plugins/openselected.lua27
4 files changed, 157 insertions, 10 deletions
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/minimap.lua b/plugins/minimap.lua
index 3f4a2a2..b129f40 100644
--- a/plugins/minimap.lua
+++ b/plugins/minimap.lua
@@ -4,6 +4,7 @@ local common = require "core.common"
local config = require "core.config"
local style = require "core.style"
local DocView = require "core.docview"
+local Object = require "core.object"
-- General plugin settings
config.plugins.minimap = {
@@ -14,7 +15,22 @@ config.plugins.minimap = {
scale = 1,
-- how many spaces one tab is equivalent to
tab_width = 4,
- draw_background = true
+ draw_background = true,
+ highlight_align = 'left',
+ highlight_width = 3,
+ gutter_width = 5,
+ -- try these values:
+ -- full width:
+ -- config.plugins.minimap.highlight_width = 100
+ -- config.plugins.minimap.gutter_width = 0
+ -- left side:
+ -- config.plugins.minimap.highlight_align = 'left'
+ -- config.plugins.minimap.highlight_width = 3
+ -- config.plugins.minimap.gutter_width = 4
+ -- right side:
+ -- config.plugins.minimap.highlight_align = 'right'
+ -- config.plugins.minimap.highlight_width = 5
+ -- config.plugins.minimap.gutter_width = 0
}
-- Configure size for rendering each char in the minimap
@@ -22,6 +38,17 @@ local char_height = 1 * SCALE * config.plugins.minimap.scale
local char_spacing = 0.8 * SCALE * config.plugins.minimap.scale
local line_spacing = 2 * SCALE * config.plugins.minimap.scale
+local MiniMap = Object:extend()
+
+function MiniMap:new()
+end
+
+function MiniMap:line_highlight_color(line_index)
+ -- other plugins can override this, and return a color
+end
+
+local minimap = MiniMap()
+
-- Overloaded since the default implementation adds a extra x3 size of hotspot for the mouse to hit the scrollbar.
local prev_scrollbar_overlaps_point = DocView.scrollbar_overlaps_point
DocView.scrollbar_overlaps_point = function(self, x, y)
@@ -101,7 +128,6 @@ DocView.on_mouse_pressed = function(self, button, x, y, clicks)
-- if user didn't click on the visible area (ie not dragging), scroll accordingly
if not hit_visible_area then
self:scroll_to_line(jump_to_line, false, config.plugins.minimap.instant_scroll)
- return
end
end
@@ -196,6 +222,10 @@ DocView.draw_scrollbar = function(self)
-- draw visual rect
renderer.draw_rect(x, visible_y, w, scroller_height, visual_color)
+ local highlight_align = config.plugins.minimap.highlight_align
+ local highlight_width = config.plugins.minimap.highlight_width
+ local gutter_width = config.plugins.minimap.gutter_width
+
-- time to draw the actual code, setup some local vars that are used in both highlighted and plain renderind.
local line_y = y
@@ -225,6 +255,19 @@ DocView.draw_scrollbar = function(self)
batch_width = 0
end
+ local highlight_x
+ if highlight_align == 'left' then
+ highlight_x = x
+ else
+ highlight_x = x + w - highlight_width
+ end
+ local function render_highlight(idx, line_y)
+ local highlight_color = minimap:line_highlight_color(idx)
+ if highlight_color then
+ renderer.draw_rect(highlight_x, line_y, highlight_width, line_spacing, highlight_color)
+ end
+ end
+
-- render lines with syntax highlighting
if config.plugins.minimap.syntax_highlight then
@@ -236,9 +279,11 @@ DocView.draw_scrollbar = function(self)
endidx = math.min(endidx, line_count)
for idx = minimap_start_line, endidx do
batch_syntax_type = nil
- batch_start = x
+ batch_start = x + gutter_width
batch_width = 0
+ render_highlight(idx, line_y)
+
-- per token
for _, type, text in self.doc.highlighter:each_token(idx) do
-- flush prev batch
@@ -268,9 +313,11 @@ DocView.draw_scrollbar = function(self)
else -- render lines without syntax highlighting
for idx = 1, line_count - 1 do
- batch_start = x
+ batch_start = x + gutter_width
batch_width = 0
+ render_highlight(idx, line_y)
+
for char in common.utf8_chars(self.doc.lines[idx]) do
if char == " " or char == "\n" then
flush_batch()
@@ -304,3 +351,6 @@ command.add(nil, {
config.plugins.minimap.syntax_highlight = not config.plugins.minimap.syntax_highlight
end
})
+
+return minimap
+
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
diff --git a/plugins/openselected.lua b/plugins/openselected.lua
index a1e21a2..af00194 100644
--- a/plugins/openselected.lua
+++ b/plugins/openselected.lua
@@ -2,6 +2,17 @@
local core = require "core"
local command = require "core.command"
local keymap = require "core.keymap"
+local config = require "core.config"
+
+
+config.plugins.openselected = {}
+if PLATFORM == "Windows" then
+ config.plugins.openselected.filemanager = "start"
+elseif PLATFORM == "Mac OS X" then
+ config.plugins.openselected.filemanager = "open"
+else
+ config.plugins.openselected.filemanager = "xdg-open"
+end
command.add("core.docview", {
@@ -13,15 +24,21 @@ command.add("core.docview", {
end
local text = doc:get_text(doc:get_selection())
- core.log("Opening \"%s\"...", text)
- if PLATFORM == "Windows" then
- system.exec("start " .. text)
- else
- system.exec(string.format("xdg-open %q", text))
+ -- trim whitespace from the ends
+ text = text:match( "^%s*(.-)%s*$" )
+
+ -- non-Windows platforms need the text quoted (%q)
+ if PLATFORM ~= "Windows" then
+ text = string.format("%q", text)
end
+
+ core.log("Opening %s...", text)
+
+ system.exec(config.plugins.openselected.filemanager .. " " .. text)
end,
})
keymap.add { ["ctrl+shift+o"] = "open-selected:open-selected" }
+