Skip to content

Commit

Permalink
company-c-headers and README v5.0
Browse files Browse the repository at this point in the history
- company-c-headers supported
- tested all supported plugin
- take screenshots and updated README
  • Loading branch information
Chen Bin committed Dec 10, 2014
1 parent 0d96fcc commit b54d1a5
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 44 deletions.
78 changes: 38 additions & 40 deletions README.org
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
* cpputils-cmake.el (v0.4.22)
cpputils-cmake gives you *perfect* syntax check (Flymake) and IntelliSense/code-completion if you use [[http://www.cmake.org][CMake]].
* cpputils-cmake.el (v0.5.0)
*Perfect* syntax check (Flymake) and code-completion if you use [[http://www.cmake.org][CMake]].

It does all the dirty setup *automatically* for following plugins and commands,
cpputils-cmake does all the dirty setup *automatically* for following plugins and commands,
- [[http://flymake.sourceforge.net/][Flymake]]
- [[https://github.com/flycheck/flycheck][Flycheck]]
- [[http://cx4a.org/software/auto-complete/][auto-complete]]
- [[https://github.com/brianjcj/auto-complete-clang][auto-complete-clang]]
- [[https://github.com/company-mode/company-mode][company-mode]]
- [[https://github.com/randomphrase/company-c-headers][company-c-headers]]
- [[https://www.gnu.org/software/emacs/manual/html_node/emacs/Semantic.html][semantic]]
- [[http://www.emacswiki.org/emacs/CompileCommand]["M-x compile"]]
- "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)

Please note cpputils-cmake is *independent* on those plugins. Only CMake is required.

Tested at Emacs 23.4, 24.3, 24.4
* Install
** Easy way
cpputils-cmake is available at [[https://github.com/milkypostman/melpa]].
Expand Down Expand Up @@ -42,54 +45,44 @@ Insert below code into your .emacs:
(setq cppcm-extra-preprocss-flags-from-user '("-I/usr/src/linux/include" "-DNDEBUG"))
#+END_SRC

Then follow this work flow:
- 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.
Quick start:
- 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.
- Go to build directory to run cmake and make
- *Done!* Enjoy programming in Emacs as usual.

* Plugins (OPTIONAL)
Let's start by creating a "hello world" C++ project.

Execute below command in shell:
* Demo (OPTIONAL)
Let's start by creating a "hello world" C++ project:
#+BEGIN_SRC sh
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
#+END_SRC
** Flymake
Open C++ file. "M-x flymake-mode".

Type some random C++ code and watch the real time hint on your syntax errors.
** flymake
[[https://cloud.githubusercontent.com/assets/184553/5368660/cbc0c70c-805c-11e4-8723-a2ae752a549d.png]]

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

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

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

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`
** Start gdb
Press hotkey `C-c C-g` (suppose you've copied my configuration from previous section).
gud-gdb starts and the binary "~/your-projects-blah-blah/hello/build/main" is loaded automatically.

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

** Auto-complete & auto-complete-clang (OPTIONAL)
Use them as usual. You can see that the Intellisense/auto-complete is more precise.

** Company-mode (OPTIONAL)
Use them as usual. You can see that the Intellisense/auto-complete is more precise.
** company-mode
[[https://cloud.githubusercontent.com/assets/184553/5368579/c03fec24-805b-11e4-8fce-b611b2621318.png]]
** company-c-headers
[[https://cloud.githubusercontent.com/assets/184553/5368489/e7b8ecf2-805a-11e4-8b06-818b96fb2049.png]]

** Open header file
Press the hotkey `C-x C-o` or `M-x ff-find-other-file`. The corresponding header is opened correctly.

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.
Press the hotkey `C-x C-o` or `M-x ff-find-other-file`. The corresponding header is opened.

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

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

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

You can insert above code into ~/.emacs!

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

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

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

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

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.

You should have received a copy of the GNU General Public License along with this program. If not, see [[http://www.gnu.org/licenses/]].
You should have received a copy of the GNU General Public License along with this program. If not, see [[http://www.gnu.org/licenses/]].
2 changes: 1 addition & 1 deletion cpputils-cmake-pkg.el
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
(define-package "cpputils-cmake" "0.4.22"
(define-package "cpputils-cmake" "0.5.0"
"Easy real time C++ syntax check and intellisense if you use CMake")
8 changes: 6 additions & 2 deletions cpputils-cmake.el
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
;; Author: Chen Bin <chenbin.sh@gmail.com>
;; URL: http://github.com/redguardtoo/cpputils-cmake
;; Keywords: CMake IntelliSense Flymake Flycheck
;; Version: 0.4.22
;; Version: 0.5.0

;; This file is not part of GNU Emacs.

Expand Down Expand Up @@ -641,7 +641,7 @@ Require the project be compiled successfully at least once."
;;;###autoload
(defun cppcm-version ()
(interactive)
(message "0.4.22"))
(message "0.5.0"))
;;;###autoload
(defun cppcm-compile (&optional prefix)
Expand Down Expand Up @@ -742,6 +742,10 @@ by customize `cppcm-compile-list'."
ac-clang-flags)))
(if cppcm-debug (message "flycheck-clang-definitions=%s" flycheck-clang-definitions))

;; company-c-headers-path-system
(setq company-c-headers-path-system flycheck-clang-include-path)
(if cppcm-debug (message "company-c-headers-path-system=%s" company-c-headers-path-system))

;; set cc-search-directories automatically, so ff-find-other-file will succeed
(add-hook 'ff-pre-find-hook
'(lambda ()
Expand Down
2 changes: 1 addition & 1 deletion pkg.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash
#pkg=cpputils-cmake-`date +%Y%m%d.%H%M`
pkg=cpputils-cmake-0.4.22
pkg=cpputils-cmake-0.5.0
mkdir $pkg
cp README.org $pkg
cp *.el $pkg
Expand Down

0 comments on commit b54d1a5

Please sign in to comment.