Skip to content

Commit

Permalink
[Fix #2023] Make popup-buffer sexp indentation optional (#2038)
Browse files Browse the repository at this point in the history
- Add optional inhibit-indent argument to cider-emit-into-popup-buffer.

- Inhibit indentation where output is already indented (pprint) or not sexps.
  • Loading branch information
ak-coram authored and bbatsov committed Jul 10, 2017
1 parent 2dafa65 commit d445ffc
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 14 deletions.
28 changes: 17 additions & 11 deletions cider-interaction.el
Original file line number Diff line number Diff line change
Expand Up @@ -806,15 +806,18 @@ COMMENT-PREFIX is the comment prefix to use."
"Make a handler for evaluating and printing stdout/stderr in popup BUFFER.
This is used by pretty-printing commands and intentionally discards their results."
(nrepl-make-response-handler (or buffer (current-buffer))
'()
;; stdout handler
(lambda (buffer str)
(cider-emit-into-popup-buffer buffer (ansi-color-apply str)))
;; stderr handler
(lambda (buffer str)
(cider-emit-into-popup-buffer buffer (ansi-color-apply str)))
'()))
(cl-flet ((popup-output-handler (buffer str)
(cider-emit-into-popup-buffer buffer
(ansi-color-apply str)
nil
t)))
(nrepl-make-response-handler (or buffer (current-buffer))
'()
;; stdout handler
#'popup-output-handler
;; stderr handler
#'popup-output-handler
'())))

(defun cider-visit-error-buffer ()
"Visit the `cider-error-buffer' (usually *cider-error*) if it exists."
Expand Down Expand Up @@ -1483,7 +1486,7 @@ Defaults to the current ns. With prefix arg QUERY, prompts for a ns."
"Refresh LOG-BUFFER with RESPONSE."
(nrepl-dbind-response response (out err reloading status error error-ns after before)
(cl-flet* ((log (message &optional face)
(cider-emit-into-popup-buffer log-buffer message face))
(cider-emit-into-popup-buffer log-buffer message face t))

(log-echo (message &optional face)
(log message face)
Expand Down Expand Up @@ -1577,7 +1580,10 @@ refresh functions (defined in `cider-refresh-before-fn' and
(when cider-refresh-show-log-buffer
(cider-popup-buffer-display log-buffer))
(when inhibit-refresh-fns
(cider-emit-into-popup-buffer log-buffer "inhibiting refresh functions\n"))
(cider-emit-into-popup-buffer log-buffer
"inhibiting refresh functions\n"
nil
t))
(when clear?
(cider-nrepl-send-sync-request '("op" "refresh-clear") conn))
(cider-nrepl-send-request
Expand Down
8 changes: 5 additions & 3 deletions cider-popup.el
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,9 @@ and automatically removed when killed."
nil 'local))
(current-buffer)))

(defun cider-emit-into-popup-buffer (buffer value &optional face)
"Emit into BUFFER the provided VALUE optionally using FACE."
(defun cider-emit-into-popup-buffer (buffer value &optional face inhibit-indent)
"Emit into BUFFER the provided VALUE optionally using FACE.
Indents emitted sexp value unless INHIBIT-INDENT is specified and non-nil."
;; Long string output renders Emacs unresponsive and users might intentionally
;; kill the frozen popup buffer. Therefore, we don't re-create the buffer and
;; silently ignore the output.
Expand All @@ -121,7 +122,8 @@ and automatically removed when killed."
(add-face-text-property 0 (length value-str) face nil value-str)
(add-text-properties 0 (length value-str) (list 'face face) value-str)))
(insert value-str))
(indent-sexp)
(unless inhibit-indent
(indent-sexp))
(set-marker cider-popup-output-marker (point)))
(when moving (goto-char cider-popup-output-marker))))))

Expand Down

0 comments on commit d445ffc

Please sign in to comment.