~protesilaos/denote

This thread contains a patchset. You're looking at the original emails, but you may wish to use the patch review UI. Review patch
1

[PATCH] Fix: Handle no-matching-files in denote-sort-dired

Details
Message ID
<20231211062103.26923-1-ved.manerikar@gmail.com>
DKIM signature
missing
Download raw message
Patch: +20 -19
Where there are no files matching the input regex,
`denote-sort-get-directory-files` returns nil. Passing this to `dired`
throws an error:
```
(file-missing "Reading directory" "No such file or directory" ".../denote/Testing Dired")
```

This commit handles the empty case by returning an appropriate error
message.
---
 denote-sort.el | 39 ++++++++++++++++++++-------------------
 1 file changed, 20 insertions(+), 19 deletions(-)

diff --git a/denote-sort.el b/denote-sort.el
index ac3fed5..c2face4 100644
--- a/denote-sort.el
+++ b/denote-sort.el
@@ -174,26 +174,27 @@ a non-nil value, respectively."
    (denote-sort-component-prompt)
    (y-or-n-p "Reverse sort? ")))
  (let* ((default-directory (denote-directory))
         ;; NOTE 2023-12-04: Passing the FILES-MATCHING-REGEXP here produces
         ;; an error if the regexp contains a wildcard for a directory.  I
         ;; can reproduce this in emacs -Q and am not sure if it is a bug.
         ;; Anyway, I will report it upstream, but even if it is fixed we
         ;; cannot use it for now (whatever fix will be available for Emacs
         ;; 30+).
         ;;
         ;; (format "Denote sort `%s' by `%s'" files-matching-regexp sort-by-component)
         ;; NOTE 2023-12-04: Passing the FILES-MATCHING-REGEXP as
         ;; buffer-name produces an error if the regexp contains a
         ;; wildcard for a directory. I can reproduce this in emacs -Q
         ;; and am not sure if it is a bug. Anyway, I will report it
         ;; upstream, but even if it is fixed we cannot use it for now
         ;; (whatever fix will be available for Emacs 30+).
         (denote-sort-dired-buffer-name (format "Denote sort `%s' by `%s'" files-matching-regexp sort-by-component))
         (buffer-name (format "Denote sort by `%s' at %s" sort-by-component (format-time-string "%T")))
         (files (denote-sort-get-directory-files files-matching-regexp sort-by-component reverse))
         (dired-buffer (dired (cons buffer-name (mapcar #'file-relative-name files)))))
    (setq denote-sort--dired-buffer dired-buffer)
    (with-current-buffer dired-buffer
      (setq-local revert-buffer-function
                  (lambda (&rest _)
                    (kill-buffer dired-buffer)
                    (denote-sort-dired files-matching-regexp sort-by-component reverse)))))
  ;; Because of the above NOTE, I am printing a message.  Not what I
  ;; want, but it is better than nothing...
  (message "Denote sort `%s' by `%s'" files-matching-regexp sort-by-component))
         (files (denote-sort-get-directory-files files-matching-regexp sort-by-component reverse)))
    (if (car files)
        (let ((dired-buffer (dired (cons buffer-name (mapcar #'file-relative-name files)))))
          (setq denote-sort--dired-buffer dired-buffer)
          (with-current-buffer dired-buffer
            (setq-local revert-buffer-function
                        (lambda (&rest _)
                          (kill-buffer dired-buffer)
                          (denote-sort-dired files-matching-regexp sort-by-component reverse))))
          ;; Because of the above NOTE, I am printing a message.  Not what I
          ;; want, but it is better than nothing...
          (message denote-sort-dired-buffer-name))
      (message "No matching files for %s" denote-sort-dired-buffer-name))))

(provide 'denote-sort)
;;; denote-sort.el ends here
-- 
2.43.0
Details
Message ID
<87plzdkzkz.fsf@protesilaos.com>
In-Reply-To
<20231211062103.26923-1-ved.manerikar@gmail.com> (view parent)
DKIM signature
missing
Download raw message
> From: Vedang Manerikar <ved.manerikar@gmail.com>
> Date: Mon, 11 Dec 2023 11:51:03 +0530
>
> Where there are no files matching the input regex,
> `denote-sort-get-directory-files` returns nil. Passing this to `dired`
> throws an error:
> ```
> (file-missing "Reading directory" "No such file or directory" ".../denote/Testing Dired")
> ```
>
> This commit handles the empty case by returning an appropriate error
> message.

Thank you Vedang! I installed your patch. Then made a few tweaks on top
to use 'if-let' and change what is shown in the final 'message'.

-- 
Protesilaos Stavrou
https://protesilaos.com
Reply to thread Export thread (mbox)