unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Sebastian Wiesner <swiesner@lunaryorn.com>
To: Stefan Monnier <monnier@iro.umontreal.ca>
Cc: emacs-devel@gnu.org
Subject: Re: tabulated-list-revert runs hook before re-printing the table
Date: Mon, 15 Sep 2014 11:11:04 +0200	[thread overview]
Message-ID: <01171E2D-7940-41AF-B891-2B9A1BC362E7@lunaryorn.com> (raw)
In-Reply-To: <jwvsijtddte.fsf-monnier+emacs@gnu.org>

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


      reply	other threads:[~2014-09-15  9:11 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=01171E2D-7940-41AF-B891-2B9A1BC362E7@lunaryorn.com \
    --to=swiesner@lunaryorn.com \
    --cc=emacs-devel@gnu.org \
    --cc=monnier@iro.umontreal.ca \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).