fix(navigation): workaround dired+ incompatibility with dired in master branch

Commit 194d54a929a83fede75d618b104acd1b544feb10 changed behavior of
deletion functions in Dired, causing Dired+ to break deletion, as it
wholesale replaces a bunch of Dired functions with it's own
implementation. For now I've just copied the Dired variants of those
functions to restore them.
This commit is contained in:
2021-06-21 03:51:16 +01:00
parent b049ec652a
commit 688b14a775

View File

@@ -99,7 +99,98 @@
:config
(unbind-key "M-i" dired-mode-map)
(unbind-key "M-l" dired-mode-map))
(unbind-key "M-l" dired-mode-map)
;; BEGINING OF WORKAROUND
;;
;; TODO: Remove this hacky workaround once Dired+ is updated for Emacs 28.x
;;
;; As of commit 194d54a929a83fede75d618b104acd1b544feb10 in Emacs' master
;; branch, Dired+'s replacements of dired-do-*-deletes functions breaks
;; file/folder deletion in Dired.
;;
;; Until a fix is available in Dired+, lets just restore the original fuctions
;; from Dired.
;;
;; Dired change: https://github.com/emacs-mirror/emacs/commit/194d54a929a83fede75d618b104acd1b544feb10
(defun dired-do-delete (&optional arg)
"Delete all marked (or next ARG) files.
`dired-recursive-deletes' controls whether deletion of
non-empty directories is allowed."
;; This is more consistent with the file marking feature than
;; dired-do-flagged-delete.
(interactive "P")
(let (markers)
(dired-internal-do-deletions
(nreverse
;; this may move point if ARG is an integer
(dired-map-over-marks (cons (dired-get-filename)
(let ((m (point-marker)))
(push m markers)
m))
arg))
arg t)
(dolist (m markers) (set-marker m nil))))
(defun dired-do-flagged-delete (&optional nomessage)
"In Dired, delete the files flagged for deletion.
If NOMESSAGE is non-nil, we don't display any message
if there are no flagged files.
`dired-recursive-deletes' controls whether deletion of
non-empty directories is allowed."
(interactive)
(let* ((dired-marker-char dired-del-marker)
(regexp (dired-marker-regexp))
case-fold-search markers)
(if (save-excursion (goto-char (point-min))
(re-search-forward regexp nil t))
(dired-internal-do-deletions
(nreverse
;; this can't move point since ARG is nil
(dired-map-over-marks (cons (dired-get-filename)
(let ((m (point-marker)))
(push m markers)
m))
nil))
nil t)
(dolist (m markers) (set-marker m nil))
(or nomessage
(message "(No deletions requested)")))))
(defun dired-buffers-for-dir (dir &optional file subdirs)
"Return a list of buffers for DIR (top level or in-situ subdir).
If FILE is non-nil, include only those whose wildcard pattern (if any)
matches FILE.
If SUBDIRS is non-nil, also include the dired buffers of
directories below DIR.
The list is in reverse order of buffer creation, most recent last.
As a side effect, killed dired buffers for DIR are removed from
dired-buffers."
(setq dir (file-name-as-directory dir))
(let (result buf)
(dolist (elt dired-buffers)
(setq buf (cdr elt))
(cond
((null (buffer-name buf))
;; Buffer is killed - clean up:
(setq dired-buffers (delq elt dired-buffers)))
((file-in-directory-p (car elt) dir)
(with-current-buffer buf
(when (and (or subdirs
(assoc dir dired-subdir-alist))
(or (null file)
(if (stringp dired-directory)
(let ((wildcards (file-name-nondirectory
dired-directory)))
(or (zerop (length wildcards))
(string-match-p (dired-glob-regexp wildcards)
file)))
(member (expand-file-name file dir)
(cdr dired-directory)))))
(setq result (cons buf result)))))))
result))
;; END OF WORKAROUND
)
(use-package dired-subtree
:after dired