2

I like using indirect buffers and narrowing to work on multiple sections of code simultaneously.

I noticed recently that if I disable font-lock-mode in an indirect buffer then I cannot get proper syntax highlighting back. I can reenable the mode, but no colors show up and instead I get the following error message:

Not enabling jit-lock: it does not work in indirect buffer

I've tried reading the documentation on font locking and looked in the jit-lock customize group ... but I can't find any way to tell Emacs to skip over jit locking and just try to fontify the whole indirect buffer. Is there some way to do this? If not, what else can I try? If there's nothing I can do ... why can't I fontify an indirect buffer?

  • I also learned to hate that issue. This is how I understand the situation: font-lock-mode uses text properties. Text properties are stored with the text (characters) and not buffer-locally. Indirect buffers work on the same text as the original buffer. Therefore they also have the same fontification. So font-lock (jit-lock) of the clone is prohibited to avoid interference of the clone fontification with the fontification of the original buffer. – Tobias Jun 11 '18 at 20:42
  • @Tobias: Yes, but I'm not convinced it should be inhibited. Anyway, there is a workaround: just make whatever font-lock changes you need in the base buffer. You can thus go through the base buffer to affect both it and all of its indirect buffers in any way you like wrt font-locking (including just turning it on/off). – Drew Jun 11 '18 at 22:47
1

You should be able to go to the base buffer (the one that you derived the indirect buffer from) and toggle font-lock-mode there (probably twice), to turn font-locking back on (in both the base and the indirect buffer).

But what you say is true. However the base buffer or any indirect buffer for it is font-locked, the other will have the same font-locking.

You can, for example, have different bits of a buffer in different languages, and you can narrow them as indirect buffers. And you can put any of them in any mode and font-lock it according to that mode. But doing that does the same for the base buffer and all the other indirect buffers for that base. IOW, you can deal with one at a time (different mode, different font-locking). That's a workaround, though, for what is a real limitation of indirect buffers (as you pointed out).


(BTW, if you use indirect buffers that are narrowed bits of a base buffer then library narrow-indirect.el can help. That's just what it's for. See Narrow Indirect.)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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