On Tue, 2002-05-07 at 20:20, Miles Bader wrote: > There could be a `font-lock-refontify-function' variable that such modes > set, which `font-lock-mode' would call if necessary to refontify the > buffer. Ok, That might be one way to optimize things, if it turns out to be necessary. > Then the interface will seem to work consistently for users, but special > modes can avoid the overhead of the font-lock engine if they desire. OK. I have thought about this issue a lot more carefully. Richard: I have changed my mind with regards to your proposal. I first actually wrote a patch which implemented things the way you suggested. But from a user perspective, things still wouldn't be consistent, because typing 'M-x font-lock-mode' wouldn't always do the Right Thing in special buffers. So we might as well have kept the status quo. I believe your original objection to my approach was that loading font-lock.el was a lot of overhead. I have addressed this in the attached patch, by creating a "font-core.el". Miles: You objected to putting special text properties on the buffer text, and then fontifying on them later, correct? Unfortunately this is the only way I can think of to implement fontification for special buffers, such that typing M-x font-lock-mode will always do the Right Thing. I believe I can optimize this such that the mode's `font-lock-fontify-region' function is only called *once*. This should minimize the overhead. I don't think this will actually be very slow at all, anyways. Text properties are quite fast. Or we could solve this issue the way you suggest above. So this should not be a problem. One other issue that came up was that special modes wouldn't be fontified by default. I have solved this in a simple way; we add `font-lock-mode' to the default value of the mode's hooks. This allows a user to customize fontification in a clean way. If a user *doesn't* want those modes fontified, they can (remove-hook 'foo-mode-hook 'font-lock-mode) Let me restate things in terms of advantages and disadvantages: Advantages: * From a user perspective, the attached patch doesn't change anything at all, except that typing M-x font-lock-mode will now suddenly work in special modes like Occur; if we decide to put this patch in, then I will change Info and all the other modes to support it. * The memory impact should be quite small, since we only load font-core.el for special modes. Disadvantages: * Fontification of special buffers may take a bit longer. I personally don't believe the difference will be noticeable. If it is (and I haven't noticed any slowdown), I will work on making it faster. In this patch, most of the changes are moved functions. See the entries for font-core.el to see what (little) code was actually changed. 2002-05-08 Colin Walters * font-lock.el (font-lock) (font-lock-highlighting-faces, font-lock-extra-types) (fast-lock, lazy-lock, jit-lock, font-lock-maximum-size) (font-lock-maximum-decoration, font-lock-verbose) (font-lock-defaults, font-lock-fontify-buffer-function) (font-lock-unfontify-buffer-function) (font-lock-fontify-region-function) (font-lock-unfontify-region-function) (font-lock-inhibit-thing-lock, font-lock-multiline) (font-lock-fontified, save-buffer-state) (font-lock-face-attributes, font-lock-mode) (turn-on-font-lock, global-font-lock-mode) (font-lock-global-modes, font-lock-support-mode) (fast-lock-mode, lazy-lock-mode, jit-lock-mode) (font-lock-turn-on-thing-lock, font-lock-turn-off-thing-lock) (font-lock-after-fontify-buffer, font-lock-after-unfontify-buffer) (font-lock-fontify-buffer, font-lock-unfontify-buffer) (font-lock-fontify-region, font-lock-unfontify-region) (font-lock-default-fontify-buffer) (font-lock-default-unfontify-buffer) (font-lock-default-unfontify-region) (font-lock-after-change-function): Moved to font-core.el. (font-lock-set-defaults): Renamed to `font-lock-set-defaults-1'; partially moved to font-core.el. * font-core.el: New file, with functions broken out from font-lock.el. (font-lock-core-only): New variable. (font-lock-mode): If `font-lock-core-only' is non-nil, fontify the whole buffer immediately; don't enable a font-lock support mode. (font-lock-set-defaults): Partially moved here from font-lock.el. We try to only load all of font-lock.el if the mode doesn't set `font-lock-core-only'. * replace.el (occur-mode-hooks): New variable. (occur-mode): Set `font-lock-core-only'. Run `occur-mode-hooks' too.