Useful programs
Text editors
- GNU Emacs – the universal text editor
- godit – mini Emacs-like editor with UTF-8 support (written in Go)
- mg – mini Emacs-like editor without UTF-8 support (available in Debian package
mg
)
GUI programs
Other programs
- Debian – a universal operating system
- git – distributed version control system. Comes with gitk GUI (see Use gitk to understand git also look at magit a GNU Emacs interface for git)
- Docker – powerful and easy containers (like lightweight virtual machines; the
docker
tool is written in Go) - webfront – HTTP server and reverse proxy (written in Go)
- go-mtpfs – mounting Android devices as MTP device (written in Go). This was the only such tool that worked for me without problems (when I had to choose one).
- tmux – a terminal multiplexer
Go (golang) programming language
- Go – the Go programming language
- see Learning Go below
- Tour – interactive Go tour (write and execute examples in your browser)
- Doc – Go documentation
- Pkg – Go standard’s library documentation
- GoDoc – documentation of third party Go packages
- goimports – automatically adds import statements for used identifiers, also does gofmt formatting of your code, Emacs’s go-mode may be configured to run goimports on save
- go guru – answers questions about Go programs by static analysis of the source code (see also user manual under its previous name and its Emacs package go-guru)
- Reading from io.Reader line by line
- Using Go under Emacs
- gotype – does semantic analysis of a Go program and displays errors (runs faster then the go compiler)
- Tools for working with Go Code
- gore – Yet another Go REPL (useful for short experiments with Go)
- go-playground – local Go playground in Emacs
Learning Go
Introduction
- to search for Go use “golang” term instead of Go (as in the name of the official Go webpage)
- Russ Cox – A Tour of the Go Programming Language (suggested on Go documentation page)
- A Tour of Go – interactive tutorial which allows you to edit compile and run examples in the browser
- How to Write Go Code
- IDEs and Plugins for Go. Examples (open source): using Go under Emacs, go-plus package for Atom editor, LiteIDE.
Videos (with links to slides)
- dotGo 2015 – Rob Pike – Simplicity is Complicated [slides] – one of three original authors of Go
- Øredev Conference 2012 – Andrew Gerrand – Code that grows with grace [slides] (suggested on Go documentation page)
- Google I/O 2012 – Rob Pike – Go Concurrency Patterns [slides] – one of three original authors of Go (suggested on Go documentation page)
- Google I/O 2013 – Samerr Ajmani – Advanced Go Concurrency Patterns [slides] (suggested on Go documentation page)
- Write in Go (Fall 2014)
- GopherCon 2015 – Robert Griesemer – The Evolution of Go [slides] – one of three original authors of Go
- Francesc Campoy – Twelve Go Best Practices [slides]
- GopherCon 2016 – Francesc Campoy – Understanding nil [slides]
- JustForFunc #16 – Francesc Campoy – Unit testing HTTP servers
- golang-syd in July 2014 – Andrew Gerrand – Testing techniques [slides]
- Golang UK Conference 2016 - Marcel van Lohuizen - Advanced Testing Concepts
- GopherCon 2014 – Richard Crowley – Building web services in Go [slides]
- Gophercon India 2016 – Brad Fitzpatrick – Introducing Go 1.6: asymptotically approaching boring [slides]
- Gophercon India 2017 – Filippo Valsorda – Fighting latency: the CPU profiler is not your ally [slides]
Articles
- Go Slices: usage and internals
- SliceTricks
- Strings, bytes, runes and characters in Go
- Go maps in action
- Godoc: documenting Go code
- Effective Go
- Errors are values
- Package names
- Reading from io.Reader line by line
- Go database/sql tutorial
See also
- Go language links above
Configuration of Emacs editor
Add MELPA package list
You can install many Emacs packages from MELPA
repository. To add MELPA to the package list add the following to your
~/.emacs
file
(require 'package) (setq package-archives '(("gnu" . "https://elpa.gnu.org/packages/") ("melpa" . "https://melpa.org/packages/")) tls-checktrust t tls-program '("gnutls-cli --x509cafile %t -p %p %h") gnutls-verify-error t)
This also turns on checking TLS certificates (in both possible modes)
with tls-program
set to only the first value from the default value
(for more info
see
Your Text Editor Is Malware).
Now you can list available packages by running M-x list-packages
.
Mark packages you want to install by pressing i
and later press x
to install all marked packages (the necessary dependencies will be
installed automatically).
Interesting Emacs packages available from MELPA
- magit – manage git repository from Emacs, especially interactive rewriting of the history is made easy and staging and committing individual chunks (fragments) of files is also handy
- go-mode – Go editing mode
- company-go – autocompletion for Go identifiers (the alternative is go-autocomplete)
- go-eldoc – eldoc support for Go code
- markdown-mode – Markdown editing mode (see also CommonMark)
- leuven-theme – an Emacs theme with a light background (see screenshots)
- white-sand-theme – an Emacs theme with a light background (see screenshots)
- greymatters-theme – an Emacs theme with a light background (see screenshots)
- professional-theme – Emacs port of Vim’s professional theme (see also other Emacs themes)
- htmlize – convert Emacs buffer or a file to HTML with the same syntax highlighting
- go-playground – local Go playground in Emacs
- go-guru – use Go ‘guru’ static analysis in Emacs
Using Go under Emacs
I use the following setup for the go-mode in my ~/.emacs
. This
adds syntax highlighting but without fontifing names of called
functions, autocompletion and eldoc support, auto formatting of the
code on save with adding of missing imports (goimports).
It is quite long as I define two functions: one
(my-indent-or-complete
) which is bind to TAB
key and (contextually)
either completes the symbol at point or indents the line, the other one
(my-go-electric-brace
) is bind to {
key and inserts an indented
pair of braces (if previous character is a space, otherwise it inserts
single opening brace).
(setq gofmt-command "goimports" ; use goimports instead of gofmt go-fontify-function-calls nil ; fontifing names of called functions is too much for me company-idle-delay nil) (when (require 'go-mode nil t) ;; run gofmt/goimports when saving the file (add-hook 'before-save-hook 'gofmt-before-save)) (defun my-indent-or-complete () (interactive) (if (or (looking-at "\\w") (looking-back "^\\|\s")) (indent-for-tab-command) (company-complete))) (defun my-go-electric-brace () (interactive) (if (not (looking-back " ")) (insert "{") (insert "{") (newline) (indent-according-to-mode) (save-excursion (newline) (insert "}") (indent-according-to-mode)))) (defun my-go-mode-hook-fn () (go-eldoc-setup) (set (make-local-variable 'company-backends) '(company-go)) (company-mode) (abbrev-mode 1) (local-set-key (kbd "M-.") 'go-guru-definition) ; may also use godef-jump (local-set-key "\C-cd" 'godoc-at-point) (local-set-key "\C-cg" 'godoc) (local-set-key "\C-ch" 'go-guru-hl-identifier) (local-set-key "\C-i" 'my-indent-or-complete) (local-set-key "{" 'my-go-electric-brace)) (add-hook 'go-mode-hook 'my-go-mode-hook-fn)
Now, in go buffers you can use C-c C-j
(or M-.
) to jump to the
definition of the identifier at point (use M-*
to jump back as for
normal tags) and you can also use C-c C-d
for a short description of
the identifier at point (actually it is constantly displayed in the
mode line by enabled Go eldoc support). You can use C-c d
for a
longer description of the identifier at point.
For this to work you have to
-
Install from MELPA the following Emacs packages: go-mode, company-go, go-eldoc, and go-guru.
-
Install Go compiler. Under Debian you install
golang-go
package (but in Debian 9 Stretch it is 1.7 while in Debian 8 Jessie it is 1.3.3 compared to the current 1.9, so you may consider downloading the current version of Go). Otherwise search for the package for your system or otherwise see Getting started. -
Install godef can be installed with
$ go get github.com/rogpeppe/godef
-
Install goimports which can be installed from Debian package
golang-go.tools
or with$ go get golang.org/x/tools/cmd/goimports
-
Install gocode which can be installed from Debian package
gocode
or with$ go get -u github.com/nsf/gocode
-
Install go guru with
$ go get golang.org/x/tools/cmd/guru
-
Add your
$GOPATH/bin
to yourPATH
environment variable (or copy thegodef
,goimports
,gocode
, andguru
executables from$GOPATH/bin
to some directory which is in yourPATH
).
See also Writing Go in Emacs for more info.
Using Python under Emacs
Install company-jedi from MELPA.
Add the following to your ~/.emacs
file:
(defun my-python-mode-hook-fn () (jedi:setup) (set (make-local-variable 'company-backends) '(company-jedi)) (company-mode) (abbrev-mode 1) (local-set-key (kbd "M-.") 'jedi:goto-definition) (local-set-key (kbd "M-*") 'jedi:goto-definition-pop-marker) (local-set-key "\C-i" 'my-indent-or-complete)) (add-hook 'python-mode-hook 'my-python-mode-hook-fn)
Function my-indent-or-complete
is defined above in section
Using Go under Emacs.
Using C/C++ under Emacs
-
First install from MELPA Emacs packages cmake-ide, company, and rtags. Package
cmake-ide
automatically configures other C++ Emacs packages (herecompany
andrtags
) when you open a C/C++ file from a project which uses cmake to build. -
Add the following to your
~/.emacs
file.(set-default 'c-basic-offset 8) (setq c-default-style '((java-mode . "java") (awk-mode . "awk") (other . "k&r")) company-async-timeout 5 ; completion may be slow rtags-completions-enabled t) (when (require 'cmake-ide nil t) (require 'subr-x) ; a temporary fix (cmake-ide-setup)) (when (require 'rtags nil t) (rtags-enable-standard-keybindings)) ; starts with C-c r (defun my-c-c++-mode-hook-fn () (set (make-local-variable 'company-backends) '(company-rtags)) (company-mode) (local-set-key (kbd "M-.") 'rtags-find-symbol-at-point) (local-set-key "\C-i" 'my-indent-or-complete) (local-set-key (kbd "<tab>") 'my-indent-or-complete) (local-set-key "\C-\M-i" 'my-indent-or-complete)) (add-hook 'c-mode-hook 'my-c-c++-mode-hook-fn) (add-hook 'c++-mode-hook 'my-c-c++-mode-hook-fn)
Function
my-indent-or-complete
is defined above in section Using Go under Emacs. -
Install clang compiler or more accurately
libclang
library (packagelibclang-dev
or may be newerlibclang-X.Y-dev
under Debian) which is required byrtags
. -
Install
rtags
server with (it assumes first that you do havellvm-config-3.8
instead ofllvm-config
thus the extra option is needed and second that you want to install it in/opt/rtags
instead of default/usr/local
):$ git clone --recursive https://github.com/Andersbakken/rtags.git $ cd rtags $ mkdir build $ cd build $ cmake -DLIBCLANG_LLVM_CONFIG_EXECUTABLE=llvm-config-3.8 -DCMAKE_INSTALL_PREFIX=/opt/rtags .. $ make
And as root
# make install # ln -s /opt/rtags/bin/rc /usr/local/bin/rc # ln -s /opt/rtags/bin/rdm /usr/local/bin/rdm
-
Usefull
rtags
functions (useC-c r C-h
to see these and other key bindings)Key Function C-c r .
rtags-find-symbol-at-point
C-c r [
rtags-location-stack-back
C-c r ,
rtags-find-references-at-point
C-c r /
rtags-find-all-references-at-point
rtags-find-references-current-file
rtags-find-references-current-dir
C-c r v
rtags-find-virtuals-at-point
C-c r ;
rtags-find-file
(in the current project no metter in which directory)
Cross-compiliation of Go programs
Instead of just builind a program with
$ go build
in the package directory. To cross-compile a pure Go program to run on a Raspberry Pi 2 machine running Linux run
$ GOOS=linux GOARCH=arm GOARM=7 go build
To cross-compile a Go program to run on a Raspberry Pi 2 machine running Linux but for the program involving CGO run
$ GOOS=linux GOARCH=arm GOARM=7 CGO_ENABLED=1 CC=arm-linux-gnueabi-gcc go build
For the above command to work you need (on Debian) to install
gcc-arm-linux-gnueabi
.
While to cross-compile from an amd64 machine running Linux to the corresponding 32-bit i386 machine running Linux run
$ GOOS=linux GOARCH=386 go build
for the same cross-compilation but for the program involving CGO run
$ GOOS=linux GOARCH=386 CGO_ENABLED=1 go build
For the above command to work you need (on Debian) to install
gcc-multilib
(or if needed also g++-multilib
).
See also
A more up to date version of this page may be available at lupan.pl.