branch: externals/denote commit 79fc1d2cff4e72aeab403c56d3045e85ab40904e Author: Protesilaos Stavrou <i...@protesilaos.com> Commit: Protesilaos Stavrou <i...@protesilaos.com>
Make denote-sort-dired revert to an empty buffer if no matching files This is discussed with Alan Schmitt and Rory Molinari in issue 618: <https://github.com/protesilaos/denote/issues/618>. I am using a bespoke buffer because I cannot find a way to achieve the same result with a call to (dired (cons DIR FILES)). If that is possible, then I am happy to switch to it. But this will do for the time being. --- denote.el | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/denote.el b/denote.el index 7b13ec92dd..7b4fe987c3 100644 --- a/denote.el +++ b/denote.el @@ -1828,6 +1828,17 @@ If REVERSE is nil, use the value of the user option (or sort-by-component denote-sort-dired-default-sort-component 'identifier) (or reverse denote-sort-dired-default-reverse-sort nil))) +(defun denote-sort-dired--revert-to-empty () + "Revert current Dired buffer to an empty buffer with a warning." + (when (derived-mode-p 'dired-mode) + (let ((inhibit-read-only t)) + (fundamental-mode) + (erase-buffer) + (delete-all-overlays) + (insert (propertize "Denote Dired" 'face 'bold)) + (insert "\n\n") + (insert (propertize "No more matching files" 'face 'warning))))) + (defun denote-sort-dired--prepare-buffer (directory files-fn dired-name buffer-name) "Prepare buffer for `denote-sort-dired'. DIRECTORY is an absolute path to the `default-directory' of the Dired @@ -1849,9 +1860,10 @@ BUFFER-NAME is the name of the resulting buffer." (lambda (&rest _) (if-let* ((default-directory directory) (files (funcall files-fn))) - (setq-local dired-directory (cons dired-name files)) - (setq-local dired-directory (cons "Denote no files" nil))) - (dired-revert)))) + (progn + (setq-local dired-directory (cons dired-name files)) + (dired-revert)) + (denote-sort-dired--revert-to-empty))))) buffer-name)) (defun denote-sort-dired--find-common-directory (directories)