From: Roland Winkler <roland.winkler@physik.uni-erlangen.de>
Subject: dynamic-completion-table
Date: Thu, 19 Jun 2003 16:31:46 +0200 [thread overview]
Message-ID: <16113.51538.619271.508717@tfkp07.physik.uni-erlangen.de> (raw)
In order to avoid duplicating code in bibtex.el Stefan Monnier
suggested to me to use a macro dynamic-completion-table.
(defmacro dynamic-completion-table (fun)
"Turn a function FUN returning a completion table, into a completion table.
FUN is called with no argument and should return a completion table.
If completion is performed in the minibuffer, FUN will be called in the
buffer from which the minibuffer was entered."
;; (declare (debug t))
`(lambda (string predicate mode)
(with-current-buffer (let ((win (minibuffer-selected-window)))
(if (window-live-p win) (window-buffer win)
(current-buffer)))
(cond
((eq mode t) (all-completions string (,fun) predicate))
((not mode) (try-completion string (,fun) predicate))
(t (test-completion string (,fun) predicate))))))
I'd like to suggest that it could be made available in, e.g.,
simple.el. I think it comes quite handy if a completion table must
be calculated dynamically by means of an appropriate function. For
example, the function sh-add-completer in sh-script.el could use
dynamic-completion-table.
If completion is performed in the minibuffer, FUN will be called in
the buffer from which the minibuffer was entered. I believe that
such a "well-defined environment" for evaluating FUN is in general
more useful than a macro without it. An alternative to using
minibuffer-selected-window might be that the buffer name for
evaluating FUN is passed to dynamic-completion-table as an
(optional) argument or via a variable like sh-add-buffer in
sh-script.el. However, for my application it is an important part of
dynamic-completion-table that the buffer name is determined
automatically:
I use dynamic-completion-table to define the global initial values
of buffer-local variables that contain completion lists. The idea is
that if the user hits tab, FUN calculates the completion list and
stores it in the buffer-local variables. In that way, the
buffer-local values of the completion lists are calculated only once
- provided the completion lists are required at all. (Maybe, this
scheme for initializing completion lists is of interest elsewhere,
too?)
Maybe, the macro dynamic-completion-table requires some adjustment
in order to make it even more useful for other purposes, too.
Suggestions welcome!
Roland
PS: I have not subscribed to emacs-devel@gnu.org
next reply other threads:[~2003-06-19 14:31 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2003-06-19 14:31 Roland Winkler [this message]
2003-06-20 14:11 ` dynamic-completion-table Richard Stallman
2003-06-24 14:11 ` dynamic-completion-table Roland Winkler
2003-06-25 19:53 ` dynamic-completion-table Richard Stallman
2003-06-26 13:17 ` dynamic-completion-table Roland Winkler
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=16113.51538.619271.508717@tfkp07.physik.uni-erlangen.de \
--to=roland.winkler@physik.uni-erlangen.de \
/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.