Function: denote-sort--define-lessp
denote-sort--define-lessp is a macro defined in denote.el.
Signature
(denote-sort--define-lessp COMPONENT)
Documentation
Define function to sort by COMPONENT.
Source Code
;; Defined in ~/.emacs.d/elpa/denote-4.2.3/denote.el
;; NOTE 2023-12-04: We can have compound sorting algorithms such as
;; title+signature, but I want to keep this simple for the time being.
;; Let us first hear from users to understand if there is a real need
;; for such a feature.
(defmacro denote-sort--define-lessp (component)
"Define function to sort by COMPONENT."
(let ((retrieve-fn (intern (format "denote-retrieve-filename-%s" component)))
(comparison-fn (intern (format "denote-sort-%s-comparison-function" component))))
`(defun ,(intern (format "denote-sort-%s-lessp" component)) (file1 file2)
,(format
"Return smallest among FILE1, FILE2 based on their %s.
The `%s' performs the comparison."
component comparison-fn)
(let* ((one (,retrieve-fn file1))
(two (,retrieve-fn file2))
(one-empty-p (or (null one) (string-empty-p one)))
(two-empty-p (or (null two) (string-empty-p two))))
(cond
(one-empty-p nil)
((and (not one-empty-p) two-empty-p) one)
(t (funcall (or ,comparison-fn denote-sort-comparison-fallback-function) one two)))))))