Skip to content

Commit

Permalink
Add separate defcustom for cljs connection params
Browse files Browse the repository at this point in the history
  • Loading branch information
yuhan0 committed May 10, 2024
1 parent f56f1f7 commit 46007a0
Showing 1 changed file with 48 additions and 10 deletions.
58 changes: 48 additions & 10 deletions cider.el
Original file line number Diff line number Diff line change
Expand Up @@ -1500,21 +1500,54 @@ server buffer, in which case a new session for that server is created."
(plist-put :session-name ses-name)
(plist-put :repl-type 'cljs)))))

(defvar-local cider-connect-default-params nil
"Default plist of params to pass to `cider-connect'.
Recognized keys are :host, :port and :project-dir.")
(defcustom cider-connect-default-params nil
"Default plist of params for connecting to an external nREPL server.
Recognized keys are :host, :port and :project-dir.
These are used as arguments to the commands `cider-connect-clj',
`cider-connect-cljs' and `cider-connect-clj&cljs', in order to bypass
the corresponding user prompts.
This defcustom is intended for use with .dir-locals.el on a per-project basis.
See `cider-connect-default-cljs-params' in order to specify a separate set of params
for cljs REPL connections.
Note: it is recommended to set the variable `cider-default-cljs-repl'
instead of specifying the :cljs-repl-type key."
:type '(plist :key-type
(choice (const :host)
(const :port)
(const :project-dir)))
:group 'cider)

(defcustom cider-connect-default-cljs-params nil
"Default plist of params for connecting to a ClojureScript REPL.
Recognized keys are :host, :port and :project-dir.
If non-nil, overrides `cider-connect-default-params' for the commands
`cider-connect-cljs' and (the latter half of) `cider-connect-clj&cljs'.
Note: it is recommended to set the variable `cider-default-cljs-repl'
instead of specifying the :cljs-repl-type key."
:type '(plist :key-type
(choice (const :host)
(const :port)
(const :project-dir)))
:group 'cider)

;;;###autoload
(defun cider-connect-clj (&optional params)
"Initialize a Clojure connection to an nREPL server.
PARAMS is a plist optionally containing :host, :port and :project-dir.
If nil, use the default parameters in `cider-connect-default-params'.
When called interactively with a prefix argument, prompt for all the
parameters."
With the prefix argument, prompt for all the parameters regardless of
their supplied or default values."
(interactive "P")
(cider-nrepl-connect
;; Make sure to copy the list, as the following steps will mutate it
(thread-first (or params (copy-sequence cider-connect-default-params))
(thread-first (or params cider-connect-default-params)
(copy-sequence) ;; Note: the following steps mutate the list
(map-delete :cljs-repl-type)
(cider--update-project-dir)
(cider--update-host-port)
(cider--check-existing-session)
Expand All @@ -1527,12 +1560,17 @@ parameters."
"Initialize a ClojureScript connection to an nREPL server.
PARAMS is a plist optionally containing :host, :port, :project-dir and
:cljs-repl-type (e.g. 'shadow, 'node, 'figwheel, etc).
If nil, use the default parameters in `cider-connect-default-params' or
`cider-connect-default-cljs-params'.
On prefix, prompt for all the
parameters regardless of their supplied or default values."
With the prefix argument, prompt for all the parameters regardless of
their supplied or default values."
(interactive "P")
(cider-nrepl-connect
(thread-first params
(thread-first (or params
cider-connect-default-cljs-params
cider-connect-default-params)
(copy-sequence)
(cider--update-project-dir)
(cider--update-host-port)
(cider--check-existing-session)
Expand Down

0 comments on commit 46007a0

Please sign in to comment.