Andy Piper wrote:
> 3] keep in mind there are many revert-buffer hooks, some of which
> explicitly
> replace the normal operation of inserting the file. your patch
> as is completely
> runs over them. the only hook that you can [reasonably safely]
Good point. Since I am only trying to hit a sweet spot here I guess it
would be possible to only use the optimization if there were no hooks, it
was called non-interactively and there were no coding system changes in
place.
> optimize away is
> `after-revert-hook' [and possibly `before-revert-hook']. to make
> your patch
> safe, it would have to do all the steps to actually revert the
> buffer, but do it
> in another buffer, and then finally compare the results and skip calling
> `after-revert-hook' if they're the same. if semantic hooks off of
> `after-revert-hook' [which it probably does], you're in luck.
> with a bit of
> effort you can also avoid having the before/after-change functions called.
I don't really understand this. Things like font-lock don't use
after-revert-hook, they use after-change-functions don't they? So how would
this work?
just disable the change hooks while you're inserting into a temp buffer. once
you do the compare, and the results are the same, leave the old buffer as is.
no triggering of font-lock.
there is also code in insert-file-contents to figure out how much has changed --
it searches for a region [hopefully small] containing all the changes, and then
arranges for the extents and markers to be preserved in the remaining text
[essentially by just deleting and replacing the changed section]. to work
properly in the case of coding systems, etc. you need to insert into a temp
buffer and do the compare. we don't actually implement this code currently, but
fsf does (but DO NOT TRY to copy their implementation, you'll just cause more
grief for yourself). the only reason to do all this [provided your more general
revert code is in] is in the case where only a small change was made before
reverting, and it only affects font-lock [and only if you don't use lazy-lock],
so it may not be worth fussing with.
I still think we are actually missing a function, something like
`refresh-buffer', since revert-buffer is too fierce. Maybe
find-file-noselect is a better place for this?
NOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO!!!!!
not another api doing exactly what an existing one does just fine, provided the
correct optimizations are there. adding user-callable functions is tantamount
to adding new options, and there needs to be a clear benefit that outweighs the
confusion. just correctly implement the revert-buffer optimizations the way
i've outlined them, and you'll get everything nice and speedy without any need
for a kludgy vfork equivalent.
andy
andy