Skip to content

Commit

Permalink
pwsh 7.3 quoting rules compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
ikappaki committed Dec 2, 2023
1 parent 0134a0b commit 93c7807
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 7 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## master (unreleased)

### Changes

- [#3588](https://github.com/clojure-emacs/cider/issues/3588): Compatibility with pwsh 7.3 quoting rules.

## 1.12.0 (2023-11-24)

### Changes
Expand Down
5 changes: 4 additions & 1 deletion cider.el
Original file line number Diff line number Diff line change
Expand Up @@ -810,7 +810,10 @@ rules to quote it."
(defun cider--powershell-encode-command (cmd-params)
"Base64 encode the powershell command and jack-in CMD-PARAMS for clojure-cli."
(let* ((quoted-params cmd-params)
(command (format "clojure %s" quoted-params))
;; Also ensure compatibility with pwsh 7.3 quoting rules
;;
;; https://stackoverflow.com/a/59036879
(command (format "$PSNativeCommandArgumentPassing = 'Legacy'; clojure %s" quoted-params))
(utf-16le-command (encode-coding-string command 'utf-16le)))
(format "-encodedCommand %s" (base64-encode-string utf-16le-command t))))

Expand Down
19 changes: 14 additions & 5 deletions doc/modules/ROOT/pages/basics/up_and_running.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -208,11 +208,20 @@ so we'll examine them tool by tool.
* `cider-clojure-cli-parameters` - the command-line parameters to start a REPL
* `cider-clojure-cli-aliases` - a list of aliases to be used at jack-in time

To use `cider-jack-in` with `tools.deps` on Windows set the
`cider-clojure-cli-command` to `"powershell"`. This happens by default
if you are on Windows and no `clojure` executable is found. Using
`"powershell"` will Base64 encode the clojure launch command before
passing it to PowerShell and avoids shell-escaping issues.
On MS-Windows, CIDER will employ `PowerShell` to execute Clojure if no
`clojure` executable is found in the PATH (e.g. like the one supplied
by https://github.com/borkdude/deps.clj[deps.clj]). The default
executable used is `powershell` which is available on all Windows
platforms. Using `PowerShell` will Base64 encode the clojure launch
command before passing it to PowerShell and avoids shell-escaping
issues.

The functionality of `cider-clojure-cli-command` has been verified
with the following alternatives

* `pwsh`: This option proves beneficial when the user has installed the https://github.com/clojure/tools.deps.alpha/wiki/clj-on-Windows[ClojureTools] module on pwsh in a directory not accessible by the system's PowerShell installation.
* `deps.exe`: This executable is part of the tools provided by
https://github.com/borkdude/deps.clj[deps.clj] as an alternative name for `clojure.exe`.

NOTE: Alternatively you can use WSL (e.g. to run nREPL and Emacs there), which
will likely result in a better overall development experience.
Expand Down
6 changes: 5 additions & 1 deletion test/integration/integration-tests.el
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,11 @@ If CLI-COMMAND is nil, then use the default."
(jack-in-clojure-cli-test nil))

(when (eq system-type 'windows-nt)
(it "to clojure tools cli (alternative deps.exe)"
(it "to clojure tools cli (alternative pwsh)"
(jack-in-clojure-cli-test "pwsh")))

(when (eq system-type 'windows-nt)
(it "to clojure tools cli (alternative deps.exe)"
(jack-in-clojure-cli-test "deps.exe")))

(it "to leiningen"
Expand Down

0 comments on commit 93c7807

Please sign in to comment.