aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLukas Tobler <luk4s.tobler@gmail.com>2017-09-11 11:12:05 +0200
committerLukas Tobler <luk4s.tobler@gmail.com>2017-09-11 11:12:05 +0200
commit485a7dee9f8478f1f5bcef6896af02dc8d4969c6 (patch)
treee664da1c3c3134496c743c8d5ce3c0afc4b2d152
parent14dc94bcaa955e9b08b8b78ff5f222722922a197 (diff)
downloadvis-commentary-485a7dee9f8478f1f5bcef6896af02dc8d4969c6.tar.gz
Fix bug: crash when trying to comment empty lines
-rw-r--r--vis-commentary.lua5
1 files changed, 5 insertions, 0 deletions
diff --git a/vis-commentary.lua b/vis-commentary.lua
index b401a28..d8e38b9 100644
--- a/vis-commentary.lua
+++ b/vis-commentary.lua
@@ -49,6 +49,11 @@ local function get_lexer()
end
local function toggle_line_comment(lines, lnum, prefix, suffix)
+ if not lines or not lines[lnum] then return end
+
+ local stripped = lines[lnum]:match("^%s*(.+)") -- empty lines: nil
+ if not stripped then return end
+
-- remove comment
if lines[lnum]:match("^%s*(.+)"):sub(0, #prefix) == prefix then
local match_str = "^(%s*)" .. esc(prefix) .. "%s?(.*)" .. esc(suffix)