summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim King <kingtim@gmail.com>2013-01-30 18:22:25 -0800
committerBozhidar Batsov <bozhidar@tradeo.com>2013-01-31 11:43:39 +0200
commit9793e2b4f19c423dbedd8287ea049512433d768f (patch)
treeab5b0bbbabc1138a24b7da57a6c6e8a237d6cba0
parentc81b3848a2a19d3b2fd43b67254ea97e96b777f5 (diff)
Merge pull request #162. pprint mode for REPL.
-rw-r--r--nrepl.el21
1 files changed, 18 insertions, 3 deletions
diff --git a/nrepl.el b/nrepl.el
index ce78d1a3..c90a9bf3 100644
--- a/nrepl.el
+++ b/nrepl.el
@@ -201,6 +201,8 @@ you'd like to use the default Emacs behavior use
:type 'symbol
:group 'nrepl)
+(defvar nrepl-pretty nil)
+
(defun nrepl-make-variables-buffer-local (&rest variables)
"Make all VARIABLES buffer local."
(mapcar #'make-variable-buffer-local variables))
@@ -1183,6 +1185,7 @@ This function is meant to be used in hooks to avoid lambda
["Display Source" nrepl-src]
["Display JavaDoc" nrepl-javadoc]
["Switch to REPL" nrepl-switch-to-repl-buffer]
+ ["Toggle REPL Pretty Print" nrepl-pretty-toggle]
["Clear REPL" nrepl-find-and-clear-repl-buffer]
["Load current buffer" nrepl-load-current-buffer]
["Load file" nrepl-load-file]
@@ -1612,7 +1615,7 @@ If NEWLINE is true then add a newline at the end of the input."
(unless (nrepl-in-input-area-p)
(error "No input at point"))
(goto-char (point-max))
- (let ((end (point))) ; end of input, without the newline
+ (let ((end (point))) ; end of input, without the newline
(nrepl-add-to-input-history (buffer-substring nrepl-input-start-mark end))
(when newline
(insert "\n")
@@ -1627,11 +1630,13 @@ If NEWLINE is true then add a newline at the end of the input."
;; by kill/yank.
(overlay-put overlay 'read-only t)
(overlay-put overlay 'face 'nrepl-input-face)))
- (let ((input (nrepl-current-input)))
+ (let* ((input (nrepl-current-input))
+ (form (if (and (not (string-match "\\`[ \t\r\n]*\\'" input)) nrepl-pretty)
+ (format "(clojure.pprint/pprint %s)" input) input)))
(goto-char (point-max))
(nrepl-mark-input-start)
(nrepl-mark-output-start)
- (nrepl-send-string input (nrepl-handler (current-buffer)) nrepl-buffer-ns)))
+ (nrepl-send-string form (nrepl-handler (current-buffer)) nrepl-buffer-ns)))
(defun nrepl-newline-and-indent ()
"Insert a newline, then indent the next line.
@@ -1738,6 +1743,16 @@ text property `nrepl-old-input'."
(insert ")")))
(nrepl-return))
+(defun nrepl-pretty-toggle ()
+ (interactive)
+ (if nrepl-pretty
+ (progn
+ (setq nrepl-pretty nil)
+ (message "nrepl pretty printing now OFF"))
+ (progn
+ (setq nrepl-pretty t)
+ (message "nrepl pretty printing now ON"))))
+
(defvar nrepl-clear-buffer-hook)
(defun nrepl-clear-buffer ()