Skip to content
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: auto tangle #1413

Merged
merged 2 commits into from
Jul 15, 2024
Merged

feat: auto tangle #1413

merged 2 commits into from
Jul 15, 2024

Conversation

benlubas
Copy link
Contributor

@benlubas benlubas commented May 3, 2024

Adds the tangle_on_write option to the tangle module. Defaults to false, when true, call :Neorg tangle current-file on BufWritePost.

Fixes an annoying "bug" where tangling fails when code is de-dented. This is just a qol thing, I don't see a point in failing with a loud error in this case when we can easily handle the error and correctly export anyway.

@benlubas benlubas force-pushed the feat/auto_tangle branch 2 times, most recently from 7733184 to 226cb46 Compare May 3, 2024 22:35
@vhyrro
Copy link
Member

vhyrro commented Jul 7, 2024

Sorry for taking a while to get around to this. I generally disagree with the lenient tag checking (allowing arbitrary indentation), because it will cause some confusion amongst users. The reason all this behaviour exists in the first place is because you can't correctly "guess" where the start of the indentation is unless you have a strong rule like we do. Imagine someone does the following:

   @code
   -- This is correctly indented
this will get cut off
   @end
   @code 
-- This is incorrectly indented
   this is correctly indented visually, but will not show up as such in the tangle output
   @end
   @code 
  -- Oops, I accidentally dedented this line by one character, and so now everything else will be indented incorrectly.
   this has the correct indentation, but will now appear one character to the right in the tangle output
and this will be cut off
   @end

I'd much rather have a single case which can fail: "you've dedented too far". This is much less ambiguous and better UX than trying to guess what the user meant and then being unpredictable in our output :)

@benlubas
Copy link
Contributor Author

benlubas commented Jul 7, 2024

For most practical purposes tangled code need not be indented perfectly.

Python and haskal are the two exceptions. Could there be a list of languages to allow correction on? Can it be configurable?

The main reason I changed the intent handling was to avoid annoying/excessive error messages while I was editing code with auto tangle. Because I use an auto save plugin, it was very easy to trigger those errors.

We could also make it a diagnostic warning instead of error for languages other than Python and haskal. That way it's hard for users to unknowingly have an intent error.

@vhyrro
Copy link
Member

vhyrro commented Jul 8, 2024

If the errors are annoying on auto-save, then I see two paths forward:

  • enable lenient tag checking only when auto-tangle is enabled, otherwise always perform strict tag checking
  • when auto-tangle is enabled, instead of erroring loudly, just print a message in the bottom left saying that tangling didn't succeed

I'm personally more fond of the second approach. I really feel like lenient tag checks are a source of confusion, especially since ill-indented code will produce garbled output. More convenience is not a good reason for invalid output.

@benlubas
Copy link
Contributor Author

@vhyrro I updated this PR with some customizable behavior for the error messages

@vhyrro
Copy link
Member

vhyrro commented Jul 15, 2024

ty!

@vhyrro vhyrro merged commit 0f24e4a into nvim-neorg:main Jul 15, 2024
5 of 6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants