mmontone / emacs-inspector

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

Line truncation in *inspector* buffers #20

Closed yantar92 closed 1 year ago

yantar92 commented 1 year ago

I am trying to use inspector to check a real nested list data and I find the current truncation behaviour inconvenient. I just got the following

proper list ──────────────────────────────────────────────────────────────────────────────────────────── length: 7

0: paragraph 1: (:begin 1 :end 44 :contents-begin 1 :contents-end 42 :post-blank 2 :post-affili… 2: #("Text with newline " 0 18 (:parent (paragraph (:begin 1 :end 44 :contents-beg… 3: (line-break (:begin 19 :end 22 :post-blank 0 :parent (paragraph (:begin 1 :end … 4: #(" " 0 1 (:parent (paragraph (:begin 1 :end 44 :contents-begin 1 :contents-end… 5: (footnote-reference (:label "1" :type standard :begin 23 :end 31 :contents-begi… 6: #("more text. " 0 11 (:parent (paragraph (:begin 1 :end 44 :contents-begin 1 :co…

I see two problems with this text:

  1. Upon resizing the window, the truncation does not get updated.
  2. The truncation is much less convenient compared to what debugger does in similar scenarios - it would be more useful to truncate by depth:

    ("Text with newline " 0 18 (:parent (paragraph …)) )

mmontone commented 1 year ago

Ok. If you know how to code in elisp I welcome some tips on a possible implementation approach :)

yantar92 commented 1 year ago

Check out backtrace--print-to-string.

mmontone commented 1 year ago

Thanks for the pointer. I'll look.

About the horizontal line, I couldn't find anything about how to draw a horizontal line that adapts to window size when it changes. It'd help if you can find something about that too.

mmontone commented 1 year ago

Or perhaps I should just consider removing the horizontal line and give emphasis to the title, with bold font, or color/background color, something like that.

yantar92 commented 1 year ago

Try

(with-silent-modifications (insert (propertize " " 'display '(space :align-to right-fringe))))
(with-silent-modifications (put-text-property (1- (point)) (point) 'face '(:strike-through t)))
mmontone commented 1 year ago

Ok. I'll do.

About the resizes, there's window-size-change-functions hook.

I could try to hook and redraw the buffer when window changes. Truncation should be made to use current window size.

yantar92 commented 1 year ago

About the resizes, there's window-size-change-functions hook.

Be careful about performance. An alternative could be allowing to refresh the buffer manually.

mmontone commented 1 year ago

Noted. Perhaps use a customization variable to toggle that behavior.

mmontone commented 1 year ago

Yes. I like the ability to be able to refresh the buffer in any case. That should be added.

mmontone commented 1 year ago

Pushed first attempt of truncation method based on backtrace--print-string. It looks better IMO. The ... buttons don't work though, because there's an inspector button that overwrites those and performs navigation to the object.

yantar92 commented 1 year ago

buttons don't work though, because there's an inspector button that overwrites those and performs navigation to the object.

Sounds like not a big deal. Navigation will reveal the details anyway. I will be able to tell more when I actually use this in practice.

mmontone commented 1 year ago

You can try it now with your data and give me some feedback. It is better IMO.

mmontone commented 1 year ago

I'm using this to test:

(require 'request)
(require 'json)

(request "https://www.govtrack.us/api/v2/role?current=true&role_type=senator"
  :success (lambda (&rest args)
         (inspector-inspect (json-read-from-string (cl-getf args :data)))))
yantar92 commented 1 year ago

Sure, it looks better. But I was referring to actual daily usage when debugging staff, where I need to get meaningful understanding of the data. It will take time.

Should not prevent you from considering this aspect of the issue closed though. I will open a new issue if necessary.

yantar92 commented 1 year ago

Yes. I like the ability to be able to refresh the buffer in any case. That should be added.

A standard way would be revert-buffer-function.

mmontone commented 1 year ago

Ah. I've pushed an inspector-refresh command. I should look at the revert-buffer-function.

mmontone commented 1 year ago

I've hooked into revert-buffer-function in https://github.com/mmontone/emacs-inspector/commit/4d58a95ad9d8c6093d5daffd324aa9331fdb1430

yantar92 commented 1 year ago

LGTM.