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

Autoformat file #874

Closed
1 task done
treeman opened this issue May 16, 2023 · 14 comments
Closed
1 task done

Autoformat file #874

treeman opened this issue May 16, 2023 · 14 comments
Labels
feature Issues related to feature proposals. Please attach a module.

Comments

@treeman
Copy link

treeman commented May 16, 2023

Issues

  • I have checked existing issues and there are no existing ones with the same request.

Feature description

I'm not sure if this is already possible or if this a feature request, but I'd like to format .norg files when saved.

For me this is super convenient and it's a good timesaver. For instance, sometimes the content under headings aren't indented correctly and now I need to indent them manually (visual selection with = works ok). Of course formatting is more than just indentation, this is just an example.

Is this possible somehow? Either with autocmd or something like Neoformat.

Help

No

Implementation help

No response

@treeman treeman added the feature Issues related to feature proposals. Please attach a module. label May 16, 2023
@github-project-automation github-project-automation bot moved this to added-updated-reopened in sorting neorg issue tracker May 16, 2023
@katawful
Copy link
Contributor

Indenting, which is most of the formatting needed, should be handled out of the box. You can check what the indent expression is set to with :set indentexpr?. It should be a neorg function, not a treesitter one

There is no norg formatter atm, but since indentation handles most of the formatting, gg=G will jump to the top of the file then indent down to the bottom

For line widths and style issues, you'll have to handle these manually. gq can format a paragraph to whatever the textwidth is set to

@hardfau1t hardfau1t mentioned this issue May 19, 2023
1 task
@d-r-a-b
Copy link
Contributor

d-r-a-b commented May 20, 2023

You can also set this up with a little vim knowledge. :h autocmd :h BufWritePre.

There are cases where this is harmful, i.e. if you have manual formatting that you don't want the indent engine to touch. An easy example is code blocks which do not have treesitter indent support (:TSModuleInfo). As such, it is not a good fit to implement this as part of Neorg in a non-robust way. My sense as a community observer is that other dev priorities are likely to be the primary focus for a while unless a contributor steps up.

@d-r-a-b d-r-a-b moved this from added-updated-reopened to needs-PR-angel in sorting neorg issue tracker May 20, 2023
@pysan3
Copy link
Contributor

pysan3 commented May 25, 2023

Found this.

Maybe you can try it out?

https://github.com/nvim-neorg/norg-fmt

@NTBBloodbath
Copy link
Member

Found this.

Maybe you can try it out?

https://github.com/nvim-neorg/norg-fmt

That project isn't functional yet, it still has a long way to go before it's usable so the best solution for now is the native Neovim gg=G :p

@CRAG666
Copy link

CRAG666 commented Jun 7, 2023

What are the formatting directives? I ask to configure.

@UtkarshVerma
Copy link

Found this.
Maybe you can try it out?
https://github.com/nvim-neorg/norg-fmt

That project isn't functional yet, it still has a long way to go before it's usable so the best solution for now is the native Neovim gg=G :p

That's a nice builtin method, but it does not play nicely with metadata. The categories are always pushed to the line beginning.

@leongjs98
Copy link
Contributor

Found this.
Maybe you can try it out?
https://github.com/nvim-neorg/norg-fmt

That project isn't functional yet, it still has a long way to go before it's usable so the best solution for now is the native Neovim gg=G :p

That's a nice builtin method, but it does not play nicely with metadata. The categories are always pushed to the line beginning.

do you still have this issue now on NVIM v0.9.2 with Neorg v6.0.0?

the built-in method gg=G shouldn't push the metadata categories to the start of the line now

should we close this old issue?

@pysan3
Copy link
Contributor

pysan3 commented Sep 26, 2023

the built-in method gg=G shouldn't push the metadata categories to the start of the line now

should we close this old issue?

Yes, this method now works perfectly for almost all situation for me.

One last issue I have is in between norg code blocks. All indents in the code block gets shifted to the left.

-- Before gg=G

** Usage
*** Template Norg Files
    @code norg
    * {TITLE_INPUT}
      Weather: {WEATHER}
      {{:{YESTERDAY}:}}[Yesterday] - {{:{TOMORROW}:}}[Tomorrow]

    ** Daily Review
       - {CURSOR}
    @end

-- After gg=G

** Usage
*** Template Norg Files
    @code norg
    * {TITLE_INPUT}
    Weather: {WEATHER}                                            <- This line
    {{:{YESTERDAY}:}}[Yesterday] - {{:{TOMORROW}:}}[Tomorrow]     <- This line

    ** Daily Review
    - {CURSOR}                                                    <- This line
    @end

This issue does not happen on lua code block I only found this behavior in norg code blocks (tho I haven't tested for all).

This file is the one I'm having problem with.

https://github.com/pysan3/neorg-templates/blob/d96b4fbcb38223778696b48e3bf6e4e6a8a94ad8/README.norg#L39

@leongjs98
Copy link
Contributor

I have just tested some other languages and these are the result on NVIM v0.9.2 with Neorg v6.0.0

code auto-format result
Bash not working
Go working
JavaScript working
Lua working
Norg not working

I believe we should close this issue and open another issue for this
Because this issue is mainly dealing with the code blocks whereas the original issue is general formating

"Auto-indent/format with - doesn't work with some code blocks"
@pysan3 what do you think this new issue title, if you think it's alright, let's just open a new issue and close this one

@pysan3
Copy link
Contributor

pysan3 commented Sep 26, 2023

Thanks @leongjs98 for testing!

Auto-indent/format with = doesn't work with some code blocks

Nice title. Tho I believe you mistyped = with -.
Could you open the issue? I haven't got spare time now and don't have time to test it unfortunately.

@treeman
Copy link
Author

treeman commented Sep 26, 2023

I do not think this issue should be closed as it tracks a general formatter, not just indentation.

For example removing extra empty lines or formatting authors: [ ... ] into one or multiple lines depending on the count are some things a proper formatter should handle.

And besides that I think there are more things that auto-indent doesn't cover. I tried with the 1.0 specification and it produces a fairly large diff. I'm not familiar enough with neorg to pinpoint if all are valid or if the specification file itself isn't formatted correctly from the start, but I do think there are some auto-indent issues with that file.

@leongjs98
Copy link
Contributor

Thanks @leongjs98 for testing!

Auto-indent/format with = doesn't work with some code blocks

Nice title. Tho I believe you mistyped = with -. Could you open the issue? I haven't got spare time now and don't have time to test it unfortunately.

Yes, I mistyped. Thanks for spotting it!

will open a specific issue right away.

@leongjs98
Copy link
Contributor

@treeman

I do not think this issue should be closed as it tracks a general formatter, not just indentation.

My point of closing this issue is that it's hard to solve a problem when we don't know the specifics of the problem. And L

The example in the original issue:

For instance, sometimes the content under headings aren't indented correctly and now I need to indent them manually (visual selection with = works ok).

is solved with the newer version of NeoVim and Neorg

Other than that, the original issue didn't have other specific formating issue. And the actual issues are scattered around in the comments. This just makes it harder for the developer to try to solve this.

Whilst the formater can definitely be improved, my suggestion is to open new issues with more specifics so it's easier to discuss and solve them.

@treeman
Copy link
Author

treeman commented Oct 1, 2023

Other than that, the original issue didn't have other specific formating issue. And the actual issues are scattered around in the comments. This just makes it harder for the developer to try to solve this.

Good points! Closing this.

@treeman treeman closed this as completed Oct 1, 2023
@github-project-automation github-project-automation bot moved this from needs-PR-angel to done in sorting neorg issue tracker Oct 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature Issues related to feature proposals. Please attach a module.
Projects
None yet
Development

No branches or pull requests

8 participants