Created
July 28, 2020 13:27
-
-
Save anddam/8f5d2db5c0aa7b05ee247df71f5761f0 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module = {} | |
vis:option_register("strip-trailing-spaces", "bool", function(value, toogle) | |
if not vis.win then | |
return false | |
end | |
vis.win.strip_trailing_spaces = toogle and not vis.win.strip_trailing_spaces or value | |
return true | |
end, "Strip line trailing spaces on save") | |
vis:command_register("sts", function(argv, force, win, selection, range) | |
if win.strip_trailing_spaces then | |
local lines = win.file.lines | |
for index = 1, #lines do | |
lines[index] = lines[index]:gsub("%s+$", "") | |
end | |
vis:info("Line trailing spaces trimmed." .. type(win.file.lines)) | |
end | |
return true; | |
end, "Strip line trailing spaces" | |
) | |
vis.events.subscribe(vis.events.FILE_SAVE_PRE, function(file, path) | |
vis:command("sts") | |
return nil | |
end, 1) | |
return module | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment