Skip to content

Easy real time C++ syntax check and intellisense if you use CMake

Notifications You must be signed in to change notification settings

vjohansen/cpputils-cmake

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

38 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

cpputils-cmake.el (current version 0.2.0)

cpputils-cmake automatically enable real time syntax check (Flymake) and IntelliSense (auto-complete+auto-complete-clang) if you use CMake.

It does all the configuration dirty job automatically for you. So you can use Flymake, auto-complete, auto-complete-clang, compile with almost no configuration.

Install

cpputils-cmake is already uploaded to http://marmalade-repo.org/. So the best way to install it is using Emacs’ package manager.

Set up

Copy and paste below code into your .emacs:

(add-hook 'c-mode-common-hook (lambda ()
  (cppcm-reload-all)
  ; fixed rinari's bug.
  (remove-hook 'find-file-hook 'rinari-launch)
  ))
;; OPTIONAL, avoid typing full path when starting gdb
(global-set-key (kbd "C-c C-g")
 '(lambda ()(interactive) (gud-gdb (concat "gdb --fullname " (cppcm-get-exe-path-current-buffer))))
)

One minute step by step tutorial

Create a “hello world” C++ project by running one line shell script

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

Use cmake as usual

Please note you need run “Make” at least once before using cpputils-cmake:

mkdir hello/build;cd hello/build;cmake ../src;make clean;make

If you use another directory name like “mybuild” instead of “build”, you must add following line into your .emacs:

(setq cppcm-build-dirname "mybuild")

Open main.cpp with Emacs and enable flymake: `M-x flymake-mode`.

Now typing some random code and watch the real time hint on your syntax errors.

Compile as usual

Compile the program: `M-x compile`

You can see the default command line displayed in minibuffer is `make -C ~/your-projects-blah-blah/hello/build`

BTW, you can also run the command `M-x cppcm-compile` to compile the current excutable only.

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 hot key `C-c C-g` (suppose you’ve copied my configuration from previous section).

You can see the gud-gdb starts and the executable “~/your-projects-blah-blah/hello/build/main” is loaded automatically.

If you’ve installed auto-complete and auto-complete-clang (OPTIONAL)

Use them as usual. You can see that the Intellisense/auto-complete is more precise.

Open included C/C++ header file

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

This is the default feature of Emacs. What cpputils-cmake does is set up the directories of those header files for you automatically so that the header files could be found by Emacs.

Tips (OPTIONAL)

The command “cppcm-get-exe-path-current-buffer” will copy the current executable into the kill ring (clipboard).

This could be very useful if you want to access the directory directory of the executable as quickly as possible.

You can yank (paste) the full path to the eshell or minibuffer and press “M-backspace” to get the directory name.

Contact me

You can report bugs at https://github.com/redguardtoo/cpputils-cmake. My email is <chenbin DOT sh AT gmail>.

License

Copyright (C) 2012 Chen Bin

Author: Chen Bin <chenbin DOT sh AT gmail DOT com> Keywords: flymake IntelliSense cmake

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

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/.

About

Easy real time C++ syntax check and intellisense if you use CMake

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Emacs Lisp 98.2%
  • Shell 1.8%