From 69a857bbbfd4ab12dc5ef463508dc44c69c67e93 Mon Sep 17 00:00:00 2001 From: takase1121 <20792268+takase1121@users.noreply.github.com> Date: Sun, 26 Dec 2021 15:05:27 +0800 Subject: [PATCH] fallback to toggle-line-comment and vice versa if needed --- data/core/commands/doc.lua | 16 +++++++++++++--- data/plugins/language_c.lua | 2 +- data/plugins/language_cpp.lua | 2 +- data/plugins/language_css.lua | 2 +- data/plugins/language_html.lua | 2 +- data/plugins/language_js.lua | 2 +- data/plugins/language_lua.lua | 2 +- data/plugins/language_xml.lua | 2 +- 8 files changed, 20 insertions(+), 10 deletions(-) diff --git a/data/core/commands/doc.lua b/data/core/commands/doc.lua index 1e65ad11..edf36bbd 100644 --- a/data/core/commands/doc.lua +++ b/data/core/commands/doc.lua @@ -293,8 +293,13 @@ local commands = { end, ["doc:toggle-block-comments"] = function() - local comment = doc().syntax.multiline_comment - if not comment then return end + local comment = doc().syntax.block_comment + if not comment then + if doc().syntax.comment then + command.perform "doc:toggle-line-comments" + end + return + end for idx, line1, col1, line2, col2 in doc_multiline_selections(true) do local text = doc():get_text(line1, col1, line2, col2) @@ -342,7 +347,12 @@ local commands = { ["doc:toggle-line-comments"] = function() local comment = doc().syntax.comment - if not comment then return end + if not comment then + if doc().syntax.block_comment then + command.perform "doc:toggle-block-comments" + end + return + end local indentation = doc():get_indent_string() local comment_text = comment .. " " for idx, line1, _, line2 in doc_multiline_selections(true) do diff --git a/data/plugins/language_c.lua b/data/plugins/language_c.lua index ecbeed7a..c4d3b07b 100644 --- a/data/plugins/language_c.lua +++ b/data/plugins/language_c.lua @@ -5,7 +5,7 @@ syntax.add { name = "C", files = { "%.c$", "%.h$", "%.inl$" }, comment = "//", - multiline_comment = { "/*", "*/" }, + block_comment = { "/*", "*/" }, patterns = { { pattern = "//.-\n", type = "comment" }, { pattern = { "/%*", "%*/" }, type = "comment" }, diff --git a/data/plugins/language_cpp.lua b/data/plugins/language_cpp.lua index 03554a48..2b3a104f 100644 --- a/data/plugins/language_cpp.lua +++ b/data/plugins/language_cpp.lua @@ -10,7 +10,7 @@ syntax.add { "%.c++$", "%.hh$", "%.H$", "%.hxx$", "%.hpp$", "%.h++$" }, comment = "//", - multiline_comment = { "/*", "*/" }, + block_comment = { "/*", "*/" }, patterns = { { pattern = "//.-\n", type = "comment" }, { pattern = { "/%*", "%*/" }, type = "comment" }, diff --git a/data/plugins/language_css.lua b/data/plugins/language_css.lua index 871598a2..96c3eb8d 100644 --- a/data/plugins/language_css.lua +++ b/data/plugins/language_css.lua @@ -4,7 +4,7 @@ local syntax = require "core.syntax" syntax.add { name = "CSS", files = { "%.css$" }, - multiline_comment = { "/*", "*/" }, + block_comment = { "/*", "*/" }, patterns = { { pattern = "\\.", type = "normal" }, { pattern = "//.-\n", type = "comment" }, diff --git a/data/plugins/language_html.lua b/data/plugins/language_html.lua index e22e8897..ff61fa7f 100644 --- a/data/plugins/language_html.lua +++ b/data/plugins/language_html.lua @@ -4,7 +4,7 @@ local syntax = require "core.syntax" syntax.add { name = "HTML", files = { "%.html?$" }, - multiline_comment = { "" }, + block_comment = { "" }, patterns = { { pattern = { diff --git a/data/plugins/language_js.lua b/data/plugins/language_js.lua index d23e412b..2e6d5d87 100644 --- a/data/plugins/language_js.lua +++ b/data/plugins/language_js.lua @@ -5,7 +5,7 @@ syntax.add { name = "JavaScript", files = { "%.js$", "%.json$", "%.cson$" }, comment = "//", - multiline_comment = { "/*", "*/" }, + block_comment = { "/*", "*/" }, patterns = { { pattern = "//.-\n", type = "comment" }, { pattern = { "/%*", "%*/" }, type = "comment" }, diff --git a/data/plugins/language_lua.lua b/data/plugins/language_lua.lua index 79a8289b..993e53c8 100644 --- a/data/plugins/language_lua.lua +++ b/data/plugins/language_lua.lua @@ -6,7 +6,7 @@ syntax.add { files = "%.lua$", headers = "^#!.*[ /]lua", comment = "--", - multiline_comment = { "--[[", "]]" }, + block_comment = { "--[[", "]]" }, patterns = { { pattern = { '"', '"', '\\' }, type = "string" }, { pattern = { "'", "'", '\\' }, type = "string" }, diff --git a/data/plugins/language_xml.lua b/data/plugins/language_xml.lua index 971a53de..297b6d73 100644 --- a/data/plugins/language_xml.lua +++ b/data/plugins/language_xml.lua @@ -5,7 +5,7 @@ syntax.add { name = "XML", files = { "%.xml$" }, headers = "<%?xml", - multiline_comment = { "" }, + block_comment = { "" }, patterns = { { pattern = { "" }, type = "comment" }, { pattern = { '%f[^>][^<]', '%f[<]' }, type = "normal" },