This guide is meant as supplement to Tudho's C/C++ Development Enivornment for Emacs Guide. It assumes you:
rtags from MELPA and add the following to your emacs init file:
(require 'rtags) (require 'company-rtags)
(setq rtags-completions-enabled t) (eval-after-load 'company '(add-to-list 'company-backends 'company-rtags)) (setq rtags-autostart-diagnostics t) (rtags-enable-standard-keybindings)
To enable Helm integration add:
(setq rtags-use-helm t)
RTags you need to start rdm and index your project. In order to index your project, RTags requires you to export your project's compile commands with cmake.
$ rdm & $ cd /path/to/project/root $ cmake . -DCMAKE_EXPORT_COMPILE_COMMANDS=1 $ rc -J .
We'll see how to automate this process with cmake-ide below.
forward-sexp, move forward over a balanced expression that can be a pair or a symbol.
backward-sexp, move backward over a balanced expression that can be a pair or a symbol.
kill-sexp, kill balanced expression forward that can be a pair or a symbol.
mark-sexp, put mark after following expression that can be a pair or a symbol.
beginning-of-defun, which moves point to beginning of a function.
end-of-defun, which moves point to end of a function.
mark-defun, which put a region around whole current or following function.
rtags-find-symbol-at-point, which jumps to the definition of the symbol under the cursor.
rtags-find-references-at-point, which lists all references to the symbol under the cursor.
rtags-find-references, which prompts for the symbol name and finds all references.
rtags-find-symbol, which prompts for symbol name and finds all references.
rtags-find-file, which prompts for file name to search for out of currently indexed files.
Alternatively, this can be better accomplished with Projectile.
irony-mode from MELPA and add the following to your emacs init file:
(add-hook 'c++-mode-hook 'irony-mode) (add-hook 'c-mode-hook 'irony-mode) (add-hook 'objc-mode-hook 'irony-mode)
(defun my-irony-mode-hook () (define-key irony-mode-map [remap completion-at-point] 'irony-completion-at-point-async) (define-key irony-mode-map [remap complete-symbol] 'irony-completion-at-point-async))
(add-hook 'irony-mode-hook 'my-irony-mode-hook) (add-hook 'irony-mode-hook 'irony-cdb-autosetup-compile-options)
NOTE: Like RTags, Irony requires a compilation database. To create one run the following:
$ cd /path/to/project/root $ cmake . -DCMAKE_EXPORT_COMPILE_COMMANDS=1
The first time you run irony you must install the irony-server by runing the command:
company-mode with Irony:
company-irony from melpa and add the following to your emacs init file:
(add-hook 'irony-mode-hook 'company-irony-setup-begin-commands) (setq company-backends (delete 'company-semantic company-backends)) (eval-after-load 'company '(add-to-list 'company-backends 'company-irony))
If you want to enable tab-completion with no delay use the following:
(setq company-idle-delay 0) (define-key c-mode-map [(tab)] 'company-complete) (define-key c++-mode-map [(tab)] 'company-complete)
To add support for completing C++ headers:
Removethe following to your emacs init file:
(eval-after-load 'company '(add-to-list 'company-backends 'company-irony))
Addthe following to your emacs init file:
(require 'company-irony-c-headers) (eval-after-load 'company '(add-to-list 'company-backends '(company-irony-c-headers company-irony)))
flycheck from MELPA and add the following to your emacs init file:
(add-hook 'c++-mode-hook 'flycheck-mode) (add-hook 'c-mode-hook 'flycheck-mode)
To enable RTags and flycheck integration add the following to your emacs init file:
(require 'flycheck-rtags) (defun my-flycheck-rtags-setup () (flycheck-select-checker 'rtags) (setq-local flycheck-highlighting-mode nil) ;; RTags creates more accurate overlays. (setq-local flycheck-check-syntax-automatically nil)) ;; c-mode-common-hook is also called by c++-mode (add-hook 'c-mode-common-hook #'my-flycheck-rtags-setup)'))
flycheck-irony from MELPA and add the following to your emacs init file:
(eval-after-load 'flycheck '(add-hook 'flycheck-mode-hook #'flycheck-irony-setup))
cmake-ide from MELPA and add the following to your emacs init file:
To have cmake-ide automatically create a compilation commands file in your project root create a .dir-locals.el containing the following:
((nil . ((cmake-ide-build-dir "<PATH_TO_PROJECT_BUILD_DIRECTORY>"))))
You can now build your project using
M-x cmake-ide-compile. Additionally, cmake-ide will automatically update your RTags index as well.
原文时间: 2016-03-28 00:56
整理时间: 2016-04-21 01:38
本文由 Hick 整理，转载请保留以上信息;
The articles on this site come from Internet, thanks to all the original authors.
If anything about COPYRIGHT, or LEFT, please contact Emacsist at gmail dot com .