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

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

[nongnu] elpa/hyperdrive bfbdac1319 08/30: Add: (-dir-toggle-sort-direct


From: ELPA Syncer
Subject: [nongnu] elpa/hyperdrive bfbdac1319 08/30: Add: (-dir-toggle-sort-direction) Move sort toggle into own function
Date: Wed, 6 Sep 2023 18:59:42 -0400 (EDT)

branch: elpa/hyperdrive
commit bfbdac1319fcc742711ee20d2faac5140d5482dd
Author: Joseph Turner <joseph@ushin.org>
Commit: Joseph Turner <joseph@ushin.org>

    Add: (-dir-toggle-sort-direction) Move sort toggle into own function
---
 hyperdrive-dir.el | 23 ++++++++++++++++++++++-
 hyperdrive-lib.el | 15 ---------------
 2 files changed, 22 insertions(+), 16 deletions(-)

diff --git a/hyperdrive-dir.el b/hyperdrive-dir.el
index 342d6c6135..888084a6f3 100644
--- a/hyperdrive-dir.el
+++ b/hyperdrive-dir.el
@@ -137,6 +137,27 @@ Columns are suffixed with up/down arrows according to
                            (propertize mtime-header 'face 
'hyperdrive-column-header))
                     (propertize name-header 'face 
'hyperdrive-column-header)))))
 
+(defun hyperdrive-dir-complete-sort ()
+  "Return a value for `hyperdrive-directory-sort' selected with completion."
+  (pcase-let* ((read-answer-short t)
+               (choices (mapcar (lambda (field)
+                                  (let ((desc (symbol-name (car field))))
+                                    (list desc (aref desc 0) (format "Sort by 
%s" desc))))
+                                hyperdrive-dir-sort-fields))
+               (column (intern (read-answer "Sort by column: " choices))))
+    (hyperdrive-dir-toggle-sort-direction column hyperdrive-directory-sort)))
+
+(defun hyperdrive-dir-toggle-sort-direction (column sort)
+  "Return `hyperdrive-directory-sort' cons cell for COLUMN.
+If SORT is already sorted using COLUMN, toggle direction.
+Otherwise, set direction to \\+`:descending'."
+  (pcase-let* ((`(,current-column . ,current-direction) sort)
+               (direction (if (and (eq column current-column)
+                                   (eq current-direction :ascending))
+                              :descending
+                            :ascending)))
+    (cons column direction)))
+
 (defun hyperdrive-dir-pp (thing)
   "Pretty-print THING.
 To be used as the pretty-printer for `ewoc-create'."
@@ -286,7 +307,7 @@ Interactively, opens file or directory at point in
   "Sort current `hyperdrive-dir' buffer by DIRECTORY-SORT.
 DIRECTORY-SORT should be a valid value of
 `hyperdrive-directory-sort'."
-  (interactive (list (hyperdrive-complete-sort)))
+  (interactive (list (hyperdrive-dir-complete-sort)))
   (setq-local hyperdrive-directory-sort directory-sort)
   (with-silent-modifications
     (let ((entries (ewoc-collect hyperdrive-ewoc #'hyperdrive-entry-p)))
diff --git a/hyperdrive-lib.el b/hyperdrive-lib.el
index 1c689964a4..907fcdc28c 100644
--- a/hyperdrive-lib.el
+++ b/hyperdrive-lib.el
@@ -1035,21 +1035,6 @@ 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* ((read-answer-short t)
-               (choices (mapcar (lambda (field)
-                                  (let ((desc (symbol-name (car field))))
-                                    (list desc (aref desc 0) (format "Sort by 
%s" desc))))
-                                hyperdrive-dir-sort-fields))
-               (column (intern (read-answer "Sort by column: " choices)))
-               (`(,current-column . ,current-direction) 
hyperdrive-directory-sort)
-               (direction (if (and (eq column current-column)
-                                   (eq current-direction :ascending))
-                              :descending
-                            :ascending)))
-    (cons column direction)))
-
 (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]