Skip to content

Commit

Permalink
Add option to open .h files with c++-mode
Browse files Browse the repository at this point in the history
Remove default auto-mode-alist mapping from *.h to c++-mode.
Introduce a variable and use that in the init: section of cc-mode to
conditionally update the auto-mode-alist.
Updated the documentation.

Conflicts:
	contrib/!lang/c-c++/README.md
  • Loading branch information
ceales authored and syl20bnr committed Jun 1, 2015
1 parent e57c8aa commit a78c59c
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 3 deletions.
22 changes: 20 additions & 2 deletions contrib/!lang/c-c++/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@
- [Features](#features)
- [Install](#install)
- [Layer](#layer)
- [Default mode for header files](#default-mode-for-header-files)
- [Enable Clang support](#enable-clang-support)
- [clang-format](#clang-format)
- [clang-format](#clang-format)
- [Company-clang and flycheck](#company-clang-and-flycheck)
- [Key Bindings](#key-bindings)

Expand Down Expand Up @@ -45,6 +46,20 @@ To use this contribution add it to your `~/.spacemacs`

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

### Default mode for header files

By default header files are open in `c-mode`, you can open them in `c++-mode`
by setting the variable `c-c++-use-c++-mode-for-dot-h` to `t`.

```elisp
(setq-default dotspacemacs-configuration-layers
'((c-c++ variables: c-c++-use-c++-mode-for-dot-h t)))
```

**Note** To set the variable for a given project, create a directory local
variable at the root of your project. More info on directory local variables
can be found in the [emacs documentation][dir-locals].

### Enable Clang support

To enable Clang support set the layer variable `c-c++-enable-clang-support`
Expand All @@ -55,7 +70,7 @@ to `t` in the dotfile:
'((c-c++ :variables c-c++-enable-clang-support t)))
```

### clang-format
#### 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
Expand Down Expand Up @@ -95,8 +110,11 @@ doesn't complain about missing header files.
<kbd>SPC m g O</kbd> | open matching file in another window (e.g. switch between .cpp and .h)
<kbd>SPC m r</kbd> | srefactor: refactor thing at point.

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

[CMake]: http://www.cmake.org/
[semantic-refactor]: https://github.com/tuhdo/semantic-refactor
[srefactor-demos]: https://github.com/tuhdo/semantic-refactor/blob/master/srefactor-demos/demos.org
[stickyfunc-demos]: https://github.com/tuhdo/semantic-stickyfunc-enhance
[clang-format]: http://clang.llvm.org/docs/ClangFormat.html
[dir-locals]: http://www.gnu.org/software/emacs/manual/html_node/elisp/Directory-Local-Variables.html
3 changes: 3 additions & 0 deletions contrib/!lang/c-c++/config.el
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,6 @@

(spacemacs|defvar-company-backends c-mode-common)
(spacemacs|defvar-company-backends cmake-mode)

(defvar c-c++-use-c++-mode-for-dot-h nil
"If non nil then use c++-mode when opening .h files.")
3 changes: 2 additions & 1 deletion contrib/!lang/c-c++/packages.el
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@
(use-package cc-mode
:defer t
:init
(add-to-list 'auto-mode-alist '("\\.h$" . c++-mode))
(when c-c++-use-c++-mode-for-dot-h
(add-to-list 'auto-mode-alist '("\\.h$" . c++-mode)))
:config
(progn
(require 'compile)
Expand Down

0 comments on commit a78c59c

Please sign in to comment.