summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CHANGELOG.md1
-rw-r--r--cider-client.el2
-rw-r--r--cider-interaction.el16
-rw-r--r--cider-repl.el17
-rw-r--r--test/cider-repl-tests.el11
5 files changed, 35 insertions, 12 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 783ec582..526c429c 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -13,6 +13,7 @@
### Bugs Fixed
* [#1707](https://github.com/clojure-emacs/cider/issues/1707): Allow to customize line truncating in CIDER's special buffers.
+* [#1876](https://github.com/clojure-emacs/cider/issues/1876): Set pretty-printing width with `cider-repl-pretty-print-width`. If this variable is not set, fall back to `fill-column`.
## 0.14.0 (2016-10-13)
diff --git a/cider-client.el b/cider-client.el
index 90b3193c..cc5ae78d 100644
--- a/cider-client.el
+++ b/cider-client.el
@@ -995,7 +995,7 @@ CONTEXT represents a completion context for compliment."
(cider-nrepl-send-sync-request)
(nrepl-dict-get "formatted-code")))
-(defun cider-sync-request:format-edn (edn &optional right-margin)
+(defun cider-sync-request:format-edn (edn right-margin)
"Perform \"format-edn\" op with EDN and RIGHT-MARGIN."
(let* ((response (thread-first (list "op" "format-edn"
"session" (cider-current-session)
diff --git a/cider-interaction.el b/cider-interaction.el
index 261ba72b..36b62212 100644
--- a/cider-interaction.el
+++ b/cider-interaction.el
@@ -1141,13 +1141,11 @@ If invoked with a PREFIX argument, switch to the REPL buffer."
"Evaluate the expression preceding point and insert its pretty-printed result in the REPL.
If invoked with a PREFIX argument, switch to the REPL buffer."
(interactive "P")
- (let* ((conn-buffer (cider-current-connection))
- (right-margin (max fill-column
- (1- (window-width (get-buffer-window conn-buffer))))))
+ (let* ((conn-buffer (cider-current-connection)))
(cider-interactive-eval nil
(cider-insert-eval-handler conn-buffer)
(cider-last-sexp 'bounds)
- (cider--nrepl-pprint-request-plist (or right-margin fill-column))))
+ (cider--nrepl-pprint-request-plist (cider--pretty-print-width))))
(when prefix
(cider-switch-to-repl-buffer)))
@@ -1162,13 +1160,11 @@ Print its value into the current buffer."
(defun cider--pprint-eval-form (form)
"Pretty print FORM in popup buffer."
(let* ((result-buffer (cider-popup-buffer cider-result-buffer nil 'clojure-mode))
- (handler (cider-popup-eval-out-handler result-buffer))
- (right-margin (max fill-column
- (1- (window-width (get-buffer-window result-buffer))))))
+ (handler (cider-popup-eval-out-handler result-buffer)))
(cider-interactive-eval (when (stringp form) form)
handler
(when (consp form) form)
- (cider--nrepl-pprint-request-plist (or right-margin fill-column)))))
+ (cider--nrepl-pprint-request-plist (cider--pretty-print-width)))))
(defun cider-pprint-eval-last-sexp ()
"Evaluate the sexp preceding point and pprint its value in a popup buffer."
@@ -1598,7 +1594,7 @@ of the buffer into a formatted string."
(interactive)
(cider-ensure-connected)
(cider--format-buffer (lambda (edn)
- (cider-sync-request:format-edn edn fill-column))))
+ (cider-sync-request:format-edn edn (cider--pretty-print-width)))))
(defun cider--format-reindent (formatted start)
"Reindent FORMATTED to align with buffer position START."
@@ -1632,7 +1628,7 @@ START and END represent the region's boundaries."
(interactive "r")
(cider-ensure-connected)
(let* ((start-column (save-excursion (goto-char start) (current-column)))
- (right-margin (- fill-column start-column)))
+ (right-margin (- (cider--pretty-print-width) start-column)))
(cider--format-region start end
(lambda (edn)
(cider-sync-request:format-edn edn right-margin)))))
diff --git a/cider-repl.el b/cider-repl.el
index a4b1aef1..fd9bf18a 100644
--- a/cider-repl.el
+++ b/cider-repl.el
@@ -113,6 +113,15 @@ change the setting's value."
:type 'boolean
:group 'cider-repl)
+(defcustom cider-repl-pretty-print-width nil
+ "Control the width of pretty printing on the REPL.
+This sets the wrap point for pretty printing on the repl. If nil, it
+defaults to the variable `fill-column'."
+ :type '(restricted-sexp :match-alternatives
+ (integerp 'nil))
+ :group 'cider-repl
+ :package-version '(cider . "0.15.0"))
+
(defcustom cider-repl-use-clojure-font-lock t
"Non-nil means to use Clojure mode font-locking for input and result.
Nil means that `cider-repl-input-face' and `cider-repl-result-face'
@@ -719,7 +728,7 @@ If NEWLINE is true then add a newline at the end of the input."
(cider-column-number-at-pos input-start)
(unless (or (not cider-repl-use-pretty-printing)
(string-match-p "\\`[ \t\r\n]*\\'" input))
- (cider--nrepl-pprint-request-plist (1- (window-width)))))))
+ (cider--nrepl-pprint-request-plist (cider--pretty-print-width))))))
(defun cider-repl-return (&optional end-of-input)
"Evaluate the current input string, or insert a newline.
@@ -789,6 +798,12 @@ text property `cider-old-input'."
(message "Pretty printing in REPL %s."
(if cider-repl-use-pretty-printing "enabled" "disabled")))
+(defun cider--pretty-print-width ()
+ "Returns the width to use for pretty-printing."
+ (or cider-repl-pretty-print-width
+ fill-column
+ 80))
+
(defun cider-repl-switch-to-other ()
"Switch between the Clojure and ClojureScript REPLs for the current project."
(interactive)
diff --git a/test/cider-repl-tests.el b/test/cider-repl-tests.el
index 8fb2be90..79684cf4 100644
--- a/test/cider-repl-tests.el
+++ b/test/cider-repl-tests.el
@@ -131,3 +131,14 @@ PROPERTY shoudl be a symbol of either 'text, 'ansi-context or
(it "preserves the context"
(let ((context (simulate-cider-output "abcd" 'ansi-context)))
(expect context :to-equal '((31) nil))))))
+
+(describe "cider--pretty-print-width"
+ (it "prefers cider-repl-pretty-print-width"
+ (let ((cider-repl-pretty-print-width 40))
+ (expect (cider--pretty-print-width)
+ :to-equal cider-repl-pretty-print-width)))
+ (it "falls back to fill-column"
+ (let ((cider-repl-pretty-print-width nil)
+ (fill-column 80))
+ (expect (cider--pretty-print-width)
+ :to-equal fill-column))))