-
Notifications
You must be signed in to change notification settings - Fork 69
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
Ignore indentation effect of a specific block #889
Comments
I should also mention I tried the first thing I thought of: #! format: off
@mymacro begin
#! format: on
...
#! format: off
end
#! format: on but this sadly did not work. (This might be the right API for this, because at the time it felt the most intuitive to me.) |
this should work, not sure why it doesn't. essentially all this happens here: https://github.com/domluna/JuliaFormatter.jl/blob/master/src/print.jl#L1-L79 |
Here's a MWE: julia> using JuliaFormatter
julia> format_text("\n#! format: off\n@mymacro begin\n#! format: on\nfoo() = nothing\n#! format: off\nend\n#! format: on")
"\n#! format: off\n@mymacro begin\n#! format: on\n foo() = nothing\n#! format: off\nend\n#! format: on" You can see the extra spaces added before the (inline version of this: #! format: off
@mymacro begin
#! format: on
foo() = nothing
#! format: off
end
#! format: on |
unless I'm missing something this part
will be formatted and it is. Hmmm perhaps the confusion is the scope of the format on/off rule. It's based on the lines and that's it. so the initial format off in this case would just ignore doing anything to
|
Oh I think I got confused. So, in this case, how could I turn off indentation for a specific code block, without disabling formatting within said block? |
indentation is tied to formatting so right now you can't
…On Wed, Dec 11, 2024 at 9:29 PM Miles Cranmer ***@***.***> wrote:
Oh I think I got confused. So, in this case, how could I turn off
indentation for a specific code block, *without* disabling formatting
within said block?
—
Reply to this email directly, view it on GitHub
<#889 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAORUFZO7VFBDUIDAXUJWXT2FDYIZAVCNFSM6AAAAABTOSI7H6VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDKMZXGYZTOOBVGA>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
I see, thanks. Could I request it as a new feature? I want to be able to remove a single indentation for a |
I'd be fine with it as a new feature but I probably won't get around to implementing this any time soon. |
In case I or someone else reading this thread in the future wants to try adding it, where should we start? |
Sometimes in my code I would like to use a macro on a block of code without indenting it. For example, I want to go from
to this:
This could be something like DispatchDoctor.jl
@stable
orBase.@assume_effects
, which can operate on entire code blocks.Now, if I have the formatter turned on, this will turn into
This is of course valid, but I would like to disable it for the code block. I want the
@mymacro begin
to just sit at the top level without affecting the rest of the code. (It's kind of like howmodule A ... end
doesn't indent everything in the contents.)The only workaround at the moment is to use
#! format: off
for the entire code block. This works but it prevents me from using JuliaFormatter.jl for internal code.Thus, @domluna, I was wondering if there could be a special command to ignore the increased indentation for a single block? Happy to help add it if you can point me to where to edit.
The text was updated successfully, but these errors were encountered: