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

Indent with tabs #800

Closed
moll opened this issue May 29, 2015 · 8 comments
Closed

Indent with tabs #800

moll opened this issue May 29, 2015 · 8 comments

Comments

@moll
Copy link

moll commented May 29, 2015

Hey,

A very minor feature request, but would it be possible to get pretty printed output indented by tabs and not spaces? If necessary, configurable. Tab width tends to be user configurable everywhere, but using spaces assume a particular width preference and eyesight ability. ;-)

Thanks!

@nicowilliams
Copy link
Contributor

An option to use a given number of spaces is doable. I don't care for an option to use tabs.

@nicowilliams
Copy link
Contributor

Actually, indentation by 2 spaces is pretty hardcoded. Changing it is possible, of course, but not something I'm inclined to do at this time. I would consider a PR.

@moll
Copy link
Author

moll commented May 29, 2015

While an alternative, I don't think adding an option to set the number of spaces to jq is the right approach. An appropriate tab stop is a presentation issue better solved a level higher — either in the terminal or text editor. Just like we set TZ or font size in the environment. ;-)

Another solution would be --indent "\t". That would handle everyone.

A workaround till then, for the record, is

jq . | unexpand -t2

@nicowilliams
Copy link
Contributor

I could see using an env var for this, but I won't switch jq to using tabs by default, much less as the only setting. @stedolan likes 2-space indents, and I've grown accustomed to them :) I suspect if he were to voice an opinion, it'd be to keep things as-is, or maybe use an env var.

I don't change the tabstop myself. You're the first person I know who does it (though I've heard that others do it, I'd never heard from someone who does do it). I did just learn that one can set the hard tab stops in most terminals (huh!)... I was about to point out that the terminal emulators I use don't have that option, and then I realized it must be a terminfo escape, and sure enough it is, and there's even a tabs(1) command to set the stops. Sadly I can't just set the tabstop in the terminal, I also have to tell apps like vim. How do you manage code with styles that set max line length at 79 columns? I think it must be confusing. But maybe you can convince me of the value of this lifestyle choice :)?

As for unexpand... that's dangerous, because it will change whitespace in strings. At least tabs (and newlines, and...) in strings must be escaped, so the opposite would be OK (if jq were using tabs for indentation, which it isn't).

@kevincox
Copy link

kevincox commented Jun 3, 2015

I agree having it customizable would be the best. It's hard to post-process because you don't want to mess with whitespace in the output. It would be awesome if it could be any number of spaces or tabs.

@moll
Copy link
Author

moll commented Jun 3, 2015

Ah, damn, indeed, the BSD version of unexpand kills tabs inside a line even if -a is not given.
The GNU version, fortunately, has a --first-only to override its -t2 option, making the correct workaround to:

jq . | unexpand -t2 --first-only

@nicowilliams
Copy link
Contributor

Fixed with 24a5e5b.

@kevincox
Copy link

kevincox commented Jun 4, 2015

Thanks so much! This is awesome.
On Jun 3, 2015 9:23 PM, "Nico Williams" notifications@github.com wrote:

Fixed with 24a5e5b
24a5e5b
.


Reply to this email directly or view it on GitHub
#800 (comment).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants