Skip to content

Commit c975b48

Browse files
committed
Merge pull request #812 from vitoshka/master
Fix a number of compile warnings in `nrepl-client.el`
2 parents f843dbf + 7ad94d5 commit c975b48

File tree

1 file changed

+74
-76
lines changed

1 file changed

+74
-76
lines changed

nrepl-client.el

Lines changed: 74 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@
7171
(require 'cl-lib)
7272
(require 'cider-util)
7373
(require 'queue)
74+
(require 'tramp)
7475

7576

7677
;;; Custom
@@ -132,6 +133,7 @@ buffer will be hidden."
132133

133134
;;; nREPL Buffer Names
134135

136+
(defconst nrepl-message-buffer-name "*nrepl-messages*")
135137
(defconst nrepl-repl-buffer-name-template "*cider-repl%s*")
136138
(defconst nrepl-connection-buffer-name-template "*nrepl-connection%s*")
137139
(defconst nrepl-server-buffer-name-template "*nrepl-server%s*")
@@ -227,6 +229,68 @@ To be used for tooling calls (i.e. completion, eldoc, etc)")
227229
(defvar-local nrepl-versions nil
228230
"Version information received from the describe op.")
229231

232+
233+
;;; Utilities
234+
(defmacro nrepl-dbind-response (response keys &rest body)
235+
"Destructure an nREPL RESPONSE dict.
236+
Bind the value of the provided KEYS and execute BODY."
237+
`(let ,(cl-loop for key in keys
238+
collect `(,key (nrepl-dict-get ,response ,(format "%s" key))))
239+
,@body))
240+
(put 'nrepl-dbind-response 'lisp-indent-function 2)
241+
242+
(defun nrepl-op-supported-p (op)
243+
"Return t iff the given operation OP is supported by nREPL server."
244+
(with-current-buffer (nrepl-current-connection-buffer)
245+
(and nrepl-ops (nrepl-dict-get nrepl-ops op))))
246+
247+
(defun nrepl-current-dir ()
248+
"Return the directory of the current buffer."
249+
(let ((file-name (buffer-file-name (current-buffer))))
250+
(or (when file-name
251+
(file-name-directory file-name))
252+
list-buffers-directory)))
253+
254+
(defun nrepl-project-directory-for (dir-name)
255+
"Return the project directory for the specified DIR-NAME."
256+
(when dir-name
257+
(locate-dominating-file dir-name "project.clj")))
258+
259+
(defun nrepl-check-for-repl-buffer (endpoint project-directory)
260+
"Check whether a matching connection buffer already exists.
261+
Looks for buffers where `nrepl-endpoint' matches ENDPOINT,
262+
or `nrepl-project-dir' matches PROJECT-DIRECTORY.
263+
If so ask the user for confirmation."
264+
(if (cl-find-if
265+
(lambda (buffer)
266+
(let ((buffer (get-buffer buffer)))
267+
(or (and endpoint
268+
(equal endpoint
269+
(buffer-local-value 'nrepl-endpoint buffer)))
270+
(and project-directory
271+
(equal project-directory
272+
(buffer-local-value 'nrepl-project-dir buffer))))))
273+
(nrepl-connection-buffers))
274+
(y-or-n-p
275+
"An nREPL connection buffer already exists. Do you really want to create a new one? ")
276+
t))
277+
278+
(defun nrepl-default-port ()
279+
"Attempt to read port from .nrepl-port or target/repl-port.
280+
Falls back to `nrepl-port' if not found."
281+
(or (nrepl--port-from-file ".nrepl-port")
282+
(nrepl--port-from-file "target/repl-port")
283+
nrepl-port))
284+
285+
(defun nrepl--port-from-file (file)
286+
"Attempts to read port from a file named by FILE."
287+
(let* ((dir (nrepl-project-directory-for (nrepl-current-dir)))
288+
(f (expand-file-name file dir)))
289+
(when (file-exists-p f)
290+
(with-temp-buffer
291+
(insert-file-contents f)
292+
(buffer-string)))))
293+
230294

231295
;;; nREPL dict
232296

@@ -518,7 +582,7 @@ process buffer and run the hook `nrepl-disconnected-hook'."
518582
(run-hooks 'nrepl-disconnected-hook)))
519583

520584

521-
;;; Client: Initialization
585+
;;; Client: Process Handling
522586

523587
;; `nrepl-start-client-process' is called from `nrepl-server-filter'. It
524588
;; starts the client process described by `nrepl-client-filter' and
@@ -609,33 +673,17 @@ If REPLP is non-nil, also initialize it as a REPL buffer."
609673
(setq nrepl-tooling-session new-session))
610674
(error "Could not create new tooling session (%s)" err)))))
611675

612-
(defun nrepl--port-from-file (file)
613-
"Attempts to read port from a file named by FILE."
614-
(let* ((dir (nrepl-project-directory-for (nrepl-current-dir)))
615-
(f (expand-file-name file dir)))
616-
(when (file-exists-p f)
617-
(with-temp-buffer
618-
(insert-file-contents f)
619-
(buffer-string)))))
620-
621-
(defun nrepl-default-port ()
622-
"Attempt to read port from .nrepl-port or target/repl-port.
623-
Falls back to `nrepl-port' if not found."
624-
(or (nrepl--port-from-file ".nrepl-port")
625-
(nrepl--port-from-file "target/repl-port")
626-
nrepl-port))
676+
(defun nrepl-close (connection-buffer)
677+
"Close the nrepl connection for CONNECTION-BUFFER."
678+
(interactive (list (nrepl-current-connection-buffer)))
679+
(nrepl--close-connection-buffer connection-buffer)
680+
(run-hooks 'nrepl-disconnected-hook)
681+
(nrepl--connections-refresh))
627682

628683

629684
;;; Client: Response Handling
630685
;; After being decoded, responses (aka, messages from the server) are dispatched
631686
;; to handlers. Handlers are constructed with `nrepl-make-response-handler'.
632-
(defmacro nrepl-dbind-response (response keys &rest body)
633-
"Destructure an nREPL RESPONSE dict.
634-
Bind the value of the provided KEYS and execute BODY."
635-
`(let ,(cl-loop for key in keys
636-
collect `(,key (nrepl-dict-get ,response ,(format "%s" key))))
637-
,@body))
638-
(put 'nrepl-dbind-response 'lisp-indent-function 2)
639687

640688
(defvar nrepl-err-handler 'cider-default-err-handler
641689
"Evaluation error handler.")
@@ -909,11 +957,7 @@ fall back to specifying a direct connection to the remote host."
909957
(if moving (goto-char (process-mark proc)))))))))
910958

911959

912-
;;; Utilities
913-
914-
;; message logging
915-
(defconst nrepl-message-buffer-name "*nrepl-messages*"
916-
"Buffer for nREPL message logging.")
960+
;;; Messages
917961

918962
(defcustom nrepl-log-messages nil
919963
"If non-nil, log protocol messages to the `nrepl-message-buffer-name' buffer."
@@ -944,7 +988,7 @@ number of buffer shrinking operations.")
944988
(goto-char (point-max))
945989
(nrepl--pp msg)
946990
(-when-let (win (get-buffer-window))
947-
(set-window-point win (point-max))))))
991+
(set-window-point win (point-max))))))
948992

949993
(defvar nrepl--message-colors
950994
'("red" "brown" "coral" "orange" "green" "deep sky blue" "blue" "dark violet")
@@ -972,7 +1016,7 @@ number of buffer shrinking operations.")
9721016
do (let ((str (format "%s%s " (make-string indent ? ) (car l))))
9731017
(insert str)
9741018
(nrepl--pp (cadr l))))
975-
(insert (color (format "%s)\n" (make-string (- indent 2) ? ))))))))))
1019+
(insert (color (format "%s)\n" (make-string (- indent 2) ? ))))))))))
9761020

9771021
(defun nrepl-messages-buffer ()
9781022
"Return or create the buffer given by `nrepl-message-buffer-name'.
@@ -985,52 +1029,6 @@ The default buffer name is *nrepl-messages*."
9851029
(setq-local comment-end ""))
9861030
buffer)))
9871031

988-
989-
;; other utility functions
990-
(defun nrepl-op-supported-p (op)
991-
"Return t iff the given operation OP is supported by nREPL server."
992-
(with-current-buffer (nrepl-current-connection-buffer)
993-
(and nrepl-ops (nrepl-dict-get nrepl-ops op))))
994-
995-
(defun nrepl-current-dir ()
996-
"Return the directory of the current buffer."
997-
(let ((file-name (buffer-file-name (current-buffer))))
998-
(or (when file-name
999-
(file-name-directory file-name))
1000-
list-buffers-directory)))
1001-
1002-
(defun nrepl-project-directory-for (dir-name)
1003-
"Return the project directory for the specified DIR-NAME."
1004-
(when dir-name
1005-
(locate-dominating-file dir-name "project.clj")))
1006-
1007-
(defun nrepl-check-for-repl-buffer (endpoint project-directory)
1008-
"Check whether a matching connection buffer already exists.
1009-
Looks for buffers where `nrepl-endpoint' matches ENDPOINT,
1010-
or `nrepl-project-dir' matches PROJECT-DIRECTORY.
1011-
If so ask the user for confirmation."
1012-
(if (cl-find-if
1013-
(lambda (buffer)
1014-
(let ((buffer (get-buffer buffer)))
1015-
(or (and endpoint
1016-
(equal endpoint
1017-
(buffer-local-value 'nrepl-endpoint buffer)))
1018-
(and project-directory
1019-
(equal project-directory
1020-
(buffer-local-value 'nrepl-project-dir buffer))))))
1021-
(nrepl-connection-buffers))
1022-
(y-or-n-p
1023-
"An nREPL connection buffer already exists. Do you really want to create a new one? ")
1024-
t))
1025-
1026-
(defun nrepl-close (connection-buffer)
1027-
"Close the nrepl connection for CONNECTION-BUFFER."
1028-
(interactive (list (nrepl-current-connection-buffer)))
1029-
(nrepl--close-connection-buffer connection-buffer)
1030-
(run-hooks 'nrepl-disconnected-hook)
1031-
(nrepl--connections-refresh))
1032-
1033-
10341032

10351033
;;; Connection Buffer Management
10361034

0 commit comments

Comments
 (0)