Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #2327 - request for rtags layer for c/c++ completion #2327

Closed
autosquid opened this issue Jul 15, 2015 · 19 comments
Closed

Fixes #2327 - request for rtags layer for c/c++ completion #2327

autosquid opened this issue Jul 15, 2015 · 19 comments
Assignees
Labels
C/C++ Fixed in develop stale marked as a stale issue/pr (usually by a bot)

Comments

@autosquid
Copy link
Contributor

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' andirony`.

You should really have a look at it. It will make the current c-c++ layer much much better.

@yinchunlong
Copy link

Although ycmd is Good enough for complete, but the spacemacs lack of c++ code navigation tools, Rtags is a good choice.

@autosquid
Copy link
Contributor Author

I do not think ycmd is fast and powerful enough for a serious c/c++ project.

@tuhdo
Copy link
Contributor

tuhdo commented Jul 28, 2015

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.

@autosquid
Copy link
Contributor Author

create a decent layer is beyond my ability currently. I used it in pure emacs but have trouble with key-bindings with spacemacs

@duerrp
Copy link
Contributor

duerrp commented Oct 27, 2015

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.

@autosquid
Copy link
Contributor Author

@duerrp There's already someone submitting a PR. #2834

I have it in my private layer too, and use it everyday.

@duerrp
Copy link
Contributor

duerrp commented Oct 28, 2015

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

@naseer
Copy link
Contributor

naseer commented Nov 2, 2015

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

@duerrp
Copy link
Contributor

duerrp commented Nov 3, 2015

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

@autosquid
Copy link
Contributor Author

see also: #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)
      )
    )
  )

@naseer
Copy link
Contributor

naseer commented Nov 3, 2015

Thanks!

@tdejager
Copy link

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?

@magthe
Copy link
Contributor

magthe commented Feb 7, 2016

This seems to be the older of two tickets on rtags support. In December I posted a comment on the other ticket, #2834 (comment). Maybe someone reading along in this ticket has something to add?

@cviebig
Copy link

cviebig commented Feb 8, 2016

@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

@syl20bnr syl20bnr self-assigned this Mar 5, 2016
@syl20bnr syl20bnr changed the title request for rtags layer for c/c++ completion Fixes #2327 - request for rtags layer for c/c++ completion Mar 5, 2016
@olejorgenb
Copy link
Contributor

Adding (add-hook 'rtags-jump-hook 'evil-set-jump) integrates rtags nicely with the evil jump list.

Andersbakken/rtags#559

@arbishop
Copy link

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

@myrgy
Copy link
Contributor

myrgy commented Jan 8, 2018

@syl20bnr , this issue could be closed hence rtags support was merged to develop

@d12frosted
Copy link
Collaborator

@myrgy thanks for bumping this issue. It will be closed when the fix gets to the master 😸

@github-actions
Copy link

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!

@github-actions github-actions bot added the stale marked as a stale issue/pr (usually by a bot) label Feb 29, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C/C++ Fixed in develop stale marked as a stale issue/pr (usually by a bot)
Projects
None yet
Development

No branches or pull requests