aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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,
})
+