mmontone / emacs-inspector

Inspection tool for Emacs Lisp objects.
GNU General Public License v3.0
107 stars 9 forks source link

A second format for the history #8

Open edrx opened 2 years ago

edrx commented 2 years ago
Hi Mario,

can you help me to add a second format for the "history" to inspector?
I saw that one of the buffer-local variables of an "*inspector*"
buffer is `inspector-history`, and I'm imagining some changes in which
inspector would also keep a second buffer-local variable, called, say,
`inspector-history-b`... let me start by explaining its format.

If we run this with our favorite variant or C-x C-e,

  (setq aaa '(20 (((3 3.0) "3") 30 300) 40))
  (inspect-expression 'aaa)

then we can navigate to "sub-objects" of aaa, in this order:

   (20 (((3 3.0) "3") 30 300) 40)
       (((3 3.0) "3") 30 300)
        ((3 3.0) "3")
         (3 3.0)
            3.0

After reaching the 3.0 the value of `inspector-history-b` would the
`reverse` of this list:

  (aaa
   (nth 1 it)
   car
   car
   cdr)

The first element of that list is something that when eval-ed would
yield the original object on which we called inspector, and the other
items of the list are instructions to obtain each next object from the
previous one... I played a bit with a prototype of this idea, and I
used this code:

  (defun ee-sub1 (it f)
    (if (symbolp f) (funcall f it) (eval f)))

  (defun ee-sub (itfs)
    (let* ((it (eval (car itfs)))
           (fs (cdr itfs)))
      (while fs
        (setq it (ee-sub1 it (car fs)))
        (setq fs (cdr fs)))
      it))

  (setq aaa '(20 (((3 3.0) "3") 30 300) 40))

  (ee-sub '(aaa))
  (ee-sub '(aaa cadr))
  (ee-sub '(aaa cadr car))
  (ee-sub '(aaa cadr car (car it)))
  (ee-sub '(aaa cadr car (car it) cadr))

This feature would be very useful to me because with it I will be able
to keep series of elisp hyperlinks like this

  (find-einspectorb '(aaa))
  (find-einspectorb '(aaa cadr))
  (find-einspectorb '(aaa cadr car))
  (find-einspectorb '(aaa cadr car (car it)))
  (find-einspectorb '(aaa cadr car (car it) cadr))

in my notes - for the rationale see
<http://angg.twu.net/find-elisp-intro.html>, from 15:58 onwards, and
<http://angg.twu.net/eev-intros/find-here-links-intro.html#2> - and
this would be great for inspecting objects that contain byte-compiled
code, because then I will be able to record a path to a position that
I want to understand, then I can run some sexps like (load "foo.el") -
not (load "foo.elc")! - and then I'll be able to follow the same path
and see if the byte-compiled code became a lambda...
mmontone commented 2 years ago

Hi.

I don't understand this stuff very well. I'm a bit concerned it might complicate the inspector package unnecessarily. Do you think this could be implemented as a separate package as an extension? I can modify the inspector history calls somehow so that you can plug-in your package.

edrx commented 2 years ago
Hi Mario,

Hi! Sure, let's keep this idea in a separate file that can be loaded
after inspector, and that adds some functions and redefines some other
ones...

Can you take a look at this

http://angg.twu.net/elisp/eev-inspect.el.html
http://angg.twu.net/elisp/eev-inspect.el

and see if it makes sense? And then if it does, can you take a look at
the definition of `inspect-expression-b' and help me with the setqs in
comments?

Thanks in advance!!!
  Eduardo
mmontone commented 2 years ago

Hi, sorry, but I don't have much time for this atm. I can evaluate a pull request and merge, but you have to do the work.

About your question:

;;
    ;; HELP NEEDED HERE:
    ;; These setqs need to be run in the "*inspector" buffer.
    ;; Mario, what is the right way to do that?
    ;; (setq inspector-inspected-object (car history))
    ;; (setq inspector-history (cdr history))
    ;; (setq inspector-history-b history-b)
    ;;

Use

(with-current-buffer "*inspector*"
 (setq inspector-inspected-object (car history))
  (setq inspector-history (cdr history))
   (setq inspector-history-b history-b))
edrx commented 2 years ago

Thanks! It works, and this does a part of what I need. The other part will require patching several of the "(cl-defmethod inspect-object ...)"s, and I don't have time to play with that now, either... so: see you in a few months, and thanks for inspector! =)