From 4e8373c9d60607b7dbdc5c860be4eae6ba84ac15 Mon Sep 17 00:00:00 2001 From: rxi Date: Mon, 27 Apr 2020 18:55:05 +0100 Subject: Made `sort` plugin ignore trailing/leading empty-lines --- plugins/sort.lua | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'plugins/sort.lua') 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, }) + -- cgit v1.2.3