aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrxi <rxi@users.noreply.github.com>2020-03-29 08:59:42 +0100
committerrxi <rxi@users.noreply.github.com>2020-03-29 09:00:40 +0100
commit7002660c874933a4d3eb563ee65c7a0c5ba206d6 (patch)
tree8fbbf6320285f681c5bb149007959ba890eaa276
parentcc1aacfa755001965670420cacbd03d69884aae6 (diff)
downloadlite-xl-plugins-7002660c874933a4d3eb563ee65c7a0c5ba206d6.tar.gz
lite-xl-plugins-7002660c874933a4d3eb563ee65c7a0c5ba206d6.zip
Added sort plugin
-rw-r--r--README.md4
-rw-r--r--sort.lua20
2 files changed, 22 insertions, 2 deletions
diff --git a/README.md b/README.md
index 426e793..0c700b0 100644
--- a/README.md
+++ b/README.md
@@ -11,6 +11,6 @@ Plugin | Description
[`language_odin`](language_odin.lua?raw=1) | Syntax for the [Odin](https://github.com/odin-lang/Odin) programming language
[`language_wren`](language_wren.lua?raw=1) | Syntax for the [Wren](http://wren.io/) programming language
[`macmodkeys`](macmodkeys.lua?raw=1) | Remaps mac modkeys `command/option` to `ctrl/alt`
+[`sort`](sort.lua?raw=1) | Sorts selected lines
[`titleize`](titleize.lua?raw=1) | Titleizes selected string (`hello world` => `Hello World`)
-[`togglesnakecamel`](togglesnakecamel.lua?raw=1) | Toggles symbols between snake\_case and camelCase
-
+[`togglesnakecamel`](togglesnakecamel.lua?raw=1) | Toggles symbols between `snake\_case` and `camelCase`
diff --git a/sort.lua b/sort.lua
new file mode 100644
index 0000000..e104043
--- /dev/null
+++ b/sort.lua
@@ -0,0 +1,20 @@
+local core = require "core"
+local command = require "core.command"
+
+local function split_lines(text)
+ local res = {}
+ for line in (text .. "\n"):gmatch("(.-)\n") do
+ table.insert(res, line)
+ end
+ return res
+end
+
+command.add("core.docview", {
+ ["sort:sort"] = function()
+ core.active_view.doc:replace(function(text)
+ local lines = split_lines(text)
+ table.sort(lines, function(a, b) return a:lower() < b:lower() end)
+ return table.concat(lines, "\n")
+ end)
+ end,
+})