From 9337c3f8c367964e28e09ad74e02425fd75e7d15 Mon Sep 17 00:00:00 2001 From: Henrik Lissner Date: Sun, 21 Oct 2018 17:53:23 -0400 Subject: [PATCH] feature/lookup: fix OTHER-WINDOW arg For +lookup/definition, +lookup/references and +lookup/documentation. --- modules/feature/lookup/autoload/lookup.el | 39 ++++++++++++++--------- 1 file changed, 24 insertions(+), 15 deletions(-) diff --git a/modules/feature/lookup/autoload/lookup.el b/modules/feature/lookup/autoload/lookup.el index acd7c4395..d10fbedfc 100644 --- a/modules/feature/lookup/autoload/lookup.el +++ b/modules/feature/lookup/autoload/lookup.el @@ -87,21 +87,30 @@ properties: ((require 'xref nil t) (xref-backend-identifier-at-point (xref-find-backend))))) -(defun +lookup--jump-to (prop identifier) +(defun +lookup--jump-to (prop identifier &optional other-window) (cl-loop with origin = (point-marker) - for fn in (plist-get (list :definition +lookup-definition-functions - :references +lookup-references-functions - :documentation +lookup-documentation-functions - :file +lookup-file-functions) - prop) + for fn + in (plist-get (list :definition +lookup-definition-functions + :references +lookup-references-functions + :documentation +lookup-documentation-functions + :file +lookup-file-functions) + prop) for cmd = (or (command-remapping fn) fn) if (condition-case e - (or (if (commandp cmd) - (call-interactively cmd) - (funcall cmd identifier)) - (/= (point-marker) origin)) - ('error (ignore (message "%s" e)))) - return it)) + (save-window-excursion + (when (or (if (commandp cmd) + (call-interactively cmd) + (funcall cmd identifier)) + (/= (point-marker) origin)) + (point-marker))) + (error (ignore (message "%s" e)))) + return + (progn + (funcall (if other-window + #'pop-to-buffer + #'pop-to-buffer-same-window) + (marker-buffer it)) + (goto-char it)))) (defun +lookup--file-search (identifier) (unless identifier @@ -220,7 +229,7 @@ evil-mode is active." (cond ((null identifier) (user-error "Nothing under point")) ((and +lookup-definition-functions - (+lookup--jump-to :definition identifier))) + (+lookup--jump-to :definition identifier other-window))) ((error "Couldn't find the definition of '%s'" identifier)))) @@ -236,7 +245,7 @@ search otherwise." (cond ((null identifier) (user-error "Nothing under point")) ((and +lookup-references-functions - (+lookup--jump-to :references identifier))) + (+lookup--jump-to :references identifier other-window))) ((error "Couldn't find references of '%s'" identifier)))) @@ -254,7 +263,7 @@ Goes down a list of possible backends: (cond ((null identifier) (user-error "Nothing under point")) ((and +lookup-documentation-functions - (+lookup--jump-to :documentation identifier))) + (+lookup--jump-to :documentation identifier other-window))) ((user-error "Couldn't find documentation for '%s'" identifier))))