reddit / emacs
New package: text-categories
pcorrectness · 2022-04-05 17:53
Hi everyone,
I have made an emacs package and I would appreciate any feedback.
Its name is text-categories located here: [https://github.com/Dspil/text-categories](https://github.com/Dspil/text-categories)
Its purpose is to make debugging easier, but it might have other use cases. It essentially introduces categories for text. Each character in the buffer belongs to a category. The user can change the current category and every character inserted from then on will belong to the new category. The user can store a category which deletes all of its characters but remembers their position so they can be restored later. A category can also be completely erased. Lastly, the categories can be visualized in a separate buffer and the user can navigate through them in this buffer.
The main thing I use it for is adding all debugging extra code into a different category. I can switch to the main category and correct the bugs and when I am done, I can erase all the extra code as it all belongs to a different category.
bespokey · 2022-04-05 19:28
Looks interesting! What other packages are you familiar with that do similar things?
pcorrectness · 2022-04-05 20:45
When I made the pull request to add it to MELPA the closest thing the reviewers could think of is the built in undo in a specific region that emacs has. Other than that, I don't have anything in mind. Of course if you just want to locate bugs, maybe a debugger suits better, this is just general purpose.
bespokey · 2022-04-05 20:49
I see it persists across sessions, right?
Did you consider project-level categories so categories can be switched on/off on all files in a project?
arthurno1 · 2022-04-05 22:35
> When debugging code, it is not unusual to insert print statements and other temporary code in the program to locate the bugs. After locating all of them, it is impossible to undo or revert just the code used for debugging because it will revert the bug corrections too. This package defines a text category for inserted text. All text inserted belongs to text category “0” by default. It is possible to instruct the package to change the text category to any string.
That sounds interesting, but maybe not for the purpose you mention. We have all done our share of so called "printf" debugging 😀. I suggest you to invest 15 minutes into learning edebig, and you will never go back to printf-debugging again. I promise, it will save you a lot of time when debugging if you run your code in debugger instead of inserting printing statements and later on removing them, not to mention for the shear amount of data ut can produce.
Anyway, being able to quickly associate text property (category) with a text sounds like a useful thing. For example to mark text as bold, italic etc.
ndamee · 2022-04-06 05:31
Are you aware of this page of the manual and EDebug in it?
https://www.gnu.org/software/emacs/manual/html_node/elisp/Debugging.html
pcorrectness · 2022-04-06 07:12
Yes, it persists across sessions for a file but that can be disabled. I haven't considered the project level categories you mention but when you enable them on a file, the whole file belongs to the default category until you change that. So enabling it on many files at once seems unnecessary. Deleting a category across a whole project though sounds interesting, I'll consider that!
pcorrectness · 2022-04-06 07:16
Yes, for languages that I write a lot I use a debugger too, but when I write in an new language that I don't know how to use a debugger yet or if I want something very specific to check out across multiple runs of the program this has been useful for me.
pcorrectness · 2022-04-06 07:29
I agree that a debugger is more useful than printing stuff. Edebug though is for emacs lisp. This is for any language you want even if they don't have a debugger or you haven't invested the time yet to learn how to use the debugger.
arthurno1 · 2022-04-06 14:58
Sure, but other language have debuggers too. GDB is much better than sprinkling code with prints all over the place.
Don't misunderstand me, I think it looks like a useful package. As I mentioned previously, it might have good uses, I just gave you a tip that debugger is better than printing messages.
organic-bookworm · 2022-04-06 17:36
In terms of general purpose usage, `text-categories` description reminded me of [zones.el](https://www.emacswiki.org/emacs/Zones).
>You can think of zones as enlarging the notion of region. \[...\]
>
>A zone position can also be a readable marker, which is a Lisp sexp that can be written to disk \[...\]
>
>A zone can have an identifier
pcorrectness · 2022-04-06 18:15
I wasn't aware of that package, it seems interesting and has some similarities with this package. I'll check it out more, thank you!
pcorrectness · 2022-04-06 18:22
I agree with you that a debugger is superior in finding bugs. No misunderstanding at all! When I made this package I was working with many languages at the same time that I wasn't previously familiar with and I hadn't learned how to use a debugger for each of them yet. I guess it would be more useful in other use cases too since it is not necessarily made for code but for arbitrary text. I just haven't used it yet for something else. I maybe have to make it more clear in the README though.