branch: externals/dtache commit b247ddc6dd4fc100ffd0c9240beeed41c38be5b3 Author: Niklas Eklund <niklas.ekl...@posteo.net> Commit: Niklas Eklund <niklas.ekl...@posteo.net>
Rewrite dtache-dtach-command Implement the function using defmethod in order to work both for commands as well as sessions. --- dtache-shell.el | 3 +-- dtache.el | 36 ++++++++++++++++++++++-------------- 2 files changed, 23 insertions(+), 16 deletions(-) diff --git a/dtache-shell.el b/dtache-shell.el index 664929cf4c..9d73eb680f 100644 --- a/dtache-shell.el +++ b/dtache-shell.el @@ -133,8 +133,7 @@ cluttering the comint-history with dtach commands." dtache-shell-new-block-list) 'create dtache--dtach-mode)) - (session (dtache-create-session (substring-no-properties string))) - (dtach-command (dtache-dtach-command session t))) + (dtach-command (dtache-dtach-command (substring-no-properties string) t))) (comint-simple-send proc dtach-command) (comint-simple-send proc string)))) diff --git a/dtache.el b/dtache.el index af70718a43..364cf355ee 100644 --- a/dtache.el +++ b/dtache.el @@ -455,8 +455,7 @@ Optionally SUPPRESS-OUTPUT." (dtache-redirect-only-p command))) (let* ((inhibit-message t) (dtache--dtach-mode 'new) - (session (dtache-create-session command)) - (dtach-command (dtache-dtach-command session))) + (dtach-command (dtache-dtach-command command))) (apply #'start-file-process `("dtache" nil ,dtache-dtach-program ,@dtach-command))) (cl-letf* ((inhibit-message t) @@ -655,8 +654,17 @@ If session is not valid trigger an automatic cleanup on SESSION's host." (dtache--session-macos-monitor session) (dtache--session-filenotify-monitor session)))) -(defun dtache-dtach-command (session &optional concat) - "Return a list of arguments to run SESSION. +(cl-defgeneric dtache-dtach-command (entity &optional concat) + "Return dtach command for ENTITY optionally CONCAT.") + +(cl-defgeneric dtache-dtach-command ((command string) &optional concat) + "Return dtach command for COMMAND. + +Optionally CONCAT the command return command into a string." + (dtache-dtach-command (dtache-create-session command) concat)) + +(cl-defgeneric dtache-dtach-command ((session dtache-session) &optional concat) + "Return dtach command for SESSION. Optionally CONCAT the command return command into a string." (with-connection-local-variables @@ -674,16 +682,16 @@ Optionally CONCAT the command return command into a string." " ") `(,(dtache--dtach-arg) ,socket)) (if concat - (mapconcat 'identity - `(,dtache-dtach-program - ,(dtache--dtach-arg) - ,socket "-z" - ,dtache-shell-program "-c" - ,(shell-quote-argument (dtache--magic-command session))) - " ") - `(,(dtache--dtach-arg) ,socket "-z" - ,dtache-shell-program "-c" - ,(dtache--magic-command session))))))) + (mapconcat 'identity + `(,dtache-dtach-program + ,(dtache--dtach-arg) + ,socket "-z" + ,dtache-shell-program "-c" + ,(shell-quote-argument (dtache--magic-command session))) + " ") + `(,(dtache--dtach-arg) ,socket "-z" + ,dtache-shell-program "-c" + ,(dtache--magic-command session))))))) (defun dtache-redirect-only-p (command) "Return t if COMMAND should run in degreaded mode."