Skip to content

Commit b54d1a5

Browse files
committed
company-c-headers and README v5.0
- company-c-headers supported - tested all supported plugin - take screenshots and updated README
1 parent 0d96fcc commit b54d1a5

File tree

4 files changed

+46
-44
lines changed

4 files changed

+46
-44
lines changed

README.org

Lines changed: 38 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,20 @@
1-
* cpputils-cmake.el (v0.4.22)
2-
cpputils-cmake gives you *perfect* syntax check (Flymake) and IntelliSense/code-completion if you use [[http://www.cmake.org][CMake]].
1+
* cpputils-cmake.el (v0.5.0)
2+
*Perfect* syntax check (Flymake) and code-completion if you use [[http://www.cmake.org][CMake]].
33

4-
It does all the dirty setup *automatically* for following plugins and commands,
4+
cpputils-cmake does all the dirty setup *automatically* for following plugins and commands,
55
- [[http://flymake.sourceforge.net/][Flymake]]
66
- [[https://github.com/flycheck/flycheck][Flycheck]]
77
- [[http://cx4a.org/software/auto-complete/][auto-complete]]
88
- [[https://github.com/brianjcj/auto-complete-clang][auto-complete-clang]]
99
- [[https://github.com/company-mode/company-mode][company-mode]]
10+
- [[https://github.com/randomphrase/company-c-headers][company-c-headers]]
1011
- [[https://www.gnu.org/software/emacs/manual/html_node/emacs/Semantic.html][semantic]]
1112
- [[http://www.emacswiki.org/emacs/CompileCommand]["M-x compile"]]
1213
- "M-x ff-find-other-file" (if you press `C-x C-o` in C/C++ file, ff-find-other-file will open *correct* header file under cursor)
1314

1415
Please note cpputils-cmake is *independent* on those plugins. Only CMake is required.
16+
17+
Tested at Emacs 23.4, 24.3, 24.4
1518
* Install
1619
** Easy way
1720
cpputils-cmake is available at [[https://github.com/milkypostman/melpa]].
@@ -42,54 +45,44 @@ Insert below code into your .emacs:
4245
(setq cppcm-extra-preprocss-flags-from-user '("-I/usr/src/linux/include" "-DNDEBUG"))
4346
#+END_SRC
4447

45-
Then follow this work flow:
46-
- Make sure the build directory has the same name as value of *cppcm-build-dirname*. It is "build" by default. Make sure the build is located somewhere in the directory hierarchy from C++ file.
48+
Quick start:
49+
- The build directory should have the *same name as value of cppcm-build-dirname*. It is "build" by default. Make sure the build is located somewhere in the directory hierarchy from C++ file.
4750
- Go to build directory to run cmake and make
4851
- *Done!* Enjoy programming in Emacs as usual.
4952

50-
* Plugins (OPTIONAL)
51-
Let's start by creating a "hello world" C++ project.
52-
53-
Execute below command in shell:
53+
* Demo (OPTIONAL)
54+
Let's start by creating a "hello world" C++ project:
5455
#+BEGIN_SRC sh
5556
mkdir -p hello/src;printf "#include <stdio.h>\nint main(void) {\nprintf(\"hello world\");\nreturn 0;\n}" > hello/src/main.cpp;printf "cmake_minimum_required(VERSION 2.6)\nadd_executable(main main.cpp)" > hello/src/CMakeLists.txt
5657
#+END_SRC
57-
** Flymake
58-
Open C++ file. "M-x flymake-mode".
59-
60-
Type some random C++ code and watch the real time hint on your syntax errors.
58+
** flymake
59+
[[https://cloud.githubusercontent.com/assets/184553/5368660/cbc0c70c-805c-11e4-8723-a2ae752a549d.png]]
6160

62-
If you don't like flymake, you can tell cpputils-cmake NOT to create Makefile for flyemake by inserting below code into ~/.emacs:
63-
#+BEGIN_SRC elisp
64-
(setq cppcm-write-flymake-makefile nil)
65-
#+END_SRC
66-
** Flycheck
67-
See [[https://github.com/flycheck/flycheck]] for flycheck setup. No setup needed here.
68-
** Compile
69-
Compile the program: `M-x compile`
61+
** flycheck
62+
[[https://cloud.githubusercontent.com/assets/184553/5368798/ca25c044-805e-11e4-9859-805601784519.png]]
63+
** M-x compile
64+
[[https://cloud.githubusercontent.com/assets/184553/5368693/43295ad4-805d-11e4-9125-f21209c8bd88.png]]
7065

71-
The command line displayed in minibuffer is `make -C ~/your-projects-blah-blah/hello/build`
66+
You can also `M-x cppcm-compile` to compile the current excutable only.
7267

73-
BTW, you can also `M-x cppcm-compile` to compile the current excutable only.
68+
** gdb
69+
Press hotkey `C-c C-g` (I suppose you've copied my setup).
7470

75-
You can see the actual command displayed in minibuffer is `make -C ~/your-project-blah-blah/hello/build/sub-project-dir-if-your-are-editing-its-cpp-file`
76-
** Start gdb
77-
Press hotkey `C-c C-g` (suppose you've copied my configuration from previous section).
71+
gud-gdb starts and the binary "~/your-projects-blah-blah/hello/build/main" is loaded automatically.
7872

79-
You can see the gud-gdb starts and the executable "~/your-projects-blah-blah/hello/build/main" is loaded automatically.
73+
** auto-complete
74+
You also need install auto-complete-clang.
75+
[[https://cloud.githubusercontent.com/assets/184553/5369140/721c9648-8063-11e4-9ab4-75f0e8ea88c8.png]]
8076

81-
** Auto-complete & auto-complete-clang (OPTIONAL)
82-
Use them as usual. You can see that the Intellisense/auto-complete is more precise.
83-
84-
** Company-mode (OPTIONAL)
85-
Use them as usual. You can see that the Intellisense/auto-complete is more precise.
77+
** company-mode
78+
[[https://cloud.githubusercontent.com/assets/184553/5368579/c03fec24-805b-11e4-8fce-b611b2621318.png]]
79+
** company-c-headers
80+
[[https://cloud.githubusercontent.com/assets/184553/5368489/e7b8ecf2-805a-11e4-8b06-818b96fb2049.png]]
8681

8782
** Open header file
88-
Press the hotkey `C-x C-o` or `M-x ff-find-other-file`. The corresponding header is opened correctly.
89-
90-
This is the default feature of Emacs. What cpputils-cmake does is to set up the directories of those header files for you automatically so that the header files could be found by Emacs.
83+
Press the hotkey `C-x C-o` or `M-x ff-find-other-file`. The corresponding header is opened.
9184

92-
* Advanced Tips
85+
* FAQ
9386
** Avoid scanning when opening system header files
9487
cpputils-cmake scanning is light weight enough so below code is *optional*:
9588
#+BEGIN_SRC elisp
@@ -101,7 +94,7 @@ cpputils-cmake scanning is light weight enough so below code is *optional*:
10194
(cppcm-reload-all))
10295
)))
10396
#+END_SRC
104-
** Get executable's full path of executable to build
97+
** Get executable's full path
10598
The command "cppcm-get-exe-path-current-buffer" will copy current executable into kill ring AND OS clipboard.
10699

107100
You need install `xsel` under Linux to support OS clipboard.
@@ -132,7 +125,7 @@ Please press "C-h v cppcm-compile-list" for other compile options.
132125
** Make clean && make
133126
"M-x cppcm-recompile"
134127

135-
** Manually specify the binary's path if you modify the default target output directory
128+
** Customize target path
136129
For example, if the CMakeLists.txt contains something like this:
137130
#+begin_src cmake
138131
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/lib)
@@ -167,7 +160,7 @@ Here is a sample:
167160

168161
You can insert above code into ~/.emacs!
169162

170-
** About macro and included cmake file
163+
** Macro and included cmake file
171164
cpputils-cmake assumes that CMakeLists.txt contains a rule to create executable.
172165

173166
*The rule is either "add_executable" or "add_library"*.
@@ -185,6 +178,11 @@ add_executable(${TGT} ${SOURCES})
185178

186179
The executable's name will be "hello-proj1-a1-a2".
187180

181+
** Stop creating Makefiles for flymake
182+
Insert below code into ~/.emacs:
183+
#+BEGIN_SRC elisp
184+
(setq cppcm-write-flymake-makefile nil)
185+
#+END_SRC
188186
* Credits
189187
- [[https://github.com/dojeda][David Ojeda (AKA dojeda)]] developed the algorithm to locate the top level project
190188
- [[https://github.com/erreina][Ernesto Rodriguez Reina (AKA erreina)]] added the command "cppcm-recompile"
@@ -211,4 +209,4 @@ This program is free software; you can redistribute it and/or modify it under th
211209

212210
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
213211

214-
You should have received a copy of the GNU General Public License along with this program. If not, see [[http://www.gnu.org/licenses/]].
212+
You should have received a copy of the GNU General Public License along with this program. If not, see [[http://www.gnu.org/licenses/]].

cpputils-cmake-pkg.el

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
(define-package "cpputils-cmake" "0.4.22"
1+
(define-package "cpputils-cmake" "0.5.0"
22
"Easy real time C++ syntax check and intellisense if you use CMake")

cpputils-cmake.el

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
;; Author: Chen Bin <chenbin.sh@gmail.com>
66
;; URL: http://github.com/redguardtoo/cpputils-cmake
77
;; Keywords: CMake IntelliSense Flymake Flycheck
8-
;; Version: 0.4.22
8+
;; Version: 0.5.0
99

1010
;; This file is not part of GNU Emacs.
1111

@@ -641,7 +641,7 @@ Require the project be compiled successfully at least once."
641641
;;;###autoload
642642
(defun cppcm-version ()
643643
(interactive)
644-
(message "0.4.22"))
644+
(message "0.5.0"))
645645
646646
;;;###autoload
647647
(defun cppcm-compile (&optional prefix)
@@ -742,6 +742,10 @@ by customize `cppcm-compile-list'."
742742
ac-clang-flags)))
743743
(if cppcm-debug (message "flycheck-clang-definitions=%s" flycheck-clang-definitions))
744744

745+
;; company-c-headers-path-system
746+
(setq company-c-headers-path-system flycheck-clang-include-path)
747+
(if cppcm-debug (message "company-c-headers-path-system=%s" company-c-headers-path-system))
748+
745749
;; set cc-search-directories automatically, so ff-find-other-file will succeed
746750
(add-hook 'ff-pre-find-hook
747751
'(lambda ()

pkg.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/bin/bash
22
#pkg=cpputils-cmake-`date +%Y%m%d.%H%M`
3-
pkg=cpputils-cmake-0.4.22
3+
pkg=cpputils-cmake-0.5.0
44
mkdir $pkg
55
cp README.org $pkg
66
cp *.el $pkg

0 commit comments

Comments
 (0)