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

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

[nongnu] elpa/with-editor 4d3d50b 049/140: with-editor--setup: create fr


From: Jonas Bernoulli
Subject: [nongnu] elpa/with-editor 4d3d50b 049/140: with-editor--setup: create from code previously in with-editor
Date: Fri, 6 Aug 2021 12:51:18 -0400 (EDT)

branch: elpa/with-editor
commit 4d3d50b09dee3305a365d7eb005313d42dddd6ea
Author: Jonas Bernoulli <jonas@bernoul.li>
Commit: Jonas Bernoulli <jonas@bernoul.li>

    with-editor--setup: create from code previously in with-editor
    
    This makes it easier to make changes without having to recompile
    all packages that use the `with-editor' macro, and the result of
    macro-expansion gets smaller too.
---
 with-editor.el | 65 ++++++++++++++++++++++++++++++----------------------------
 1 file changed, 34 insertions(+), 31 deletions(-)

diff --git a/with-editor.el b/with-editor.el
index de9f3f9..fb60724 100644
--- a/with-editor.el
+++ b/with-editor.el
@@ -408,39 +408,42 @@ ENVVAR is provided then bind that environment variable 
instead.
                                    (pop body)
                                  '(or with-editor--envvar "EDITOR")))
          (process-environment process-environment))
-     (if (or (not with-editor-emacsclient-executable)
-             (file-remote-p default-directory))
-         (push (concat with-editor--envvar "=" with-editor-sleeping-editor)
-               process-environment)
-       ;; Make sure server-use-tcp's value is valid.
-       (unless (featurep 'make-network-process '(:family local))
-         (setq server-use-tcp t))
-       ;; Make sure the server is running.
-       (unless server-process
-         (when (server-running-p server-name)
-           (setq server-name (format "server%s" (emacs-pid)))
-           (when (server-running-p server-name)
-             (server-force-delete server-name)))
-         (server-start))
-       ;; Tell $EDITOR to use the Emacsclient.
-       (push (concat with-editor--envvar "="
-                     (shell-quote-argument with-editor-emacsclient-executable)
-       ;; Tell the process where the server file is.
-                     (and (not server-use-tcp)
-                          (concat " --socket-name="
-                                  (shell-quote-argument
-                                   (expand-file-name server-name
-                                                     server-socket-dir)))))
-             process-environment)
-       (when server-use-tcp
-         (push (concat "EMACS_SERVER_FILE="
-                       (expand-file-name server-name server-auth-dir))
-               process-environment))
-       ;; As last resort fallback to the sleeping editor.
-       (push (concat "ALTERNATE_EDITOR=" with-editor-sleeping-editor)
-             process-environment))
+     (with-editor--setup)
      ,@body))
 
+(defun with-editor--setup ()
+  (if (or (not with-editor-emacsclient-executable)
+          (file-remote-p default-directory))
+      (push (concat with-editor--envvar "=" with-editor-sleeping-editor)
+            process-environment)
+    ;; Make sure server-use-tcp's value is valid.
+    (unless (featurep 'make-network-process '(:family local))
+      (setq server-use-tcp t))
+    ;; Make sure the server is running.
+    (unless server-process
+      (when (server-running-p server-name)
+        (setq server-name (format "server%s" (emacs-pid)))
+        (when (server-running-p server-name)
+          (server-force-delete server-name)))
+      (server-start))
+    ;; Tell $EDITOR to use the Emacsclient.
+    (push (concat with-editor--envvar "="
+                  (shell-quote-argument with-editor-emacsclient-executable)
+                  ;; Tell the process where the server file is.
+                  (and (not server-use-tcp)
+                       (concat " --socket-name="
+                               (shell-quote-argument
+                                (expand-file-name server-name
+                                                  server-socket-dir)))))
+          process-environment)
+    (when server-use-tcp
+      (push (concat "EMACS_SERVER_FILE="
+                    (expand-file-name server-name server-auth-dir))
+            process-environment))
+    ;; As last resort fallback to the sleeping editor.
+    (push (concat "ALTERNATE_EDITOR=" with-editor-sleeping-editor)
+          process-environment)))
+  
 (defun with-editor-server-window ()
   (or (and buffer-file-name
            (cdr (cl-find-if (lambda (cons)



reply via email to

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