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

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

[elpa] externals/dtache 3ac8a5b8e8 1/6: Simplify setup for users


From: ELPA Syncer
Subject: [elpa] externals/dtache 3ac8a5b8e8 1/6: Simplify setup for users
Date: Sat, 22 Jan 2022 15:57:27 -0500 (EST)

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

    Simplify setup for users
    
    Keybindings are moved into the different library files.
---
 README.org       | 42 ++++++++++++++++--------------------------
 dtache-eshell.el | 18 +++++++++++-------
 dtache-shell.el  |  6 ++++++
 dtache.el        | 16 ++++++++++++++--
 4 files changed, 47 insertions(+), 35 deletions(-)

diff --git a/README.org b/README.org
index 2994db487f..3ef28dbc9d 100644
--- a/README.org
+++ b/README.org
@@ -63,9 +63,7 @@ A minimal configuration for =dtache=.
 #+begin_src elisp :lexical t :results none
   (use-package dtache
     :hook (after-init . dtache-setup)
-    :bind (([remap async-shell-command] . dtache-shell-command)
-           :map dtache-shell-mode-map
-           ("C-c C-q" . dtache-detach-session)))
+    :bind (([remap async-shell-command] . dtache-shell-command)))
 #+end_src
 
 * Commands
@@ -83,7 +81,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-shell-send-input= is for those that want to run a command through 
=dtache= when inside a =shell= buffer. The =dtache-eshell-send-input= is the 
equivalent for =eshell=. The =dtache-compile= is supposed to be used as a 
replacement for =compile=. Last there is the =dtache-start-session= function, 
which users can utilize in their o [...]
 
-To detach from a =dtache= session you should use the univeral 
=dtache-detach-dwim= command.
+To detach from a =dtache= session you should use the universal 
=dtache-detach-session= command. The keybinding for this command is defined by 
the =dtache-detach-key= variable, which by default has the value =C-c C-d=.
 
 ** Interacting with a session
 
@@ -125,21 +123,19 @@ A =use-package= configuration of the =dtache-shell= 
extension, which provides th
 
 #+begin_src elisp :lexical t :results none
   (use-package dtache-shell
-    :hook (after-init . dtache-shell-setup)
-    :bind (:map dtache-shell-mode-map
-           (("<S-return>" . dtache-shell-send-input)
-            ("<C-return>" . dtache-shell-attach-session)))
+    :after dtache
     :config
+    (dtache-shell-setup)
     (setq dtache-shell-history-file "~/.bash_history"))
 #+end_src
 
 A minor mode named =dtache-shell-mode= is provided, and will be enabled in 
=shell=. The commands that are implemented are:
 
-| Command                     | Description                  |
-|-----------------------------+------------------------------|
-| dtache-shell-send-input     | Run command with dtache      |
-| dtache-shell-attach-session | Attach to a dtache session   |
-| dtache-detach-session       | Detach from a dtache session |
+| Command                     | Description                  | Keybinding      
  |
+|-----------------------------+------------------------------+-------------------|
+| dtache-shell-send-input     | Run command with dtache      | <S-return>      
  |
+| dtache-shell-attach-session | Attach to a dtache session   | <C-return>      
  |
+| dtache-detach-session       | Detach from a dtache session | 
dtache-detach-key |
 
 ** Dtache-eshell
 
@@ -147,20 +143,16 @@ A =use-package= configuration of the =dtache-eshell= 
extension, which provides t
 
 #+begin_src elisp :lexical t :results none
   (use-package dtache-eshell
-    :hook (after-init . dtache-eshell-setup)
-    :bind (:map dtache-eshell-mode-map
-           (("<S-return>" . dtache-eshell-send-input)
-            ("<C-return>" . dtache-eshell-attach-session)
-            ("C-c C-q" . dtache-detach-session))))
+    :hook (eshell-mode . dtache-eshell-mode))
 #+end_src
 
 A minor mode named =dtache-eshell-mode= is provided, and will be enabled in 
=eshell=. The commands that are implemented are:
 
-| Command                      | Description                  |
-|------------------------------+------------------------------|
-| dtache-eshell-send-input     | Run command with dtache      |
-| dtache-eshell-attach-session | Attach to a dtache session   |
-| dtache-detach-session        | Detach from a dtache session |
+| Command                      | Description                  | Keybinding     
   |
+|------------------------------+------------------------------+-------------------|
+| dtache-eshell-send-input     | Run command with dtache      | <S-return>     
   |
+| dtache-eshell-attach-session | Attach to a dtache session   | <C-return>     
   |
+| dtache-detach-session        | Detach from a dtache session | 
dtache-detach-key |
 
 In this [[https://niklaseklund.gitlab.io/blog/posts/dtache_eshell/][blog 
post]] there are examples and more information about the extension.
 
@@ -172,9 +164,7 @@ A =use-package= configuration of the =dtache-compile= 
extension, which provides
   (use-package dtache-compile
     :hook (after-init . dtache-compile-setup)
     :bind (([remap compile] . dtache-compile)
-           ([remap recompile] . dtache-compile-recompile)
-           :map dtache-compilation-mode-map
-           ("C-c C-q" . dtache-detach-session)))
+           ([remap recompile] . dtache-compile-recompile)))
 #+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-eshell.el b/dtache-eshell.el
index b6186ed53e..c58b8c8f8c 100644
--- a/dtache-eshell.el
+++ b/dtache-eshell.el
@@ -42,13 +42,6 @@
 
 ;;;; Functions
 
-;;;###autoload
-(defun dtache-eshell-setup ()
-  "Setup `dtache-eshell'."
-  (dtache-setup)
-  (add-hook 'eshell-prepare-command-hook #'dtache-eshell--maybe-create-session)
-  (add-hook 'eshell-mode-hook #'dtache-eshell-mode))
-
 (defun dtache-eshell-select-session ()
   "Return selected session."
   (let* ((host-name (car (dtache--host)))
@@ -121,6 +114,14 @@ If prefix-argument directly DETACH from the session."
 
 ;;;; Minor mode
 
+(defvar dtache-eshell-mode-map
+  (let ((map (make-sparse-keymap)))
+    (define-key map (kbd "<S-return>") #'dtache-eshell-send-input)
+    (define-key map (kbd "<C-return>") #'dtache-eshell-attach-session)
+    (define-key map (kbd dtache-detach-key) #'dtache-detach-session)
+    map)
+  "Keymap for `dtache-eshell-mode'.")
+
 ;;;###autoload
 (define-minor-mode dtache-eshell-mode
   "Integrate `dtache' in `eshell-mode'."
@@ -130,8 +131,11 @@ If prefix-argument directly DETACH from the session."
   (make-local-variable 'eshell-preoutput-filter-functions)
   (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)))
 
diff --git a/dtache-shell.el b/dtache-shell.el
index d3069b0266..890a67d89a 100644
--- a/dtache-shell.el
+++ b/dtache-shell.el
@@ -141,6 +141,12 @@ This function also makes sure that the HISTFILE is 
disabled for local shells."
   "Add hook to save history when killing `shell' buffer."
   (add-hook 'kill-buffer-hook #'dtache-shell--save-history 0 t))
 
+;;;; Minor mode
+
+(let ((map dtache-shell-mode-map))
+  (define-key map (kbd "<S-return>") #'dtache-shell-send-input)
+  (define-key map (kbd "<C-return>") #'dtache-shell-attach-session))
+
 (provide 'dtache-shell)
 
 ;;; dtache-shell.el ends here
diff --git a/dtache.el b/dtache.el
index 209c4945fe..97cc733f4d 100644
--- a/dtache.el
+++ b/dtache.el
@@ -121,6 +121,11 @@
   :type 'function
   :group 'dtache)
 
+(defcustom dtache-detach-key "C-c C-d"
+  "Variable to set the keybinding for detaching."
+  :type 'string
+  :group 'dtache)
+
 ;;;;; Public
 
 (defvar dtache-enabled nil)
@@ -619,8 +624,9 @@ Optionally SUPPRESS-OUTPUT."
                  (seq-uniq)
                  (seq-do #'dtache--watch-session-directory))
 
-    ;; Add hooks
-    (add-hook 'shell-mode-hook #'dtache-shell-mode)))
+    ;; Other
+    (add-hook 'shell-mode-hook #'dtache-shell-mode)
+    (global-set-key (kbd dtache-detach-key) #'dtache-detach-session)))
 
 (defun dtache-valid-session (session)
   "Ensure that SESSION is valid.
@@ -1191,6 +1197,12 @@ session and trigger a state transition."
 
 ;;;; Minor modes
 
+(defvar dtache-shell-mode-map
+  (let ((map (make-sparse-keymap)))
+    (define-key map (kbd dtache-detach-key) #'dtache-detach-session)
+    map)
+  "Keymap for `dtache-shell-mode'.")
+
 ;;;###autoload
 (define-minor-mode dtache-shell-mode
   "Integrate `dtache' in `shell-mode'."



reply via email to

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