Morgan Smith <morgan.j.sm...@outlook.com> writes: >> It is the time to refactor this function yet again. >> (a tricky endeavour considering all the edge cases we can encounter when >> there are changes in buffer while `org-element-cache-map' is mapping >> over it). > > See attached for a way to break :from-pos as well. I would like to help > refactor but studying this function is a little dizzying for me.
At this point, it might be easier to rewrite the whole thing from scratch, just based on the commentary (I tried my best to leave detailed commentary explaining the intended logic). We have a decent test coverage when mapping headings in buffer, so edge cases will be checked by make test. In particular, it might be a good idea to get rid of the idea of START variable and just make use of AFTER-ELEMENT. For now, they serve kinda the same purpose, but the latter was added because START was not enough when the buffer is modified by FUNC. -- Ihor Radchenko // yantar92, Org mode contributor, Learn more about Org mode at <https://orgmode.org/>. Support Org development at <https://liberapay.com/org-mode>, or support my work at <https://liberapay.com/yantar92>