Skip to content

Commit 28a51bc

Browse files
committed
Tweak the generation of the pprint request options
1 parent 0d72bd3 commit 28a51bc

File tree

1 file changed

+16
-8
lines changed

1 file changed

+16
-8
lines changed

cider-client.el

+16-8
Original file line numberDiff line numberDiff line change
@@ -213,9 +213,15 @@ two arguments - an object to print and an options map. The options map will
213213
have string keys. If the function
214214
cannot be resolved, an exception will be thrown.
215215
216-
The function is assumed to respect the contract of \\=`clojure.pprint/pprint\\=`
217-
with respect to the bound values of \\=`*print-length*\\=`, \\=`*print-level*\\=`,
218-
\\=`*print-meta*\\=`, and \\=`clojure.pprint/*print-right-margin*\\=`."
216+
The function should ideally have a two-arity variant that accepts the
217+
object to print and a map of configuration options for the printer. See
218+
`cider-pprint-options' for details.
219+
220+
The function is also assumed to respect the contract of
221+
\\=`clojure.pprint/pprint\\=` with respect to the bound values of
222+
\\=`*print-length*\\=`, \\=`*print-level*\\=`, \\=`*print-meta*\\=`, and
223+
\\=`clojure.pprint/*print-right-margin*\\=`. Those would normally serve as
224+
fallback values when a map of print options is not supplied explicitly."
219225
:type '(choice (const pprint)
220226
(const fipp)
221227
(const puget)
@@ -246,11 +252,13 @@ able to handle those. Here's an example for `pprint':
246252
PPRINT-FN is the name of the Clojure function to use.
247253
RIGHT-MARGIN specifies the maximum column-width of the pretty-printed
248254
result, and is included in the request if non-nil."
249-
(nconc `("printer" ,(or pprint-fn (cider--pprint-fn)))
250-
(and cider-pprint-options `("print-options" ,cider-pprint-options))
251-
;; TODO: figure out what to do with this margin
252-
;; probably it should be merged with the cider-pprint-options
253-
(and right-margin `("print-right-margin" ,right-margin))))
255+
(let* ((print-options (or cider-pprint-options (nrepl-dict))))
256+
;; TODO: Currently this will work only for pprint. We have to add some function
257+
;; to translate the option names for the various pprint backends.
258+
(when right-margin
259+
(setq print-options (nrepl-dict-put print-options "right-margin" right-margin)))
260+
(nconc `("printer" ,(or pprint-fn (cider--pprint-fn)))
261+
(and (not (nrepl-dict-empty-p print-options)) `("print-options" ,print-options)))))
254262

255263
(defun cider--nrepl-content-type-plist ()
256264
"Plist to be appended to an eval request to make it use content-types."

0 commit comments

Comments
 (0)