Skip to content

Commit 6a9bc1c

Browse files
vspinubbatsov
authored andcommitted
Add support for sesman-browser
- allow cider connection management commands to be used in sesman browsers - implement new format of sesman-session-info generic - add cider-sesman-browser-map
1 parent dc57cdc commit 6a9bc1c

File tree

1 file changed

+53
-24
lines changed

1 file changed

+53
-24
lines changed

cider-connection.el

Lines changed: 53 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
(require 'cl-lib)
3434
(require 'format-spec)
3535
(require 'sesman)
36+
(require 'sesman-browser)
3637

3738
(defcustom cider-session-name-template "%J:%h:%p"
3839
"Format string to use for session names.
@@ -318,28 +319,36 @@ about this buffer (like variable `cider-repl-type')."
318319

319320
;;; Cider's Connection Management UI
320321

321-
(defun cider-quit ()
322-
"Quit the currently active CIDER connection."
322+
(defun cider-quit (&optional repl)
323+
"Quit the CIDER connection associated with REPL.
324+
REPL defaults to the current REPL."
323325
(interactive)
324-
(cider-ensure-connected)
325-
(let ((connection (cider-current-repl)))
326-
(cider--close-connection connection))
326+
(let ((repl (or repl
327+
(sesman-browser-get 'object)
328+
(cider-current-repl nil 'ensure))))
329+
(cider--close-connection repl))
327330
;; if there are no more connections we can kill all ancillary buffers
328331
(unless (cider-connected-p)
329-
(cider-close-ancillary-buffers)))
330-
331-
(defun cider-restart ()
332-
"Restart the currently active CIDER connection.
333-
Don't restart the server or other connections within the same session. Use
334-
`sesman-restart' to restart the entire session."
332+
(cider-close-ancillary-buffers))
333+
;; need this to refresh sesman browser
334+
(run-hooks 'sesman-post-command-hook))
335+
336+
(defun cider-restart (&optional repl)
337+
"Restart CIDER connection associated with REPL.
338+
REPL defaults to the current REPL. Don't restart the server or other
339+
connections within the same session. Use `sesman-restart' to restart the
340+
entire session."
335341
(interactive)
336-
(let* ((repl (or (cider-current-repl)
337-
(user-error "No linked REPL")))
342+
(let* ((repl (or repl
343+
(sesman-browser-get 'object)
344+
(cider-current-repl nil 'ensure)))
338345
(params (thread-first (cider--gather-connect-params nil repl)
339346
(plist-put :session-name (sesman-session-name-for-object 'CIDER repl))
340347
(plist-put :repl-buffer repl))))
341348
(cider--close-connection repl 'no-kill)
342-
(cider-nrepl-connect params)))
349+
(cider-nrepl-connect params)
350+
;; need this to refresh sesman browser
351+
(run-hooks 'sesman-post-command-hook)))
343352

344353
(defun cider-close-ancillary-buffers ()
345354
"Close buffers that are shared across connections."
@@ -348,11 +357,15 @@ Don't restart the server or other connections within the same session. Use
348357
(when (get-buffer buf-name)
349358
(kill-buffer buf-name))))
350359

351-
(defun cider-describe-current-connection ()
352-
"Display information about the current connection."
360+
(defun cider-describe-connection (&optional repl)
361+
"Display information about the connection associated with REPL.
362+
REPL defaults to the current REPL."
353363
(interactive)
354-
(message "%s" (cider--connection-info (cider-current-repl nil 'ensure))))
355-
(define-obsolete-function-alias 'cider-display-connection-info 'cider-describe-current-connection "0.18.0")
364+
(let ((repl (or repl
365+
(sesman-browser-get 'object)
366+
(cider-current-repl nil 'ensure))))
367+
(message "%s" (cider--connection-info repl))))
368+
(define-obsolete-function-alias 'cider-display-connection-info 'cider-describe-connection "0.18.0")
356369

357370
(defconst cider-nrepl-session-buffer "*cider-nrepl-session*")
358371

@@ -387,13 +400,27 @@ Don't restart the server or other connections within the same session. Use
387400
(cl-defmethod sesman-more-relevant-p ((_system (eql CIDER)) session1 session2)
388401
(sesman-more-recent-p (cdr session1) (cdr session2)))
389402

403+
(defvar cider-sesman-browser-map
404+
(let ((map (make-sparse-keymap)))
405+
(define-key map (kbd "j q") #'cider-quit)
406+
(define-key map (kbd "j k") #'cider-quit)
407+
(define-key map (kbd "j r") #'cider-restart)
408+
(define-key map (kbd "j d") #'cider-describe-connection)
409+
(define-key map (kbd "j i") #'cider-describe-connection)
410+
(define-key map (kbd "C-c C-q") #'cider-quit)
411+
(define-key map (kbd "C-c C-q") #'cider-quit)
412+
(define-key map (kbd "C-c C-r") #'cider-restart)
413+
(define-key map (kbd "C-c M-r") #'cider-restart)
414+
(define-key map (kbd "C-c C-d") #'cider-describe-connection)
415+
(define-key map (kbd "C-c M-d") #'cider-describe-connection)
416+
(define-key map (kbd "C-c C-i") #'cider-describe-connection)
417+
map)
418+
"Map active on REPL objects in sesman browser.")
419+
390420
(cl-defmethod sesman-session-info ((_system (eql CIDER)) session)
391421
(interactive "P")
392-
(let ((repl (cadr session)))
393-
(format "\t%s: %s\n\tREPLS: %s"
394-
(if (buffer-local-value 'nrepl-server-buffer repl) "SERVER" "CONNECTION")
395-
(cider--connection-info repl t)
396-
(mapconcat #'buffer-name (cdr session) ", "))))
422+
(list :objects (cdr session)
423+
:map cider-sesman-browser-map))
397424

398425
(declare-function cider "cider")
399426
(cl-defmethod sesman-start-session ((_system (eql CIDER)))
@@ -486,7 +513,9 @@ removed."
486513
""
487514
host))
488515
(repl-type (or (plist-get params :repl-type) "unknown"))
489-
(cljs-repl-type (or (plist-get params :cljs-repl-type) ""))
516+
(cljs-repl-type (or (and (equal repl-type "cljs")
517+
(plist-get params :cljs-repl-type))
518+
""))
490519
(specs `((?h . ,host)
491520
(?H . ,remote-host)
492521
(?p . ,port)

0 commit comments

Comments
 (0)