On Wed, Feb 25, 2015 at 12:42 AM, Florin Patan <
flori...@gmail.com> wrote:
> On Monday, February 23, 2015 at 6:42:04 PM UTC+1, Ian Lance Taylor wrote:
>>
>> As far as I know nobody has ever written down any rules for gofmt.
>> Although there are multiple implementations of the Go compiler, there
>> has (until now) been only a single implementation of gofmt. So this
>> is a case where the implementation is the spec.
>>
>> There are tests for gofmt in the directory cmd/gofmt/testdata.
>
> Ian, would it be possible to have the implementation translated to actual
> specifications somewhere? How could I contribute with a documentation
> to provide this?
This is Robert's question to answer, but I don't see that ending well.
The basic approach is straightforward, and is, for example,
implemented in emacs go-mode
(
https://github.com/dominikh/go-mode.el). There are probably other
editor plugins that partially implement the formatting; see
https://github.com/golang/go/wiki/IDEsAndTextEditorPlugins . The idea
is simply to format as you type, imprecisely, and format precisely
using gofmt on file save. Usually the differences will only be with
things like indentation of struct fields. Note in particular that
full gofmt support as you type means that earlier lines will be
reindented as you type later lines, which I think many people will
find confusing.
Ian