branch: externals/dtache commit 82e5859d5a1abd1e91cd342dbb39fe72c9fb870f Author: Niklas Eklund <niklas.ekl...@posteo.net> Commit: Niklas Eklund <niklas.ekl...@posteo.net>
Improve dtache-detach-session This patch renames dtache-detach-session to dtache-detach-dwim. It also improves the function by making it possible to kill buffers with non active sessions, as long as the buffers originate from dtache-shell-command or dtache-compile. --- CHANELOG.org | 2 +- README.org | 12 ++++++------ dtache.el | 45 +++++++++++++++++++++++++-------------------- 3 files changed, 32 insertions(+), 27 deletions(-) diff --git a/CHANELOG.org b/CHANELOG.org index 21b066228f..bbf7b42afa 100644 --- a/CHANELOG.org +++ b/CHANELOG.org @@ -5,7 +5,7 @@ * Development - Add dtache-type-open-dispatch variable for users to customize how to open a function which doesn't have an open function implemented. This together with the new attach functions for shell-command/compile makes it possible to seamlessly reattach to sessions started with shell-command/compile. -- Add a generic detach command, =dtache-detach-session=. This command is supposed to be used to detach from sessions in all supported modes. +- Add a generic detach command, =dtache-detach-dwim=. This command is supposed to be used to detach from sessions in all supported modes. - Add =dtache-compile.el=. This library provides commands =dtache-compile= and =dtache-compile-recompile= which are supposed to be used instead of =compile=/=recompile=. - Improve =dtache-shell-command=, the command is now very similar to =async-shell-command= and can be considered a replacement of the latter. - Add integration with the =consult= package through =dtache-consult.el=. diff --git a/README.org b/README.org index 7580439638..f0d6b93a12 100644 --- a/README.org +++ b/README.org @@ -60,7 +60,7 @@ A minimal configuration for =dtache=. :hook (after-init . dtache-initialize) :bind (([remap async-shell-command] . dtache-shell-command) :map dtache-shell-mode-map - ("C-c C-q" . dtache-detach-session))) + ("C-c C-q" . dtache-detach-dwim))) #+end_src * Commands @@ -78,7 +78,7 @@ There are tree different ways to create a dtache session. The =dtache-shell-command= is for the Emacs users that are accustomed to running shell commands from =M-x shell-command= or =M-x async-shell-command=. The =dtache-start-session= is supposed to be called from custom user functions, or for other packages to integrate towards. The user can also choose to override built in functions with it, for example =compile=. Lastly there is the =dtache-shell-create-session= command which is supposed to be bound to a key. It is a command that the user c [...] -To detach from a =dtache= session you should use the univeral =dtache-detach-session=. +To detach from a =dtache= session you should use the univeral =dtache-detach-dwim=. ** Interacting with a session @@ -133,7 +133,7 @@ A minor mode named =dtache-shell-mode= is provided, and will be enabled in =shel |-----------------------+-----------------------| | dtache-shell-create | Create a session | | dtache-shell-attach | Attach to a session | -| dtache-detach-session | Detach from a session | +| dtache-detach-dwim | Detach from a session | ** Dtache-eshell @@ -145,7 +145,7 @@ A =use-package= configuration of the =dtache-eshell= extension, which provides t :bind (:map dtache-eshell-mode-map (("<S-return>" . dtache-eshell-create-session) ("<C-return>" . dtache-eshell-attach) - ("C-c C-q" . dtache-detach-session)))) + ("C-c C-q" . dtache-detach-dwim)))) #+end_src A minor mode named =dtache-eshell-mode= is provided, and will be enabled in =eshell=. The commands that are implemented are: @@ -154,7 +154,7 @@ A minor mode named =dtache-eshell-mode= is provided, and will be enabled in =esh |------------------------------+-----------------------| | dtache-eshell-create-session | Create a session | | dtache-eshell-attach | Attach to a session | -| dtache-detach-session | Detach from a session | +| dtache-detach-dwim | Detach from a session | In this [[https://niklaseklund.gitlab.io/blog/posts/dtache_eshell/][blog post]] there are examples and more information about the extension. @@ -168,7 +168,7 @@ A =use-package= configuration of the =dtache-compile= extension, which provides :bind (([remap compile] . dtache-compile) ([remap recompile] . dtache-compile-recompile) :map dtache-compilation-mode-map - ("C-c C-q" . dtache-detach-session))) + ("C-c C-q" . dtache-detach-dwim))) #+end_src The package implements the commands =dtache-compile= and =dtache-compile-recompile=, which are thin wrappers around the original =compile= and =recompile= commands. The users should be able to use the former as replacements for the latter without noticing any difference except from the possibility to =detach=. diff --git a/dtache.el b/dtache.el index bb754efbb9..108e710f0c 100644 --- a/dtache.el +++ b/dtache.el @@ -375,32 +375,37 @@ Optionally SUPPRESS-OUTPUT." (ediff-buffers buffer1 buffer2)))) ;;;###autoload -(defun dtache-detach-session () +(defun dtache-detach-dwim () "Detach from current session. This command is only activated if `dtache--buffer-session' is set and `dtache--session-active-p' returns t." (interactive) (if (dtache-session-p dtache--buffer-session) - (if (dtache--session-active-p dtache--buffer-session) - (if-let ((process (and (eq major-mode 'eshell-mode) - (dtache-eshell-get-dtach-process)))) - (progn - (setq dtache--buffer-session nil) - (process-send-string process dtache--dtach-detach-character)) - (let ((proc (get-buffer-process (current-buffer))) - (input dtache--dtach-detach-character)) - (comint-simple-send proc input) - (setq dtache--buffer-session nil) - (when - (cond ((string-match "\*Dtache Shell Command" (buffer-name)) t) - ((string-match "\*dtache-compilation" (buffer-name)) t) - (t nil)) - (let ((kill-buffer-query-functions nil)) - (kill-buffer-and-window) - (message "[detached]"))))) - (setq dtache--buffer-session nil)) - (message "No `dtache-session' found in buffer."))) + (if-let ((command-or-compile + (cond ((string-match "\*Dtache Shell Command" (buffer-name)) t) + ((string-match "\*dtache-compilation" (buffer-name)) t) + (t nil)))) + ;; `dtache-shell-command' or `dtache-compile' + (let ((kill-buffer-query-functions nil)) + (when-let ((process (get-buffer-process (current-buffer)))) + (comint-simple-send process dtache--dtach-detach-character)) + (setq dtache--buffer-session nil) + (kill-buffer-and-window) + (message "[detached]")) + (if (dtache--session-active-p dtache--buffer-session) + ;; `dtache-eshell' + (if-let ((process (and (eq major-mode 'eshell-mode) + (dtache-eshell-get-dtach-process)))) + (progn + (setq dtache--buffer-session nil) + (process-send-string process dtache--dtach-detach-character)) + ;; `dtache-shell' + (let ((process (get-buffer-process (current-buffer)))) + (comint-simple-send process dtache--dtach-detach-character) + (setq dtache--buffer-session nil))) + (message "No active dtache-session found in buffer."))) + (message "No dtache-session found in buffer."))) ;;;###autoload (defun dtache-quit-tail-output ()