emacs-devel
[Top][All Lists]
Advanced

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

Re: emacsclient in elisp


From: chad
Subject: Re: emacsclient in elisp
Date: Wed, 19 May 2021 15:43:11 -0700

Are you perhaps trying to build emacs-async?
  https://github.com/jwiegley/emacs-async
~Chad


On Wed, May 19, 2021 at 2:57 PM Daniel Mendler <mail@daniel-mendler.de> wrote:
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))


reply via email to

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