nesbox / TIC-80

TIC-80 is a fantasy computer for making, playing and sharing tiny games.
https://tic80.com
MIT License
4.91k stars 474 forks source link

[Suggestion] Save code editor bookmarks in cart as formfeed character #2272

Open AlecTroemel opened 12 months ago

AlecTroemel commented 12 months ago

As far as I can tell Bookmarks within the Code editor are not actually saved to the cart. That means they go away when you reload the cart or restart tic80 in any way.

My suggestion is to save these bookmarks in the source code using a Formfeed Character. I've been experimenting with this within emacs. Some observations/thoughts

  1. It doesnt break tic80 in any way.. at least not in Janet code
  2. Shows up as a blank character within the code editor
  3. seems like a good easy way for external text editors to also display bookmarks!

Some more details on the formfeed character and "Pages" here --> https://www.gnu.org/software/emacs/manual/html_node/emacs/Pages.html

If this is agreeable to the people here, I'd be happy to try my hand at implementing this!

joshgoebel commented 12 months ago

I'd be against this approach as this as it sounds very much like a hack IMHO... if we really want to save bookmarks lets define a chunk type of the cartridge for doing so and then persist them properly.

AlecTroemel commented 12 months ago

the only downside to storing bookmarks in a chunk type is that the bookmarks are separated from the source. That would complicate any external editor support, but that shouldn't really be the concern of tic80. Plus chunks do seem like the more "conical" way of saving any sort of cart data... Im convinced!

A simple approach would be to simply store the line number of the bookmark, something like this

<BOOKMARKS>
001:10
002:123

the example would result in bookmarks at lines 10 and 123.

joshgoebel commented 12 months ago

Well tic80 already has code to persist binary chunks to TXT (that it uses for all the other areas of a cartridge inside a TXT file)... so any editor that really wanted to support bookmarks could just read and write that area of the TXT cartridge... I can't imagine it would be encoded all the difficult, perhaps just an array of words?

Skeptim commented 11 months ago

Thumb up to this conversation ! :+1: Bookmark persistence may be one of the last big misses for me, subjectively.

AlecTroemel commented 11 months ago

@joshgoebel I'm still try to wrap my head around chunks so forgive my ignorance :smile:

By "just an array of words", do you mean a list of "binary words"? like 00000110 means "there's a bookmark on line 3"?

joshgoebel commented 11 months ago

Well that's a byte, 8 bits... I meant a word (2 bytes)... which lets you bookmark values between 1-65535... no need to get fancy. So for 20 bookmarks you'd need 20 words or a chunk of 40 bytes...