-
Notifications
You must be signed in to change notification settings - Fork 71
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
Can we indent with tabs rather than spaces? #421
Comments
Would that mean using '\t' instead of ' '? |
To be exact, use one '\t' instead of four ' '. |
what if the number of spaces is different than 4? |
I don't think it's a problem, the options can be whether to indent with X spaces or 1 tab. |
Maybe instead of |
In general, the right way to indent with tabs is to use them for the "semantic" indent while continuing to use spaces for the "physical" indent. For instance, when indenting with four spaces, JuliaFormatter produces the following code: @testset "Contrived example" begin
@test (@test_logs very_very_very_very_very_very_very_very_very_very_long_expression()) ==
another_very_very_very_very_very_very_very_very_very_very_long_expression() ==
if contrived_example
println("42")
return 1
else
return 0
end
end The whole If using tabs to indent, then # tab width = 2
@testset "Contrived example" begin
[]@test (@test_logs very_very_very_very_very_very_very_very_very_very_long_expression()) ==
[] another_very_very_very_very_very_very_very_very_very_very_long_expression() ==
[] if contrived_example
[] []println("42")
[] []return 1
[] else
[] []return 0
[] end
end
# tab width = 4
@testset "Contrived example" begin
[ ]@test (@test_logs very_very_very_very_very_very_very_very_very_very_long_expression()) ==
[ ] another_very_very_very_very_very_very_very_very_very_very_long_expression() ==
[ ] if contrived_example
[ ] [ ]println("42")
[ ] [ ]return 1
[ ] else
[ ] [ ]return 0
[ ] end
end
# tab width = 16!?
@testset "Contrived example" begin
[ ]@test (@test_logs very_very_very_very_very_very_very_very_very_very_long_expression()) ==
[ ] another_very_very_very_very_very_very_very_very_very_very_long_expression() ==
[ ] if contrived_example
[ ] [ ]println("42")
[ ] [ ]return 1
[ ] else
[ ] [ ]return 0
[ ] end
end Everything stays aligned regardless of the tab size, and you still get the right semantic indent. |
@rben01 I think you are mixing the concept of continuation indent and code alignment. I don't know your preference, but for me, I usually turn off all possible code alignment. My settings for most IDEs are like no code alignment, tab size = 4, indent = 1 tab, continuation indent = 1 tab. So in your example, For the tab size, I think many IDEs have such an option to choose its width. My idea is: don't decide for users, give them options. |
@liurui39660 Sure, the option is nice. But I don't think that JuliaFormatter currently has that option; it always aligns when there's a continuation (try replacing |
Any progress on this issue? It’s the one thing preventing me from using this package 😅 |
Can we set the formatter to indent with tabs instead of spaces? |
Some people asked me whether they can indent with tabs instead of spaces. Can
JuliaFormatter.jl
do that?The text was updated successfully, but these errors were encountered: