@@ -491,6 +491,26 @@ and kill the process buffer."
491491
492492; ;; Network
493493
494+ (defun nrepl--unix-connect (socket-file &optional no-error )
495+ " If SOCKET-FILE is given, try to `make-network-process' .
496+ If NO-ERROR is non-nil, show messages instead of throwing an error."
497+ (if (not socket-file)
498+ (unless no-error
499+ (error " [nREPL] Socket file not provided " ))
500+ (message " [nREPL] Establishing unix socket connection to %s ... " socket-file)
501+ (condition-case nil
502+ (prog1 (list :proc (make-network-process :name " nrepl-connection" :buffer nil
503+ :family 'local :service socket-file)
504+ :host " local-unix-domain-socket"
505+ :port socket-file
506+ :socket-file socket-file)
507+ (message " [nREPL] Unix socket connection to %s established " socket-file))
508+ (error (let ((msg (format " [nREPL] Unix socket connection to %s failed " socket-file)))
509+ (if no-error
510+ (message msg)
511+ (error msg))
512+ nil )))))
513+
494514(defun nrepl-connect (host port )
495515 " Connect to the nREPL server identified by HOST and PORT.
496516For local hosts use a direct connection. For remote hosts, if
@@ -629,14 +649,16 @@ Do not kill the server if there is a REPL connected to that server."
629649 (buffer-list )))
630650 (nrepl-kill-server-buffer server-buf)))))
631651
632- (defun nrepl-start-client-process (&optional host port server-proc buffer-builder )
633- " Create new client process identified by HOST and PORT.
634- In remote buffers, HOST and PORT are taken from the current tramp
635- connection. SERVER-PROC must be a running nREPL server process within
636- Emacs. BUFFER-BUILDER is a function of one argument (endpoint returned by
637- `nrepl-connect' ) which returns a client buffer. Return the newly created
638- client process."
639- (let* ((endpoint (nrepl-connect host port))
652+ (defun nrepl-start-client-process (&optional host port server-proc buffer-builder socket-file )
653+ " Create new client process identified by either HOST and PORT or SOCKET-FILE.
654+ If SOCKET-FILE is non-nil, it takes precedence. In remote buffers, HOST
655+ and PORT are taken from the current tramp connection. SERVER-PROC must be
656+ a running nREPL server process within Emacs. BUFFER-BUILDER is a function
657+ of one argument (endpoint returned by `nrepl-connect' ) which returns a
658+ client buffer. Return the newly created client process."
659+ (let* ((endpoint (if socket-file
660+ (nrepl--unix-connect (expand-file-name socket-file))
661+ (nrepl-connect host port)))
640662 (client-proc (plist-get endpoint :proc ))
641663 (builder (or buffer-builder (error " `buffer-builder' must be provided" )))
642664 (client-buf (funcall builder endpoint)))
0 commit comments