branch: externals/detached commit c72236c67fc755d2672f849c159d745bae1df336 Author: Niklas Eklund <niklas.ekl...@posteo.net> Commit: Niklas Eklund <niklas.ekl...@posteo.net>
Implement attach command --- detached-compile.el | 3 +- detached-eshell.el | 3 +- detached-shell.el | 3 +- detached-vterm.el | 7 +++-- detached.el | 80 ++++++++++++++++++++++++++++++++++------------------- 5 files changed, 62 insertions(+), 34 deletions(-) diff --git a/detached-compile.el b/detached-compile.el index 9481b97782..bcf1b6fc29 100644 --- a/detached-compile.el +++ b/detached-compile.el @@ -114,7 +114,8 @@ Optionally EDIT-COMMAND." (if (eq detached-session-mode 'create) (detached-start-detached-session detached--current-session) (apply compilation-start `(,(if (detached-session-started-p detached--current-session) - (detached--shell-command detached--current-session t) + (detached-session-attach-command detached--current-session + :type 'string) (detached-session-start-command detached--current-session :type 'string)) ,(or mode 'detached-compilation-mode) diff --git a/detached-eshell.el b/detached-eshell.el index 6add34cda5..53c943005f 100644 --- a/detached-eshell.el +++ b/detached-eshell.el @@ -79,7 +79,8 @@ If prefix-argument directly DETACH from the session." (if (detached-session-active-p session) (cl-letf* ((detached-session-mode 'attach) (input - (detached--shell-command session t)) + (detached-session-attach-command session + :type 'string)) ((symbol-function #'eshell-add-to-history) #'ignore)) (let ((kill-ring nil)) (eshell-kill-input)) diff --git a/detached-shell.el b/detached-shell.el index 8c0c679e8a..d7e58830e3 100644 --- a/detached-shell.el +++ b/detached-shell.el @@ -102,7 +102,8 @@ cluttering the `comint-history' with dtach commands." "Attach to `detached--session' and send the attach command to PROC." (let* ((detached-session-mode 'attach) (input - (detached--shell-command detached--current-session t))) + (detached-session-attach-command detached--current-session + :type 'string))) (comint-simple-send proc input))) (defun detached-shell--create-input-sender (proc string) diff --git a/detached-vterm.el b/detached-vterm.el index e84cf1ce37..948fa64f5a 100644 --- a/detached-vterm.el +++ b/detached-vterm.el @@ -79,9 +79,12 @@ Optionally DETACH from it." (string= (detached-session-host-name it) host-name))) (seq-filter #'detached-session-active-p)))) (detached-completing-read sessions)))) - (let ((detached-session-mode 'attach)) + (let ((detached-session-mode 'attach) + (command + (detached-session-attach-command session + :type 'string))) (setq detached--buffer-session session) - (process-send-string vterm--process (detached--shell-command session t)) + (process-send-string vterm--process command) (vterm-send-return))) (cl-defmethod detached--detach-session ((_mode (derived-mode vterm-mode))) diff --git a/detached.el b/detached.el index eda942353a..4570d3fab2 100644 --- a/detached.el +++ b/detached.el @@ -726,7 +726,8 @@ Optionally SUPPRESS-OUTPUT." (buffer (detached--generate-buffer detached--shell-command-buffer (lambda (buffer) (not (get-buffer-process buffer))))) - (command (detached--shell-command detached--current-session t))) + (command (detached-session-start-command detached--current-session + :type 'string))) (setq detached-enabled nil) (funcall #'async-shell-command command buffer) (with-current-buffer buffer @@ -897,7 +898,7 @@ This function uses the `notifications' library." (buffer (get-buffer-create detached--shell-command-buffer)) (detached-local-session (detached--session-local session)) (default-directory (detached--session-directory session)) - (command (detached--shell-command session t))) + (command (detached-session-attach-command session :type 'string))) (when (get-buffer-process buffer) (setq buffer (generate-new-buffer (buffer-name buffer)))) (funcall #'async-shell-command command buffer) @@ -909,36 +910,57 @@ This function uses the `notifications' library." (cl-defun detached-session-start-command (session &key type) "Return command to start SESSION with specified TYPE." + (unless (member type '(list string)) + (error "Type not specified for session start command")) (detached-connection-local-variables (let* ((socket (detached--session-file session 'socket t)) - (log (detached--session-file session 'log t))) + (log (detached--session-file session 'log t)) + (command + (if (detached-session-degraded-p session) + (progn + (when (eq 'create-and-attach + (detached--session-initial-mode session)) + (detached-start-detached-session session)) + `(,detached-tail-program + "--follow=name" + "--retry" + ,(concat "--lines=" detached-session-context-lines) + ,log)) + `(,detached-dtach-program + ,(detached--dtach-arg) ,socket "-z" + ,detached-shell-program "-c" + ,(if (eq type 'string) + (shell-quote-argument (detached--detached-command session)) + (detached--detached-command session)))))) (detached--set-session-state session 'started) - (if (detached-session-degraded-p session) - (let ((tail-command - `(,detached-tail-program - "--follow=name" - "--retry" - ,(concat "--lines=" detached-session-context-lines) - ,log))) - (when (eq 'create-and-attach - (detached--session-initial-mode session)) - (detached-start-detached-session session)) - (pcase type - ('string (string-join tail-command " ")) - ('list tail-command) - (_ (error "Type not specified for session start command"))) - (if )) - (let ((dtach-command - `(,detached-dtach-program - ,(detached--dtach-arg) ,socket "-z" - ,detached-shell-program "-c" - ,(if (eq type 'string) - (shell-quote-argument (detached--detached-command session)) - (detached--detached-command session))))) - (pcase type - ('string (string-join dtach-command " ")) - ('list dtach-command) - (_ (error "Type not specified for session start command")))))))) + (pcase type + ('string (string-join command " ")) + ('list command))))) + +(cl-defun detached-session-attach-command (session &key type) + "Return command to attach SESSION with specified TYPE." + (unless (member type '(list string)) + (error "Type not specified for session start command")) + (detached-connection-local-variables + (let* ((socket (detached--session-file session 'socket t)) + (log (detached--session-file session 'log t)) + (dtach-arg (detached--dtach-arg)) + (command + (if (detached-session-degraded-p session) + `(,detached-tail-program + "--follow=name" + "--retry" + ,(concat "--lines=" detached-session-context-lines) + ,log) + `(,(when detached-show-session-context + (format "%s -n %s %s;" detached-tail-program detached-session-context-lines log)) + ,detached-dtach-program + ,dtach-arg + ,socket + "-r none")))) + (pcase type + ('string (string-join command " ")) + ('list command))))) (defun detached-session-output (session) "Return content of SESSION's output."