all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* tabulated-list-revert runs hook before re-printing the table
@ 2014-09-14  8:11 Sebastian Wiesner
  2014-09-14 19:20 ` Stefan Monnier
  0 siblings, 1 reply; 5+ messages in thread
From: Sebastian Wiesner @ 2014-09-14  8:11 UTC (permalink / raw)
  To: emacs-devel

Hello,

tabulated-list-mode implements a custom `revert-buffer-function' named `tabulated-list-revert', which does not run the standard `after-revert-hook` function as far as I can see.

Instead, it has its own hook `tabulated-list-revert-hook', but this hook runs *before* the list is re-printed with `tabulated-list-print'.

Hence, the hook still works on the “old” list, before it is updated.

What is the rationale for this?  When does the hook make sense in its current implementation?

Wouldn't it be rather more useful to run the hook *after* re-printing the error list, so that the hook can work with the newly refreshed list?

My use case was to automatically resize a custom tabulated-list-mode to fit its contents after every update.  Currently that doesn't seem possible…

Thank you
Sebastian Wiesner


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: tabulated-list-revert runs hook before re-printing the table
  2014-09-14  8:11 tabulated-list-revert runs hook before re-printing the table Sebastian Wiesner
@ 2014-09-14 19:20 ` Stefan Monnier
  2014-09-14 20:35   ` Sebastian Wiesner
  0 siblings, 1 reply; 5+ messages in thread
From: Stefan Monnier @ 2014-09-14 19:20 UTC (permalink / raw)
  To: Sebastian Wiesner; +Cc: emacs-devel

> Instead, it has its own hook `tabulated-list-revert-hook', but this hook
> runs *before* the list is re-printed with `tabulated-list-print'.

Indeed, because this is the hook that re-computes the list (if needed).
At least that's how I see it used (thanks to "grep").


        Stefan



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: tabulated-list-revert runs hook before re-printing the table
  2014-09-14 19:20 ` Stefan Monnier
@ 2014-09-14 20:35   ` Sebastian Wiesner
  2014-09-14 22:43     ` Stefan Monnier
  0 siblings, 1 reply; 5+ messages in thread
From: Sebastian Wiesner @ 2014-09-14 20:35 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: emacs-devel


Am 14.09.2014 um 21:20 schrieb Stefan Monnier <monnier@iro.umontreal.ca>:

>> Instead, it has its own hook `tabulated-list-revert-hook', but this hook
>> runs *before* the list is re-printed with `tabulated-list-print'.
> 
> Indeed, because this is the hook that re-computes the list (if needed).
> At least that's how I see it used (thanks to "grep").

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'?  

Why would a mode do that, rather than just using a function for `tabulated-list-entries' that directly returns the list of entries?

Unrelated to that question, could we have a hook run *after* `tabulated-list-print' by `tabulated-list-revert'?

Sebastian


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: tabulated-list-revert runs hook before re-printing the table
  2014-09-14 20:35   ` Sebastian Wiesner
@ 2014-09-14 22:43     ` Stefan Monnier
  2014-09-15  9:11       ` Sebastian Wiesner
  0 siblings, 1 reply; 5+ messages in thread
From: Stefan Monnier @ 2014-09-14 22:43 UTC (permalink / raw)
  To: Sebastian Wiesner; +Cc: emacs-devel

> 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.

> 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?

> 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.


        Stefan



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: tabulated-list-revert runs hook before re-printing the table
  2014-09-14 22:43     ` Stefan Monnier
@ 2014-09-15  9:11       ` Sebastian Wiesner
  0 siblings, 0 replies; 5+ messages in thread
From: Sebastian Wiesner @ 2014-09-15  9:11 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: emacs-devel

Am 15.09.2014 um 00:43 schrieb Stefan Monnier <monnier@iro.umontreal.ca>:

>> 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


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2014-09-15  9:11 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-09-14  8:11 tabulated-list-revert runs hook before re-printing the table Sebastian Wiesner
2014-09-14 19:20 ` Stefan Monnier
2014-09-14 20:35   ` Sebastian Wiesner
2014-09-14 22:43     ` Stefan Monnier
2014-09-15  9:11       ` Sebastian Wiesner

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.