snosov1 / toc-org

toc-org is an Emacs utility to have an up-to-date table of contents in the org files without exporting (useful primarily for readme files on GitHub)
GNU General Public License v3.0
292 stars 29 forks source link

Feature request: "Back to top" href link #72

Closed tru2dagame closed 3 years ago

tru2dagame commented 3 years ago

Hi,

Would it be possible to have an options to add a "back to top" href link? Because when reading a long readme, it takes a long time to scroll to the TOC, and it's not easy to find where you just clicked.

Thanks.

snosov1 commented 3 years ago

Hey, @tru2dagame !

I think you should try to approach this by using emacs navigation facilities.

  1. point-to-register might be the most "conventional" way to do it
  2. Personally, I use pop-mark-jump to jump around. It's a heuristic (so doesn't work in 100% of cases), but it cuts it for me.

Hopefully, that helps

tru2dagame commented 3 years ago

@snosov1 Thanks for the reply. Thanks for the suggestion also.

Actually the problem isn't in Emacs world. It happens when read the file in GitHub web.

snosov1 commented 3 years ago

Hmm, i thought about it only after i sent the previous message. Though, I'm not sure how can you implement that. Can you give an example ?

tru2dagame commented 3 years ago

I don't have a good way to implement this yet. Currently I added a link manually like this:

[[#contents][🔝]]

You can preview the demo here. It would be a lot easy if I share the GitHub page to someone reading.

snosov1 commented 3 years ago

Well, that's what I was thinking. The thing is - it kinda violates the implicit design choice for this package to confine itself to a single heading only. It doesn't require any special metadata in other headings (like, :PROPERTIES:) and it doesn't edit anything beyond the TOC heading itself.

Another problem is that there can be various opinions on how deep do you wanna go. Does every heading has a back button? Even level-4,5,6 headings? I guess, this can get rather hairy. If it's only for level-1 (2, 3?) headings - is it frequently enough? I don't know.

And as leaving an explicit href is something that's trivial to do manually (or programmatically - you almost don't need any parsing, just copy-paste the same link around), I think, it's ok to leave it up to the user.

tru2dagame commented 3 years ago

Yes. The problem is that I don't find a way to set every TOC header an unique id like this

<a href="#header1" id="header1-top">header1</a>

If above is possible, we could easily set every top button to go back to the TOC header itself.

<a href="#header1-top">🔝</a>