TIL. Do you have an example? FWIW, I can think of a simpler reason why the Config has a Tabwidth field - to use it to decide how many spaces to use for a "tab". Which seems to be at least part of what it's used for <https://go.dev/play/p/GAE5ofn_V5N>. I agree that the use of a TabWriter seems to indicate that more is going on.
On Wed, Sep 14, 2022 at 12:02 AM David Finkel <david.fin...@gmail.com> wrote: > > > On Tue, Sep 13, 2022 at 5:39 PM Axel Wagner <axel.wagner...@googlemail.com> > wrote: > >> >> >> On Tue, Sep 13, 2022 at 10:46 PM David Finkel <david.fin...@gmail.com> >> wrote: >> >>> On Tue, Sep 13, 2022 at 3:55 PM Moein Halvaei <moeinn....@gmail.com> >>> wrote: >>> >>>> When I read codes from https://cs.opensource.google/go, indents are 2 >>>> spaces and when using gofmt indents are 2 tabs. Why? >>>> >>> Google's Codesearch defaults to matching Google's C++ style guide rather >>> than Go's recommended style: >>> https://google.github.io/styleguide/cppguide.html#Spaces_vs._Tabs >>> To be clear: gofmt uses an 8-spaces per tab, not two tabs. >>> >> >> gofmt doesn't determine how many spaces are tab stops aligned to at all. >> That's a property of your editor, IDE or code browser and usually >> configurable. That's part of the appeal of using tabs for indentation and >> why spaces are better for alignment. >> > Well, that's partially true. > There are a few places where gofmt aligns tokens after indentation where > the alignment doesn't quite work out correctly if the tab-stop interval > isn't exactly 8 characters. > The `go/printer` package's Config includes a Tabwidth > <https://pkg.go.dev/go/printer@go1.19.1#Config.Tabwidth> field for a > reason (it's actually passed to a > <https://cs.opensource.google/go/go/+/refs/tags/go1.19.1:src/go/printer/printer.go;l=1391;drc=54182ff54a687272dd7632c3a963e036ce03cb7c> > TabWriter <https://pkg.go.dev/text/tabwriter#Writer> to do the alignment). > > (I didn't realize before that the go/printer package actually underlies > the implementation of go/format and cmd/gofmt -- I had assumed that it was > a reimplementation like go/ast vs the compiler-internal ast) > >> >> >>> -- >>>> You received this message because you are subscribed to the Google >>>> Groups "golang-nuts" group. >>>> To unsubscribe from this group and stop receiving emails from it, send >>>> an email to golang-nuts+unsubscr...@googlegroups.com. >>>> To view this discussion on the web visit >>>> https://groups.google.com/d/msgid/golang-nuts/3b43a2be-8001-4f53-a952-417b6a909bd9n%40googlegroups.com >>>> <https://groups.google.com/d/msgid/golang-nuts/3b43a2be-8001-4f53-a952-417b6a909bd9n%40googlegroups.com?utm_medium=email&utm_source=footer> >>>> . >>>> >>> -- >>> You received this message because you are subscribed to the Google >>> Groups "golang-nuts" group. >>> To unsubscribe from this group and stop receiving emails from it, send >>> an email to golang-nuts+unsubscr...@googlegroups.com. >>> To view this discussion on the web visit >>> https://groups.google.com/d/msgid/golang-nuts/CANrC0BgCHM_m2nkAjkqnLDP02-FfYFtOyRv9SW8SAup4NHp1UA%40mail.gmail.com >>> <https://groups.google.com/d/msgid/golang-nuts/CANrC0BgCHM_m2nkAjkqnLDP02-FfYFtOyRv9SW8SAup4NHp1UA%40mail.gmail.com?utm_medium=email&utm_source=footer> >>> . >>> >> -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/CAEkBMfGYEjtjsq5DDiM-wivPs8hxUkzGXg8w0ukP%2BwB7XSJuqw%40mail.gmail.com.