unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Roland Winkler <Roland.Winkler@physik.uni-erlangen.de>
Cc: emacs-devel@gnu.org
Subject: Re: dynamic-completion-table
Date: Thu, 26 Jun 2003 15:17:41 +0200	[thread overview]
Message-ID: <16122.62069.333817.338097@tfkp07.physik.uni-erlangen.de> (raw)
In-Reply-To: <E19VGKR-0000GM-LP@fencepost.gnu.org>

On Wed Jun 25 2003 Richard Stallman wrote:
>       "Use function FUN as a dynamic completion table.
>     FUN is called with one argument, the string for which
>     completion is required, and it should return an alist
>     containing all the intended possible completions.
> 
> Is FUN required to return only the possible completions of that
> string, or can it ignore the string and always return the full list of
> possibilities?  Looking at the code, I think it can ignore the string.
> The doc string should say so.
> 
> Both macros seem useful--you can install them.

Stefan,

Could you please do that for me? Thank you very much!
I hope that the docstring of dynamic-completion-table is now OK.

(defmacro dynamic-completion-table (fun)
  "Use function FUN as a dynamic completion table.
FUN is called with one argument, the string for which completion is required,
and it should return an alist containing all the intended possible
completions. This alist may be a full list of possible completions so that FUN
can ignore the value of its argument. If completion is performed in the
minibuffer, FUN will be called in the buffer from which the minibuffer was
entered. `dynamic-completion-table' then computes the completion, see Info
node `(elisp)Programmed Completion'."
  (let ((win (make-symbol "window"))
        (string (make-symbol "string"))
        (predicate (make-symbol "predicate"))
        (mode (make-symbol "mode")))
    `(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 ,string) ,predicate))
          ((not ,mode) (try-completion ,string (,fun ,string) ,predicate))
          (t (test-completion ,string (,fun ,string) ,predicate)))))))

(defmacro lazy-completion-table (var fun &rest args)
  "Initialize variable VAR as a lazy completion table.
If the completion table VAR is used for the first time (e.g., by passing VAR
as an argument to `try-completion'), the function FUN is called with arguments
ARGS. FUN must return the completion table that will be stored in VAR. If
completion is requested in the minibuffer, FUN will be called in the buffer
from which the minibuffer was entered. The return value of
`lazy-completion-table' must be used to initialize the value of VAR."
  (let ((str (make-symbol "string")))
    `(dynamic-completion-table
      (lambda (,str)
        (unless (listp ,var)
          (setq ,var (funcall ',fun ,@args)))
        ,var))))


> Don't forget to mention them in etc/NEWS.

The following should be put into etc/NEWS:

*** The new macro dynamic-completion-table supports using functions
as a dynamic completion table.

  (dynamic-completion-table FUN)

FUN is called with one argument, the string for which completion is required,
and it should return an alist containing all the intended possible
completions. This alist may be a full list of possible completions so that FUN
can ignore the value of its argument. If completion is performed in the
minibuffer, FUN will be called in the buffer from which the minibuffer was
entered. dynamic-completion-table then computes the completion.

*** The new macro lazy-completion-table initializes a variable
as a lazy completion table.

  (lazy-completion-table VAR FUN &rest ARGS)

If the completion table VAR is used for the first time (e.g., by passing VAR
as an argument to `try-completion'), the function FUN is called with arguments
ARGS. FUN must return the completion table that will be stored in VAR. If
completion is requested in the minibuffer, FUN will be called in the buffer
from which the minibuffer was entered. The return value of
`lazy-completion-table' must be used to initialize the value of VAR.




Roland

      reply	other threads:[~2003-06-26 13:17 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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       ` Roland Winkler [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=16122.62069.333817.338097@tfkp07.physik.uni-erlangen.de \
    --to=roland.winkler@physik.uni-erlangen.de \
    --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 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).