completion/ivy: fix M-RET opening result in other-window

This commit is contained in:
Henrik Lissner 2017-05-14 17:40:33 +02:00
parent 806f856cb6
commit 28ba0607a5

View file

@ -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))))))