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