diff options
author | Jonas Bernoulli <jonas@bernoul.li> | 2017-08-03 18:17:46 +0200 |
---|---|---|
committer | Jonas Bernoulli <jonas@bernoul.li> | 2017-08-03 18:17:46 +0200 |
commit | 4d3d50b09dee3305a365d7eb005313d42dddd6ea (patch) | |
tree | 7a17723703bc8e248062fe69a9d6d874a9de1739 /with-editor.el | |
parent | 890f9238ef123190eb7eb72c97eb56eb873a9178 (diff) |
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.
Diffstat (limited to 'with-editor.el')
-rw-r--r-- | with-editor.el | 65 |
1 files 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) |