From fa4b7502c28ef3a2be9c3886a5129cdc2a67015e Mon Sep 17 00:00:00 2001 From: Henrik Lissner Date: Sat, 4 Aug 2018 13:41:38 +0200 Subject: [PATCH] lang/cc: add +cc/imenu command Plus minor reformatting of autoloads file --- modules/lang/cc/autoload.el | 55 ++++++++++++++++++++++++------------- modules/lang/cc/config.el | 2 +- 2 files changed, 37 insertions(+), 20 deletions(-) diff --git a/modules/lang/cc/autoload.el b/modules/lang/cc/autoload.el index 000f7eb70..1ab7cd017 100644 --- a/modules/lang/cc/autoload.el +++ b/modules/lang/cc/autoload.el @@ -8,25 +8,6 @@ ;; Library ;; -;;;###autoload -(defun +cc/reload-compile-db () - "Reload the current project's JSON compilation database." - (interactive) - (unless (memq major-mode '(c-mode c++-mode objc-mode)) - (user-error "Not a C/C++/ObjC buffer")) - (unless (project-file-exists-p! "compile_commands.json") - (user-error "No compile_commands.json file")) - ;; first rtag - (when (and (featurep 'rtags) - rtags-enabled - (executable-find "rc")) - (with-temp-buffer - (message "Reloaded compile commands for rtags daemon") - (rtags-call-rc :silent t "-J" (doom-project-root)))) - ;; then irony - (when (and (featurep 'irony) irony-mode) - (+cc|irony-init-compile-options))) - ;;;###autoload (defun +cc-sp-point-is-template-p (id action context) "Return t if point is in the right place for C++ angle-brackets." @@ -106,6 +87,42 @@ preceded by the opening brace or a comma (disregarding whitespace in between)." ((c-mode))))) +;; +;; Commands +;; + +;;;###autoload +(defun +cc/reload-compile-db () + "Reload the current project's JSON compilation database." + (interactive) + (unless (memq major-mode '(c-mode c++-mode objc-mode)) + (user-error "Not a C/C++/ObjC buffer")) + (unless (project-file-exists-p! "compile_commands.json") + (user-error "No compile_commands.json file")) + ;; first rtag + (when (and (featurep 'rtags) + rtags-enabled + (executable-find "rc")) + (with-temp-buffer + (message "Reloaded compile commands for rtags daemon") + (rtags-call-rc :silent t "-J" (doom-project-root)))) + ;; then irony + (when (and (featurep 'irony) irony-mode) + (+cc|irony-init-compile-options))) + +;;;###autoload +(defun +cc/imenu () + "Invoke `rtags-imenu' if a running rdm process is available, otherwise invoke +`imenu'." + (interactive) + (call-interactively + (if (and (processp rtags-rdm-process) + (not (eq (process-status rtags-rdm-process) 'exit)) + (not (eq (process-status rtags-rdm-process) 'signal))) + #'rtags-imenu + #'imenu))) + + ;; ;; Hooks ;; diff --git a/modules/lang/cc/config.el b/modules/lang/cc/config.el index 9ebedc341..602855658 100644 --- a/modules/lang/cc/config.el +++ b/modules/lang/cc/config.el @@ -220,7 +220,7 @@ compilation database is present in the project.") (add-hook! 'kill-emacs-hook (ignore-errors (rtags-cancel-process))) ;; Use rtags-imenu instead of imenu/counsel-imenu - (define-key! (c-mode-map c++-mode-map) [remap imenu] #'rtags-imenu) + (define-key! (c-mode-map c++-mode-map) [remap imenu] #'+cc/imenu) (when (featurep 'evil) (add-hook 'rtags-jump-hook #'evil-set-jump))