joaotavora / sly

Sylvester the Cat's Common Lisp IDE
1.26k stars 142 forks source link

Multiple selection in sly-toggle-fancy-trace and sly-trace-dialog-toggle-trace? #362

Open Ambrevar opened 3 years ago

Ambrevar commented 3 years ago

In big complex systems it can br quickly useful to be able to trace many functions in bulk.

For instance I would like to trace all functions in a given package, or maybe all functions that start with "foo-".

I believe the easy fix would be to allow multiple results in sly-toggle-fancy-trace and sly-trace-dialog-toggle-trace.

Currently the trace commands prompt the user with sly-flex-completions. By the way, it uses sly-flex-completions even when sly-complete-symbol-function is set to sly-simple-completions. Bug?

I can see 2 options:

Thoughts?

Ambrevar commented 3 years ago

In the meantime, I'm using this workaround in Common Lisp:

(export 'trace-all)
(defun trace-all (regexp &optional (package *package*))
  (asdf:load-system :cl-ppcre)
  (let ((package (if (packagep package)
                     package
                     (uiop:ensure-package package)))
        (result nil))
    (do-symbols (s package)
      (when (and (eq (symbol-package s) package)
                 (funcall (symbol-function (find-symbol (string 'scan)
                                                        (find-package 'ppcre)))
                          regexp (string s)))
        (push s result)))
    (eval `(trace ,@result))))
joaotavora commented 3 years ago

eval looks pretty bad, but any reasonable and simple solution to your problem would entail exposing the primitives in the Common Lisp side that do the tracing and letting a user like you call them however you wish.

By the way there are two different trace facilities in SLY.

  1. Regular Common Lisp trace, as you seem to be using in your snippet
    1. The SLY trace dialog (and then there are lots of implementation specific encapsulation/advice facilities)

I assume we're talking about 2, the SLY trace dialog. This clarification is important because sly-toggle-fancy-trace, as you mention in the title, is not specific to the SLY trace dialog. In fact, I don't understand what its relevance here is.

Ambrevar commented 3 years ago

João Távora notifications@github.com writes:

eval looks pretty bad, but any reasonable and simple solution to your problem would entail exposing the primitives in the Common Lisp side that do the tracing and letting a user like you call them however you wish.

Indeed, trace is a macro.

By the way there are two different trace facilities in SLY.

  1. Regular Common Lisp trace, as you seem to be using in your snippet
    1. The SLY trace dialog (and then there are lots of implementation specific encapsulation/advice facilities)

I assume we're talking about 2, the SLY trace dialog.

Yes, my snippet uses 1. simply because that's the fastest workaround I found. An ideal implementation would use 2.

This clarification is important because sly-toggle-fancy-trace, as you mention in the title, is not specific to the SLY trace dialog. In fact, I don't understand what its relevance here is.

I don't know the details, but I've mentioned sly-toggle-fancy-trace because it completes against the same symbols as sly-trace-dialog-toggle-trace. Or does it?

Anyways, for the sake of this discussion, we can focus on sly-trace-dialog-toggle-trace.