What I think I want out of autocompletion in GNU Emacs (for Go coding)

November 21, 2015

I mentioned a while back that I had set up autocompletion in GNU Emacs for Go, using gocode and the auto-complete Emacs package. I also mentioned that I wasn't sure if I liked autocompletion and was going to stick with it. Well, the verdict is in for now; I found it too annoying and I wound up turning it off. However, I still kind of miss it. Thinking about what I miss and what made me hate it enough to turn it off has led me to what I think I want out of autocompletion.

Why I turned autocompletion off is that it kept stealing my keystrokes (in order to do the wrong autocompletion); cursor keys, the return key, and I think even sometimes the space bar. I type fast and I type ahead, so I absolutely, utterly hate having the sequence of what I'm typing be derailed because autocompletion decided to grab a cursor motion or a return or whatever. Unless I go out of my way, I want what I type at the keyboard to actually be what shows up in the file I'm editing. At the same time, the prompting and information that autocompletion gave me was genuinely useful; it was a great way to not have to remember the full names of things in Go packages and so on.

Given that I liked the information display, I don't want all of (auto)completion to be deferred until I use a special key sequence like C-M-i. If I spent a lot of time in GNU Emacs I might be able to train myself to hit that by reflex, but with my more casual use it'd just insure that I mostly never used completion at all. But I don't want any actual completing of things to happen until I hit a key to start it (and once I hit the key, it's fine if autocompletion steals my cursor keys and return key and so on).

So in short what I want from autocompletion is immediate information on possible completions coupled with deferred actual completion until I take some active step to start the completion process. This is fairly similar to the completion model I'm happy with in Unix shells, where nothing starts getting filled in until you hit TAB.

(Defering only actual completion doesn't appear to be possible in auto-complete. I can't entirely blame the package, because what I'm calling an information display is what it thinks of as a completion menu and completion prompt.)

Part of my irritation with autocompletion is specific to the Go autocompletion mode provided by gocode. For instance, in Go I don't want to have completion happen when I'm typing in language keywords like package and func; I find it both distracting and not useful. Completion is for things that I might have to look up; if I'm typing a keyword, that is not the case.

(This completion of keywords is especially irritating because it's blind to context. If I start typing 'pa' on a new line in a function body, I'll still get offered 'package' as a possible completion despite that clearly not being correct or even valid. Gocode is context aware in general, in that it does things like offer local variables as completions.)

PS: That part of my issues are with gocode itself suggests that even switching to vim wouldn't entirely help.


Comments on this page:

By dominikh at 2015-11-21 09:25:57:

I'm not sure why you're seeing completion of keywords in the first place. Gocode completes built-in types, but it doesn't complete keywords (see https://github.com/nsf/gocode/blob/master/decl.go#L1316-L1396 and https://github.com/nsf/gocode/issues/312). The completion of built-ins can also be disabled entirely.

Are you sure auto-complete isn't using a 2nd data source for these keywords?

By cks at 2015-11-21 14:25:46:

I haven't configured any extra data sources as far as I know (I'm using the standard setup that's covered here) and I'm using an up to date copy of gocode (and thus of go-autocomplete.el). For what it's worth, 'gocode set' says that I have propose-builtins set to false and that seems to work.

My specific .emacs configuration right now is:

(add-to-list 'load-path "~/go/src/github.com/nsf/gocode/emacs")
(require 'go-autocomplete)
(require 'auto-complete-config)
(ac-config-default)

(define-key ac-completing-map [down] nil)
(define-key ac-completing-map [up] nil)

Auto-complete is installed through MELPA, taking all of the defaults.

Ah. There is a dict/go-mode file in auto-complete that has all of the keywords in it. However, moving it completely out of the way, restarting Emacs, and doing ac-clear-dictionary-cache doesn't stop keywords from completing (and as far as I can tell I have no other copy of the go-mode file lurking somewhere in the underbrush).

By dominikh at 2015-11-21 19:38:31:

I'm not really familiar with auto-complete (I use company-mode myself), but if I remember correctly, ac will also integrate with dabbrev-expand by default, completing words from buffers.

All I know for sure is that it shouldn't be gocode that's pushing the completion and thus it's a configuration issue with auto-complete. Hope that helps.

Written on 21 November 2015.
« What modern version control systems are
I should find some good small packages for templates and forms for CGIs »

Page tools: View Source, View Normal, Add Comment.
Search:
Login: Password:
Atom Syndication: Recent Comments.

Last modified: Sat Nov 21 03:25:34 2015
This dinky wiki is brought to you by the Insane Hackers Guild, Python sub-branch.