[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/dtache f73aa7ef98 089/158: Cleanup dtache-shell
From: |
ELPA Syncer |
Subject: |
[elpa] externals/dtache f73aa7ef98 089/158: Cleanup dtache-shell |
Date: |
Wed, 19 Jan 2022 18:58:01 -0500 (EST) |
branch: externals/dtache
commit f73aa7ef98de1801b33fb52b1639625067d66357
Author: Niklas Eklund <niklas.eklund@posteo.net>
Commit: Niklas Eklund <niklas.eklund@posteo.net>
Cleanup dtache-shell
---
dtache-shell.el | 33 ++++++++-------------------------
dtache.el | 44 ++++++++++++++++++++++++++++----------------
2 files changed, 36 insertions(+), 41 deletions(-)
diff --git a/dtache-shell.el b/dtache-shell.el
index e4043c5c1a..4fae7c4ea2 100644
--- a/dtache-shell.el
+++ b/dtache-shell.el
@@ -31,17 +31,9 @@
(defvar dtache-shell-history-file nil
"File to store history.")
-(defvar dtache-shell-block-list '("^$")
- "A list of regexps to block non-supported input.")
-(defvar dtache-shell-new-block-list '("^sudo.*")
- "A list of regexps to block from creating a session without attaching.")
(defvar dtache-shell-session-action '(:attach dtache-shell-command-attach
:view dtache-view-dwim)
"Actions for a session created with `dtache-shell'.")
-;;;;; Private
-
-(defvar dtache-shell--current-session nil "The current session.")
-
;;;; Functions
(defun dtache-shell-override-history (orig-fun &rest args)
@@ -95,7 +87,7 @@ cluttering the comint-history with dtach commands."
(when (dtache-valid-session session)
(if (and (dtache--session-active-p session)
(not (dtache--session-redirect-only session)))
- (cl-letf ((dtache-shell--current-session session)
+ (cl-letf ((dtache--current-session session)
(comint-input-sender #'dtache-shell--attach-input-sender)
((symbol-function 'comint-add-to-input-history) (lambda (_)
t)))
(setq dtache--buffer-session session)
@@ -109,27 +101,18 @@ cluttering the comint-history with dtach commands."
"Attach to `dtache--session' and send the attach command to PROC."
(let* ((dtache-session-mode 'attach)
(input
- (dtache-dtach-command dtache-shell--current-session t)))
+ (dtache-dtach-command dtache--current-session t)))
(comint-simple-send proc input)))
(defun dtache-shell--create-input-sender (proc string)
"Create a dtache session based on STRING and send to PROC."
(with-connection-local-variables
- (if-let* ((supported-input
- (not (seq-find
- (lambda (blocked)
- (string-match-p blocked string))
- dtache-shell-block-list)))
- (dtache-session-mode
- (if (seq-find
- (lambda (blocked)
- (string-match-p blocked string))
- dtache-shell-new-block-list)
- 'create
- dtache-session-mode))
- (dtach-command (dtache-dtach-command (substring-no-properties
string) t)))
- (comint-simple-send proc dtach-command)
- (comint-simple-send proc string))))
+ (let* ((command (substring-no-properties string))
+ (dtache-session-mode (if (dtache-redirect-only-p command)
+ 'new
+ 'create))
+ (dtach-command (dtache-dtach-command command t)))
+ (comint-simple-send proc dtach-command))))
(defun dtache-shell--comint-read-input-ring-advice (orig-fun &rest args)
"Set `comint-input-ring-file-name' before calling ORIG-FUN with ARGS."
diff --git a/dtache.el b/dtache.el
index 207c60bdd3..cea1bda1bf 100644
--- a/dtache.el
+++ b/dtache.el
@@ -229,14 +229,8 @@ Optionally SUPPRESS-OUTPUT."
(list (dtache-completing-read (dtache-get-sessions))))
(when (dtache-valid-session session)
(if (dtache--session-active-p session)
- (if (dtache--session-redirect-only session)
- (dtache-tail-output session)
- (let ((attach (or (plist-get (dtache--session-action session)
:attach)
- #'dtache-tail-output)))
- (funcall attach session)))
- (let ((view (or (plist-get (dtache--session-action session) :view)
- #'dtache-view-dwim)))
- (funcall view session)))))
+ (dtache-attach-session session)
+ (dtache-view-session session))))
;;;###autoload
(defun dtache-post-compile-session (session)
@@ -453,15 +447,13 @@ Optionally SUPPRESS-OUTPUT."
(or dtache--current-session
(dtache-create-session command))))
(if-let ((run-in-background
- (and (not (eq dtache-session-mode 'attach))
- (or suppress-output
+ (and (or suppress-output
(eq dtache-session-mode 'new)
(dtache--session-redirect-only
dtache--current-session))))
(dtache-session-mode 'new))
- (apply #'start-file-process-shell-command
- `("dtache" nil ,command))
- (cl-letf* (((symbol-function #'set-process-sentinel) #'ignore)
- (dtache-session-mode (or dtache-session-mode 'create))
+ (apply #'start-file-process-shell-command `("dtache" nil ,command))
+ (cl-letf* ((dtache-session-mode 'create)
+ ((symbol-function #'set-process-sentinel) #'ignore)
(buffer "*Dtache Shell Command*"))
(funcall #'async-shell-command command buffer)
(with-current-buffer buffer (setq dtache--buffer-session
dtache--current-session))))))
@@ -637,14 +629,34 @@ If session is not valid trigger an automatic cleanup on
SESSION's host."
"Attach to `dtache' SESSION."
(when (dtache-valid-session session)
(let* ((dtache--current-session session)
- (dtache-session-mode 'attach))
- (dtache-start-session (dtache--session-command session)))))
+ (dtache-session-mode 'attach)
+ (inhibit-message t))
+ (if (dtache--session-redirect-only session)
+ (dtache-attach-session session)
+ (cl-letf* (((symbol-function #'set-process-sentinel) #'ignore)
+ (buffer "*Dtache Shell Command*"))
+ (funcall #'async-shell-command (dtache--session-command session)
buffer)
+ (with-current-buffer buffer (setq dtache--buffer-session
dtache--current-session)))))))
(defun dtache-delete-sessions ()
"Delete all `dtache' sessions."
(seq-do #'dtache--db-remove-entry
(dtache-get-sessions)))
+(defun dtache-attach-session (session)
+ "Attach to SESSION."
+ (if (dtache--session-redirect-only session)
+ (dtache-tail-output session)
+ (if-let ((attach-fun (plist-get (dtache--session-action session) :attach)))
+ (funcall attach-fun session)
+ (dtache-tail-output session))))
+
+(defun dtache-view-session (session)
+ "View SESSION."
+ (if-let ((view-fun (plist-get (dtache--session-action session) :view)))
+ (funcall view-fun session)
+ (dtache-view-dwim session)))
+
;;;;; Other
(defun dtache-start-process-advice (start-process-fun name buffer &rest args)
- [elpa] externals/dtache a36e89486f 055/158: Add package dtache-eshell, (continued)
- [elpa] externals/dtache a36e89486f 055/158: Add package dtache-eshell, ELPA Syncer, 2022/01/19
- [elpa] externals/dtache eab014faad 050/158: Version 0.2, ELPA Syncer, 2022/01/19
- [elpa] externals/dtache 9a2f4a4d43 057/158: Introduce caching variable for candidates, ELPA Syncer, 2022/01/19
- [elpa] externals/dtache 02b93a3778 060/158: Minor cleanup, ELPA Syncer, 2022/01/19
- [elpa] externals/dtache d693d4c386 065/158: Update README with links to blog posts, ELPA Syncer, 2022/01/19
- [elpa] externals/dtache 69b001d0e5 069/158: Make eshell-preoutput-filter-functions local, ELPA Syncer, 2022/01/19
- [elpa] externals/dtache be23732c84 079/158: Update documentation in README, ELPA Syncer, 2022/01/19
- [elpa] externals/dtache 2e5a097da4 080/158: Implement dtache-compile-open, ELPA Syncer, 2022/01/19
- [elpa] externals/dtache c09328ca1e 081/158: Add actions to a session, ELPA Syncer, 2022/01/19
- [elpa] externals/dtache 82e5859d5a 098/158: Improve dtache-detach-session, ELPA Syncer, 2022/01/19
- [elpa] externals/dtache f73aa7ef98 089/158: Cleanup dtache-shell,
ELPA Syncer <=
- [elpa] externals/dtache 71966f0d2f 099/158: Add run as an action property, ELPA Syncer, 2022/01/19
- [elpa] externals/dtache 5831137cf7 101/158: Rename dtache-initialize to dtache-setup, ELPA Syncer, 2022/01/19
- [elpa] externals/dtache 9746f4713c 106/158: Rename session-directory to log-directory, ELPA Syncer, 2022/01/19
- [elpa] externals/dtache c6aece77d2 113/158: Enhance dtache-detach-dwim command, ELPA Syncer, 2022/01/19
- [elpa] externals/dtache bf71be0eae 118/158: Change output-size to log-size, ELPA Syncer, 2022/01/19
- [elpa] externals/dtache f77c57f608 120/158: Update duration part 2, ELPA Syncer, 2022/01/19
- [elpa] externals/dtache c8a99aed35 123/158: Add version to the dtache database, ELPA Syncer, 2022/01/19
- [elpa] externals/dtache 4fa1c9e8a2 134/158: Simplify call to dtache--dtach-arg, ELPA Syncer, 2022/01/19
- [elpa] externals/dtache 3942dc6326 135/158: Remove unnecessary checks for dtache-session-mode, ELPA Syncer, 2022/01/19
- [elpa] externals/dtache 3aa5babca5 139/158: Update table formatting, ELPA Syncer, 2022/01/19