branch: externals/dtache commit f9c287a925dab66aaf8e8d2a70b406a53c7db728 Author: Niklas Eklund <niklas.ekl...@posteo.net> Commit: Niklas Eklund <niklas.ekl...@posteo.net>
Make create session function public This patch makes the dtache-create-session public, since we need to expose this function in order to implement for example dtache-shell. At the same time we also make sure that this function takes care of starting a monitor for the session. --- dtache-shell.el | 6 ++---- dtache.el | 49 ++++++++++++++++++++++++------------------------- test/dtache-test.el | 2 +- 3 files changed, 27 insertions(+), 30 deletions(-) diff --git a/dtache-shell.el b/dtache-shell.el index f6072c851f..fded894e84 100755 --- a/dtache-shell.el +++ b/dtache-shell.el @@ -171,7 +171,7 @@ cluttering the comint-history with dtach commands." dtache-shell-new-block-list) 'create dtache--dtach-mode)) - (session (dtache--create-session + (session (dtache-create-session (substring-no-properties string))) (command (dtache-dtach-command session)) (shell-command @@ -179,9 +179,7 @@ cluttering the comint-history with dtach commands." ,@(butlast command) ,(shell-quote-argument (car (last command)))) " "))) - (progn - (dtache-setup-notification session) - (comint-simple-send proc shell-command)) + (comint-simple-send proc shell-command) (comint-simple-send proc string)))) (defun dtache-shell--comint-read-input-ring-advice (orig-fun &rest args) diff --git a/dtache.el b/dtache.el index 76ab90404a..1c361b1d63 100644 --- a/dtache.el +++ b/dtache.el @@ -356,12 +356,34 @@ nil before closing." ;;;;; Session +(defun dtache-create-session (command) + "Create a `dtache' session from COMMAND." + (dtache-create-session-directory) + (let ((session + (dtache--session-create :id (intern (dtache--create-id command)) + :command command + :type dtache-session-type + :open-function dtache-open-session-function + :callback-function dtache-session-callback-function + :status-function dtache-session-status-function + :working-directory (dtache-get-working-directory) + :redirect-only (dtache-redirect-only-p command) + :creation-time (time-to-seconds (current-time)) + :status 'unknown + :output-size 0 + :session-directory (file-name-as-directory dtache-session-directory) + :host (dtache--host) + :metadata (dtache-metadata) + :active t))) + (dtache--db-insert-entry session) + (dtache-start-session-monitor session) + session)) + (defun dtache-start-session (command) "Start a `dtache' session running COMMAND." (let* ((dtache--dtach-mode 'new) - (session (dtache--create-session command)) + (session (dtache-create-session command)) (dtache-command (dtache-dtach-command session))) - (dtache-setup-notification session) (apply #'start-file-process `("dtache" nil ,dtache-dtach-program ,@dtache-command)))) @@ -608,29 +630,6 @@ Sessions running on current host or localhost are updated." ;;;;; Session -(defun dtache--create-session (command) - "Create a `dtache' session from COMMAND." - (dtache-create-session-directory) - (let ((session - (dtache--session-create :id (intern (dtache--create-id command)) - :command command - :type dtache-session-type - :open-function dtache-open-session-function - :callback-function dtache-session-callback-function - :status-function dtache-session-status-function - :working-directory (dtache-get-working-directory) - :redirect-only (dtache-redirect-only-p command) - :creation-time (time-to-seconds (current-time)) - :status 'unknown - :output-size 0 - :session-directory (file-name-as-directory dtache-session-directory) - :host (dtache--host) - :metadata (dtache-metadata) - :active t))) - ;; Update database - (dtache--db-insert-entry session) - session)) - (defun dtache--session-pid (session) "Return SESSION's pid." (let* ((socket diff --git a/test/dtache-test.el b/test/dtache-test.el index 930f4c6c68..46134ab602 100644 --- a/test/dtache-test.el +++ b/test/dtache-test.el @@ -51,7 +51,7 @@ "Create session with COMMAND running on HOST." (cl-letf* (((symbol-function #'dtache--host) (lambda () host)) ((symbol-function #'dtache-metadata) (lambda () nil)) - (session (dtache--create-session command))) + (session (dtache-create-session command))) (dtache-test--change-session-state session 'activate) session))