diff options
author | rxi <rxi@users.noreply.github.com> | 2020-03-29 08:59:42 +0100 |
---|---|---|
committer | rxi <rxi@users.noreply.github.com> | 2020-03-29 09:00:40 +0100 |
commit | 7002660c874933a4d3eb563ee65c7a0c5ba206d6 (patch) | |
tree | 8fbbf6320285f681c5bb149007959ba890eaa276 | |
parent | cc1aacfa755001965670420cacbd03d69884aae6 (diff) | |
download | lite-xl-plugins-7002660c874933a4d3eb563ee65c7a0c5ba206d6.tar.gz lite-xl-plugins-7002660c874933a4d3eb563ee65c7a0c5ba206d6.zip |
Added sort plugin
-rw-r--r-- | README.md | 4 | ||||
-rw-r--r-- | sort.lua | 20 |
2 files changed, 22 insertions, 2 deletions
@@ -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, +}) |