[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/detached 09b37f681c 30/38: Add detached-with-session ma
From: |
ELPA Syncer |
Subject: |
[elpa] externals/detached 09b37f681c 30/38: Add detached-with-session macro |
Date: |
Thu, 17 Nov 2022 17:57:56 -0500 (EST) |
branch: externals/detached
commit 09b37f681c68572aa18496994852a041e6c0704a
Author: Niklas Eklund <niklas.eklund@posteo.net>
Commit: Niklas Eklund <niklas.eklund@posteo.net>
Add detached-with-session macro
---
detached-compile.el | 37 ++++++++++++---------------
detached.el | 73 ++++++++++++++++++++++++++++-------------------------
2 files changed, 54 insertions(+), 56 deletions(-)
diff --git a/detached-compile.el b/detached-compile.el
index a9b9cb9b63..26b3926c18 100644
--- a/detached-compile.el
+++ b/detached-compile.el
@@ -65,19 +65,16 @@ Optionally enable COMINT if prefix-argument is provided."
"Re-compile by running `compile' but in a 'detached' session.
Optionally EDIT-COMMAND."
(interactive "P")
- (let* ((detached-enabled t)
- (detached-session-action detached-compile-session-action)
- (detached-session-origin 'compile)
- (detached-session-mode 'attached)
- (command
- (if edit-command
- (compilation-read-command
- (detached-session-command detached-buffer-session))
- (detached-session-command detached-buffer-session)))
- (detached-session-environment
- (detached--session-env detached-buffer-session))
- (detached-current-session (detached-create-session command)))
- (apply #'compilation-start `(,command))))
+ (detached-with-session detached-buffer-session
+ (let* ((detached-enabled t)
+ (detached-session-mode 'attached)
+ (detached-session-command
+ (if edit-command
+ (compilation-read-command
+ (detached-session-command detached-buffer-session))
+ (detached-session-command detached-buffer-session)))
+ (detached-current-session (detached-create-session
detached-session-command)))
+ (apply #'compilation-start `(,detached-session-command)))))
(defun detached-compile-kill ()
"Kill a 'detached' session."
@@ -90,18 +87,16 @@ Optionally EDIT-COMMAND."
(defun detached-compile-attach (session)
"Attach to SESSION with `compile'."
(when (detached-valid-session session)
- (let* ((detached-enabled t)
- (detached-current-session session)
- (detached-local-session (detached-session-local-p session))
- (default-directory (detached-session-directory session)))
- (compilation-start (detached-session-command session)))))
+ (detached-with-session session
+ (let* ((detached-enabled t))
+ (compilation-start detached-session-command)))))
;;;###autoload
(defun detached-compile-start-session (session)
"Start SESSION with `detached-compile'."
- (let* ((detached-enabled t)
- (detached-current-session session))
- (detached-compile (detached-session-command session))))
+ (detached-with-session session
+ (let* ((detached-enabled t))
+ (detached-compile detached-session-command))))
;;;;; Support functions
diff --git a/detached.el b/detached.el
index bb14c9bf07..a63e37d157 100644
--- a/detached.el
+++ b/detached.el
@@ -416,6 +416,19 @@ This version is encoded as [package-version].[revision].")
(progn
,@body))))
+(defmacro detached-with-session (session &rest body)
+ "A macro that set up SESSION's environment before evaluating BODY."
+ (declare (indent 1))
+ `(let ((default-directory (detached-session-working-directory ,session))
+ (detached-session-origin (detached--session-origin ,session))
+ (detached-local-session (detached-session-local-p ,session))
+ (detached-session-mode (detached--session-initial-mode ,session))
+ (detached-session-action (detached--session-action ,session))
+ (detached-session-command (detached-session-command ,session))
+ (detached-session-environment (detached--session-env ,session))
+ (detached-current-session ,session))
+ ,@body))
+
;;;; Commands
;;;###autoload
@@ -495,22 +508,20 @@ Optionally TOGGLE-SESSION-MODE."
(interactive
(list (detached-session-in-context)
current-prefix-arg))
- (when-let* ((detached-session-command
- (read-string "Edit command: "
- (detached-session-command session))))
- (let* ((detached-session-mode
- (if toggle-session-mode
- (if (eq 'detached (detached--session-initial-mode session))
- 'attached
- 'detached)
- (detached--session-initial-mode session)))
- (default-directory (detached-session-working-directory session))
- (detached-local-session (detached-session-local-p session))
- (detached-session-action (detached--session-action session))
- (detached-session-environment (detached--session-env session))
- (detached-current-session
- (detached-create-session detached-session-command)))
- (detached-start-session detached-current-session))))
+ (when session
+ (detached-with-session session
+ (when-let* ((detached-session-command
+ (read-string "Edit command: "
+ (detached-session-command session)))
+ (detached-session-mode
+ (if toggle-session-mode
+ (if (eq 'detached (detached--session-initial-mode
session))
+ 'attached
+ 'detached)
+ (detached--session-initial-mode session)))
+ (detached-current-session
+ (detached-create-session detached-session-command)))
+ (detached-start-session detached-current-session)))))
;;;###autoload
(defun detached-rerun-session (session &optional toggle-session-mode)
@@ -520,20 +531,16 @@ Optionally TOGGLE-SESSION-MODE."
(interactive
(list (detached-session-in-context)
current-prefix-arg))
- (let* ((detached-session-mode
- (if toggle-session-mode
- (if (eq 'detached (detached--session-initial-mode session))
- 'attached
- 'detached)
- (detached--session-initial-mode session)))
- ;; TODO: Implement macro detached-with-session
- (default-directory (detached-session-working-directory session))
- (detached-local-session (detached-session-local-p session))
- (detached-session-action (detached--session-action session))
- (detached-session-environment (detached--session-env session))
- (detached-current-session
- (detached-create-session (detached-session-command session))))
- (detached-start-session detached-current-session)))
+ (when session
+ (detached-with-session session
+ (let* ((detached-session-mode
+ (if toggle-session-mode
+ (if (eq 'detached (detached--session-initial-mode session))
+ 'attached
+ 'detached)
+ (detached--session-initial-mode session)))
+ (detached-current-session (detached-create-session
detached-session-command)))
+ (detached-start-session detached-current-session)))))
;;;###autoload
(defun detached-describe-session ()
@@ -925,11 +932,7 @@ This function uses the `notifications' library."
(detached-session-start-command
session
:type 'string))
- (let* ((default-directory (detached-session-working-directory session))
- (detached-local-session (detached-session-local-p session))
- (detached-session-mode (detached--session-initial-mode session))
- (detached-session-action (detached--session-action session))
- (detached-session-environment (detached--session-env session)))
+ (detached-with-session session
(funcall (detached-session-run-function session) session))))
(cl-defun detached-session-start-command (session &key type)
- [elpa] externals/detached 4cc2c4e40f 12/38: Add select host session completion function, (continued)
- [elpa] externals/detached 4cc2c4e40f 12/38: Add select host session completion function, ELPA Syncer, 2022/11/17
- [elpa] externals/detached d1c3861e8e 16/38: Add public function for session directory, ELPA Syncer, 2022/11/17
- [elpa] externals/detached ca0ee7e465 37/38: Add detach key to session map, ELPA Syncer, 2022/11/17
- [elpa] externals/detached 274993d9c9 20/38: Remove 'started state, ELPA Syncer, 2022/11/17
- [elpa] externals/detached 51858bceb7 26/38: Begin rework of how to start a session, ELPA Syncer, 2022/11/17
- [elpa] externals/detached 65c661bc9c 27/38: Change detached env to text-mode, ELPA Syncer, 2022/11/17
- [elpa] externals/detached 3dc3651e98 18/38: Add session working directory function, ELPA Syncer, 2022/11/17
- [elpa] externals/detached 88618a9cee 17/38: Add public function for session command, ELPA Syncer, 2022/11/17
- [elpa] externals/detached 4b3609385d 01/38: Start session rewrite, ELPA Syncer, 2022/11/17
- [elpa] externals/detached f0f9728e2c 31/38: Make local predicate private, ELPA Syncer, 2022/11/17
- [elpa] externals/detached 09b37f681c 30/38: Add detached-with-session macro,
ELPA Syncer <=
- [elpa] externals/detached a57a728382 22/38: Remove detached-session-mode 'attach, ELPA Syncer, 2022/11/17
- [elpa] externals/detached 4e36d9de69 10/38: Make current session public, ELPA Syncer, 2022/11/17
- [elpa] externals/detached f896cd9777 32/38: Reformat code, ELPA Syncer, 2022/11/17
- [elpa] externals/detached 0d607044d9 03/38: Add session started predicate, ELPA Syncer, 2022/11/17
- [elpa] externals/detached 4eb5e3e9aa 04/38: Add side effect to start command, ELPA Syncer, 2022/11/17
- [elpa] externals/detached b3fa3b9893 13/38: Move functions to end to prepare for deprecation, ELPA Syncer, 2022/11/17
- [elpa] externals/detached 1604a7b5b8 11/38: Make detached-buffer-session public, ELPA Syncer, 2022/11/17
- [elpa] externals/detached 26210dc5a8 28/38: Improve the core structure, ELPA Syncer, 2022/11/17