[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: tabulated-list-revert runs hook before re-printing the table
From: |
Sebastian Wiesner |
Subject: |
Re: tabulated-list-revert runs hook before re-printing the table |
Date: |
Mon, 15 Sep 2014 11:11:04 +0200 |
Am 15.09.2014 um 00:43 schrieb Stefan Monnier <address@hidden>:
>> You mean that a mode derived from `tabulated-list-mode' would add a function
>> to this hook in order to re-compute `tabulated-list-entries'?
>
> That's what it looks like, yes. Try a "grep tabulated-list-revert-hook
> **/*.el" in Emacs's sources and see for yourself.
Indeed, I now remember that I saw this pattern when I studied other tabulated
list modes to find out how it is supposed to be used. I also remember, though,
that I also didn't understand its motivation back then.
>> Why would a mode do that, rather than just using a function for
>> `tabulated-list-entries' that directly returns the list of entries?
>
> I don't know, but my guess is that it's perceived that
> tabulated-list-entries would be called too often and would hence be too
> taxing on CPU resources?
Is that really the case? I looked at tabulated-list.el, and I don't think so.
`tabulated-list-print' calls tabulated-list-entries once if its a function, and
`tabulated-list-print' itself is only called at two places: In the revert
function, which `tabulated-list-revert-hook' is called as well, and in the
function that handles explicit sorting, i.e. the user pressing S or clicking on
the header line.
As far as I can see, using the hook instead of a `tabulated-list-entries' would
only make explicit sorting a little more efficient.
Imho, it seems that the real use case for this pattern is to abuse
`tabulated-list-entries' as data structure. At least, that's the case in
package.el, which uses `package-list-entries' to compute package updates,
rather than `package-alist', which would be the right data structure for this
purpose, imho.
Anyhow, I was just curious, so never mind. I've solved my original problem by
simply adding my own hook to my derived mode.
>> Unrelated to that question, could we have a hook run *after*
>> `tabulated-list-print' by `tabulated-list-revert'?
>
> It would make sense for it to run after-revert-hook, I guess.
>
Indeed. It should probably run `before-revert-hook' as well, before
`tabulated-list-revert-hook'. I wonder why there's even a separate hook for
tabulated-list-mode.
Thanks for your help, and your feedback
Sebastian Wiesner