-
-
Notifications
You must be signed in to change notification settings - Fork 213
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: delimit tangled code blocks with headings #981
Conversation
It would be nice if this supported immediately nested headings, i.e.
should output comments with both foo and bar, which I don't think the current impl does. Also, I think we want to insert the heading even if nothing's been tangled to the current file, whereas we only want to insert a newline when something has been tangled to the current file. If I'm reading it right, the current PR doesn't do that. |
Heading to the beginning of the file is trivial and has been added now. Immediat nested heading is doable, but I think I want the reviewers input before making the PR more complex than it already is. |
I like the idea of this! But yeah this should definitely be put behind some feature flag as to not confuse users. It could be interesting as a fancy default, but there also should be a way to turn it off if wanted. I guess we want to read data from the document metadata where we could have some info regarding this. Maybe |
Additionally I see that there are conflicts here. When I am again free to work solely on Neorg I'll gladly help out with this PR. It might take some time for me to revisit this though! Not ignoring the PR, just busy with priorities :) |
sounds good to me! |
An extention to the idea discussed in nvim-neorg#958. Add heading text as delimiter as a comment if: 1. There is in-fact a current heading. Headings are optional. 2. Current heading hasn't been used as a delimiter before. 3. `commentstring` is available for the filetype in question. Otherwise just use a newline. That last one (3) requires making a temporary scratch buffer to trigger ftplugin, which retrieves `commentstring` for all supported filetypes in vim.
Heading as comment followed by an extra newline above the first block above the first codeblock assuming it is under a heading. Nothing otherwise. As before, an extra newline above the heading as a comment after that. This give the flow: ``` -- Heading 1 print("Codeblock 1") -- Heading 2 print("Codeblock 2") ```
@vhyrro, I am glad you like the idea! I've done as you suggested and added a configuration option, and moved the branch to the tip of main. In addition I've done two more things:
I appologies if this is considered feature creep, but I feel it adds to the completness of the feature I am proposing. |
elseif type(parsed_document_metadata.tangle) == "string" then | ||
options.languages[vim.filetype.match({ filename = parsed_document_metadata.tangle })] = | ||
parsed_document_metadata.tangle |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I realized that one feature stopped working as a result of this being removed - you should also be able to specify e.g. tangle: ./init.lua
in the metadata, which now errors with the new version. It always assumes that languages
is a thing, which it may not be :p
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch. I have a handler for it, on line 220, but it was implemented incorrectly. Fixed now.
Tried stress testing it and it seems to work with the cases I threw at it, thank you for this PR! 💜 |
An extention to the idea discussed in #955 .
Add heading text as delimiter as a comment if:
commentstring
is available for the filetype in question.Otherwise just use a newline.
That last one (3) requires making a temporary scratch buffer to trigger ftplugin, which retrieves
commentstring
for all supported filetypes in vim.