Support neorg format#129
Conversation
| make = { M.hash }, | ||
| mbsyncrc = { M.double_hash }, | ||
| meson = { M.hash }, | ||
| norg = { "+%s+" }, -- blockwise comments work unexpected |
There was a problem hiding this comment.
What do you mean by blockwise comments work unexpected?
There was a problem hiding this comment.
Neorg does not support blockwise comments you are used for, instead there's this kind of syntax:
@comment
blockwise comment, you can't nest \@comment on one line
@end
or
#comment
This is a comment
after a blank line it is not a comment
this syntax would not work
+
comment
+
I think that creator of this plugin could answer better, @vhyrro
There was a problem hiding this comment.
Hi, I've been summoned :P
Yeah Neorg's syntax doesn't have any true blockwise structure which will probably make it difficult to fully support, only the aforementioned:
@comment
comment contents
@end
Is a valid multiline (or block) comment.
This is invalid, therefore I don't think it'd work with Comment.nvim's implementation:
@comment my comment @end
The + modifiers have strict rules, in that:
+
this
+
and
+ this +
are not valid in Neorg. That probably puts them out of the question if you want to add blockwise support. I dunno if there's any proper way to do this 🤔
There was a problem hiding this comment.
If this + comment + (spaces after/before +) is invalid, in that case you have to disable padding option to make it +comment+.
Also, i've read the docs and I am assuming that norg file is only be usable with neorg plugin. Am I missing something?
|
I played a little bit with norg comments trying to find the best way to do commenting in norg files. And I, kinda, found a way to do it with
So, I came up with the following which works for the most part, there might a bug here and there. local A = vim.api
local U = require('Comment.utils')
local F = require('Comment.ft')
F.set('norg', { '+%s+', '@comment%s@comment' })
require('Comment').setup({
padding = function()
-- NOTE: this is important for linewise comment
return vim.bo.filetype ~= 'norg'
end,
post_hook = function(ctx)
if vim.bo.filetype == 'norg' and ctx.ctype == U.ctype.block then
if ctx.cmode == U.cmode.comment then
-- Getting the first and the last line of the commented block
-- NOTE: this will also include the comment chars
local first_line = A.nvim_buf_get_lines(0, ctx.range.srow - 1, ctx.range.srow, true)[1]
local last_line = A.nvim_buf_get_lines(0, ctx.range.erow - 1, ctx.range.erow, true)[1]
-- Separting the comment chars from the lines, so that we can set them properly
local s_cstr, e_cstr = U.unwrap_cstr(F.calculate(ctx))
local s_pad, s_line = first_line:match('(%s*)' .. vim.pesc(s_cstr) .. '(.*)')
local e_pad, e_line = last_line:match('(%s*)(.-)' .. vim.pesc(e_cstr))
-- Finally, set the comment and and line into mutliple lines
A.nvim_buf_set_lines(0, ctx.range.erow - 1, ctx.range.erow, true, {
e_pad .. e_line,
e_pad .. e_cstr,
})
A.nvim_buf_set_lines(0, ctx.range.srow - 1, ctx.range.srow, true, {
s_pad .. s_cstr,
s_pad .. s_line,
})
else
-- We created the new lines, so we should also delete them
A.nvim_buf_set_lines(0, ctx.range.erow - 1, ctx.range.erow, true, {})
A.nvim_buf_set_lines(0, ctx.range.srow - 1, ctx.range.srow, true, {})
end
end
end,
})See for yourself :) 2022-03-17.12-51-34.mp4 |
|
I am going to close this as the linewise commentstring i.e |
No description provided.