karthink / dired-hist

Traverse dired history in Emacs
31 stars 1 forks source link

emacs28.1 `dired-kill-when-opening-new-dired-buffer` is not respected #2

Open etern opened 2 years ago

etern commented 2 years ago

Hi, thanks for this convenient package, emacs28.1 dired-kill-when-opening-new-dired-buffer is not respected, is it possible to add support?

And, any plan for Melpa release?

agreselin commented 1 year ago

The issue lies in the sexp (dired (cdr item)) in dired-hist--visit: it tells Dired to open a new Dired buffer on the history node and it's invoked when no buffers are visiting that node, which is the norm for past locations when dired-kill-when-opening-new-dired-buffer is non-nil.

This advice replaces the original dired-hist--visit when dired-kill-when-opening-new-dired-buffer is non-nil. It kills the current Dired buffer before opening the requested one. At least this is the idea. I've written it quickly and didn't test it enough.

(define-advice dired-hist--visit (:before-until (item) respecting-dired-kill-when-opening-new-dired-buffer)
  "Navigate the Dired history using one Dired buffer if
‘dired-kill-when-opening-new-dired-buffer’ is non-nil."
  (when (and (file-directory-p (cdr item))
             dired-kill-when-opening-new-dired-buffer)
    (dired--find-file #'find-alternate-file (cdr item))))