From 485a7dee9f8478f1f5bcef6896af02dc8d4969c6 Mon Sep 17 00:00:00 2001 From: Lukas Tobler Date: Mon, 11 Sep 2017 11:12:05 +0200 Subject: Fix bug: crash when trying to comment empty lines --- vis-commentary.lua | 5 +++++ 1 file changed, 5 insertions(+) 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) -- cgit