universal-ctags / citre

A superior code reading & auto-completion tool with pluggable backends.
GNU General Public License v3.0
326 stars 26 forks source link

tool, feat: peek through #35

Closed AmaiKinono closed 3 years ago

AmaiKinono commented 3 years ago

Go down the rabbit hole without leaving current buffer!

peek-through

When in a peek session, call M-x peek-through or M-o t (the key binding may change), then an "ace" string will be attached to each symbol in the peek window, type it to peek the definition of that symbol.

This is really powerful, we can chase a definition/call chain without even moving the cursor!

@masatake please give me flowers, I bet you'll like it ;)

TODO:

Update: I found this gives an elegant solution to cross reading.

So, let's also implement cross reading in this PR.

masatake commented 3 years ago

I'm sorry that I don't respond to your calls. It will be nice.

I would like you to ask one thing; when making a screencast(?), could you use emacs started with -q option? (Of course, the extension your code requires must be enabled. I'm talking about the rest extensions.) Your emacs is so different from mine. So it is hard for me to recognize which parts you wrote.

AmaiKinono commented 3 years ago

Here you go:

peek-through-vanilla-emacs

I do changed the font, and set suggest-key-bindings to nil (the "you can press some key to run some command" defers the peek window to show up).

masatake commented 3 years ago

I understand it well. ~This looks very powerful.~ This makes code-reading more predictable (or deterministic); this reduces unwanted-jumps. How do I say... this change provides the way to do pre-fetching or speculative-execution in code reading.

The most impressive one is the last line: stringList -> ptrArray -> sPtrArray. I'm feeling something important is in the line.

How do you call A -> B -> C? Privately, I call it a chain. If citre records the chains a user has built, citre can calculate hot-subchains.

I must try this one.

AmaiKinono commented 3 years ago

this reduces unwanted-jumps.

Yes. Even citre-peek already saves many of them, it's still a pain to peek - jump - peek - jump... then clean up unwanted buffers afterwards.

How do you call A -> B -> C? Privately, I call it a chain.

In my code I call it "symbol history". Chain is definitely a better name, let me think about it...

If citre records the chains a user has built...

This is a planned feature. It will save all your peek sessions, and the chain of each session. I expect people to use clue to arrange them later.

citre can calculate hot-subchains.

Looks like a fancy idea. I was thinking of presenting history in the order of time, but with this concept we could presenting them in the order of frequency (but that may become "hot-locations" and not "hot-subchains"). Anyway, this is to be explored after we support history in citre-peek. Do you have more ideas on this?

AmaiKinono commented 3 years ago

Actually I've thought about something like grep-peek. The "peeking" approach in Citre seems to be a general mechanism to offer convenient filtering/reading experience on locations. But that's out the scope of Citre, and unrealistic for me to write another package now...

AmaiKinono commented 3 years ago

I am thinking should we allow the chain to branch. I don't have much experience in code reading, but I'm learning and hacking C recently, and sometimes I was peeking a struct, and more than 1 fields in it have custom types, and I want to know all of them.

We could:

The real question is whether we really need a tree for history. Ideally we should give the answer based on how people read code in real life. But if we can't get relevant facts or testimonies, I may have to do what I prefer.

To keep the chain useable even after some editing, we could reuse the technique of locating a tag in Citre.

This is just the history of one peek session. How to deal with the whole peek history (with all the sessions) is another problem, but we could consider it later.

masatake commented 3 years ago

codetour uses a term "tour".

masatake commented 3 years ago

The result of reading may be linear. However, the process for reading requires a tree. At the start of the reading, the reader may build a tree. At the end of the reading, the reader finds the best path from the root to a leaf.

AmaiKinono commented 3 years ago

codetour uses a term "tour".

That plugin looks very interesting. Maybe it's possible to bring some of its idea to clue.

About the name...

Btw, I have to say you have the talent to name things. Although you always says you are not good at English, I feel at least you are very good at technical terms, and they seem to be your inspiration on naming things...

The result of reading may be linear. However, the process for reading requires a tree. At the start of the reading, the reader may build a tree. At the end of the reading, the reader finds the best path from the root to a leaf.

Thanks for this good summary! I also tend to let citre-peek to support tree history. I do want to say:

AmaiKinono commented 3 years ago

I've finished most of the works. Some ideas of further improving citre-peek will be put in #18.

Now it's able to browse through the tree history:

peek-tree

Notice the bottom line, where it shows the symbol chain. It uses < to show a branch, and you could switch between branches. I've set the keymap to use meta+up/down/left/right to browse the tree.

Another goodie is the command citre-peek-restore. After citre-abort, it restores the aborted session. This allows you to pause a code reading session and continue it later.