aboutsummaryrefslogtreecommitdiff
path: root/plugins/sort.lua
diff options
context:
space:
mode:
authorrxi <rxi@users.noreply.github.com>2020-04-27 18:55:05 +0100
committerrxi <rxi@users.noreply.github.com>2020-04-27 18:55:05 +0100
commit4e8373c9d60607b7dbdc5c860be4eae6ba84ac15 (patch)
tree7e655b4888e8c1ec82536b4e0deca57c22b94d33 /plugins/sort.lua
parent3c9af5d7289fb079517df630f6d17a98657b10b7 (diff)
downloadlite-xl-plugins-4e8373c9d60607b7dbdc5c860be4eae6ba84ac15.tar.gz
lite-xl-plugins-4e8373c9d60607b7dbdc5c860be4eae6ba84ac15.zip
Made `sort` plugin ignore trailing/leading empty-lines
Diffstat (limited to 'plugins/sort.lua')
-rw-r--r--plugins/sort.lua6
1 files changed, 4 insertions, 2 deletions
diff --git a/plugins/sort.lua b/plugins/sort.lua
index e104043..ce899e9 100644
--- a/plugins/sort.lua
+++ b/plugins/sort.lua
@@ -12,9 +12,11 @@ end
command.add("core.docview", {
["sort:sort"] = function()
core.active_view.doc:replace(function(text)
- local lines = split_lines(text)
+ local head, body, foot = text:match("(\n*)(.-)(\n*)$")
+ local lines = split_lines(body)
table.sort(lines, function(a, b) return a:lower() < b:lower() end)
- return table.concat(lines, "\n")
+ return head .. table.concat(lines, "\n") .. foot
end)
end,
})
+