all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Spencer Baugh <sbaugh@janestreet.com>
To: emacs-devel@gnu.org
Subject: State and caching in completion tables
Date: Wed, 22 Nov 2023 14:36:30 -0500	[thread overview]
Message-ID: <ierjzq9lgw1.fsf@janestreet.com> (raw)


If I have a completion table which wants to store internal state - in my
case, for caching data used to generate completions - is there a good
place to do that?

Ideally, the state (in my case, a cache) would only be preserved for a
given call to completing-read.  If a new call to completing-read starts,
I'd like the state to be reset.

Usually, I would do this by having a function which creates a fresh
completion table with fresh state, and call that each time to generate
the completion table to pass to completing-read.  So state would
naturally be preserved only for a given completing-read, because each
completing-read would use a new completion table.

But more specifically, I'm adding a new file-name-handler.  As a
file-name-handler, I don't get the chance to return a fresh completion
table for each read-file-name invocation; I only get to handle
file-name-all-completions and file-name-completion.  Given that, I don't
know where my file-name-all-completions and file-name-completion
functions could store some state which is specific to a read-file-name
call.

I want to store state for a read-file-name call to avoid making
duplicate network requests each time file-name-all-completions and
file-name-completion are called; instead I'd like to store the result I
got the first time.  I'm happy with any way of achieving that.

Is there a natural place for a completion table to store state which is
specific to a given invocation of completing-read?

Or failing that more general solution, a way for a file-name-handler to
save state for a given read-file-name call?




                 reply	other threads:[~2023-11-22 19:36 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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

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

  git send-email \
    --in-reply-to=ierjzq9lgw1.fsf@janestreet.com \
    --to=sbaugh@janestreet.com \
    --cc=emacs-devel@gnu.org \
    /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 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.