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

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

[elpa] externals/detached cb637df4fc 3/8: Add chained commands section i


From: ELPA Syncer
Subject: [elpa] externals/detached cb637df4fc 3/8: Add chained commands section in README
Date: Tue, 31 May 2022 10:57:32 -0400 (EDT)

branch: externals/detached
commit cb637df4fc0d8829eebd3bd86fbf91291c55a4fe
Author: Niklas Eklund <niklas.eklund@posteo.net>
Commit: Niklas Eklund <niklas.eklund@posteo.net>

    Add chained commands section in README
---
 README.md   | 21 +++++++++++++++++++++
 detached.el | 12 ++++++++++++
 2 files changed, 33 insertions(+)

diff --git a/README.md b/README.md
index 2a2c67464c..d49cda5087 100644
--- a/README.md
+++ b/README.md
@@ -284,6 +284,27 @@ The tool `script` can have different options depending on 
version and operating
 
 Which is compatible with the options described in [script(1) - Linux manual 
page](https://man7.org/linux/man-pages/man1/script.1.html).
 
+## Chained commands
+
+With `detached` there exists the possibility to enable callback for a session. 
With this functionality its possible to create a new session once a session is 
finished. Here is an example which essentially provides `sleep 1 && ls && ls 
-la` but every step in the chain is run in isolation.
+
+``` emacs-lisp
+(let* ((default-directory "/tmp")
+       (detached-session-action
+        `(,@detached-shell-command-session-action
+          :callback (lambda (session1)
+                      (when (eq 'success (detached-session-status session1))
+                        (let ((default-directory 
(detached--session-working-directory session1))
+                              (detached-session-action
+                               `(,@detached-shell-command-session-action
+                                 :callback (lambda (session2)
+                                             (when (eq 'success 
(detached-session-status session2))
+                                               (let ((default-directory 
(detached--session-working-directory session2)))
+                                                 (detached-start-session "ls 
-la" t)))))))
+                          (detached-start-session "ls" t)))))))
+  (detached-start-session "sleep 1" t))
+```
+
 # Tips & Tricks
 
 The `detached.el` package integrates with core Emacs packages as well as 3rd 
party packages. Integration is orchestrated in the `detached-init.el`. In this 
section you can find tips for integrations that are not supported in the 
package itself.
diff --git a/detached.el b/detached.el
index e3ae6f1a5a..e0a8f820e1 100644
--- a/detached.el
+++ b/detached.el
@@ -764,6 +764,18 @@ This function uses the `notifications' library."
         (funcall #'async-shell-command dtach-command buffer)
         (with-current-buffer buffer (setq detached--buffer-session 
detached--current-session))))))
 
+(defun detached-session-exit-code (session)
+  "Return exit code for SESSION."
+  (pcase-let ((`(,_status . ,exit-code)
+               (detached--session-status session)))
+    exit-code))
+
+(defun detached-session-status (session)
+  "Return status for SESSION."
+  (pcase-let ((`(,status . ,_exit-code)
+               (detached--session-status session)))
+    status))
+
 ;;;;; Other
 
 (cl-defgeneric detached-dtach-command (entity &optional concat)



reply via email to

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