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

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

[elpa] externals/detached 8be0a4827c 1/2: Add edit-and-run command


From: ELPA Syncer
Subject: [elpa] externals/detached 8be0a4827c 1/2: Add edit-and-run command
Date: Sat, 5 Nov 2022 09:57:32 -0400 (EDT)

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

    Add edit-and-run command
    
    This command makes it possible to rerun a session, but first edit the
    command in case it should be tweaked.
---
 CHANGELOG.org    |  2 ++
 detached-list.el | 21 +++++++++++++++++++++
 detached.el      | 20 ++++++++++++++++++++
 3 files changed, 43 insertions(+)

diff --git a/CHANGELOG.org b/CHANGELOG.org
index 1c212733a0..5aac39f27a 100644
--- a/CHANGELOG.org
+++ b/CHANGELOG.org
@@ -4,6 +4,8 @@
 
 * Development
 
+- Add =edit-and-run= command, which is convenient when a session command needs 
to be tweaked before re-running.
+  
 * Version 0.9.2 (2022-11-01)
 
 - Use =display-buffer= in =detached-list= in order for users to more easily 
customize the display of the buffer.
diff --git a/detached-list.el b/detached-list.el
index c0002da400..e206dcd383 100644
--- a/detached-list.el
+++ b/detached-list.el
@@ -222,6 +222,26 @@ Optionally DELETE the session if prefix-argument is 
provided."
          detached-list-open-session-display-buffer-action))
     (detached-view-dwim session)))
 
+(defun detached-list-edit-and-run-session (session &optional 
toggle-suppress-output)
+  "Edit and run SESSION at point.
+
+Optionally TOGGLE-SUPPRESS-OUTPUT."
+  (interactive
+   (list (tabulated-list-get-id)
+         current-prefix-arg))
+  (let ((detached-session-mode
+         (if toggle-suppress-output
+             (if (eq 'create (detached--session-initial-mode session))
+                 'create-and-attach
+               'create)
+           (detached--session-initial-mode session))))
+    (unless (eq detached-session-mode 'create)
+      (when-let ((single-window (> (length (window-list)) 1))
+                 (buffer (current-buffer)))
+        (delete-window (get-buffer-window))
+        (bury-buffer buffer)))
+    (detached-edit-and-run-session session)))
+
 (defun detached-list-rerun-session (session &optional toggle-suppress-output)
   "Rerun SESSION at point.
 
@@ -863,6 +883,7 @@ If prefix-argument is provided unmark instead of mark."
   (let ((map (make-sparse-keymap)))
     (define-key map (kbd "a") #'detached-list-edit-annotation)
     (define-key map (kbd "d") #'detached-list-delete-session)
+    (define-key map (kbd "e") #'detached-list-edit-and-run-session)
     (define-key map (kbd "f") #'detached-list-select-filter)
     (define-key map (kbd "g") #'detached-list-revert)
     (define-key map (kbd "i") #'detached-list-initialize-session-directory)
diff --git a/detached.el b/detached.el
index f50908b7b7..33732b8998 100644
--- a/detached.el
+++ b/detached.el
@@ -462,6 +462,26 @@ The session is compiled by opening its output and enabling
         (select-window
          (display-buffer buffer-name 
detached-open-session-display-buffer-action))))))
 
+;;;###autoload
+(defun detached-edit-and-run-session (session &optional suppress-output)
+  "Edit SESSION and run, optionally SUPPRESS-OUTPUT."
+  (interactive
+   (list (detached-completing-read (detached-get-sessions))
+         current-prefix-arg))
+  (when (detached-valid-session session)
+    (let* ((default-directory
+             (detached--session-working-directory session))
+           (detached-session-mode (or detached-session-mode
+                                      (detached--session-initial-mode 
session)))
+           (detached-session-action (detached--session-action session))
+           (command
+            (read-string "Edit command: " (detached--session-command 
session))))
+      (if suppress-output
+          (detached-start-session command suppress-output)
+        (if-let ((run-fun (plist-get (detached--session-action session) :run)))
+            (funcall run-fun command)
+          (detached-start-session command))))))
+
 ;;;###autoload
 (defun detached-rerun-session (session &optional suppress-output)
   "Rerun SESSION, optionally SUPPRESS-OUTPUT."



reply via email to

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