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

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

[nongnu] elpa/hyperdrive c2af53e72d 07/32: Add: (hyperdrive-dir-sort, hy


From: ELPA Syncer
Subject: [nongnu] elpa/hyperdrive c2af53e72d 07/32: Add: (hyperdrive-dir-sort, hyperdrive-complete-sort)
Date: Mon, 4 Sep 2023 18:59:34 -0400 (EDT)

branch: elpa/hyperdrive
commit c2af53e72de8efae4d39bf89e05e7ab60ac67cd6
Author: Adam Porter <adam@alphapapa.net>
Commit: Adam Porter <adam@alphapapa.net>

    Add: (hyperdrive-dir-sort, hyperdrive-complete-sort)
---
 hyperdrive-dir.el | 13 +++++++++++++
 hyperdrive-lib.el | 24 ++++++++++++++++++++++++
 2 files changed, 37 insertions(+)

diff --git a/hyperdrive-dir.el b/hyperdrive-dir.el
index adf6a51c6b..f2bd3ae6d5 100644
--- a/hyperdrive-dir.el
+++ b/hyperdrive-dir.el
@@ -95,6 +95,7 @@ With point on header, returns directory entry."
   "^"   #'hyperdrive-up
   "D"   #'hyperdrive-dir-delete
   "H"   #'hyperdrive-dir-history
+  "o"   #'hyperdrive-dir-sort
   "?"   #'hyperdrive-describe-hyperdrive)
 
 ;; TODO: Get rid of this?
@@ -173,6 +174,18 @@ Interactively, visit file or directory at point in
   (interactive (list (hyperdrive-dir--entry-at-point)))
   (hyperdrive-history entry))
 
+(defun hyperdrive-dir-sort (directory-sort)
+  "Sort current `hyperdrive-dir' buffer by DIRECTORY-SORT.
+DIRECTORY-SORT should be a valid value of
+`hyperdrive-directory-sort'."
+  (interactive (list (hyperdrive-complete-sort)))
+  (setq-local hyperdrive-directory-sort directory-sort)
+  (let ((entries (ewoc-collect hyperdrive-ewoc #'hyperdrive-entry-p)))
+    (setf entries (hyperdrive-sort-entries entries))
+    (ewoc-filter hyperdrive-ewoc #'ignore)
+    (dolist (entry entries)
+      (ewoc-enter-last hyperdrive-ewoc entry))))
+
 ;;;; Imenu support
 
 (defun hyperdrive-dir--imenu-create-index-function ()
diff --git a/hyperdrive-lib.el b/hyperdrive-lib.el
index fa44f07f65..7551330ba1 100644
--- a/hyperdrive-lib.el
+++ b/hyperdrive-lib.el
@@ -940,6 +940,30 @@ Prompts with PROMPT and DEFAULT, according to 
`format-prompt'.
 DEFAULT and INITIAL-INPUT are passed to `read-string' as-is."
   (read-string (format-prompt prompt default) initial-input 
'hyperdrive--name-history default))
 
+(defun hyperdrive-complete-sort ()
+  "Return a value for `hyperdrive-directory-sort' selected with completion."
+  (pcase-let* ((fn (pcase-lambda (`(cons :tag ,tag (const :format "" ,accessor)
+                                         (choice :tag "Direction" :value 
,_default-direction
+                                                 (const :tag "Ascending" 
,ascending-predicate)
+                                                 (const :tag "Descending" 
,descending-predicate))))
+                     (cons tag (list accessor ascending-predicate 
descending-predicate))))
+               (columns (mapcar fn (cdr (get 'hyperdrive-directory-sort 
'custom-type))))
+               (read-answer-short t)
+               (choices (cl-loop for (tag . _) in columns
+                                 for name = (substring tag 3)
+                                 for key = (aref name 0)
+                                 collect (cons name (list key tag))))
+               (column-choice (read-answer "Sort by column: " choices))
+               (`(,accessor ,ascending-predicate ,descending-predicate)
+                (map-elt columns (concat "By " column-choice)))
+               (direction-choice (read-answer "Sort in direction: "
+                                              (list (cons "ascending" (list ?a 
"Ascending"))
+                                                    (cons "descending" (list 
?d "Descending")))))
+               (predicate (pcase direction-choice
+                            ("ascending" ascending-predicate)
+                            ("descending" descending-predicate))))
+    (list accessor predicate)))
+
 (cl-defun hyperdrive-put-metadata (hyperdrive &key then)
   "Put HYPERDRIVE's metadata into the appropriate file, then call THEN."
   (declare (indent defun))



reply via email to

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