From c9d52677fea262ba43bd6803e63e889e737309dc Mon Sep 17 00:00:00 2001 From: yuhan0 Date: Sun, 25 Jun 2023 20:55:35 +0800 Subject: [PATCH 1/3] feat: specify default connection params --- cider.el | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/cider.el b/cider.el index c54863e6e..03bcf822b 100644 --- a/cider.el +++ b/cider.el @@ -1500,14 +1500,21 @@ 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.") + ;;;###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. On -prefix argument, prompt for all the parameters." +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." (interactive "P") (cider-nrepl-connect - (thread-first params + ;; Make sure to copy the list, as the following steps will mutate it + (thread-first (or params (copy-sequence cider-connect-default-params)) (cider--update-project-dir) (cider--update-host-port) (cider--check-existing-session) From 1adbf169e17ea7f8c2a23da36bdfbdfc720c2fc8 Mon Sep 17 00:00:00 2001 From: yuhan0 Date: Wed, 8 May 2024 03:21:24 +0800 Subject: [PATCH 2/3] Add separate defcustom for cljs connection params --- cider.el | 58 ++++++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 48 insertions(+), 10 deletions(-) diff --git a/cider.el b/cider.el index 03bcf822b..a4e6b3a22 100644 --- a/cider.el +++ b/cider.el @@ -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) @@ -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) From 803c7fc476d3fc3ea519b0a052bd03164d5eb944 Mon Sep 17 00:00:00 2001 From: yuhan0 Date: Tue, 28 May 2024 22:09:54 +0800 Subject: [PATCH 3/3] Refactor cider-connect-clj&cljs --- cider.el | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/cider.el b/cider.el index a4e6b3a22..f6873a9f9 100644 --- a/cider.el +++ b/cider.el @@ -1583,22 +1583,27 @@ their supplied or default values." (defun cider-connect-clj&cljs (params &optional soft-cljs-start) "Initialize a Clojure and 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). When SOFT-CLJS-START is -non-nil, don't start if ClojureScript requirements are not met." +:cljs-repl-type (e.g. 'shadow, 'node, 'figwheel, etc). +If nil, use the default parameters in `cider-connect-default-params' and +`cider-connect-default-cljs-params'. + +When SOFT-CLJS-START is non-nil, don't start if ClojureScript requirements are +not met. + +With the prefix argument, prompt for all the parameters regardless of +their supplied or default values." (interactive "P") - (let* ((params (thread-first params - (cider--update-project-dir) - (cider--update-host-port) - (cider--check-existing-session) - (cider--update-cljs-type))) - (clj-params (thread-first params - copy-sequence - (map-delete :cljs-repl-type))) - (clj-repl (cider-connect-clj clj-params))) + (let* ((clj-repl (cider-connect-clj params)) + (cljs-params + (thread-first (or params cider-connect-default-cljs-params) + (copy-sequence) + (cider--update-cljs-type) + ;; already asked, don't ask on sibling connect + (plist-put :do-prompt nil)))) (when (if soft-cljs-start - (cider--check-cljs (plist-get params :cljs-repl-type) 'no-error) + (cider--check-cljs (plist-get cljs-params :cljs-repl-type) 'no-error) t) - (cider-connect-sibling-cljs params clj-repl)))) + (cider-connect-sibling-cljs cljs-params clj-repl)))) (defvar cider-connection-init-commands '(cider-jack-in-clj