- (reftex-unhighlight 0)
- (or (one-window-p) (delete-window))
- ;; If `show-window' is still live, show-buffer is already visible
- ;; so let's not make it visible in yet-another-window.
- (if (window-live-p show-window)
- (set-buffer show-buffer)
- (switch-to-buffer show-buffer))
- (reftex-re-enlarge))
- (t nil))))
+ (let ((show-window (selected-window))
+ (show-buffer (window-buffer)))
+ (unless (eq show-window toc-window) ;FIXME: Can this happen?
+ (with-selected-window toc-window
+ (reftex-unhighlight 0)
+ (or (one-window-p) (delete-window))))
+ ;; If `show-window' is still live, show-buffer is already visible
+ ;; so let's not make it visible in yet-another-window.
+ (unless (window-live-p show-window)
+ ;; FIXME: How could show-window not be live?
+ (switch-to-buffer show-buffer))
+ (reftex-re-enlarge)))
+ (t
+ (unless (eq (selected-frame) (window-frame toc-window))
+ ;; Make sure `toc-window' is not just selected but has focus.
+ (select-frame-set-input-focus (window-frame toc-window)))
+ (select-window toc-window)))))