2

I want to keep track of some stuff happening in the buffer, with elisp, and display indicators depending on that stuff. To that end, I need to cache calculated data for different parts of the file, and then quickly access and update that data. Specifically, this will be going on in Org-mode, and my data is associated with individual headings.

The conundrum here is, how do I best store this data, in memory, so it's associated with headings but not visible and not written to the file? I.e. when I insert or remove text in one place, points later in the file need to keep data associated with them—I can't just use text positions as keys in a dictionary (not without lots of hassle). It's also preferable that hidden data is not copied around together with yanked text.

To clarify, I'm aware that I can add properties on Org headings, or create IDs and associate my data with them—but I want to do this without any changes to the content.

So far it seems that ‘text properties’ might vaguely be what I want—if I can add my own custom fields in properties on headings. Elisp documentation notes that these properties are copied when text is yanked, and suggests putting them on an overlay instead. I'm rather hazy yet on how overlays function at all (though will probably need them for the indicators). Is this the best route, or maybe I'm looking in an entirely wrong place? Any nice rakes here for me to step on or shoot my feet?

Meanwhile, ‘invisible text’, popular in web search results, is not the thing I need—as afaict it's written to the file.

7
  • The question seeks opinions, not a finite set of answers or a unique answer. reddit with the Emacs tag is the best place for lots of opinions / discussion. If you need help adding text-properties to store hidden data, then please provide a minimal working example and explain where it is that you are having problems. The data can be stored with text properties. The data can be stored in a variable that is buffer local. The data can be stored in a global variable. The data can be stored in a separate file. The data can be stored in a separate buffer that is not written to a file.
    – lawlist
    Sep 19, 2020 at 16:02
  • FYI: text properties are not written to the file; however, they do alter / modify the buffer contents when added/removed/modified. Overlays, on the other hand, do not alter/modify the buffer contents.
    – lawlist
    Sep 19, 2020 at 16:09
  • @lawlist I don't see how storing data in variables or a separate buffer keeps it tied to text positions, other than my code explicitly keeping track of the positions' movement on changes.
    – aaa
    Sep 19, 2020 at 17:27
  • The initial problem is that you do not have a question narrowly defined, and the comments underneath the question become discussions and opinions that are not suited for this particular forum. I'm sure that if I spent a few minutes, i could come up with something ... and then you might say that it doesn't work for your particular use case or some other reason why the proposed solution does not suit your needs ... and then I will have just wasted my time ... All of this can be avoided with a narrowly defined question that seeks a unique answer or a finite set of answers.
    – lawlist
    Sep 19, 2020 at 17:31
  • FYI: Emacs has something called Markers that may be helpful for your particular use-case ("A marker is a Lisp object used to specify a position in a buffer relative to the surrounding text. A marker changes its offset from the beginning of the buffer automatically whenever text is inserted or deleted, so that it stays with the two characters on either side of it."): gnu.org/software/emacs/manual/html_node/elisp/Markers.html
    – lawlist
    Sep 19, 2020 at 17:38

2 Answers 2

1

John Kitchin wrote a package called ov-highlighter that makes highlighting persistent. IIRC, it has a hook that update after each file saving a local variable storing a list of region and propertized string. I suggest you to read his post, then you can move to the source code to read the two relevant functions ov-highlight-load and ov-highlight-save to see how that is done.

A second idea may be using something like l3kn/org-el-cache to cache Org mode data. I didn't try it, but AFAIK it is used in l3kn/org-zettelkasten.

0

I believe you're looking for "overlays":

You can use overlays to alter the appearance of a buffer’s text on the screen, for the sake of presentation features. An overlay is an object that belongs to a particular buffer, and has a specified beginning and end. It also has properties that you can examine and set; these affect the display of the text within the overlay.

1
  • 1
    Please elaborate, to make clear how overlays relate to the question. Otherwise, the answer risks being deleted as "low-quality because of its length and content".
    – Drew
    Sep 19, 2020 at 20:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.