[ANN] Improved go-mode for Emacs

1,134 views
Skip to first unread message

Dominik Honnef

unread,
Feb 1, 2013, 6:33:54 PM2/1/13
to golan...@googlegroups.com
Hello gophers,

I want to present to you an improved go-mode for Emacs.

The main improvements over the mode that's shipped with Go are a proper
syntax table and stable, less buggy fontification and indentation.

Where the original go-mode completely reinvents fontification and
parsing (and messes up in a lot of places), this mode lets Emacs do the
hard work. This also causes comment-dwim and extensions like
extend-region to work properly, because now they're aware of strings and
comments, something that's not possible with the original mode because
it does away with the syntax table and just manually adds colors.

This approach made implementing new features easier as well. Thus, the
improved go-mode supports the beginning-of-defun, end-of-defun and
mark-defun functions of Emacs. Additionally, one can directly jump to
the import section, and even add new imports with a simple key press.
Including tab completion!

Last but not least, I've made some small adjustments to fontification,
enabling proper handling of unicode in identifiers, type names in
slices/arrays/maps, anonymous functions and a few others.

A complete list of improvements, as well as the mode itself, can be
found at GitHub[1].

If you're wondering why I haven't tried to submit my changes upstream
yet: My mode has one regression, in that it doesn't handle the (lack of)
escaping in raw strings, which means that the character sequence \`
(backslash followed by backtick) in a raw string will mess up
indentation as well as fontification. This issue is, in part, the reason
why the original go-mode doesn't use a syntax table but (poorly)
reinvents the wheel. I, however, think that the sequence \` is rare
enough, and can be worked around easily enough, that this doesn't
justify breaking many aspects of Emacs. Furthermore, Emacs 24 allows new
ways of aiding the parser, so making this work isn't entirely
impossible, I just haven't gotten to it yet.

If you can live with that one issue, or want to get away from all the
other issues, please check out my mode and let me know if you encounter
any problems.

[1] https://github.com/dominikh/go-mode.el

Vladimir Mihailenco

unread,
Feb 2, 2013, 4:54:36 AM2/2/13
to golang-nuts
Thanks for sharing! Can you please add it to the emacs packages repository?




--
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...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.



Dominik Honnef

unread,
Feb 2, 2013, 10:05:00 AM2/2/13
to golan...@googlegroups.com
Vladimir Mihailenco <vladimi...@gmail.com> writes:

> Thanks for sharing! Can you please add it to the emacs packages repository?

Only if I can come up with a fair name for the package, because go-mode
is obviously taken already and I don't feel too comfortable with
suffixes à la -ng or -2.

On the long run I'm still hoping to get it adopted upstream, so that
it'll become the official go-mode. But that won't happen before I get
rid of the \` issue.

Naming ideas will be appreciated :)

Greg Ward

unread,
Feb 2, 2013, 5:43:20 PM2/2/13
to golan...@googlegroups.com
On 02 February 2013, Dominik Honnef said:
> I want to present to you an improved go-mode for Emacs.

Woo-hoo! Awesome, thank you. I've been afraid that I would have to
break down and finally learn how to program Emacs for real in order to
fix the bugs in go-mode.el that annoyed me. Thank you for doing it for
me. Now I can put my head back in the sand regarding Emacs Lisp.

I'm now going to start opening bugs against your go-mode.el. (I've
already found two bugs with {beginning,end}-of-defun, which I have
sorely missed.) Please take that as a compliment; it means I'm using
it! ;-)

Greg
--
Greg Ward http://www.gerg.ca
<gr...@gerg.ca> @gergdotca

Dominik Honnef

unread,
Feb 2, 2013, 8:54:10 PM2/2/13
to golan...@googlegroups.com
Greg Ward <gr...@gerg.ca> writes:

> On 02 February 2013, Dominik Honnef said:
>> I want to present to you an improved go-mode for Emacs.
>
> Woo-hoo! Awesome, thank you. I've been afraid that I would have to
> break down and finally learn how to program Emacs for real in order to
> fix the bugs in go-mode.el that annoyed me. Thank you for doing it for
> me. Now I can put my head back in the sand regarding Emacs Lisp.

Be very glad that you can. Writing elisp isn't as fun as it sounds :)

> I'm now going to start opening bugs against your go-mode.el. (I've
> already found two bugs with {beginning,end}-of-defun, which I have
> sorely missed.) Please take that as a compliment; it means I'm using
> it! ;-)

Oh I definitely take it as a compliment. In fact I am glad you found
those issues. That means I could fix them before I had to encounter them
myself while trying to write some code. Keep the tickets coming. I also
appreciate suggestions for improvements, such as missing integration
with other Emacs functionality.

I'm glad I could help someone other than me with this mode :)

Cheers

Mats Lidell

unread,
Feb 3, 2013, 9:16:45 AM2/3/13
to golan...@googlegroups.com
>>>>> Dominik Honnef <domi...@fork-bomb.org> writes:

> Only if I can come up with a fair name for the package, because go-mode
> is obviously taken already and I don't feel too comfortable with
> suffixes à la -ng or -2.

golang-mode?

Yours
--
%% Mats

Brad Fitzpatrick

unread,
Feb 13, 2013, 8:33:53 PM2/13/13
to golan...@googlegroups.com
You know you could also just contribute to the existing go-mode, so we have one good Emacs mode and not two slightly-good-in-different-ways ones for people to choose between.

We have no full-time owner or maintainer of the existing go-mode code.

Emacs user and gopher,
Brad

Dominik Honnef

unread,
Feb 14, 2013, 8:18:51 AM2/14/13
to golan...@googlegroups.com
I intend to "contribute" my changes to the original go-mode once a certain
bug in mine is fixed.

There's no point in "contributing to the existing go-mode" because it
is, quite frankly, written in a horrible way, based on some very wrong
assumptions on how Emacs works. The only way forward would be to replace
it.

I have entirely replaced the handling of syntax parsing, fontification
and indentation, but that reintroduces a bug that the original go-mode
fixed, and I don't see much point in trying to submit changes that
reintroduce a bug.

And all other additions (features) that I have made rely on the changes
regarding syntax parsing, so those cannot be contributed back yet,
either.

I do know that having two "slightly different" modes around isn't a good
option, but right now the choice is between a mode that can handle \` in
raw strings, and a mode that does everything else better. Once my mode
knows how to handle \`, I'll try to get it merged upstream.

The only other obstacle could be that I personally do not use or care
about XEmacs or GNU Emacs <24 much, so someone would have to make sure
that my changes work on those. I see more merit in writing a mode that
works very well on one specific platform, than writing a mode that does
a mediocre job across multiple platforms. This is another reason I
haven't tried to contribute anything to the existing go-mode yet: My
mode makes some assumptions that might not be true for everyone.

Last but not least, my implementation of indentation is rather new and
people still manage to discover new obscure bugs and corner cases. By
maintaining the mode myself, I can quickly fix those bugs and push out
new versions, without having to wait for the fixes to go through a
review process. That's another strong reason why I am not that keen on
merging the two modes yet. I'd rather wait with that until I am
confident that there are only a few bugs left.

Please don't take my reply personal or consider it rude. I'm just
focussing on other aspects right now.

Rob Pike

unread,
Feb 14, 2013, 12:18:30 PM2/14/13
to golan...@googlegroups.com
I too would prefer to see a single, clean, working go-mode checked in
to misc, for the benefit of users. I encourage you to fix your `\` bug
and send a CL to install it in the standard repo.

-rob

Dominik Honnef

unread,
Feb 15, 2013, 9:36:44 PM2/15/13
to golan...@googlegroups.com
Okay, I'm close to the point where I see myself sending a CL (the \` bug
is fixed¹ and I'm only waiting for feedback on some other issues
reported by some users) and I'm wondering how to proceed. In particular,
because this mode is almost an entire rewrite (only keeping the gofmt
and godoc related functions), the unified diff is roughly 1400 lines
long, somewhat more than half of it being deletions. Should I send this
as a single CL to replace most of the existing go-mode in misc or
somehow try to split it up, say into two parts, one replacing the
indentation/fontification and one adding the new features?

Cheers,
Dominik

¹: It's fixed in XEmacs and GNU Emacs >=24. GNU Emacs <=23 will still
have the \` bug but behave correctly in all other cases.

Ian Lance Taylor

unread,
Feb 16, 2013, 12:00:18 AM2/16/13
to golan...@googlegroups.com
On Fri, Feb 15, 2013 at 6:36 PM, Dominik Honnef <domi...@fork-bomb.org> wrote:
> Okay, I'm close to the point where I see myself sending a CL (the \` bug
> is fixed¹ and I'm only waiting for feedback on some other issues
> reported by some users) and I'm wondering how to proceed. In particular,
> because this mode is almost an entire rewrite (only keeping the gofmt
> and godoc related functions), the unified diff is roughly 1400 lines
> long, somewhat more than half of it being deletions. Should I send this
> as a single CL to replace most of the existing go-mode in misc or
> somehow try to split it up, say into two parts, one replacing the
> indentation/fontification and one adding the new features?

For something like this, sending a single CL is fine. Sending two CLs
is also fine if you find that preferable.

Ian

Dominik Honnef

unread,
Feb 16, 2013, 1:14:05 PM2/16/13
to golan...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages