emacs-devel
[Top][All Lists]
Advanced

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

Re: emacsclient in elisp


From: Arthur Miller
Subject: Re: emacsclient in elisp
Date: Thu, 20 May 2021 17:59:37 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (windows-nt)

Daniel Mendler <mail@daniel-mendler.de> writes:

> On 5/19/21 2:50 PM, Daniel Mendler wrote:
>> I am looking for an elisp implementation of emacsclient. Is such a
>> functionality already build into Emacs? This would allow to start a
>> separate Emacs instance which can then be used as an asynchronous worker.
> Turns out such an `emacsclient` is rather easy to build using
> `make-network-process`. This is probably neither robust nor platform
> independent due to the use of unix sockets. Nevertheless such a client
> is useful to communicate with asynchronous Emacs workers. With some
> effort it is possible to replace the current `emacsclient` protocol with
> something more robust. I assume there is no guarantee for backward
> compatibility in this protocol?
>
> Daniel
>
> ~~~~
>
> (defun emacsclient (name expr callback)
>   (let* ((result)
>          (proc (make-network-process
>                 :name name
>                 :noquery t
>                 :sentinel
>                 (lambda (_proc _event)
>                   (funcall callback (and result (read result))))
>                 :filter
>                 (lambda (_proc out)
>                   (dolist (line (split-string out "\n"))
>                     (cond
>                      ((string-prefix-p "-print " line)
>                       (setq result (server-unquote-arg
>                                     (string-remove-prefix "-print " line))))
>                      ((string-prefix-p "-print-nonl " line)
>                       (setq result
>                             (concat
>                              result
>                              (server-unquote-arg
>                               (string-remove-prefix "-printnonl "
> line))))))))
>                 :coding 'raw-text-unix
>                 :family 'local
>                 :service (expand-file-name name server-socket-dir))))
>     (process-send-string
>      proc
>      (format "-eval %s \n" (server-quote-arg (prin1-to-string expr))))
>     proc))

Isn't that what 'server-eval-at' already does?

emacs --daemon=foo

(server-eval-at "foo" '(some-complex-eval))

> This is probably neither robust nor platform
> independent due to the use of unix sockets.

Docs says tcp sockets are used where local sockets are not avialable and:

https://www.gnu.org/software/emacs/manual/html_node/emacs/TCP-Emacs-server.html





reply via email to

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