diff options
author | Dmitry Gutov <dgutov@yandex.ru> | 2019-05-31 18:30:36 +0300 |
---|---|---|
committer | Dmitry Gutov <dgutov@yandex.ru> | 2019-06-09 17:14:46 +0300 |
commit | ec563971ecf5d5edde053d965b995a722fe7d79d (patch) | |
tree | 0157679350d4b2d3f3efe6c9bb29811f433f5e9b /lisp | |
parent | b7e26952f0f6ee3061b9bb855e36dee8e1ea6bf4 (diff) | |
download | emacs-ec563971ecf5d5edde053d965b995a722fe7d79d.tar.gz |
Add a built-in alternative for xref-show-definitions-function
* lisp/progmodes/xref.el (xref--transient-buffer-mode-map):
New variable.
(xref--transient-buffer-mode): New major mode.
(xref--button-map): Remove the RET binding (it was unnecessary in
the first place).
(xref--show-common-initialize):
Extract from xref--show-xref-buffer.
(xref--show-defs-buffer-at-bottom): New function.
Diffstat (limited to 'lisp')
-rw-r--r-- | lisp/progmodes/xref.el | 56 |
1 files changed, 43 insertions, 13 deletions
diff --git a/lisp/progmodes/xref.el b/lisp/progmodes/xref.el index fde8464da29..324087f490b 100644 --- a/lisp/progmodes/xref.el +++ b/lisp/progmodes/xref.el @@ -704,6 +704,16 @@ references displayed in the current *xref* buffer." (setq next-error-function #'xref--next-error-function) (setq next-error-last-buffer (current-buffer))) +(defvar xref--transient-buffer-mode-map + (let ((map (make-sparse-keymap))) + (define-key map (kbd "RET") #'xref-quit-and-goto-xref) + (set-keymap-parent map xref--xref-buffer-mode-map) + map)) + +(define-derived-mode xref--transient-buffer-mode + xref--xref-buffer-mode + "XREF Transient") + (defun xref--next-error-function (n reset?) (when reset? (goto-char (point-min))) @@ -725,7 +735,6 @@ references displayed in the current *xref* buffer." (defvar xref--button-map (let ((map (make-sparse-keymap))) - (define-key map [(control ?m)] #'xref-goto-xref) (define-key map [mouse-1] #'xref-goto-xref) (define-key map [mouse-2] #'xref--mouse-2) map)) @@ -789,18 +798,21 @@ Return an alist of the form ((FILENAME . (XREF ...)) ...)." (funcall fetcher))) (xref-alist (xref--analyze xrefs))) (with-current-buffer (get-buffer-create xref-buffer-name) - (setq buffer-undo-list nil) - (let ((inhibit-read-only t) - (buffer-undo-list t)) - (erase-buffer) - (xref--insert-xrefs xref-alist) - (xref--xref-buffer-mode) - (pop-to-buffer (current-buffer)) - (goto-char (point-min)) - (setq xref--original-window (assoc-default 'window alist) - xref--original-window-intent (assoc-default 'display-action alist)) - (setq xref--fetcher fetcher) - (current-buffer))))) + (xref--show-common-initialize xref-alist fetcher alist) + (xref--xref-buffer-mode) + (pop-to-buffer (current-buffer)) + (current-buffer)))) + +(defun xref--show-common-initialize (xref-alist fetcher alist) + (setq buffer-undo-list nil) + (let ((inhibit-read-only t) + (buffer-undo-list t)) + (erase-buffer) + (xref--insert-xrefs xref-alist) + (goto-char (point-min)) + (setq xref--original-window (assoc-default 'window alist) + xref--original-window-intent (assoc-default 'display-action alist)) + (setq xref--fetcher fetcher))) (defun xref-revert-buffer () "Refresh the search results in the current buffer." @@ -830,6 +842,24 @@ Return an alist of the form ((FILENAME . (XREF ...)) ...)." (cons (cons 'fetched-xrefs xrefs) alist)))))) +(defun xref--show-defs-buffer-at-bottom (fetcher alist) + "Show definitions list in a window at the bottom. +When there is more than one definition, split the selected window +and show the list in a small window at the bottom. And use a +local keymap that binds `RET' to `xref-quit-and-goto-xref'." + (let ((xrefs (funcall fetcher))) + (cond + ((not (cdr xrefs)) + (xref--pop-to-location (car xrefs) + (assoc-default 'display-action alist))) + (t + (with-current-buffer (get-buffer-create xref-buffer-name) + (xref--show-common-initialize (xref--analyze xrefs) fetcher alist) + (xref--transient-buffer-mode) + (pop-to-buffer (current-buffer) + '(display-buffer-in-direction . ((direction . below)))) + (current-buffer)))))) + (defvar xref-show-xrefs-function 'xref--show-xref-buffer "Function to display a list of search results. |