update
[emacs-init.git] / setup / rtags.el
1 (let ((base (file-name-directory
2              (directory-file-name
3               (file-name-directory (or load-file-name
4                                        (when (boundp 'bytecomp-filename) bytecomp-filename)
5                                        buffer-file-name))))))
6   (add-to-list 'load-path (concat base
7                                   (file-name-as-directory "rtags")
8                                   (file-name-as-directory "src")))
9   (add-to-list 'load-path (concat base
10                                   (file-name-as-directory "elpa")
11                                   (file-name-as-directory "company-0.9.2")))
12
13   (setq rtags-path (concat base
14                            (file-name-as-directory "rtags")
15                            (file-name-as-directory "bin"))))
16
17 (require 'rtags)
18
19 ;; ;; ensure that we use only rtags checking
20 ;; ;; https://github.com/Andersbakken/rtags#optional-1
21 ;; (defun setup-flycheck-rtags ()
22 ;;   (interactive)
23 ;;   (flycheck-select-checker 'rtags)
24 ;;   ;; RTags creates more accurate overlays.
25 ;;   (setq-local flycheck-highlighting-mode nil)
26 ;;   (setq-local flycheck-check-syntax-automatically nil))
27
28 ;; only run this if rtags is installed
29 (when (require 'rtags nil :noerror)
30   ;; make sure you have company-mode installed
31   (require 'company)
32   (define-key c-mode-base-map (kbd "\C-c.")
33     (function rtags-find-symbol-at-point))
34   (define-key c-mode-base-map (kbd "\C-c,")
35     (function rtags-find-references-at-point))
36   (define-key c-mode-base-map (kbd "\C-cn")
37     (function rtags-next-diag))
38   ;; disable prelude's use of C-c r, as this is the rtags keyboard prefix
39   ;; (define-key prelude-mode-map (kbd "C-c r") nil)
40   ;; install standard rtags keybindings. Do M-. on the symbol below to
41   ;; jump to definition and see the keybindings.
42   (rtags-enable-standard-keybindings)
43   ;; comment this out if you don't have or don't use helm
44   (setq rtags-use-helm t)
45   ;; company completion setup
46   (setq rtags-autostart-diagnostics t)
47   (rtags-diagnostics)
48   (setq rtags-completions-enabled t)
49   (push 'company-rtags company-backends)
50   (global-company-mode)
51   (define-key c-mode-base-map (kbd "<C-tab>") (function company-complete))
52   ;; use rtags flycheck mode -- clang warnings shown inline
53   ;; (require 'flycheck-rtags)
54   ;; c-mode-common-hook is also called by c++-mode
55   ;; (add-hook 'c-mode-common-hook #'setup-flycheck-rtags)
56   )