# Spacemacs Rocks Note Day 10

2017-11-08

A series of notes that I learn Emacs hacking. More on cask and use-package, more on company-mode, backends, group-backends, how to write your own backend.

## More on cask and use-package

### cask

• After you upgrade a package, there is chance that some latest version has bugs or incompitible. In this scenario, we can set the version we want in .cask file,
1
(depends-on "monokai-theme" :git "https://github.com/xxx/yyy" :ref "178dfc9")


Then we can install that stable version to avoid bugs.

• With cask we can avoid latency in the bug fixing. (MELPA refresh every 3 or 4 hours.)

### use-package

• :ensure t key word in use-package: if a pacage does not exist in the elpa, use-package will download it for you. After that the configuration will be executed.
• :pin melpa-stable: we can change it to gnu or melpa, so that it will download from certain source. Remember to add the source in your use-package config file.

## company-mode advanced auto-completion

### Backend

• company-mode has multiple backends. They supports different workspaces by preparing different completion candidates.
• C-h v company-backends for detail. It is a list, showing the available backends. The program starts from the first one and traverse all of them to find the match one. Then the candidates are found by the company-mode. For example, we type /, company-files backend is activated.
• For another example, when we type stude and we forget how to spell the rest, we can use M-x company-ispell to list all candidates from the system dictionary.
• customize-group company-dabbrev: we can choose which buffer the company-mode will “watch”.
• company-mode also has frontend. We can customize it as well, however we don’t have to do so. Let it as default.
• C-f C-v to check how the backend is implemented.

• Situation where company-mode not working quite well.
• company-anaconda mode for python has issue on Mac. (Not going to take notes here)
• There are two types of auto-completion implementation in company-mode. One is finding the candidates from local algorithm or database. The other one is server-client architecture. anaconda-mode connects with server, where the candidates are fetched from. The server is in localhost btw, not on the internet.
• Other examples are: company-jedi (for python), company-ycmd (for C++), company-tern (for JavaScript), .etc.
• You need to make sure the server side works properly in the first place, then you may want to check whether you use the correct backend.
• If we have multiple backends, company get confused. Use M-x company-xxx or use hook to make sure the correct backend is enabled.
1
2
3
(lambda ()
(setq (make-local-variable 'company-backends) '(company-anaconda company-dabbrev))))


### Group backend

• For example, company-dabbrev-code only complete in code, and not in comments etc. We can group a bunch of backends together. See example below
1
2
3