[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: emacsclient in elisp
From: |
Daniel Mendler |
Subject: |
Re: emacsclient in elisp |
Date: |
Wed, 19 May 2021 23:56:36 +0200 |
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))
- Re: emacsclient in elisp, (continued)
- Re: emacsclient in elisp, Jean Louis, 2021/05/21
- Re: emacsclient in elisp, Jean Louis, 2021/05/21
- Re: emacsclient in elisp, Eli Zaretskii, 2021/05/21
- Re: emacsclient in elisp, Jean Louis, 2021/05/21
- Re: emacsclient in elisp, Eli Zaretskii, 2021/05/21
- Re: emacsclient in elisp, Jean Louis, 2021/05/21
- Re: emacsclient in elisp, Eli Zaretskii, 2021/05/21
- Re: emacsclient in elisp, Eli Zaretskii, 2021/05/21
- Re: emacsclient in elisp, Jean Louis, 2021/05/21
- Re: emacsclient in elisp, Eli Zaretskii, 2021/05/22
Re: emacsclient in elisp,
Daniel Mendler <=