branch: externals/dtache commit 5d78cfb3b39f67741ddacf1bd146952ecd8c31e0 Author: Niklas Eklund <niklas.ekl...@posteo.net> Commit: Niklas Eklund <niklas.ekl...@posteo.net>
Add attach command --- README.org | 1 + dtache-eshell.el | 2 +- dtache-shell.el | 2 +- dtache.el | 32 ++++++++++++++++++-------------- 4 files changed, 21 insertions(+), 16 deletions(-) diff --git a/README.org b/README.org index d27e0791fe..1b2d678986 100644 --- a/README.org +++ b/README.org @@ -92,6 +92,7 @@ The actions are controlled by the customizable variables named =dtache-.*-sessio | Command (Keybinding) | Description | |-----------------------------------+---------------------------------------------| | dtache-open-output (o) | Open a session's output | +| dtache-attach (a) | Attach to a session | | dtache-tail-output (t) | Tail the output of an active session | | dtache-diff-session (=) | Diff a session with another session | | dtache-post-compile-session (c) | Open the session output in compilation mode | diff --git a/dtache-eshell.el b/dtache-eshell.el index 5083c31f88..1a0086abf4 100644 --- a/dtache-eshell.el +++ b/dtache-eshell.el @@ -33,7 +33,7 @@ ;;;; Variables (defcustom dtache-eshell-session-action - '(:attach dtache-attach + '(:attach dtache-tail-output :view dtache-view-dwim :run dtache-shell-command) "Actions for a session created with `dtache-eshell'." diff --git a/dtache-shell.el b/dtache-shell.el index 483ae3360f..1506776735 100644 --- a/dtache-shell.el +++ b/dtache-shell.el @@ -30,7 +30,7 @@ ;;;; Variables (defcustom dtache-shell-session-action - '(:attach dtache-attach + '(:attach dtache-tail-output :view dtache-view-dwim :run dtache-shell-command) "Actions for a session created with `dtache-shell'." diff --git a/dtache.el b/dtache.el index 0c58937fcf..3f19da9a38 100644 --- a/dtache.el +++ b/dtache.el @@ -149,6 +149,7 @@ This version is encoded as [package-version].[revision].") (defvar dtache-action-map (let ((map (make-sparse-keymap))) + (define-key map "a" #'dtache-attach) (define-key map "c" #'dtache-post-compile-session) (define-key map "d" #'dtache-delete-session) (define-key map "i" #'dtache-insert-session-command) @@ -320,6 +321,23 @@ Optionally SUPPRESS-OUTPUT." (funcall run-fun command) (dtache-start-session command)))))) +;;;###autoload +(defun dtache-attach (session) + "Attach to SESSION." + (interactive + (list (dtache-completing-read (dtache-get-sessions)))) + (when (dtache-valid-session session) + (let* ((dtache--current-session session) + (dtache-session-mode 'attach) + (inhibit-message t)) + (if (not (dtache--session-attachable session)) + (dtache-tail-output session) + (cl-letf* (((symbol-function #'set-process-sentinel) #'ignore) + (buffer dtache--shell-command-buffer) + (dtach-command (dtache-dtach-command session t))) + (funcall #'async-shell-command dtach-command buffer) + (with-current-buffer buffer (setq dtache--buffer-session dtache--current-session))))))) + ;;;###autoload (defun dtache-copy-session-output (session) "Copy SESSION's log." @@ -629,20 +647,6 @@ If session is not valid trigger an automatic cleanup on SESSION's host." (dtache--update-sessions) (dtache--db-get-sessions)) -(defun dtache-attach (session) - "Attach to `dtache' SESSION." - (when (dtache-valid-session session) - (let* ((dtache--current-session session) - (dtache-session-mode 'attach) - (inhibit-message t)) - (if (not (dtache--session-attachable session)) - (dtache-tail-output session) - (cl-letf* (((symbol-function #'set-process-sentinel) #'ignore) - (buffer dtache--shell-command-buffer) - (dtach-command (dtache-dtach-command session t))) - (funcall #'async-shell-command dtach-command buffer) - (with-current-buffer buffer (setq dtache--buffer-session dtache--current-session))))))) - ;;;;; Other (cl-defgeneric dtache-dtach-command (entity &optional concat)