alexluigit / dirvish

A polished Dired with batteries included.
GNU General Public License v3.0
795 stars 44 forks source link

[Bug] dirvish not working with latest denote-sort #249

Open summeremacs opened 9 months ago

summeremacs commented 9 months ago

Thank you for the bug report

Bug description

When I use the new denote-sort method, it displays an error:

dirvish-dired-noselect-a: Wrong type argument: stringp, ("Denote sort by `keywords' at 09:29:22" "reference/20230702T080512--multiple-cursors-in-emacs__emacs_package_reference.org" "reference/20230520T071146--burlyel-for-emacs-windows__emacs_package_reference.org")Error during redisplay: (dirvish-selection-change-h #<frame reference<2> 0x12aa5b440>) signaled (error "Specified program for new process is a directory")

Steps to reproduce

Just go to any directory and use denote-sort-dired, put in some values, watch what happens.

Expected behavior

It should produce a list of sorted files by the values entered.

OS

MacOS

Emacs Version

29

Emacs Configurations

Emacs Plus

Error callstack

No response

Anything else

I should note that I'm on Emacs Plus 30.0.5 but I don't think that it's the cause here. Please let me know if it is. TY!

aikrahguzar commented 8 months ago

I think this can be fixed by the following diff,

@@ -657,12 +657,12 @@ buffer, it defaults to filename under the cursor when it is nil."

 (defun dirvish-dired-noselect-a (fn dir &optional flags)
   "Return buffer for DIR with FLAGS, FN is `dired-noselect'."
-  (let* ((key (file-name-as-directory (expand-file-name dir)))
+  (let* ((key (file-name-as-directory (expand-file-name (if (stringp dir) dir (car dir)))))
          (this dirvish--this)
          (dv (if (and this (eq this-command 'dired-other-frame)) (dirvish-new)
                (or this (car (dirvish--find-reusable)) (dirvish-new))))
          (bname buffer-file-name)
-         (remote (file-remote-p dir))
+         (remote (file-remote-p key))
          (flags (or flags (dv-ls-switches dv)))
          (buffer (alist-get key (dv-roots dv) nil nil #'equal))
          (new-buffer-p (not buffer)))
summeremacs commented 8 months ago

Hi, I'm on vacation so I haven't been keeping up with this but thank you! But I'm not a coder so I'm not sure how to implement this at all. Is this something I have to put into my config? Is it an update you're going to release? I'm sorry about the confusion. I know what diff is and how it generally works but I'm just not sure about the context.

aikrahguzar commented 8 months ago

Hi, I'm on vacation so I haven't been keeping up with this but thank you! But I'm not a coder so I'm not sure how to implement this at all. Is this something I have to put into my config? Is it an update you're going to release? I'm sorry about the confusion. I know what diff is and how it generally works but I'm just not sure about the context.

The diff doesn't go into config but you can try putting the snippet below in your config and see if it helps:

(with-eval-after-load 'dirvish
 (defun my-dirvish-dired-noselect-a (fn dir &optional flags)
  "Return buffer for DIR with FLAGS, FN is `dired-noselect'."
  (let* ((key (file-name-as-directory (expand-file-name (if (stringp dir) dir (car dir)))))
         (this dirvish--this)
         (dv (if (and this (eq this-command 'dired-other-frame)) (dirvish-new)
               (or this (car (dirvish--find-reusable)) (dirvish-new))))
         (bname buffer-file-name)
         (remote (file-remote-p key))
         (flags (or flags (dv-ls-switches dv)))
         (buffer (alist-get key (dv-roots dv) nil nil #'equal))
         (new-buffer-p (not buffer)))
    (if this (set-window-dedicated-p nil nil) (setcar (dv-layout dv) nil))
    (when new-buffer-p
      (if (not remote)
          (let ((dired-buffers nil)) ; disable reuse from dired
            (setq buffer (apply fn (list dir flags))))
        (require 'dirvish-extras)
        (setq buffer (dirvish-noselect-tramp fn dir flags remote)))
      (with-current-buffer buffer (dirvish-init-dired-buffer))
      (push (cons key buffer) (dv-roots dv))
      (push (cons key buffer) dired-buffers))
    (with-current-buffer buffer
      (cond (new-buffer-p nil)
            ((and (not remote) (not (equal flags dired-actual-switches)))
             (dired-sort-other flags))
            ((eq dired-auto-revert-buffer t) (revert-buffer))
        ((functionp dired-auto-revert-buffer)
         (when (funcall dired-auto-revert-buffer dir) (revert-buffer))))
      (dirvish-prop :dv (dv-name dv))
      (dirvish-prop :gui (display-graphic-p))
      (dirvish-prop :remote remote)
      (dirvish-prop :root key)
      (when bname (dired-goto-file bname))
      (setf (dv-index dv) (cons key buffer))
      (run-hook-with-args 'dirvish-find-entry-hook key buffer)
      buffer)))
 (advice-add 'dirvish-dired-noselect-a :override #'my-dirvish-dired-noselect-a))