From 28adf5825f867726dc1656ec7f3e626deb122aa7 Mon Sep 17 00:00:00 2001 From: Henrik Lissner Date: Thu, 1 Mar 2018 13:17:07 -0500 Subject: [PATCH] lang/cc: fix rtags in other c*-mode derived modes; fix cleanup hook Also fixed rtags cleanup in doom-cleanup-hook to only kill the server if there are no more C/C++ buffers open. --- modules/lang/cc/autoload.el | 11 +++++++++++ modules/lang/cc/config.el | 18 ++++++++++-------- 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/modules/lang/cc/autoload.el b/modules/lang/cc/autoload.el index 2c58ff265..7921866cd 100644 --- a/modules/lang/cc/autoload.el +++ b/modules/lang/cc/autoload.el @@ -88,3 +88,14 @@ compilation dbs." nconc (list "-I" path))) (doom-project-root))))) +;;;###autoload +(defun +cc|init-rtags () + "Start an rtags server in c-mode and c++-mode buffers." + (when (memq major-mode '(c-mode c++-mode)) + (rtags-start-process-unless-running))) + +;;;###autoload +(defun +cc|cleanup-rtags () + "Kill rtags server(s) if there are no C/C++ buffers open." + (unless (doom-buffers-in-mode '(c-mode c++-mode) (buffer-list)) + (rtags-cancel-process))) diff --git a/modules/lang/cc/config.el b/modules/lang/cc/config.el index aa2ade660..2698bb3e9 100644 --- a/modules/lang/cc/config.el +++ b/modules/lang/cc/config.el @@ -215,7 +215,9 @@ compilation database is present in the project.") ;; (def-package! rtags - :after cc-mode + :commands (rtags-restart-process rtags-start-process-unless-running) + :init + (add-hook! (c-mode c++-mode) #'+cc|init-rtags) :config (setq rtags-autostart-diagnostics t rtags-use-bookmarks nil @@ -227,14 +229,14 @@ compilation database is present in the project.") rtags-jump-to-first-match nil) (let ((bins (cl-remove-if #'executable-find '("rdm" "rc")))) - (if (/= (length bins) 0) - (warn! "Couldn't find the rtag client and/or server programs %s. Disabling rtags support" bins) - (add-hook! (c-mode c++-mode) #'rtags-start-process-unless-running) - (set! :lookup '(c-mode c++-mode) - :definition #'rtags-find-symbol-at-point - :references #'rtags-find-references-at-point))) + (when (/= (length bins) 0) + (warn! "Couldn't find the rtag client and/or server programs %s. Disabling rtags support" bins))) - (add-hook 'doom-cleanup-hook #'rtags-cancel-process) + (set! :lookup '(c-mode c++-mode) + :definition #'rtags-find-symbol-at-point + :references #'rtags-find-references-at-point) + + (add-hook 'doom-cleanup-hook #'+cc|cleanup-rtags) (add-hook! kill-emacs (ignore-errors (rtags-cancel-process))) ;; Use rtags-imenu instead of imenu/counsel-imenu