summaryrefslogtreecommitdiff
path: root/cider-debug.el
diff options
context:
space:
mode:
authorArtur Malabarba <bruce.connor.am@gmail.com>2016-02-04 10:14:40 +0000
committerArtur Malabarba <bruce.connor.am@gmail.com>2016-02-05 20:20:13 +0000
commitc4e55e2f7bea7f0dd1386df0e3bafbbf9e7a7c84 (patch)
treeaebab266bfe9bb5727701896017f96fd34f8d2f2 /cider-debug.el
parent55aba3d7beeb8bc635e1e51e85dcc05e99dc37ef (diff)
New feature: Enlighten
Handle :enlighten messages through the debug channel. Define cider-enlighten-mode. Font-lock enlightened defns. Document Enlighten.
Diffstat (limited to 'cider-debug.el')
-rw-r--r--cider-debug.el49
1 files changed, 49 insertions, 0 deletions
diff --git a/cider-debug.el b/cider-debug.el
index 81430f5b..08c5364f 100644
--- a/cider-debug.el
+++ b/cider-debug.el
@@ -63,6 +63,23 @@
:group 'cider-debug
:package-version '(cider . "0.10.0"))
+(defface cider-enlightened
+ '((((class color) (background light)) :inherit cider-result-overlay-face
+ :box (:color "darkorange" :line-width -1))
+ (((class color) (background dark)) :inherit cider-result-overlay-face
+ ;; "#dd0" is a dimmer yellow.
+ :box (:color "#dd0" :line-width -1)))
+ "Face used to mark enlightened sexps and their return values."
+ :group 'cider-debug
+ :package-version '(cider . "0.11.0"))
+
+(defface cider-enlightened-local
+ '((((class color) (background light)) :weight bold :foreground "darkorange")
+ (((class color) (background dark)) :weight bold :foreground "yellow"))
+ "Face used to mark enlightened locals (not their values)."
+ :group 'cider-debug
+ :package-version '(cider . "0.11.0"))
+
(defcustom cider-debug-prompt 'overlay
"If and where to show the keys while debugging.
If `minibuffer', show it in the minibuffer along with the return value.
@@ -127,6 +144,8 @@ This variable must be set before starting the repl connection."
(defun cider--debug-response-handler (response)
"Handle responses from the cider.debug middleware."
(nrepl-dbind-response response (status id causes)
+ (when (member "enlighten" status)
+ (cider--handle-enlighten response))
(when (or (member "eval-error" status)
(member "stack" status))
;; TODO: Make the error buffer a bit friendlier when we're just printing
@@ -585,6 +604,36 @@ needed. It is expected to contain at least \"key\", \"input-type\", and
(error (cider-debug-mode-send-reply ":quit" key)
(message "Error encountered while handling the debug message: %S" e)))))
+(defun cider--handle-enlighten (response)
+ "Handle an enlighten notification.
+RESPONSE is a message received from the nrepl describing the value and
+coordinates of a sexp. Create an overlay after the specified sexp
+displaying its value."
+ (when-let ((marker (cider--debug-find-source-position response)))
+ (with-current-buffer (marker-buffer marker)
+ (save-excursion
+ (goto-char marker)
+ (clojure-backward-logical-sexp 1)
+ (nrepl-dbind-response response (debug-value erase-previous)
+ (when erase-previous
+ (remove-overlays (point) marker 'cider-type 'enlighten))
+ (when debug-value
+ (if (memq (char-before marker) '(?\) ?\] ?}))
+ ;; Enlightening a sexp looks like a regular return value, except
+ ;; for a different border.
+ (cider--make-result-overlay (cider-font-lock-as-clojure debug-value)
+ :where (cons marker marker)
+ :type 'enlighten
+ :prepend-face 'cider-enlightened)
+ ;; Enlightening a symbol uses a more abbreviated format. The
+ ;; result face is the same as a regular result, but we also color
+ ;; the symbol with `cider-enlightened-local'.
+ (cider--make-result-overlay (cider-font-lock-as-clojure debug-value)
+ :format "%s"
+ :where (cons (point) marker)
+ :type 'enlighten
+ 'face 'cider-enlightened-local))))))))
+
;;; Move here command
;; This is the inverse of `cider--debug-move-point'. However, that algorithm is