I have this Elisp code that allows me to use ace-window to open a file in a selected window from Dired:
(defun find-file-dired-ace-window ()
"Use ace window to select a window for opening a file from dired."
(interactive)
(let ((file (dired-get-file-for-visit)))
(if (> (length (aw-window-list)) 1)
(aw-select "" (lambda (window)
(aw-switch-to-window window)
(find-file file)))
(find-file-other-window file))))
This works well, however I find it annoying that the focus switches to the newly opened buffer. I would like the focus to stay in the Dired buffer.
I have thought to use save-window-excursion
for this, however now the file does not get opened at all, so it is totally useless:
(defun save-excursion-dired-ace-window ()
"Use ace window to select a window for opening a file from dired."
(interactive)
(save-window-excursion
(let ((file (dired-get-file-for-visit)))
(if (> (length (aw-window-list)) 1)
(aw-select "" (lambda (window)
(aw-switch-to-window window)
(find-file file)))
(find-file-other-window file)))))
How can I can get the desired behavior?