summaryrefslogtreecommitdiff
path: root/lisp/progmodes/xref.el
diff options
context:
space:
mode:
Diffstat (limited to 'lisp/progmodes/xref.el')
-rw-r--r--lisp/progmodes/xref.el51
1 files changed, 39 insertions, 12 deletions
diff --git a/lisp/progmodes/xref.el b/lisp/progmodes/xref.el
index e59bfdd36d2..87ce2299c56 100644
--- a/lisp/progmodes/xref.el
+++ b/lisp/progmodes/xref.el
@@ -71,9 +71,6 @@
(require 'ring)
(require 'project)
-(eval-when-compile
- (require 'semantic/symref)) ;; for hit-lines slot
-
(defgroup xref nil "Cross-referencing commands"
:version "25.1"
:group 'tools)
@@ -317,8 +314,12 @@ backward."
;;; Marker stack (M-. pushes, M-, pops)
(defcustom xref-marker-ring-length 16
- "Length of the xref marker ring."
- :type 'integer)
+ "Length of the xref marker ring.
+If this variable is not set through Customize, you must call
+`xref-set-marker-ring-length' for changes to take effect."
+ :type 'integer
+ :initialize #'custom-initialize-default
+ :set #'xref-set-marker-ring-length)
(defcustom xref-prompt-for-identifier '(not xref-find-definitions
xref-find-definitions-other-window
@@ -354,6 +355,14 @@ elements is negated: these commands will NOT prompt."
(defvar xref--marker-ring (make-ring xref-marker-ring-length)
"Ring of markers to implement the marker stack.")
+(defun xref-set-marker-ring-length (var val)
+ "Set `xref-marker-ring-length'.
+VAR is the symbol `xref-marker-ring-length' and VAL is the new
+value."
+ (set-default var val)
+ (if (ring-p xref--marker-ring)
+ (ring-resize xref--marker-ring val)))
+
(defun xref-push-marker-stack (&optional m)
"Add point M (defaults to `point-marker') to the marker stack."
(ring-insert xref--marker-ring (or m (point-marker))))
@@ -503,8 +512,9 @@ SELECT is `quit', also quit the *xref* window."
(xref-buffer (current-buffer)))
(cond (select
(if (eq select 'quit) (quit-window nil nil))
- (with-current-buffer xref-buffer
- (select-window (xref--show-pos-in-buf marker buf))))
+ (select-window
+ (with-current-buffer xref-buffer
+ (xref--show-pos-in-buf marker buf))))
(t
(save-selected-window
(xref--with-dedicated-window
@@ -541,9 +551,12 @@ SELECT is `quit', also quit the *xref* window."
Non-interactively, non-nil QUIT means to first quit the *xref*
buffer."
(interactive)
- (let ((xref (or (xref--item-at-point)
- (user-error "No reference at point"))))
- (xref--show-location (xref-item-location xref) (if quit 'quit t))))
+ (let* ((buffer (current-buffer))
+ (xref (or (xref--item-at-point)
+ (user-error "No reference at point")))
+ (xref--current-item xref))
+ (xref--show-location (xref-item-location xref) (if quit 'quit t))
+ (next-error-found buffer (current-buffer))))
(defun xref-quit-and-goto-xref ()
"Quit *xref* buffer, then jump to xref on current line."
@@ -876,6 +889,19 @@ is nil, prompt only if there's no usable symbol at point."
(interactive (list (xref--read-identifier "Find references of: ")))
(xref--find-xrefs identifier 'references identifier nil))
+;;;###autoload
+(defun xref-find-definitions-at-mouse (event)
+ "Find the definition of identifier at or around mouse click.
+This command is intended to be bound to a mouse event."
+ (interactive "e")
+ (let ((identifier
+ (save-excursion
+ (mouse-set-point event)
+ (xref-backend-identifier-at-point (xref-find-backend)))))
+ (if identifier
+ (xref-find-definitions identifier)
+ (user-error "No identifier here"))))
+
(declare-function apropos-parse-pattern "apropos" (pattern))
;;;###autoload
@@ -976,7 +1002,7 @@ IGNORES is a list of glob patterns."
;; do that reliably enough, without creating false negatives?
(command (xref--rgrep-command (xref--regexp-to-extended regexp)
files
- (expand-file-name dir)
+ (file-local-name (expand-file-name dir))
ignores))
(def default-directory)
(buf (get-buffer-create " *xref-grep*"))
@@ -987,7 +1013,7 @@ IGNORES is a list of glob patterns."
(erase-buffer)
(setq default-directory def)
(setq status
- (call-process-shell-command command nil t))
+ (process-file-shell-command command nil t))
(goto-char (point-min))
;; Can't use the exit status: Grep exits with 1 to mean "no
;; matches found". Find exits with 1 if any of the invocations
@@ -1089,6 +1115,7 @@ Such as the current syntax table and the applied syntax properties."
(defun xref--collect-matches (hit regexp tmp-buffer)
(pcase-let* ((`(,line ,file ,text) hit)
+ (file (and file (concat (file-remote-p default-directory) file)))
(buf (xref--find-buffer-visiting file))
(syntax-needed (xref--regexp-syntax-dependent-p regexp)))
(if buf