Useful programs

Text editors

GUI programs

Other programs

Go (golang) programming language

Learning Go

Introduction

Videos (with links to slides)

Articles

See also

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

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

  1. Install from MELPA the following Emacs packages: go-mode, company-go, go-eldoc, and go-guru.

  2. 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.

  3. Install godef can be installed with

    $ go get github.com/rogpeppe/godef
    
  4. Install goimports which can be installed from Debian package golang-go.tools or with

    $ go get golang.org/x/tools/cmd/goimports
    
  5. Install gocode which can be installed from Debian package gocode or with

    $ go get -u github.com/nsf/gocode
    
  6. Install go guru with

    $ go get golang.org/x/tools/cmd/guru
    
  7. Add your $GOPATH/bin to your PATH environment variable (or copy the godef, goimports, gocode, and guru executables from $GOPATH/bin to some directory which is in your PATH).

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

  1. First install from MELPA Emacs packages cmake-ide, company, and rtags. Package cmake-ide automatically configures other C++ Emacs packages (here company and rtags) when you open a C/C++ file from a project which uses cmake to build.

  2. 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.

  3. Install clang compiler or more accurately libclang library (package libclang-dev or may be newer libclang-X.Y-dev under Debian) which is required by rtags.

  4. Install rtags server with (it assumes first that you do have llvm-config-3.8 instead of llvm-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
    
  5. Usefull rtags functions (use C-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.