Wednesday, May 17, 2017

RTAGS Quick Setup

RTAGS is a tool for C/C++ code navigation and completion (primarily for Emacs). Here's how to get it working quickly on Arch:
  1. Get the tool: git clone https://aur.archlinux.org/packages/rtags-git/ ; cd rtags-git/ ; makepkg -si
  2. Alternatively run `rtags-install` within emacs. 
  3. Start the server: rdm &
  4. Index your project: cd project-code-dir/ ; make -nk | rc -c -
There are a couple of ways to index depending on your build tool (make, cmake etc). 
 Add to .emacs :

(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)

(define-key c-mode-base-map (kbd "M-.") 'rtags-find-symbol-at-point)
(define-key c-mode-base-map (kbd "M-,") 'rtags-location-stack-back) 



You may want to enable automatic starting of rdm:;; autostart rdm when entering c modes
(add-hook 'c-mode-hook 'rtags-start-process-unless-running)
(add-hook 'c++-mode-hook 'rtags-start-process-unless-running)
 


See also:
https://github.com/Andersbakken/rtags
http://syamajala.github.io/c-ide.html