[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/detached 9ab6eb1e6e 1/3: Update code to use public API
From: |
ELPA Syncer |
Subject: |
[elpa] externals/detached 9ab6eb1e6e 1/3: Update code to use public API functions |
Date: |
Fri, 11 Nov 2022 06:57:30 -0500 (EST) |
branch: externals/detached
commit 9ab6eb1e6ec047bf1f0d2587453a75f064186bc5
Author: Niklas Eklund <niklas.eklund@posteo.net>
Commit: Niklas Eklund <niklas.eklund@posteo.net>
Update code to use public API functions
---
detached-consult.el | 42 ++++++++++++++++++------------------------
detached-list.el | 17 +++++------------
detached.el | 17 ++++++++---------
3 files changed, 31 insertions(+), 45 deletions(-)
diff --git a/detached-consult.el b/detached-consult.el
index ebbcf8da97..b10aea1bce 100644
--- a/detached-consult.el
+++ b/detached-consult.el
@@ -96,10 +96,9 @@ See `consult-multi' for a description of the source values."
:items
,(lambda ()
(mapcar #'car
- (seq-filter
- (lambda (x)
- (eq 'active (detached--session-state (cdr x))))
- (detached-session-candidates
(detached-get-sessions))))))
+ (thread-last (detached-session-candidates
(detached-get-sessions))
+ (seq-map #'cdr)
+ (seq-filter
#'detached-session-active-p)))))
"Active `detached' sessions as a source for `consult'.")
(defvar detached-consult--source-inactive-session
@@ -111,10 +110,9 @@ See `consult-multi' for a description of the source
values."
:items
,(lambda ()
(mapcar #'car
- (seq-filter
- (lambda (x)
- (eq 'inactive (detached--session-state (cdr x))))
- (detached-session-candidates
(detached-get-sessions))))))
+ (thread-last (detached-session-candidates
(detached-get-sessions))
+ (seq-map #'cdr)
+ (seq-filter
#'detached-session-inactive-p)))))
"Inactive `detached' sessions as a source for `consult'.")
(defvar detached-consult--source-failure-session
@@ -126,10 +124,9 @@ See `consult-multi' for a description of the source
values."
:items
,(lambda ()
(mapcar #'car
- (seq-filter
- (lambda (x)
- (eq 'failure (car (detached--session-status (cdr
x)))))
- (detached-session-candidates
(detached-get-sessions))))))
+ (thread-last (detached-session-candidates
(detached-get-sessions))
+ (seq-map #'cdr)
+ (seq-filter
#'detached-session-failed-p)))))
"Failed `detached' sessions as a source for `consult'.")
(defvar detached-consult--source-success-session
@@ -141,10 +138,9 @@ See `consult-multi' for a description of the source
values."
:items
,(lambda ()
(mapcar #'car
- (seq-filter
- (lambda (x)
- (eq 'success (car (detached--session-status (cdr
x)))))
- (detached-session-candidates
(detached-get-sessions))))))
+ (thread-last (detached-session-candidates
(detached-get-sessions))
+ (seq-map #'cdr)
+ (seq-remove
#'detached-session-failed-p)))))
"Successful `detached' sessions as a source for `consult'.")
(defvar detached-consult--source-local-session
@@ -156,10 +152,9 @@ See `consult-multi' for a description of the source
values."
:items
,(lambda ()
(mapcar #'car
- (seq-filter
- (lambda (x)
- (eq 'localhost (cdr (detached--session-host (cdr
x)))))
- (detached-session-candidates
(detached-get-sessions)))))
+ (thread-last (detached-session-candidates
(detached-get-sessions))
+ (seq-map #'cdr)
+ (seq-filter
#'detached-session-localhost-p))))
"Local host `detached' sessions as a source for `consult'."))
(defvar detached-consult--source-remote-session
@@ -171,10 +166,9 @@ See `consult-multi' for a description of the source
values."
:items
,(lambda ()
(mapcar #'car
- (seq-filter
- (lambda (x)
- (eq 'remotehost (cdr (detached--session-host (cdr
x)))))
- (detached-session-candidates
(detached-get-sessions))))))
+ (thread-last (detached-session-candidates
(detached-get-sessions))
+ (seq-map #'cdr)
+ (seq-filter
#'detached-session-remotehost-p)))))
"Remote host `detached' sessions as a source for `consult'.")
(defvar detached-consult--source-current-session
diff --git a/detached-list.el b/detached-list.el
index acb03a7408..1303b4c97b 100644
--- a/detached-list.el
+++ b/detached-list.el
@@ -299,10 +299,7 @@ Optionally TOGGLE-SUPPRESS-OUTPUT."
(seq-map (lambda (it)
(pcase-let ((`(,_identifier .
,duplicate-sessions) it))
(car duplicate-sessions))))
- (seq-sort-by
- (lambda (it)
- (plist-get (detached--session-time it) :start))
- #'>))))))))
+ (seq-sort-by #'detached-session-start-time #'>))))))))
(defun detached-list-narrow-after-time (time-threshold)
"Narrow to session's created after TIME-THRESHOLD."
@@ -318,7 +315,7 @@ Optionally TOGGLE-SUPPRESS-OUTPUT."
(let ((current-time (time-to-seconds (current-time))))
(seq-filter (lambda (it)
(< (- current-time
- (plist-get (detached--session-time it)
:start))
+ (detached-session-start-time it))
parsed-threshold))
sessions))))))
(message "Cannot parse time"))))
@@ -337,7 +334,7 @@ Optionally TOGGLE-SUPPRESS-OUTPUT."
(let ((current-time (time-to-seconds (current-time))))
(seq-filter (lambda (it)
(> (- current-time
- (plist-get (detached--session-time it)
:start))
+ (detached-session-start-time it))
parsed-threshold))
sessions))))))
(message "Cannot parse time"))))
@@ -545,9 +542,7 @@ Optionally TOGGLE-SUPPRESS-OUTPUT."
`(,@detached-list--narrow-criteria
("Success" .
,(lambda (sessions)
- (seq-filter (lambda (it)
- (eq 'success (car (detached--session-status it))))
- sessions))))))
+ (seq-remove #'detached-session-failed-p sessions))))))
(defun detached-list-narrow-failure ()
"Narrow to failed sessions."
@@ -556,9 +551,7 @@ Optionally TOGGLE-SUPPRESS-OUTPUT."
`(,@detached-list--narrow-criteria
("Failure" .
,(lambda (sessions)
- (seq-filter (lambda (it)
- (eq 'failure (car (detached--session-status it))))
- sessions))))))
+ (seq-filter #'detached-session-failed-p sessions))))))
(defun detached-list-mark-regexp (regexp)
"Mark sessions which command match REGEXP.
diff --git a/detached.el b/detached.el
index 03d05ffc85..953d815407 100644
--- a/detached.el
+++ b/detached.el
@@ -425,7 +425,7 @@ Optionally SUPPRESS-OUTPUT if prefix-argument is provided."
(list (detached-completing-read (detached-get-sessions))))
(when (detached-valid-session session)
(let ((initialized-session (detached--get-initialized-session session)))
- (if (eq 'active (detached--session-state initialized-session))
+ (if (detached-session-active-p initialized-session)
(detached-attach-session initialized-session)
(if-let ((view-fun (plist-get (detached--session-action
initialized-session) :view)))
(funcall view-fun initialized-session)
@@ -525,7 +525,7 @@ The session is compiled by opening its output and enabling
(list (detached-completing-read (detached-get-sessions))))
(when (detached-valid-session session)
(let ((initialized-session (detached--get-initialized-session session)))
- (if (eq 'inactive (detached--session-state initialized-session))
+ (if (detached-session-inactive-p initialized-session)
(detached-open-session initialized-session)
(if-let ((attach-fun (plist-get (detached--session-action
initialized-session) :attach)))
(funcall attach-fun initialized-session)
@@ -844,7 +844,7 @@ If session is not valid trigger an automatic cleanup on
SESSION's host."
(defun detached-state-transitionion-echo-message (session)
"Issue a notification when SESSION transitions from active to inactive.
This function uses the echo area."
- (let ((status (pcase (car (detached-session-status session))
+ (let ((status (pcase (detached-session-status session)
('success "Detached finished")
('failure "Detached failed"))))
(message "%s [%s]: %s" status (detached-session-host-name session)
(detached--session-command session))))
@@ -1188,9 +1188,9 @@ Optionally CONCAT the command return command into a
string."
,(format "Working directory: %s" (detached--working-dir-str session))
,(format "Host: %s" (detached-session-host-name session))
,(format "Id: %s" (symbol-name (detached--session-id session)))
- ,(format "Status: %s" (car (detached--session-status session)))
+ ,(format "Status: %s" (detached-session-status session))
,(format "Annotation: %s" (if-let ((annotation
(detached--session-annotation session))) annotation ""))
- ,(format "Exit-code: %s" (cdr (detached--session-status session)))
+ ,(format "Exit-code: %s" (detached-session-exit-code session))
,(format "Metadata: %s" (detached--metadata-str session))
,(format "Created at: %s" (detached--creation-str session))
,(format "Duration: %s\n" (detached--duration-str session))
@@ -1653,7 +1653,7 @@ session and trigger a state transition."
;; if there is no active session associated with the directory
(unless
(thread-last (detached--db-get-sessions)
- (seq-filter (lambda (it) (eq 'active
(detached--session-state it))))
+ (seq-filter #'detached-session-active-p)
(seq-map #'detached--session-directory)
(seq-uniq)
(seq-filter (lambda (it) (string= it
session-directory))))
@@ -1779,12 +1779,11 @@ start searching at NUMBER offset."
"Return SESSION's creation time."
(format-time-string
"%b %d %H:%M"
- (plist-get
- (detached--session-time session) :start)))
+ (detached-session-start-time session)))
(defun detached--size-str (session)
"Return the size of SESSION's output."
- (if (eq 'active (detached--session-state session))
+ (if (detached-session-active-p session)
""
(file-size-human-readable
(detached--session-size session))))