branch: externals/detached commit c34005564459c656fcb0d54b7aceb66aa72e8dd7 Author: Niklas Eklund <niklas.ekl...@posteo.net> Commit: Niklas Eklund <niklas.ekl...@posteo.net>
Make functions private in detached-.*.el files --- detached-compile.el | 12 ++--------- detached-eshell.el | 60 ++++++++++++++++++++++++++--------------------------- detached-init.el | 42 +++++++++++++++++++------------------ detached-shell.el | 56 ++++++++++++++++++++++++------------------------- detached-vterm.el | 19 ++++++++++++----- detached.el | 4 ++-- 6 files changed, 98 insertions(+), 95 deletions(-) diff --git a/detached-compile.el b/detached-compile.el index 4847b91395..fe9a8ddd4e 100644 --- a/detached-compile.el +++ b/detached-compile.el @@ -84,16 +84,10 @@ Optionally EDIT-COMMAND." (detached--session-working-directory session))) (compilation-start (detached--session-command session))))) -;;;###autoload -(defun detached-compile-open (session) - "Open SESSION with `detached-compile'." - (when (detached-valid-session session) - (if (eq 'active (detached--session-state session)) - (detached-compile-attach session) - (detached-compile-session session)))) +;;;;; Support functions ;;;###autoload -(defun detached-compile-start (_) +(defun detached-compile--start (_) "Run in `compilation-start-hook' if `detached-enabled'." (when detached-enabled (setq detached--buffer-session detached--current-session) @@ -103,8 +97,6 @@ Optionally EDIT-COMMAND." (add-hook 'comint-preoutput-filter-functions #'detached--env-message-filter 0 t) (add-hook 'comint-preoutput-filter-functions #'detached--dtach-eof-message-filter 0 t))) -;;;;; Support functions - (defun detached-compile--compilation-start (compilation-start &rest args) "Create a `detached' session before running COMPILATION-START with ARGS." (if detached-enabled diff --git a/detached-eshell.el b/detached-eshell.el index adc0ca11ce..68b88aaf89 100644 --- a/detached-eshell.el +++ b/detached-eshell.el @@ -43,21 +43,20 @@ ;;;; Functions -(defun detached-eshell-select-session () - "Return selected session." - (let* ((host-name (car (detached--host))) - (sessions - (thread-last (detached-get-sessions) - (seq-filter (lambda (it) - (string= (car (detached--session-host it)) host-name))) - (seq-filter (lambda (it) (eq 'active (detached--determine-session-state it))))))) - (detached-completing-read sessions))) - -(defun detached-eshell-get-dtach-process () - "Return `eshell' process if `detached' is running." - (when-let* ((process (and eshell-process-list (caar eshell-process-list)))) - (and (string= (process-name process) "dtach") - process))) +;;;###autoload +(defun detached-eshell-external-command (orig-fun &rest args) + "Advice `eshell-external-command' to optionally use `detached'." + (let* ((detached-session-action detached-eshell-session-action) + (command (string-trim-right + (mapconcat #'identity + (flatten-list args) + " "))) + (session (detached-create-session command)) + (command (detached--shell-command session))) + (advice-remove #'eshell-external-command #'detached-eshell-external-command) + (setq detached--buffer-session session) + (setq detached-enabled nil) + (apply orig-fun `(,(seq-first command) ,(seq-rest command))))) ;;;; Commands @@ -78,7 +77,7 @@ If prefix-argument directly DETACH from the session." (defun detached-eshell-attach-session (session) "Attach to SESSION." (interactive - (list (detached-eshell-select-session))) + (list (detached-eshell--select-session))) (when (detached-valid-session session) (if (eq 'active (detached--determine-session-state session)) (cl-letf* ((detached-session-mode 'attach) @@ -101,20 +100,21 @@ If prefix-argument directly DETACH from the session." ;;;; Support functions -;;;###autoload -(defun detached-eshell-external-command (orig-fun &rest args) - "Advice `eshell-external-command' to optionally use `detached'." - (let* ((detached-session-action detached-eshell-session-action) - (command (string-trim-right - (mapconcat #'identity - (flatten-list args) - " "))) - (session (detached-create-session command)) - (command (detached--shell-command session))) - (advice-remove #'eshell-external-command #'detached-eshell-external-command) - (setq detached--buffer-session session) - (setq detached-enabled nil) - (apply orig-fun `(,(seq-first command) ,(seq-rest command))))) +(defun detached-eshell--get-dtach-process () + "Return `eshell' process if `detached' is running." + (when-let* ((process (and eshell-process-list (caar eshell-process-list)))) + (and (string= (process-name process) "dtach") + process))) + +(defun detached-eshell--select-session () + "Return selected session." + (let* ((host-name (car (detached--host))) + (sessions + (thread-last (detached-get-sessions) + (seq-filter (lambda (it) + (string= (car (detached--session-host it)) host-name))) + (seq-filter (lambda (it) (eq 'active (detached--determine-session-state it))))))) + (detached-completing-read sessions))) ;;;; Minor mode diff --git a/detached-init.el b/detached-init.el index aa9e3c9ea9..f258329388 100644 --- a/detached-init.el +++ b/detached-init.el @@ -40,7 +40,7 @@ (declare-function detached-diff-session "detached") (declare-function detached-shell-mode "detached") -(declare-function detached-compile-start "detached-compile") +(declare-function detached-compile--start "detached-compile") (declare-function detached-dired-do-shell-command "detached-dired") (declare-function detached-eshell-mode "detached-eshell") (declare-function detached-extra-projectile-run-compilation "detached-extra") @@ -89,15 +89,15 @@ ;;;; Support functions -(defvar detached-init--package-integration '((compile . detached-init-compile) - (dired . detached-init-dired) - (dired-rsync . detached-init-dired-rsync) - (embark . detached-init-embark) - (eshell . detached-init-eshell) - (org . detached-init-org) - (projectile . detached-init-projectile) - (shell . detached-init-shell) - (vterm . detached-init-vterm)) +(defvar detached-init--package-integration '((compile . detached-init--compile) + (dired . detached-init--dired) + (dired-rsync . detached-init--dired-rsync) + (embark . detached-init--embark) + (eshell . detached-init--eshell) + (org . detached-init--org) + (projectile . detached-init--projectile) + (shell . detached-init--shell) + (vterm . detached-init--vterm)) "Alist which contain names of packages and their initialization function.") ;;;; Functions @@ -119,45 +119,47 @@ (dolist (init-function init-functions) (funcall init-function)))) -(defun detached-init-shell () +;;;; Support functions + +(defun detached-init--shell () "Initialize integration with `shell'." (advice-add #'shell :around #'detached-shell-override-history) (add-hook 'shell-mode-hook #'detached-shell-save-history-on-kill)) -(defun detached-init-compile () +(defun detached-init--compile () "Initialize integration with `compile'." - (add-hook 'compilation-start-hook #'detached-compile-start) + (add-hook 'compilation-start-hook #'detached-compile--start) (add-hook 'compilation-shell-minor-mode-hook #'detached-shell-mode)) -(defun detached-init-eshell () +(defun detached-init--eshell () "Initialize integration with `eshell'." (add-hook 'eshell-mode-hook #'detached-eshell-mode)) -(defun detached-init-org () +(defun detached-init--org () "Initialize integration with `org'." (advice-add #'org-babel-sh-evaluate :around #'detached-org-babel-sh)) -(defun detached-init-dired () +(defun detached-init--dired () "Initialize integration with `dired'." (advice-add 'dired-do-shell-command :around #'detached-dired-do-shell-command)) -(defun detached-init-dired-rsync () +(defun detached-init--dired-rsync () "Initialize integration with `dired-rsync'." (when (functionp #'dired-rsync) (advice-add #'dired-rsync--do-run :override #'detached-extra-dired-rsync))) -(defun detached-init-projectile () +(defun detached-init--projectile () "Initialize integration with `projectile'." (when (functionp #'projectile) (advice-add 'projectile-run-compilation :override #'detached-extra-projectile-run-compilation))) -(defun detached-init-vterm () +(defun detached-init--vterm () "Initialize integration with `vterm'." (when (functionp #'vterm) (add-hook 'vterm-mode-hook #'detached-vterm-mode))) -(defun detached-init-embark () +(defun detached-init--embark () "Initialize integration with `embark'." (with-eval-after-load 'embark (defvar embark-detached-map (make-composed-keymap detached-action-map embark-general-map)) diff --git a/detached-shell.el b/detached-shell.el index e3b9e5bfff..56d3f33e72 100644 --- a/detached-shell.el +++ b/detached-shell.el @@ -39,15 +39,22 @@ ;;;; Functions -(defun detached-shell-select-session () - "Return selected session." - (let* ((host-name (car (detached--host))) - (sessions - (thread-last (detached-get-sessions) - (seq-filter (lambda (it) - (string= (car (detached--session-host it)) host-name))) - (seq-filter (lambda (it) (eq 'active (detached--determine-session-state it))))))) - (detached-completing-read sessions))) +;;;###autoload +(defun detached-shell-override-history (orig-fun &rest args) + "Override history in ORIG-FUN with ARGS. + +This function also makes sure that the HISTFILE is disabled for local shells." + (cl-letf (((getenv "HISTFILE") "")) + (advice-add 'comint-read-input-ring :around #'detached-shell--comint-read-input-ring-advice) + (apply (if (called-interactively-p 'any) + #'funcall-interactively #'funcall) + orig-fun + args))) + +;;;###autoload +(defun detached-shell-save-history-on-kill () + "Add hook to save history when killing `shell' buffer." + (add-hook 'kill-buffer-hook #'detached-shell--save-history 0 t)) ;;;; Commands @@ -66,9 +73,9 @@ "Attach to SESSION. `comint-add-to-input-history' is temporarily disabled to avoid -cluttering the comint-history with dtach commands." +cluttering the `comint-history' with dtach commands." (interactive - (list (detached-shell-select-session))) + (list (detached-shell--select-session))) (when (detached-valid-session session) (if (eq 'active (detached--determine-session-state session)) (cl-letf ((detached--current-session session) @@ -83,6 +90,16 @@ cluttering the comint-history with dtach commands." ;;;; Support functions +(defun detached-shell--select-session () + "Return selected session." + (let* ((host-name (car (detached--host))) + (sessions + (thread-last (detached-get-sessions) + (seq-filter (lambda (it) + (string= (car (detached--session-host it)) host-name))) + (seq-filter (lambda (it) (eq 'active (detached--determine-session-state it))))))) + (detached-completing-read sessions))) + (defun detached-shell--attach-input-sender (proc _string) "Attach to `detached--session' and send the attach command to PROC." (let* ((detached-session-mode 'attach) @@ -119,23 +136,6 @@ cluttering the comint-history with dtach commands." (let* ((inhibit-message t)) (comint-write-input-ring)))) -;;;###autoload -(defun detached-shell-override-history (orig-fun &rest args) - "Override history in ORIG-FUN with ARGS. - -This function also makes sure that the HISTFILE is disabled for local shells." - (cl-letf (((getenv "HISTFILE") "")) - (advice-add 'comint-read-input-ring :around #'detached-shell--comint-read-input-ring-advice) - (apply (if (called-interactively-p 'any) - #'funcall-interactively #'funcall) - orig-fun - args))) - -;;;###autoload -(defun detached-shell-save-history-on-kill () - "Add hook to save history when killing `shell' buffer." - (add-hook 'kill-buffer-hook #'detached-shell--save-history 0 t)) - ;;;; Minor mode (let ((map detached-shell-mode-map)) diff --git a/detached-vterm.el b/detached-vterm.el index 71357d247a..05b0ef01be 100644 --- a/detached-vterm.el +++ b/detached-vterm.el @@ -35,6 +35,16 @@ (defvar vterm--process) +;;;; Variables + +(defcustom detached-vterm-session-action + '(:attach detached-shell-command-attach-session + :view detached-view-dwim + :run detached-shell-command) + "Actions for a session created with `detached-vterm'." + :group 'detached + :type 'plist) + ;;;; Commands ;;;###autoload @@ -46,10 +56,7 @@ Optionally DETACH from it." (vterm-send-C-a) (let* ((input (buffer-substring-no-properties (point) (vterm-end-of-line))) (detached-session-origin 'vterm) - (detached-session-action - '(:attach detached-shell-command-attach-session - :view detached-view-dwim - :run detached-shell-command)) + (detached-session-action detached-vterm-session-action) (detached-session-mode (if detach 'create 'create-and-attach))) (vterm-send-C-k) @@ -77,7 +84,9 @@ Optionally DETACH from it." (defun detached-vterm-detach () "Detach from a `detached' session." (interactive) - (process-send-string vterm--process detached--dtach-detach-character)) + (process-send-string + vterm--process + detached--dtach-detach-character)) ;;;; Minor mode diff --git a/detached.el b/detached.el index c65f0d7844..0f95ff3136 100644 --- a/detached.el +++ b/detached.el @@ -51,7 +51,7 @@ (require 'simple) (require 'tramp) -(declare-function detached-eshell-get-dtach-process "detached-eshell") +(declare-function detached-eshell--get-dtach-process "detached-eshell") ;;;; Variables @@ -531,7 +531,7 @@ active session. For sessions created with `detached-compile' or (if (eq 'active (detached--determine-session-state detached--buffer-session)) ;; `detached-eshell' (if-let ((process (and (eq major-mode 'eshell-mode) - (detached-eshell-get-dtach-process)))) + (detached-eshell--get-dtach-process)))) (progn (setq detached--buffer-session nil) (process-send-string process detached--dtach-detach-character))