reddit / emacs

clone-indirect-buffer and font-lock

poiu- · 2022-12-19 11:49
In programming modes (at least `python`, `php`), whenever I `clone-indirect-buffer`, my `font-lock` breaks after a while. Why? How can I fix this? ​ (I'm currently using `tree-sitter-hl-mode`, but I'm pretty sure I've had this for years)
poiu- · 2022-12-19 12:27
Here's an [image of how font-lock breaks](https://i.imgur.com/leSiz6H.png).
7890yuiop · 2022-12-19 23:13
Font-lock effects are properties of the text in the buffer, and the text in the buffer is *shared* by indirect clones, so you can't fix this. It's just a trade-off you have to make if you choose to use indirect clones (assuming differing font-lock criteria between the clones). You can try `M-x font-lock-fontify-buffer` to re-fontify that text in accordance with the current clone. If that doesn't work, then try evaluating `(font-lock-flush)` or even `(progn (font-lock-flush) (font-lock-ensure))`. The latter will forcibly re-fontify all of the accessible buffer contents. I *think* the flush alone would typically mean `jit-lock-mode` would update the visible portion, and thereafter do its normal thing for processing the rest of the buffer. Re-fontifying the text takes time, of course. It may or may not be noticeable/annoying, depending on the buffer.
poiu- · 2022-12-20 08:41
Hmm, but why does it break in the first j place? Something must be going on. Am I the only one suffering from this? Then I probably need to find the package that causes this
7890yuiop · 2022-12-20 10:18
If you think it isn't explained by my previous comments and shouldn't be happening, you should provide a recipe which reproduces the issue.
walseb · 2022-12-20 22:55
I use hundreds of indirect buffers every day primarily within org mode and have only had an issue with highlighting once, which might have been due to one of my packages. Are you setting the major mode after opening up the indirect buffers? That caused a lot of problems for me.
poiu- · 2022-12-23 17:22
Thanks for the comment! Not specifically, but will check my hooks, I guess. Dang, ifdef /binary search debugging is such a pain. But wasn't there some package that does it automatically?
walseb · 2022-12-23 17:56
I don't know anything about that. I was referring to whether you created your indirect buffer with the `'clone` parameter. For instance: `(make-indirect-buffer (current-buffer) name 'clone)` Previously I used to create the indirect buffer without the `clone` parameter and ran into many issues with modifying font lock through enabling major modes in the indirect buffer.