protesilaos / dired-preview

Automatically preview file at point in Emacs Dired.
GNU General Public License v3.0
55 stars 2 forks source link

dired-preview breaks `dired-dwim-target` #13

Closed jeeger closed 4 months ago

jeeger commented 4 months ago

dired-dwim-target automatically selects directories open in other dired buffers when set to t (or some other functions). However, because the preview window is also in dired mode, it will get selected as the DWIM target, thus breaking the DWIM functionality. I'll see whether I can filter out the preview window from the DWIM target list.

jeeger commented 4 months ago

This seems to work:

  (defun dired-dwim-target-next-visible-skipping-preview-buffers ()
    ;; Return directories from all next visible windows with dired-mode buffers,
    ;; filtering out buffers that are used by dired-preview.
    (mapcan (lambda (w)
              (with-current-buffer (window-buffer w)
                (when (and (eq major-mode 'dired-mode)
                           (not (seq-contains-p dired-preview--buffers (current-buffer))))
                  (list (dired-current-directory)))))
            (delq (selected-window)
                  (window-list-1
                   (next-window nil 'nomini 'visible)
                   'nomini 'visible))))
  (setq dired-dwim-target #'dired-dwim-target-next-visible-skipping-preview-buffers)