spacemacs/contrib/lang/c-c++
2015-05-13 22:14:02 -04:00
..
img Move layer images into img directories 2014-12-24 01:03:49 -05:00
config.el add clang-format support to the c-c++ layer 2015-05-13 22:14:02 -04:00
packages.el add clang-format support to the c-c++ layer 2015-05-13 22:14:02 -04:00
README.md add clang-format support to the c-c++ layer 2015-05-13 22:14:02 -04:00

C/C++ contribution layer for Spacemacs

cc++ cmake

Table of Contents

Description

This layer adds configuration for C/C++ language as well support for CMake scripts.

Features

  • Support syntax checking with Clang.
  • Support code reformatting with clang-format.
  • Display function or variable definition at the bottom. (when semantic layer is included)
  • Display current function cursor is in at the top. See this page for demos in some programming languages. (when semantic layer is included)
  • Support common refactoring with semantic-refactor. See this page for demonstration of refactoring features. (when semantic layer is included)

Clang Fanciness

This layer adds some fancy improvements to company-clang. It includes a hook to load a projects .clang_complete file, which is just a text file with one clang flag per line, a format also used by other text editor clang plugins.

Not only does this allow proper autocomplete on projects with extra includes and flags, but there is also support for flycheck so that it doesn't complain about missing header files.

Key Bindings

Key Binding       |                 Description

----------------------|------------------------------------------------------------ SPC m g o | open matching file (e.g. switch between .cpp and .h) SPC m g O | open matching file in another window (e.g. switch between .cpp and .h) SPC m r | srefactor: refactor thing at point.

clang-format

clang-format allows reformatting either a selected region of code (clang-format-region) or a whole buffer (clang-format-buffer) to make it conform to a style defined in a .clang-format file. This file is either located in the same directory as the file being edited, or in any of its parent directories (otherwise a default style will be used).

To enable clang-format set the variable c-c++-use-clang-format to t when including the c-c++ configuration layer:

(c-c++ :variables
       c-c++-use-clang-format t)

You can add snippets similar to the following to bind clang-format to either a particular mode or all modes in your dotspacemacs/config (within your ~/.spacemacs):

;; Bind clang-format-region to C-M-tab in all modes:
(global-set-key [C-M-tab] 'clang-format-region)
;; Bind clang-format-buffer to tab on the c++-mode only:
(add-hook 'c++-mode-hook 'clang-format-bindings)
  (defun clang-format-bindings ()
    (define-key c++-mode-map [tab] 'clang-format-buffer))

Install

To use this contribution add it to your ~/.spacemacs

(setq-default dotspacemacs-configuration-layers '(c-c++))

** Note: ** semantic-refactor is only available for Emacs 24.4+