lang/cc: refactor rtags integration #305

This commit is contained in:
Henrik Lissner 2017-12-26 19:24:12 -05:00
parent 750b74379d
commit 222a2955e2
No known key found for this signature in database
GPG key ID: 5F6C0EA160557395

View file

@ -195,25 +195,38 @@ compilation database is present in the project.")
(def-package! rtags (def-package! rtags
:after cc-mode :after cc-mode
:config :config
(if (not (executable-find "rdm"))
(warn "cc-mode: couldn't find rdm, disabling rtags support")
(add-hook! (c-mode c++-mode) #'rtags-start-process-unless-running)
(set! :jump '(c-mode c++-mode)
:definition #'rtags-find-symbol-at-point
:references #'rtags-find-references-at-point))
(setq rtags-autostart-diagnostics t (setq rtags-autostart-diagnostics t
rtags-use-bookmarks nil rtags-use-bookmarks nil
rtags-jump-to-first-match nil ;; If not using ivy or helm to view results, use a pop-up window rather
rtags-results-buffer-other-window t) ;; than displaying it in the current window...
rtags-results-buffer-other-window t
;; ...and don't auto-jump to first match before making a selection.
rtags-jump-to-first-match nil)
(defun +cc|init-rtags-server-maybe ()
"Start the rtags server if it isn't already running."
(unless (or (processp rtags-rdm-process)
(cl-loop for proc in (list-system-processes)
for cmd = (cdr (assq 'args (process-attributes proc)))
if (string-match-p "/rdm\\_>" cmd)
return t))
(message "Starting rtags server")
(rtags-start-process-unless-running)))
(let ((bins (cl-remove-if-not #'executable-find '("rdm" "rc"))))
(if (/= (length bins) 2)
(warn "cc-mode: couldn't find %s, disabling rtags support" bins)
(add-hook! (c-mode c++-mode) #'+cc|init-rtags-server-maybe)
(set! :jump '(c-mode c++-mode)
:definition #'rtags-find-symbol-at-point
:references #'rtags-find-references-at-point)))
(add-hook 'doom-cleanup-hook #'rtags-cancel-process)
;; Use rtags-imenu instead of imenu/counsel-imenu
(map! (:when (featurep 'ivy) :map ivy-mode-map [remap imenu] nil)
:map (c-mode-map c++-mode-map) [remap imenu] #'rtags-imenu)
(defun +cc|cleanup-rdm-maybe ()
"Shut down the rtags daemon, if it's running."
(when (and (processp rtags-rdm-process)
(not (memq (process-status rtags-rdm-process) '(exit signal)))
(not (doom-buffers-in-mode '(c-mode c++-mode))))
(rtags-cancel-process)))
(add-hook 'doom-cleanup-hook #'+cc|cleanup-rdm-maybe)
(add-hook 'rtags-jump-hook #'evil-set-jump) (add-hook 'rtags-jump-hook #'evil-set-jump)
(add-hook 'rtags-after-find-file-hook #'recenter)) (add-hook 'rtags-after-find-file-hook #'recenter))