Closed autosquid closed 4 years ago
Although ycmd is Good enough for complete, but the spacemacs lack of c++ code navigation tools, Rtags is a good choice.
I do not think ycmd is fast and powerful enough for a serious c/c++ project.
For navigating code, you can use gtags
layer with GNU Global. It is fast and works nicely for C, decent for C++. You can comfortably jump projects the size of Linux kernel or above.
As for rtags
, I tried it already. It's easiest to install it on OS X, since clang
is the main compiler and not gcc
or g++
, so you can just do whatever with those two names. But no on Linux, and I don't think it's possible to install it on Windows.
Maybe you should create a rtags
option for C/C++ layer and make a PR. Then people may try it out and give suggestions.
create a decent layer is beyond my ability currently. I used it in pure emacs but have trouble with key-bindings with spacemacs
In my (short) experience rtags is fantastic (and much better than gtags for c++) - it really understands the code even with templates and macros. I would love to see it integrated in a spacemacs layer. I also think company-clang and flycheck's clang backend should be better supported by the c-c++ layer.
I tried rtags, and almost set it up. except that rtags-mode makes my buffer read-only and eat some key >> (for example 's'). But I cannot go any further due to my poor emacs knowledge. Really need help.
No need to activate rtags-mode - just use the commands. The easiest way to set everything up perfectly is maybe cmake-ide (if you use cmake)
create a decent layer is beyond my ability currently. I used it in pure emacs but have trouble with key-bindings with spacemacs
I wonder if it should be an enhancement of the gtags layer. rtags can fall back to gtags if unavailable, so it could be an option on top of the already existing (and super useful) gtags layer.
@duerrp There's already someone submitting a PR. https://github.com/syl20bnr/spacemacs/pull/2834
I have it in my private layer too, and use it everyday.
@autosquid Great, I am looking forwad to it appearing on master (I also have it in my private layer... but it's so much nicer if it's standardized...)
@autosquid @duerrp - would you mind sharing how you set it up in your own layer - I have it setup and it works but when I search for references, I am unable to go to the next occurence (Enter does nothing in the rtags window)
Sure, I have this in my private layer:
(defun peter/init-rtags ()
"Install from https://github.com/Andersbakken/rtags"
(use-package rtags
:config
(evil-leader/set-key-for-mode 'c++-mode "moo" 'rtags-find-symbol-at-point)
(evil-leader/set-key-for-mode 'c++-mode "mos" 'rtags-find-symbol)
(evil-leader/set-key-for-mode 'c++-mode "mor" 'rtags-rename-symbol)
(evil-leader/set-key-for-mode 'c++-mode "mof" 'rtags-find-references-at-point)
(evil-leader/set-key-for-mode 'c++-mode "moF" 'rtags-find-references)
(evil-leader/set-key-for-mode 'c++-mode "mov" 'rtags-find-virtuals-at-point)
(evil-leader/set-key-for-mode 'c++-mode "mot" 'rtags-symbol-type)
(evil-leader/set-key-for-mode 'c++-mode "mo," 'rtags-location-stack-back)
(evil-leader/set-key-for-mode 'c++-mode "mo." 'rtags-location-stack-forward)
))
(defun peter/init-cmake-ide ()
"Need clang to work"
(use-package cmake-ide
:init (with-eval-after-load 'rtags
(cmake-ide-setup))
))
see also: https://github.com/syl20bnr/spacemacs/pull/2834
This is my packages.el for rtags.
(setq rtags-packages
'(
;; package names go here
rtags
))
;; List of packages to exclude.
(setq rtags-excluded-packages '())
(defun rtags-evil-standard-keybindings (mode)
(evil-leader/set-key-for-mode mode
"mR." 'rtags-find-symbol-at-point
"mR," 'rtags-find-references-at-point
"mRv" 'rtags-find-virtuals-at-point
"mRV" 'rtags-print-enum-value-at-point
"mR/" 'rtags-find-all-references-at-point
"mRY" 'rtags-cycle-overlays-on-screen
"mR>" 'rtags-find-symbol
"mR<" 'rtags-find-references
"mR[" 'rtags-location-stack-back
"mR]" 'rtags-location-stack-forward
"mRD" 'rtags-diagnostics
"mRG" 'rtags-guess-function-at-point
"mRp" 'rtags-set-current-project
"mRP" 'rtags-print-dependencies
"mRe" 'rtags-reparse-file
"mRE" 'rtags-preprocess-file
"mRR" 'rtags-rename-symbol
"mRM" 'rtags-symbol-info
"mRS" 'rtags-display-summary
"mRO" 'rtags-goto-offset
"mR;" 'rtags-find-file
"mRF" 'rtags-fixit
"mRL" 'rtags-copy-and-print-current-location
"mRX" 'rtags-fix-fixit-at-point
"mRB" 'rtags-show-rtags-buffer
"mRI" 'rtags-imenu
"mRT" 'rtags-taglist
"mRh" 'rtags-print-class-hierarchy
"mRa" 'rtags-print-source-arguments
)
)
;; For each package, define a function rtags/init-<package-name>
;;
(defun rtags/init-rtags ()
"Initialize my package"
(use-package rtags
:init
;;(evil-set-initial-state 'rtags-mode 'emacs)
;;(rtags-enable-standard-keybindings c-mode-base-map)
:ensure company
:config
(progn
(require 'company-rtags)
(add-to-list 'company-backends 'company-rtags)
(setq company-rtags-begin-after-member-access t)
(setq rtags-completions-enabled t)
;;(rtags-diagnostics)
(define-key evil-normal-state-map (kbd "RET") 'rtags-select-other-window)
(define-key evil-normal-state-map (kbd "M-RET") 'rtags-select)
(define-key evil-normal-state-map (kbd "q") 'rtags-bury-or-delete)
(rtags-evil-standard-keybindings 'c-mode)
(rtags-evil-standard-keybindings 'c++-mode)
)
)
)
Thanks!
Sorry a quick question from an emacs starter, if I enable add this to my private layer and install the rtags server. Can I just enable the C++ layer from my spacemacs dotfile?
This seems to be the older of two tickets on rtags support. In December I posted a comment on the other ticket, https://github.com/syl20bnr/spacemacs/pull/2834#issuecomment-166923023. Maybe someone reading along in this ticket has something to add?
@autosquid @duerrp Thank you very much for sharing your rtags layer configs. I've merged cmake-ide
and updated the hotkey definition to use spacemacs/set-leader-keys-for-major-mode
as I've been told that the other function is deprecated. Also I've added a dependency on auto-completion
layer because of the company
package.
For the layer config see gist: c308dc57085ebbc0f9de.
Best Christoph
Adding (add-hook 'rtags-jump-hook 'evil-set-jump)
integrates rtags nicely with the evil jump list.
This might be helpful on the cmake-ide side of things, it populates your system includes. It's a merge of:
(require 'semantic/bovine/gcc)
(setq cmake-ide-flags-c++ (append '("-std=c++11")
(mapcar (lambda (path) (concat "-I" path)) (semantic-gcc-get-include-paths "c++"))))
(setq cmake-ide-flags-c (append (mapcar (lambda (path) (concat "-I" path)) (semantic-gcc-get-include-paths "c"))))))
@syl20bnr , this issue could be closed hence rtags support was merged to develop
@myrgy thanks for bumping this issue. It will be closed when the fix gets to the master 😸
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Please let us know if this issue is still valid!
I tried
rtags
, and almost set it up. except that rtags-mode makes my buffer read-only and eat some key (for example 's'). But I cannot go any further due to my poor emacs knowledge. Really need help.I think rtags is really promising for completion. It is fast and accurate, which is far better than
complete-clang' and
irony`.You should really have a look at it. It will make the current c-c++ layer much much better.