lang/cc: add +cc/imenu command

Plus minor reformatting of autoloads file
This commit is contained in:
Henrik Lissner 2018-08-04 13:41:38 +02:00
parent 8248e80570
commit fa4b7502c2
No known key found for this signature in database
GPG key ID: 5F6C0EA160557395
2 changed files with 37 additions and 20 deletions

View file

@ -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
;;

View file

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