Hot answers tagged

6

You need to tell company-mode what backend to use. In my init file I have the following code (add-hook 'go-mode-hook (lambda () (set (make-local-variable 'company-backends) '(company-go)) (company-mode))) You will also need the gocode autocomplete daemon which you can get by executing go get github.com/nsf/gocode.


5

You may use goimports utility and just replace gofmt in go-mode with goimports. Cite from goimports page shows how to integrate it with go-mode: (setq gofmt-command "goimports") (add-to-list 'load-path "/home/you/somewhere/emacs/") (require 'go-mode-load) (add-hook 'before-save-hook 'gofmt-before-save) Or if you have already worked go-mode then just M-x ...


3

The docs tell you to configure the go-tab-width spacemacs layer variable. In .spacemacs, inside dotspacemacs/layers is a variable called dotspacemacs-configuration-layers. Add the go layer variables like so: (defun dotspacemacs/layers () (setq-default dotspacemacs-configuration-layers '( (go :variables go-tab-width 2) )))


3

I use smartparens for exactly this. It uses sort of a cryptic syntax in the :post-handlers keyword for doing things after you insert a pair and press a button. Here's a pair config to do what you want: (sp-pair "{" nil :post-handlers '(("||\n[i]" "RET"))) And the relevant documentation on the Github wiki: Pre and Post Action Hooks


2

If you install yasnippet and ac-go-expand-arguments-into-snippets is non-nil(Default is t) then argument snippet is expanded like following animation gif. company-mode provides such feature by itself, so you can use it without yasnippet by company-mode.


2

The basic mechanism you're looking for is to add a hook; if you aren't familiar, hooks are an emacs mechanism that causes a specific function to be called at a particular time. For instance, go-mode-hook will call a set of functions every time go-mode starts. Now: there is an after-save-hook. The thing is, it's global. So you could do this, in your .emacs....


2

If you use Icicles then you can use C-M-RET (or C-M-mouse-2) to see the full doc string (in *Help*) of any completion candidates. You can use the arrow keys C-M-down and C-M-up to cycle among candidates, showing their doc the same way. Also, the first line of the doc string is shown in the mode-line, so just cycling among candidates using down etc. shows ...


2

setq-default sets the global value, whereas you want to set the value in your particular go-mode buffer. Basically, using setq-default within a mode-hook is never right. Try: (add-hook 'go-mode-hook (lambda () (setq indent-tabs-mode 1) (setq tab-width 2)))


2

This sounds like an X–Y problem, where someone has a detailed question that we could find an answer for but that seems to be leading them in the wrong direction. Since you haven’t said what you’re really trying to accomplish here, we can only guess. My guess is that next-error (or other ways of navigating to error locations, such as clicking on them) is ...


1

Based on the error, it looks like you tried passing an unquoted string to set gofmt-args. gofmt-args's type is a list of strings, so that is what you need to give it. You can set it like this: (setq gofmt-args '("-tabs=false" "-tabwidth=2" "-w=true")) If you are setting it interactively, its probably easiest to use M-x ...


1

The compilation mode documentation says the following: To parse messages from the compiler, Compilation mode uses the variable compilation-error-regexp-alist which lists various error message formats and tells Emacs how to extract the locus from each. A similar variable, grep-regexp-alist, tells Emacs how to parse output from a grep command (see ...


1

Looks like adding (speedbar-add-supported-extension ".go") Might be a big part of the solution.


1

If you use flycheck, set (setq flycheck-go-build-install-deps t) This will install your dependencies automatically. More details in flycheck docs: https://www.flycheck.org/en/latest/languages.html#go


1

Apologies, some digging around with gocode -s -debug revealed that it couldn't resolve the import paths "mydomain.tld/myname/myproject/core/" I then realised that I should be doing "go install ./..." so that the all the code in "mydomain.tld/myname/myproject" will be recursively built and installed to $GOPATH/pkg. I am new to Golang, and I realise this ...


1

M-x gofmt does this. Here is the output applied to your examples. package main type person struct { firstname string lastname string age int address string } const ( constant1 int = 1 c2 int = 2 const3 int = 3 ) gofmt runs the external command on the buffer. Here is the output of the external command: ...


1

Fixed it by changing the value of imenu-generic-expression to '(("type" "^[ \t]*type *\\([^ \t\n\r\f]*[ \t]*\\(struct\\|interface\\)\\)" 1) ("func" "^func *\\(.*\\)" 1))) Which has two advantages over the original value. it recognizes split-line functions, and it notices embedded types. I'll probably submit a PR to go-mode, but until then to get this ...


1

You can have company-go insert the arguments for a function when you complete it, like so: Not quite a hotkey for the function arguments but not too far off. If that is not enough based on https://github.com/nsf/gocode/pull/251 gocode can provide the function arguments for a given function, so showing a popup should not be too hard.


1

If you use company-mode (which is preferred by most over autocomplete these days), try company-quickhelp.


Only top voted, non community-wiki answers of a minimum length are eligible