Function: denote-sort-dired

denote-sort-dired is an autoloaded, interactive and byte-compiled function defined in denote.el.

Signature

(denote-sort-dired REGEXP SORT-BY-COMPONENT REVERSE EXCLUDE-REGEXP &optional FILES)

Documentation

Produce Dired buffer with sorted files from variable denote-directory(var)/denote-directory(fun).

When called interactively, prompt for REGEXP and, depending on the value of the user option denote-sort-dired-extra-prompts, also prompt for SORT-BY-COMPONENT, REVERSE, and EXCLUDE-REGEXP.

1. REGEXP limits the list of Denote files to those matching the provided
   regular expression.

2. SORT-BY-COMPONENT sorts the files by their file name component (one
   among denote-sort-components). If it is nil, sorting is performed
   according to the user option denote-sort-dired-default-sort-component,
   falling back to the identifier.

3. REVERSE is a boolean to reverse the order when it is a non-nil value.
   If denote-sort-dired-extra-prompts is configured to skip this
   prompt, then the sorting is done according to the user option
   denote-sort-dired-default-reverse-sort, falling back to
   nil (i.e. no reverse sort).

4. EXCLUDE-REGEXP excludes the files that match the given regular
   expression. This is done after REGEXP and OMIT-CURRENT have been
   applied.

5. Optional FILES is a list of file paths. If it is provided,
  REGEXP and EXCLUDE-REGEXP are applied to it. In
  interactive use, FILES is ignored.

When called from Lisp, the mandatory arguments are (i) a string,(ii) a symbol among denote-sort-components, (iii) a nil or non-nil value, and (iv) a string, respectively.

Key Bindings

Aliases

denote-dired

Source Code

;; Defined in ~/.emacs.d/elpa/denote-4.2.3/denote.el
;;;###autoload
(defun denote-sort-dired (regexp sort-by-component reverse exclude-regexp &optional files)
  "Produce Dired buffer with sorted files from variable `denote-directory'.
When called interactively, prompt for REGEXP and, depending on the value
of the user option `denote-sort-dired-extra-prompts', also prompt for
SORT-BY-COMPONENT, REVERSE, and EXCLUDE-REGEXP.

1. REGEXP limits the list of Denote files to those matching the provided
   regular expression.

2. SORT-BY-COMPONENT sorts the files by their file name component (one
   among `denote-sort-components').  If it is nil, sorting is performed
   according to the user option `denote-sort-dired-default-sort-component',
   falling back to the identifier.

3. REVERSE is a boolean to reverse the order when it is a non-nil value.
   If `denote-sort-dired-extra-prompts' is configured to skip this
   prompt, then the sorting is done according to the user option
   `denote-sort-dired-default-reverse-sort', falling back to
   nil (i.e. no reverse sort).

4. EXCLUDE-REGEXP excludes the files that match the given regular
   expression.  This is done after REGEXP and OMIT-CURRENT have been
   applied.

5. Optional FILES is a list of file paths.  If it is provided,
  REGEXP and EXCLUDE-REGEXP are applied to it.  In
  interactive use, FILES is ignored.

When called from Lisp, the mandatory arguments are (i) a string,(ii) a
symbol among `denote-sort-components', (iii) a nil or non-nil value,
and (iv) a string, respectively."
  (interactive (append (list (denote-files-matching-regexp-prompt)) (denote-sort-dired--prompts)))
  (pcase-let ((`(,component . ,reverse-sort) (denote-sort-dired--get-sort-parameters sort-by-component reverse)))
    (dlet ((dired-buffers nil)
           (ls-lisp-use-insert-directory-program (progn (require 'ls-lisp) nil)))
      (if-let* ((directory (and (not (null (denote-directories)))
                                (denote-directories-get-common-root)))
                (matched-files (denote-sort-dired--get-files regexp component reverse-sort exclude-regexp files directory))
                (buffer-name (funcall denote-sort-dired-buffer-name-function regexp sort-by-component reverse-sort exclude-regexp))
                (dired-buffer (dired (cons directory matched-files))))
          (with-current-buffer dired-buffer
            (rename-buffer buffer-name :unique)
            ;; NOTE 2026-04-06: I am adding the `denote-sort-dired--last-arguments' because the previous implementation
            ;; was not updating the existing Dired buffer after a subsequent `denote-sort-dired' call.
            (let ((last-arguments (list regexp component reverse-sort exclude-regexp files)))
              (cond
               ((null denote-sort-dired--last-arguments)
                (setq-local denote-sort-dired--last-arguments last-arguments))
               ((not (equal denote-sort-dired--last-arguments last-arguments))
                (setq-local denote-sort-dired--last-arguments last-arguments)
                (denote-sort-dired-revert))))
            (setq-local denote-sort-dired--last-files matched-files)
            (setq-local revert-buffer-function #'denote-sort-dired-revert))
        (message "No matching files for: %s" regexp)))))