diff options
Diffstat (limited to 'lisp/progmodes/xref.el')
-rw-r--r-- | lisp/progmodes/xref.el | 71 |
1 files changed, 50 insertions, 21 deletions
diff --git a/lisp/progmodes/xref.el b/lisp/progmodes/xref.el index c70bd5dbd60..755c3db04fd 100644 --- a/lisp/progmodes/xref.el +++ b/lisp/progmodes/xref.el @@ -281,9 +281,10 @@ current project's main and external roots." (xref-references-in-directory identifier dir) (message "Searching %s... done" dir))) (let ((pr (project-current t))) - (cons - (xref--project-root pr) - (project-external-roots pr))))) + (project-combine-directories + (cons + (xref--project-root pr) + (project-external-roots pr)))))) (cl-defgeneric xref-backend-apropos (backend pattern) "Find all symbols that match PATTERN string. @@ -638,6 +639,18 @@ If SELECT is non-nil, select the target window." "Face used to highlight matches in the xref buffer." :version "28.1") +(defvar-local xref-num-matches-found 0) + +(defvar xref-num-matches-face 'compilation-info + "Face name to show the number of matches on the mode line.") + +(defconst xref-mode-line-matches + `(" [" (:propertize (:eval (int-to-string xref-num-matches-found)) + face ,xref-num-matches-face + help-echo "Number of matches so far") + "]")) +(put 'xref-mode-line-matches 'risky-local-variable t) + (defmacro xref--with-dedicated-window (&rest body) `(let* ((xref-w (get-buffer-window xref-buffer-name)) (xref-w-dedicated (window-dedicated-p xref-w))) @@ -1235,6 +1248,8 @@ Return an alist of the form ((GROUP . (XREF ...)) ...)." (xref--ensure-default-directory dd (current-buffer)) (xref--xref-buffer-mode) (xref--show-common-initialize xref-alist fetcher alist) + (setq xref-num-matches-found (length xrefs)) + (setq mode-line-process (list xref-mode-line-matches)) (pop-to-buffer (current-buffer)) (setq buf (current-buffer))) (xref--auto-jump-first buf (assoc-default 'auto-jump alist)) @@ -1468,7 +1483,6 @@ The meanings of both arguments are the same as documented in (xref--show-xrefs fetcher display-action)) (defun xref--show-xrefs (fetcher display-action &optional _always-show-list) - (xref--push-markers) (unless (functionp fetcher) ;; Old convention. (let ((xrefs fetcher)) @@ -1479,21 +1493,32 @@ The meanings of both arguments are the same as documented in (prog1 xrefs (setq xrefs 'called-already))))))) - (funcall xref-show-xrefs-function fetcher - `((window . ,(selected-window)) - (display-action . ,display-action) - (auto-jump . ,xref-auto-jump-to-first-xref)))) + (let ((cb (current-buffer)) + (pt (point))) + (prog1 + (funcall xref-show-xrefs-function fetcher + `((window . ,(selected-window)) + (display-action . ,display-action) + (auto-jump . ,xref-auto-jump-to-first-xref))) + (xref--push-markers cb pt)))) (defun xref--show-defs (xrefs display-action) - (xref--push-markers) - (funcall xref-show-definitions-function xrefs - `((window . ,(selected-window)) - (display-action . ,display-action) - (auto-jump . ,xref-auto-jump-to-first-definition)))) - -(defun xref--push-markers () - (unless (region-active-p) (push-mark nil t)) - (xref-push-marker-stack)) + (let ((cb (current-buffer)) + (pt (point))) + (prog1 + (funcall xref-show-definitions-function xrefs + `((window . ,(selected-window)) + (display-action . ,display-action) + (auto-jump . ,xref-auto-jump-to-first-definition))) + (xref--push-markers cb pt)))) + +(defun xref--push-markers (buf pt) + (when (buffer-live-p buf) + (save-excursion + (with-no-warnings (set-buffer buf)) + (goto-char pt) + (unless (region-active-p) (push-mark nil t)) + (xref-push-marker-stack)))) (defun xref--prompt-p (command) (or (eq xref-prompt-for-identifier t) @@ -1525,7 +1550,7 @@ The meanings of both arguments are the same as documented in prompt)) (xref-backend-identifier-completion-table backend) nil nil nil - 'xref--read-identifier-history def))) + 'xref--read-identifier-history def t))) (if (equal id "") (or def (user-error "There is no default identifier")) id))) @@ -1613,7 +1638,8 @@ is nil, prompt only if there's no usable symbol at point." (defun xref-find-references-and-replace (from to) "Replace all references to identifier FROM with TO." (interactive - (let* ((query-replace-read-from-default 'find-tag-default) + (let* ((query-replace-read-from-default + (lambda () (xref-backend-identifier-at-point (xref-find-backend)))) (common (query-replace-read-args "Query replace identifier" nil))) (list (nth 0 common) (nth 1 common)))) @@ -1637,7 +1663,9 @@ This command is intended to be bound to a mouse event." (mouse-set-point event) (xref-backend-identifier-at-point (xref-find-backend))))) (if identifier - (xref-find-definitions identifier) + (progn + (mouse-set-point event) + (xref-find-definitions identifier)) (user-error "No identifier here")))) ;;;###autoload @@ -1651,6 +1679,7 @@ This command is intended to be bound to a mouse event." (xref-backend-identifier-at-point (xref-find-backend))))) (if identifier (let ((xref-prompt-for-identifier nil)) + (mouse-set-point event) (xref-find-references identifier)) (user-error "No identifier here")))) @@ -2147,7 +2176,7 @@ Such as the current syntax table and the applied syntax properties." (or (buffer-modified-p buf) (unless xref--hits-remote-id - (not (verify-visited-file-modtime (current-buffer)))))) + (not (verify-visited-file-modtime buf))))) ;; We can't use buffers whose contents diverge from disk (bug#54025). (setq buf nil)) (setq xref--last-file-buffer (cons file buf)))) |