Skip to content

Commit c980119

Browse files
committed
[Fix #1106] Display local variables in the debugger
1 parent 9fa3f31 commit c980119

File tree

1 file changed

+30
-7
lines changed

1 file changed

+30
-7
lines changed

cider-debug.el

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ sexp."
8787
RESPONSE is a message received form the nrepl describing the input
8888
needed. It is expected to contain at least \"key\", \"input-type\", and
8989
\"prompt\", and possibly other entries depending on the input-type."
90-
(nrepl-dbind-response response (debug-value key coor filename point input-type prompt)
90+
(nrepl-dbind-response response (debug-value key coor filename point input-type prompt locals)
9191
(let ((input))
9292
(unwind-protect
9393
(setq input
@@ -97,7 +97,7 @@ needed. It is expected to contain at least \"key\", \"input-type\", and
9797
((pred sequencep)
9898
(when (and filename point)
9999
(cider--debug-move-point filename point coor))
100-
(cider--debug-read-command input-type debug-value prompt))))
100+
(cider--debug-read-command input-type debug-value prompt locals))))
101101
;; No matter what, we want to send this request or the session will stay
102102
;; hanged.
103103
(nrepl-send-request
@@ -107,16 +107,39 @@ needed. It is expected to contain at least \"key\", \"input-type\", and
107107
"input" (or input ":quit"))
108108
#'ignore)))))
109109

110-
(defun cider--debug-read-command (command-list value prompt)
110+
(defvar cider--debug-display-locals nil
111+
"If non-nil, local variables are displayed while debugging.
112+
Can be toggled while debugging with `l'.")
113+
114+
(defun cider--debug-format-locals-list (locals)
115+
"Return a string description of list LOCALS.
116+
Each element of LOCALS should be a list of at least two elements."
117+
(let ((left-col-width
118+
;; To right-indent the variable names.
119+
(apply #'max (mapcar (lambda (l) (string-width (car l))) locals))))
120+
;; A format string to build a format string. :-P
121+
(mapconcat (lambda (l) (format (format "%%%ds: %%s\n" left-col-width)
122+
(propertize (car l) 'face 'font-lock-variable-name-face)
123+
(cider-font-lock-as-clojure (cadr l))))
124+
locals "")))
125+
126+
(defun cider--debug-read-command (command-list value prompt locals)
111127
"Receive input from the user representing a command to do.
112128
VALUE is displayed to the user as the output of last evaluated sexp."
113-
(let ((cider-interactive-eval-result-prefix (concat prompt "\n => ")))
129+
(let* ((prompt (concat (when cider--debug-display-locals
130+
(cider--debug-format-locals-list locals))
131+
prompt))
132+
(cider-interactive-eval-result-prefix (concat prompt " (l)ocals\n => ")))
114133
(cider--display-interactive-eval-result (or value "#unknown#")))
115134
(let ((alist `((?\C-\[ . ":quit") (?\C-g . ":quit")
116135
,@(mapcar (lambda (k) (cons (string-to-char k) (concat ":" k)))
117-
command-list))))
118-
(or (cdr (assq (read-char) alist))
119-
(cider--debug-read-command command-list value))))
136+
command-list)))
137+
(input (read-char)))
138+
(pcase input
139+
(?l (setq cider--debug-display-locals (not cider--debug-display-locals))
140+
(cider--debug-read-command command-list value prompt locals))
141+
(_ (or (cdr (assq input alist))
142+
(cider--debug-read-command command-list value prompt locals))))))
120143

121144

122145
;;; User commands

0 commit comments

Comments
 (0)