aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDmitry Gutov2019-05-31 18:30:36 +0300
committerDmitry Gutov2019-06-09 17:14:46 +0300
commitec563971ecf5d5edde053d965b995a722fe7d79d (patch)
tree0157679350d4b2d3f3efe6c9bb29811f433f5e9b
parentb7e26952f0f6ee3061b9bb855e36dee8e1ea6bf4 (diff)
downloademacs-ec563971ecf5d5edde053d965b995a722fe7d79d.tar.gz
emacs-ec563971ecf5d5edde053d965b995a722fe7d79d.zip
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.
-rw-r--r--lisp/progmodes/xref.el56
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."
704 (setq next-error-function #'xref--next-error-function) 704 (setq next-error-function #'xref--next-error-function)
705 (setq next-error-last-buffer (current-buffer))) 705 (setq next-error-last-buffer (current-buffer)))
706 706
707(defvar xref--transient-buffer-mode-map
708 (let ((map (make-sparse-keymap)))
709 (define-key map (kbd "RET") #'xref-quit-and-goto-xref)
710 (set-keymap-parent map xref--xref-buffer-mode-map)
711 map))
712
713(define-derived-mode xref--transient-buffer-mode
714 xref--xref-buffer-mode
715 "XREF Transient")
716
707(defun xref--next-error-function (n reset?) 717(defun xref--next-error-function (n reset?)
708 (when reset? 718 (when reset?
709 (goto-char (point-min))) 719 (goto-char (point-min)))
@@ -725,7 +735,6 @@ references displayed in the current *xref* buffer."
725 735
726(defvar xref--button-map 736(defvar xref--button-map
727 (let ((map (make-sparse-keymap))) 737 (let ((map (make-sparse-keymap)))
728 (define-key map [(control ?m)] #'xref-goto-xref)
729 (define-key map [mouse-1] #'xref-goto-xref) 738 (define-key map [mouse-1] #'xref-goto-xref)
730 (define-key map [mouse-2] #'xref--mouse-2) 739 (define-key map [mouse-2] #'xref--mouse-2)
731 map)) 740 map))
@@ -789,18 +798,21 @@ Return an alist of the form ((FILENAME . (XREF ...)) ...)."
789 (funcall fetcher))) 798 (funcall fetcher)))
790 (xref-alist (xref--analyze xrefs))) 799 (xref-alist (xref--analyze xrefs)))
791 (with-current-buffer (get-buffer-create xref-buffer-name) 800 (with-current-buffer (get-buffer-create xref-buffer-name)
792 (setq buffer-undo-list nil) 801 (xref--show-common-initialize xref-alist fetcher alist)
793 (let ((inhibit-read-only t) 802 (xref--xref-buffer-mode)
794 (buffer-undo-list t)) 803 (pop-to-buffer (current-buffer))
795 (erase-buffer) 804 (current-buffer))))
796 (xref--insert-xrefs xref-alist) 805
797 (xref--xref-buffer-mode) 806(defun xref--show-common-initialize (xref-alist fetcher alist)
798 (pop-to-buffer (current-buffer)) 807 (setq buffer-undo-list nil)
799 (goto-char (point-min)) 808 (let ((inhibit-read-only t)
800 (setq xref--original-window (assoc-default 'window alist) 809 (buffer-undo-list t))
801 xref--original-window-intent (assoc-default 'display-action alist)) 810 (erase-buffer)
802 (setq xref--fetcher fetcher) 811 (xref--insert-xrefs xref-alist)
803 (current-buffer))))) 812 (goto-char (point-min))
813 (setq xref--original-window (assoc-default 'window alist)
814 xref--original-window-intent (assoc-default 'display-action alist))
815 (setq xref--fetcher fetcher)))
804 816
805(defun xref-revert-buffer () 817(defun xref-revert-buffer ()
806 "Refresh the search results in the current buffer." 818 "Refresh the search results in the current buffer."
@@ -830,6 +842,24 @@ Return an alist of the form ((FILENAME . (XREF ...)) ...)."
830 (cons (cons 'fetched-xrefs xrefs) 842 (cons (cons 'fetched-xrefs xrefs)
831 alist)))))) 843 alist))))))
832 844
845(defun xref--show-defs-buffer-at-bottom (fetcher alist)
846 "Show definitions list in a window at the bottom.
847When there is more than one definition, split the selected window
848and show the list in a small window at the bottom. And use a
849local keymap that binds `RET' to `xref-quit-and-goto-xref'."
850 (let ((xrefs (funcall fetcher)))
851 (cond
852 ((not (cdr xrefs))
853 (xref--pop-to-location (car xrefs)
854 (assoc-default 'display-action alist)))
855 (t
856 (with-current-buffer (get-buffer-create xref-buffer-name)
857 (xref--show-common-initialize (xref--analyze xrefs) fetcher alist)
858 (xref--transient-buffer-mode)
859 (pop-to-buffer (current-buffer)
860 '(display-buffer-in-direction . ((direction . below))))
861 (current-buffer))))))
862
833 863
834(defvar xref-show-xrefs-function 'xref--show-xref-buffer 864(defvar xref-show-xrefs-function 'xref--show-xref-buffer
835 "Function to display a list of search results. 865 "Function to display a list of search results.