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.
- 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
(depends-on "monokai-theme" :git "https://github.com/xxx/yyy" :ref "178dfc9")
Then we can install that stable version to avoid bugs.
caskwe can avoid latency in the bug fixing. (MELPA refresh every 3 or 4 hours.)
:ensure tkey word in
use-package: if a pacage does not exist in the
use-packagewill download it for you. After that the configuration will be executed.
:pin melpa-stable: we can change it to
melpa, so that it will download from certain source. Remember to add the source in your
company-mode advanced auto-completion
company-modehas multiple backends. They supports different workspaces by preparing different completion candidates.
C-h v company-backendsfor 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-filesbackend is activated.
- For another example, when we type
studeand we forget how to spell the rest, we can use
M-x company-ispellto list all candidates from the system dictionary.
customize-group company-dabbrev: we can choose which buffer the
company-modealso has frontend. We can customize it as well, however we don’t have to do so. Let it as default.
C-f C-vto check how the backend is implemented.
- Situation where
company-modenot working quite well.
company-anacondamode 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-modeconnects with server, where the candidates are fetched from. The server is in
localhostbtw, not on the internet.
- Other examples are:
- 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,
companyget confused. Use
M-x company-xxxor use hook to make sure the correct backend is enabled.
(add-hook 'python-mode-hook (lambda () (setq (make-local-variable 'company-backends) '(company-anaconda company-dabbrev))))
- For example,
company-dabbrev-codeonly complete in code, and not in comments etc. We can group a bunch of backends together. See example below
(add-hook 'python-mode-hook (lambda () (setq (make-local-variable 'company-backends) '((company-anaconda company-dabbrev-code) company-dabbrev))))
- There are two backends in the setting, the first one is a group backend, the second one is a single backend. We can make it for our best use.
Once the first item in the company backend group, the “single” backend after the backend group will not be enabled.
- How to write your own backend. Check the following blog:
Writing the Simplest Emacs company-mode Backend - Sixty-north
Sort candidates by statistics
Address this next time.