unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* dynamic-completion-table
@ 2003-06-19 14:31 Roland Winkler
  2003-06-20 14:11 ` dynamic-completion-table Richard Stallman
  0 siblings, 1 reply; 5+ messages in thread
From: Roland Winkler @ 2003-06-19 14:31 UTC (permalink / 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

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

end of thread, other threads:[~2003-06-26 13:17 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2003-06-19 14:31 dynamic-completion-table Roland Winkler
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

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