jtbm37 / all-the-icons-dired

Adds dired support to all-the-icons
GNU General Public License v3.0
197 stars 26 forks source link

Support a buffer with missing file-name #19

Closed terlar closed 4 years ago

terlar commented 5 years ago

This is caused by a transient state when deleting files with wdired.

As mentioned in #18 this doesn't work well together with wdired-mode. I have managed to get it working by doing the following:

(defvar-local +wdired-icons-enabled nil)
(defun +wdired-before-start-advice ()
  "Execute when switching from `dired' to `wdired'."
  (setq +wdired-icons-enabled (if (bound-and-true-p all-the-icons-dired-mode)
                                  1 0))
  (when (bound-and-true-p all-the-icons-dired-mode)
    (all-the-icons-dired-mode 0)))
(defun +wdired-after-finish-advice ()
  "Execute when switching from `wdired' to `dired'"
  (when (boundp 'all-the-icons-dired-mode)
    (all-the-icons-dired-mode +wdired-icons-enabled)))
(advice-add 'wdired-change-to-wdired-mode :before #'+wdired-before-start-advice)
(advice-add 'wdired-change-to-dired-mode :after #'+wdired-after-finish-advice)

That works for renaming files, etc. But when deleting a file you end up in a state while the file-name is blank for a while (that is how you remove files). With this safeguard to skip actions when there is no filename we won't run into any nil errors.

torgeir commented 4 years ago

The suggested fix works for me too.

terlar commented 4 years ago

This should have been fixed on master via this commit: https://github.com/jtbm37/all-the-icons-dired/commit/8f0858a02fd19f6e63ab8403f6e877da4e01919c#diff-1cb694fb78131dbb71ce622763d9e08cR80