add toggle-block-comment
This commit is contained in:
parent
4be8a8b582
commit
4d31b1bc40
|
@ -292,6 +292,54 @@ local commands = {
|
|||
end
|
||||
end,
|
||||
|
||||
["doc:toggle-block-comments"] = function()
|
||||
local comment = doc().syntax.multiline_comment
|
||||
if not comment then return end
|
||||
|
||||
for idx, line1, col1, line2, col2 in doc_multiline_selections(true) do
|
||||
local text = doc():get_text(line1, col1, line2, col2)
|
||||
|
||||
-- might need to deal with unicode later...
|
||||
local cs, cse = text:find(comment[1], 1, true)
|
||||
local ce = text:find(comment[2], #text - #comment[2] + 1, true)
|
||||
|
||||
local new_col1, new_col2 = col1, col2
|
||||
-- uncomment
|
||||
if cs and ce then
|
||||
if line1 == line2 then
|
||||
new_col2 = new_col2 - #table.concat(comment)
|
||||
else
|
||||
new_col2 = new_col2 - #comment[2]
|
||||
end
|
||||
|
||||
-- remove 1 whitespace if possible
|
||||
if text:sub(cse + 1, cse + 1) == " " then
|
||||
cse = cse + 1
|
||||
if line1 == line2 then
|
||||
new_col2 = new_col2 - 1
|
||||
end
|
||||
end
|
||||
if text:sub(ce - 1, ce - 1) == " " then
|
||||
ce = ce - 1
|
||||
new_col2 = new_col2 - 1
|
||||
end
|
||||
|
||||
text = text:sub(cse + 1, ce - 1)
|
||||
-- comment
|
||||
else
|
||||
text = comment[1] .. " " .. text .. " " .. comment[2]
|
||||
if line1 == line2 then
|
||||
new_col2 = new_col2 + #table.concat(comment) + 2
|
||||
else
|
||||
new_col2 = new_col2 + #comment[2] + 1
|
||||
end
|
||||
end
|
||||
doc():remove(line1, col1, line2, col2)
|
||||
doc():insert(line1, col1, text)
|
||||
doc():set_selections(idx, line1, new_col1, line2, new_col2)
|
||||
end
|
||||
end,
|
||||
|
||||
["doc:toggle-line-comments"] = function()
|
||||
local comment = doc().syntax.comment
|
||||
if not comment then return end
|
||||
|
|
|
@ -215,6 +215,7 @@ keymap.add_direct {
|
|||
["ctrl+l"] = "doc:select-lines",
|
||||
["ctrl+shift+l"] = { "find-replace:select-add-all", "doc:select-word" },
|
||||
["ctrl+/"] = "doc:toggle-line-comments",
|
||||
["ctrl+shift+/"] = "doc:toggle-block-comments",
|
||||
["ctrl+up"] = "doc:move-lines-up",
|
||||
["ctrl+down"] = "doc:move-lines-down",
|
||||
["ctrl+shift+d"] = "doc:duplicate-lines",
|
||||
|
|
|
@ -5,6 +5,7 @@ syntax.add {
|
|||
name = "C",
|
||||
files = { "%.c$", "%.h$", "%.inl$" },
|
||||
comment = "//",
|
||||
multiline_comment = { "/*", "*/" },
|
||||
patterns = {
|
||||
{ pattern = "//.-\n", type = "comment" },
|
||||
{ pattern = { "/%*", "%*/" }, type = "comment" },
|
||||
|
|
|
@ -10,6 +10,7 @@ syntax.add {
|
|||
"%.c++$", "%.hh$", "%.H$", "%.hxx$", "%.hpp$", "%.h++$"
|
||||
},
|
||||
comment = "//",
|
||||
multiline_comment = { "/*", "*/" },
|
||||
patterns = {
|
||||
{ pattern = "//.-\n", type = "comment" },
|
||||
{ pattern = { "/%*", "%*/" }, type = "comment" },
|
||||
|
|
|
@ -4,6 +4,7 @@ local syntax = require "core.syntax"
|
|||
syntax.add {
|
||||
name = "CSS",
|
||||
files = { "%.css$" },
|
||||
multiline_comment = { "/*", "*/" },
|
||||
patterns = {
|
||||
{ pattern = "\\.", type = "normal" },
|
||||
{ pattern = "//.-\n", type = "comment" },
|
||||
|
|
|
@ -4,28 +4,29 @@ local syntax = require "core.syntax"
|
|||
syntax.add {
|
||||
name = "HTML",
|
||||
files = { "%.html?$" },
|
||||
multiline_comment = { "<!--", "-->" },
|
||||
patterns = {
|
||||
{
|
||||
pattern = {
|
||||
{
|
||||
pattern = {
|
||||
"<%s*[sS][cC][rR][iI][pP][tT]%s+[tT][yY][pP][eE]%s*=%s*" ..
|
||||
"['\"]%a+/[jJ][aA][vV][aA][sS][cC][rR][iI][pP][tT]['\"]%s*>",
|
||||
"<%s*/[sS][cC][rR][iI][pP][tT]>"
|
||||
},
|
||||
syntax = ".js",
|
||||
type = "function"
|
||||
},
|
||||
{
|
||||
pattern = {
|
||||
"<%s*[sS][cC][rR][iI][pP][tT]%s*>",
|
||||
"<%s*/%s*[sS][cC][rR][iI][pP][tT]>"
|
||||
"<%s*/[sS][cC][rR][iI][pP][tT]>"
|
||||
},
|
||||
syntax = ".js",
|
||||
type = "function"
|
||||
},
|
||||
{
|
||||
pattern = {
|
||||
"<%s*[sS][tT][yY][lL][eE][^>]*>",
|
||||
"<%s*/%s*[sS][tT][yY][lL][eE]%s*>"
|
||||
{
|
||||
pattern = {
|
||||
"<%s*[sS][cC][rR][iI][pP][tT]%s*>",
|
||||
"<%s*/%s*[sS][cC][rR][iI][pP][tT]>"
|
||||
},
|
||||
syntax = ".js",
|
||||
type = "function"
|
||||
},
|
||||
{
|
||||
pattern = {
|
||||
"<%s*[sS][tT][yY][lL][eE][^>]*>",
|
||||
"<%s*/%s*[sS][tT][yY][lL][eE]%s*>"
|
||||
},
|
||||
syntax = ".css",
|
||||
type = "function"
|
||||
|
|
|
@ -5,6 +5,7 @@ syntax.add {
|
|||
name = "JavaScript",
|
||||
files = { "%.js$", "%.json$", "%.cson$" },
|
||||
comment = "//",
|
||||
multiline_comment = { "/*", "*/" },
|
||||
patterns = {
|
||||
{ pattern = "//.-\n", type = "comment" },
|
||||
{ pattern = { "/%*", "%*/" }, type = "comment" },
|
||||
|
|
|
@ -6,6 +6,7 @@ syntax.add {
|
|||
files = "%.lua$",
|
||||
headers = "^#!.*[ /]lua",
|
||||
comment = "--",
|
||||
multiline_comment = { "--[[", "]]" },
|
||||
patterns = {
|
||||
{ pattern = { '"', '"', '\\' }, type = "string" },
|
||||
{ pattern = { "'", "'", '\\' }, type = "string" },
|
||||
|
|
|
@ -5,6 +5,7 @@ syntax.add {
|
|||
name = "XML",
|
||||
files = { "%.xml$" },
|
||||
headers = "<%?xml",
|
||||
multiline_comment = { "<!--", "-->" },
|
||||
patterns = {
|
||||
{ pattern = { "<!%-%-", "%-%->" }, type = "comment" },
|
||||
{ pattern = { '%f[^>][^<]', '%f[<]' }, type = "normal" },
|
||||
|
|
Loading…
Reference in New Issue