-
nik authored89a282e4
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
(eval-and-compile
(require 'sly))
(define-sly-contrib sly-fancy-trace
"Enhanced version of sly-trace capable of tracing local functions,
methods, setf functions, and other entities supported by specific
slynk:slynk-toggle-trace backends. Invoke via C-u C-t."
(:authors "Matthias Koeppe <mkoeppe@mail.math.uni-magdeburg.de>"
"Tobias C. Rittweiler <tcr@freebits.de>")
(:license "GPL")
(:sly-dependencies sly-parse))
(defun sly-trace-query (spec)
"Ask the user which function to trace; SPEC is the default.
The result is a string."
(cond ((null spec)
(sly-read-from-minibuffer "(Un)trace: "))
((stringp spec)
(sly-read-from-minibuffer "(Un)trace: " spec))
((symbolp spec) ; `sly-extract-context' can return symbols.
(sly-read-from-minibuffer "(Un)trace: " (prin1-to-string spec)))
(t
(sly-dcase spec
((setf n)
(sly-read-from-minibuffer "(Un)trace: " (prin1-to-string spec)))
((:defun n)
(sly-read-from-minibuffer "(Un)trace: " (prin1-to-string n)))
((:defgeneric n)
(let* ((name (prin1-to-string n))
(answer (sly-read-from-minibuffer "(Un)trace: " name)))
(cond ((and (string= name answer)
(y-or-n-p (concat "(Un)trace also all "
"methods implementing "
name "? ")))
(prin1-to-string `(:defgeneric ,n)))
(t
answer))))
((:defmethod &rest _)
(sly-read-from-minibuffer "(Un)trace: " (prin1-to-string spec)))
((:call caller callee)
(let* ((callerstr (prin1-to-string caller))
(calleestr (prin1-to-string callee))
(answer (sly-read-from-minibuffer "(Un)trace: "
calleestr)))
(cond ((and (string= calleestr answer)
(y-or-n-p (concat "(Un)trace only when " calleestr
" is called by " callerstr "? ")))
(prin1-to-string `(:call ,caller ,callee)))
(t
answer))))
(((:labels :flet) &rest _)
(sly-read-from-minibuffer "(Un)trace local function: "
(prin1-to-string spec)))
(t (error "Don't know how to trace the spec %S" spec))))))
(defun sly-toggle-fancy-trace (&optional using-context-p)
"Toggle trace."
(interactive "P")
(let* ((spec (if using-context-p
(sly-extract-context)
(sly-symbol-at-point)))
(spec (sly-trace-query spec)))
(sly-message "%s" (sly-eval `(slynk:slynk-toggle-trace ,spec)))))
;; override sly-toggle-trace-fdefinition
(define-key sly-prefix-map "\C-t" 'sly-toggle-fancy-trace)
(provide 'sly-fancy-trace)