emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/dtache bdbd007caf: Improve dtache integration with eshe


From: ELPA Syncer
Subject: [elpa] externals/dtache bdbd007caf: Improve dtache integration with eshell
Date: Sat, 19 Mar 2022 10:57:38 -0400 (EDT)

branch: externals/dtache
commit bdbd007caf16002b2b46edb7c19123195d1f91af
Author: Niklas Eklund <niklas.eklund@posteo.net>
Commit: Niklas Eklund <niklas.eklund@posteo.net>

    Improve dtache integration with eshell
    
    This commit changes the integration towards eshell. Instead of relying
    on a hook we are using and advice. With the advice we can target the
    eshell-external-command function, which should be called with data
    that is supposed to be run by an external shell. By integrating on
    this level we make sure that eshell aliases have been expanded.
---
 CHANGELOG.org    |  3 ++-
 README.org       |  4 +++-
 dtache-eshell.el | 36 +++++++++++++++++++++---------------
 3 files changed, 26 insertions(+), 17 deletions(-)

diff --git a/CHANGELOG.org b/CHANGELOG.org
index f445249aa8..8337e13590 100644
--- a/CHANGELOG.org
+++ b/CHANGELOG.org
@@ -4,7 +4,8 @@
 
 * Development
 
-- Example configuration for =dtache= integration with =vterm= added.
+- Eshell integration has been updated. The package now supports expansion of 
=eshell= aliases. However =dtache= will no longer run if commands are =elisp= 
functions.
+  - Example configuration for =dtache= integration with =vterm= added.
 - The package now uses =ansi-color= to handle ANSI escape sequences. This 
feature is enabled by default but can be turned of if 
=dtache-filter-ansi-sequences= is set to nil.
 
 * Version 0.5 (2022-02-02)
diff --git a/README.org b/README.org
index 3dd8f39048..c86be85b2b 100644
--- a/README.org
+++ b/README.org
@@ -149,7 +149,9 @@ A =use-package= configuration of the =dtache-eshell= 
extension, which provides t
 
 #+begin_src elisp :lexical t :results none
   (use-package dtache-eshell
-    :hook (eshell-mode . dtache-eshell-mode))
+    :after (eshell dtache)
+    :config
+    (dtache-eshell-setup))
 #+end_src
 
 A minor mode named =dtache-eshell-mode= is provided, and will be enabled in 
=eshell=. The commands that are implemented are:
diff --git a/dtache-eshell.el b/dtache-eshell.el
index c0079a0d04..e375e028fe 100644
--- a/dtache-eshell.el
+++ b/dtache-eshell.el
@@ -28,6 +28,7 @@
 (require 'dtache)
 (require 'eshell)
 (require 'esh-mode)
+(require 'esh-ext)
 (require 'em-hist)
 
 ;;;; Variables
@@ -58,6 +59,13 @@
     (and (string= (process-name process) "dtach")
          process)))
 
+;;;###autoload
+(defun dtache-eshell-setup ()
+  "Setup `dtache-eshell'."
+  (dtache-setup)
+  (add-hook 'eshell-mode-hook #'dtache-eshell-mode)
+  (advice-add #'eshell-external-command :around 
#'dtache-eshell--external-command))
+
 ;;;; Commands
 
 ;;;###autoload
@@ -98,19 +106,19 @@ If prefix-argument directly DETACH from the session."
 
 ;;;; Support functions
 
-(defun dtache-eshell--maybe-create-session ()
-  "Create a session if `dtache-eshell-command' value is t."
-  (when dtache-enabled
-    (let* ((dtache-session-action dtache-eshell-session-action)
-           (command (mapconcat #'identity
-                               `(,eshell-last-command-name
-                                 ,@eshell-last-arguments)
-                               " "))
-           (session (dtache-create-session command)))
-      (setq eshell-last-arguments (dtache-dtach-command session))
-      (setq dtache--buffer-session session)
-      (setq dtache-enabled nil)
-      (setq eshell-last-command-name "dtach"))))
+(defun dtache-eshell--external-command (orig-fun &rest args)
+  "Advice `eshell-external-command' to optionally use `dtache'."
+  (if dtache-enabled
+      (let* ((dtache-session-action dtache-eshell-session-action)
+             (command (string-trim-right
+                       (mapconcat #'identity
+                                  (flatten-list args)
+                                  " ")))
+             (session (dtache-create-session command)))
+        (setq dtache--buffer-session session)
+        (setq dtache-enabled nil)
+        (apply orig-fun `(,dtache-dtach-program ,(dtache-dtach-command 
session))))
+    (apply orig-fun args)))
 
 ;;;; Minor mode
 
@@ -132,10 +140,8 @@ If prefix-argument directly DETACH from the session."
   (if dtache-eshell-mode
       (progn
         (dtache-setup)
-        (add-hook 'eshell-prepare-command-hook 
#'dtache-eshell--maybe-create-session)
         (add-hook 'eshell-preoutput-filter-functions 
#'dtache--dtache-env-message-filter)
         (add-hook 'eshell-preoutput-filter-functions 
#'dtache--dtach-eof-message-filter))
-    (remove-hook 'eshell-prepare-command-hook 
#'dtache-eshell--maybe-create-session)
     (remove-hook 'eshell-preoutput-filter-functions 
#'dtache--dtache-env-message-filter)
     (remove-hook 'eshell-preoutput-filter-functions 
#'dtache--dtach-eof-message-filter)))
 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]