Skip to content
Permalink
Browse files

Prepare rtags-xref.el for MELPA release

[skip ci]
  • Loading branch information
cslux committed Dec 12, 2019
1 parent 70e397b commit 3931a69bbc8d59d00bc2d2b02b4d5e453bc97d7f
Showing with 53 additions and 25 deletions.
  1. +2 −1 README.org
  2. +51 −24 src/rtags-xref.el
@@ -1,7 +1,8 @@
#+OPTIONS: ^:nil

#+html: <div align="center"><a href="https://travis-ci.org/Andersbakken/rtags"><img alt="MELPA" src="https://travis-ci.org/Andersbakken/rtags.svg?branch=master"/></a> <a href="https://www.gnu.org/licenses/gpl-3.0.txt"><img alt="MELPA" src="https://img.shields.io/badge/license-GPL%203-brightgreen.svg"/></a></div>
#+html: <table align="center" style="width:100%"><tr><th>rtags</th><th>ac-rtags</th><th>company-rtags</th><th>flycheck-rtags</th><th>helm-rtags</th><th>ivy-rtags</th></tr><tr><td align="center"><a href="https://melpa.org/#/rtags"><img alt="MELPA" src="https://melpa.org/packages/rtags-badge.svg"/></a></td><td align="center"><a href="https://melpa.org/#/ac-rtags"><img alt="MELPA" src="https://melpa.org/packages/ac-rtags-badge.svg"/></a></td><td align="center"><a href="https://melpa.org/#/company-rtags"><img alt="MELPA" src="https://melpa.org/packages/company-rtags-badge.svg"/></a></td><td align="center"><a href="https://melpa.org/#/flycheck-rtags"><img alt="MELPA" src="https://melpa.org/packages/flycheck-rtags-badge.svg"/></a></td><td align="center"><a href="https://melpa.org/#/helm-rtags"><img alt="MELPA" src="https://melpa.org/packages/helm-rtags-badge.svg"/></a></td><td align="center"><a href="https://melpa.org/#/ivy-rtags"><img alt="MELPA" src="https://melpa.org/packages/ivy-rtags-badge.svg"/></a></td></tr></table>
#+html: <div align="center"><table align="center" style="width:100%"><tr><th>rtags</th></tr><tr><td align="center"><a href="https://melpa.org/#/rtags"><img alt="MELPA" src="https://melpa.org/packages/rtags-badge.svg"/></a></td></tr></table></div>
#+html: <table align="center" style="width:100%"><tr><th>rtags-xref</th><th>ac-rtags</th><th>company-rtags</th><th>flycheck-rtags</th><th>helm-rtags</th><th>ivy-rtags</th></tr><tr><td align="center"><a href="https://melpa.org/#/rtags-xref"><img alt="MELPA" src="https://melpa.org/packages/rtags-xref-badge.svg"/></a></td><td align="center"><a href="https://melpa.org/#/ac-rtags"><img alt="MELPA" src="https://melpa.org/packages/ac-rtags-badge.svg"/></a></td><td align="center"><a href="https://melpa.org/#/company-rtags"><img alt="MELPA" src="https://melpa.org/packages/company-rtags-badge.svg"/></a></td><td align="center"><a href="https://melpa.org/#/flycheck-rtags"><img alt="MELPA" src="https://melpa.org/packages/flycheck-rtags-badge.svg"/></a></td><td align="center"><a href="https://melpa.org/#/helm-rtags"><img alt="MELPA" src="https://melpa.org/packages/helm-rtags-badge.svg"/></a></td><td align="center"><a href="https://melpa.org/#/ivy-rtags"><img alt="MELPA" src="https://melpa.org/packages/ivy-rtags-badge.svg"/></a></td></tr></table>

* Introduction
RTags is a client/server application that indexes C/C++ code and keeps a
@@ -1,35 +1,61 @@
;;; rtags-xref.el -- rtags backend for xref.el
;;; rtags-xref.el --- RTags backend for xref.el

;; Copyright (C) 2019 Jörg Walter

;; Author: Jörg Walter
;; Maintainer: RTags Team
;; URL: http://rtags.net
;; Version: 0.2
;; Package-Requires: ((emacs "25.1") (rtags "3.37"))

;; This file is not part of GNU Emacs.

;; This file is part of RTags (http://rtags.net).
;;
;; RTags is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;;
;; RTags is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;;
;; You should have received a copy of the GNU General Public License
;; along with RTags. If not, see <http://www.gnu.org/licenses/>.

;;; Commentary:
;;;
;;; This adds support for the Emacs25 xref API (`xref-find-definitions' and
;;; friends) to rtags. Just `require' it and the default Emacs keybindings
;;; (M-., M-,, M-? etc.) use rtags.
;;;
;;; There is just one caveat: `xref-backend-apropos' (`C-M-.' by default) only
;;; supports a very limited regex subset: `.' and `.*', plus `^'/`$'. This is
;;; because rtags only supports wildcard searches right now.
;;;
;;; Apart from that, these bindings expose the full power of rtags.
;;;
;;; Enable like this:
;;;
;;; (require 'rtags-xref)
;;; (add-hook 'c-mode-common-hook 'rtags-xref-enable)
;;;
;;
;; This adds support for the Emacs25 xref API (`xref-find-definitions' and
;; friends) to rtags. Just `require' it and the default Emacs keybindings
;; (M-., M-,, M-? etc.) use rtags.
;;
;; There is just one caveat: `xref-backend-apropos' (`C-M-.' by default) only
;; supports a very limited regex subset: `.' and `.*', plus `^'/`$'. This is
;; because rtags only supports wildcard searches right now.
;;
;; Apart from that, these bindings expose the full power of rtags.
;;
;; Enable like this:
;;
;; (require 'rtags-xref)
;; (add-hook 'c-mode-common-hook 'rtags-xref-enable)
;;

;;; Code:

(require 'xref)
(require 'rtags)

(cl-defgeneric xref-backend-identifier-at-point ((_backend (eql rtags)))
(cl-defgeneric rtags-xref-backend-identifier-at-point ((_backend (eql rtags)))
"Return the relevant identifier at point."
(let ((thing (thing-at-point 'symbol)))
(and thing (propertize (substring-no-properties thing)
:rtags-fn (rtags-buffer-file-name)
:rtags-loc (rtags-current-location)))))

(defun rtags--xref-backend-find (symbol func)
(defun rtags-xref-backend-find (symbol func)
"Return definition of SYMBOL, searching via FUNC."
(save-match-data
(with-temp-buffer
@@ -54,7 +80,7 @@

(cl-defmethod xref-backend-definitions ((_backend (eql rtags)) symbol)
"Return definition of SYMBOL."
(rtags--xref-backend-find
(rtags-xref-backend-find
symbol
(lambda (symbol loc &rest args)
(if loc
@@ -77,15 +103,15 @@
(setq pattern (concat pattern "*")))
(setq pattern (replace-regexp-in-string "\\.\\*" "*" pattern t t))
(setq pattern (replace-regexp-in-string "\\." "?" pattern t t))
(rtags--xref-backend-find
(rtags-xref-backend-find
pattern
(lambda (symbol loc &rest args)
(apply #'rtags-call-rc "-a" "-F" symbol args))))


(cl-defmethod xref-backend-references ((_backend (eql rtags)) symbol)
"Return references for SYMBOL."
(rtags--xref-backend-find
(rtags-xref-backend-find
symbol
(lambda (symbol loc &rest args)
(if loc
@@ -97,12 +123,13 @@
"Return completion function."
#'rtags-symbolname-complete)

(defun rtags--xref-backend () "Return 'rtags." 'rtags)
(defun rtags-xref-backend () "Return 'rtags." 'rtags)

(defun rtags-xref-enable ()
"Use rtags as xref backend."
(interactive)
(add-hook 'xref-backend-functions #'rtags--xref-backend nil t))
(add-hook 'xref-backend-functions #'rtags-xref-backend nil t))

(provide 'rtags-xref)

;;; rtags-xref.el ends here

0 comments on commit 3931a69

Please sign in to comment.
You can’t perform that action at this time.