Table of Contents

YCMD layer

Table of ContentsClose

1 Description

This layer adds emacs-ycmd support.

2 Install

2.1 Layer

To use this configuration layer, add it to your ~/.spacemacs. You will need to add ycmd to the existing dotspacemacs-configuration-layers list in this file.

2.2 YCMD

  1. Install the ycm server. Installation instructions can be found here.
  2. Set the ycmd-server-command variable to reflect the path to the installation:

    (setq ycmd-server-command '("python" "/path/to/YouCompleteMe/third_party/ycmd/ycmd"))
  3. By default, spacemacs configures ycmd for getting the compilation flags from either a compilecommands.json or a .clangcomplete file and get additionnal flags from a .ycmextraflags file. If you do not like this behaviour, you can write your own file. See Configuration for more details.
  4. Whitelist the file by adding the following to .spacemacs:

    ;; In this example we whitelist everything in the Develop folder
    (setq ycmd-extra-conf-whitelist '("~/Develop/*"))
  5. The completion is not going to work automatically until we actually force it:

    (setq ycmd-force-semantic-completion t)

2.3 Other Requirements

This package requires the auto-completion layer in order to get actual completion. The syntax-checking layer is required for flycheck support.

3 Configuration

3.1 Activating ycmd in a major mode

By default this layer only activates ycmd for c++-mode and c-mode.

If you want ycmd support in other modes you might just want to add it for specific languages like:

(add-hook 'c++-mode-hook 'ycmd-mode)

3.2 Getting the compilation flags

Spacemacs uses its own ycmd global configuration file. If you prefer, you can write your own

Spacemacs will search for a compilecommand.json or fall back to a .clangcomplete file in all parent directories of the current translation unit. Spacemacs will try to make up for missing files in the compilecommands.json using heuristics described in

The user can provide additionnal flags by writing a .ycmextraflags in any parent directory of the current translation unit. This is particularly useful when cross-compiling.

Example .ycmextraflags:

# Additionnal flags for ycmd
--sysroot="/path/to/your/toolchain/libc" # if you are cross-compiling

If your build system doesn't handle the creation of a compilecommands.json, you can use tools such as Bear or scan-build to generate it, which both work with almost any build system.

4 Key Bindings

Adds SPC m g g go to definition binding to c++-mode as well as SPC m g G for the more imprecise but faster version.

Author: Sylvain Benner

Created: 2016-10-03 Mon 00:55