Skip to content

Commit 2d3b183

Browse files
committed
[Docs] Document the connection hooks
1 parent 993a840 commit 2d3b183

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

Diff for: doc/modules/ROOT/pages/config/basic_config.adoc

+21
Original file line numberDiff line numberDiff line change
@@ -265,3 +265,24 @@ wrapping instead of line truncating.
265265

266266
IMPORTANT: This variable should be set *before* loading CIDER (which means before
267267
`require`-ing it or autoloading it).
268+
269+
== nREPL Connection Hooks
270+
271+
CIDER provides the hooks `cider-connected-hook` and `cider-disconnected-hook`
272+
that get triggered when an nREPL connection is established or closed respectively.
273+
274+
Here's how CIDER uses the first hook internally to display its famous inspirational
275+
messages on connect:
276+
277+
[source,lisp]
278+
----
279+
(defun cider--maybe-inspire-on-connect ()
280+
"Display an inspiration connection message."
281+
(when cider-connection-message-fn
282+
(message "Connected! %s" (funcall cider-connection-message-fn))))
283+
284+
(add-hook 'cider-connected-hook #'cider--maybe-inspire-on-connect)
285+
----
286+
287+
NOTE: There are also lower-level `nrepl-connected-hook` and `nrepl-disconnected-hook` that CIDER uses internally. Most of the time end-users would be better off using
288+
the CIDER-level hooks instead.

0 commit comments

Comments
 (0)