emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/denote 1999217a51 06/10: Make sorting work for missing


From: ELPA Syncer
Subject: [elpa] externals/denote 1999217a51 06/10: Make sorting work for missing components; remove the macro
Date: Thu, 30 Nov 2023 00:57:46 -0500 (EST)

branch: externals/denote
commit 1999217a51b0b809df0f9ac89b6e64b3f35770ea
Author: Protesilaos Stavrou <info@protesilaos.com>
Commit: Protesilaos Stavrou <info@protesilaos.com>

    Make sorting work for missing components; remove the macro
    
    I am removing the macro because the title sort is a bit different than
    the others. This is due to the 'denote-retrieve-filename-title' which
    always returns a non-empty string.
---
 denote-sort.el | 51 ++++++++++++++++++++++++++++++++++++++-------------
 1 file changed, 38 insertions(+), 13 deletions(-)

diff --git a/denote-sort.el b/denote-sort.el
index 138cc0bf68..b6195373af 100644
--- a/denote-sort.el
+++ b/denote-sort.el
@@ -48,20 +48,45 @@
 (defvar denote-sort-components '(title keywords signature identifier)
   "List of sorting keys applicable for `denote-sort-files' and related.")
 
-(defmacro denote-sort--define (component)
-  "Define Denote sort function for file name COMPONENT."
-  `(defun ,(intern (format "denote-sort-%s-lessp" component)) (file1 file2)
-     ,(format "Return smallest between FILE1 and FILE2 based on their %s.
+(defun denote-sort-title-lessp (file1 file2)
+  "Return smallest between FILE1 and FILE2 based on their title.
 The comparison is done with `denote-sort-comparison-function' between the
-two signature values." component)
-     (when-let ((one (,(intern (format "denote-retrieve-filename-%s" 
component)) file1))
-                (two (,(intern (format "denote-retrieve-filename-%s" 
component)) file2))
-                (sort (funcall denote-sort-comparison-function one two)))
-       file1)))
-
-(denote-sort--define title)
-(denote-sort--define keywords)
-(denote-sort--define signature)
+two title values."
+  (let ((one (denote-retrieve-filename-title file1))
+        (two (denote-retrieve-filename-title file2)))
+    (cond
+     ((string= one (file-name-sans-extension file1))
+      file2)
+     ((or (string= two (file-name-sans-extension file2))
+          (funcall denote-sort-comparison-function one two))
+      file1)
+     (t nil))))
+
+(defun denote-sort-keywords-lessp (file1 file2)
+  "Return smallest between FILE1 and FILE2 based on their keywords.
+The comparison is done with `denote-sort-comparison-function' between the
+two keywords values."
+  (let ((one (denote-retrieve-filename-keywords file1))
+        (two (denote-retrieve-filename-keywords file2)))
+    (cond
+     ((and (string-empty-p one) (not (string-empty-p two))) file2)
+     ((or (and (not (string-empty-p one)) (string-empty-p two))
+          (funcall denote-sort-comparison-function one two))
+      file1)
+     (t nil))))
+
+(defun denote-sort-signature-lessp (file1 file2)
+  "Return smallest between FILE1 and FILE2 based on their signature.
+The comparison is done with `denote-sort-comparison-function' between the
+two signature values."
+  (let ((one (denote-retrieve-filename-signature file1))
+        (two (denote-retrieve-filename-signature file2)))
+    (cond
+     ((and (string-empty-p one) (not (string-empty-p two))) file2)
+     ((or (and (not (string-empty-p one)) (string-empty-p two))
+          (funcall denote-sort-comparison-function one two))
+      file1)
+     (t nil))))
 
 ;;;###autoload
 (defun denote-sort-files (files component &optional reverse)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]