From 28ba0607a53fdc99e64d7b06a1ad948756ac75ea Mon Sep 17 00:00:00 2001 From: Henrik Lissner Date: Sun, 14 May 2017 17:40:33 +0200 Subject: [PATCH] completion/ivy: fix M-RET opening result in other-window --- modules/completion/ivy/autoload/ivy.el | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/modules/completion/ivy/autoload/ivy.el b/modules/completion/ivy/autoload/ivy.el index 2f2148456..2a7fc0c68 100644 --- a/modules/completion/ivy/autoload/ivy.el +++ b/modules/completion/ivy/autoload/ivy.el @@ -216,10 +216,14 @@ counsel-rg)." ;;;###autoload (defun +ivy-git-grep-other-window-action (x) "Opens the current candidate in another window." - (let (dest-window) - (cl-letf (((symbol-function 'find-file) - (lambda (filename) - (find-file-other-window filename) - (setq dest-window (selected-window))))) - (counsel-git-grep-action x) - (select-window dest-window)))) + (when (string-match "\\`\\(.*?\\):\\([0-9]+\\):\\(.*\\)\\'" x) + (select-window + (with-ivy-window + (let ((file-name (match-string-no-properties 1 x)) + (line-number (match-string-no-properties 2 x))) + (find-file-other-window (expand-file-name file-name counsel--git-grep-dir)) + (goto-char (point-min)) + (forward-line (1- (string-to-number line-number))) + (re-search-forward (ivy--regex ivy-text t) (line-end-position) t) + (run-hooks 'counsel-grep-post-action-hook) + (selected-window))))))