diff options
author | rxi <rxi@users.noreply.github.com> | 2020-04-27 18:55:05 +0100 |
---|---|---|
committer | rxi <rxi@users.noreply.github.com> | 2020-04-27 18:55:05 +0100 |
commit | 4e8373c9d60607b7dbdc5c860be4eae6ba84ac15 (patch) | |
tree | 7e655b4888e8c1ec82536b4e0deca57c22b94d33 | |
parent | 3c9af5d7289fb079517df630f6d17a98657b10b7 (diff) | |
download | lite-xl-plugins-4e8373c9d60607b7dbdc5c860be4eae6ba84ac15.tar.gz lite-xl-plugins-4e8373c9d60607b7dbdc5c860be4eae6ba84ac15.zip |
Made `sort` plugin ignore trailing/leading empty-lines
-rw-r--r-- | plugins/sort.lua | 6 |
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, }) + |