From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: Roland Winkler Newsgroups: gmane.emacs.devel Subject: Re: dynamic-completion-table Date: Thu, 26 Jun 2003 15:17:41 +0200 Sender: emacs-devel-bounces+emacs-devel=quimby.gnus.org@gnu.org Message-ID: <16122.62069.333817.338097@tfkp07.physik.uni-erlangen.de> References: <16113.51538.619271.508717@tfkp07.physik.uni-erlangen.de> <16120.23570.881095.34919@tfkp07.physik.uni-erlangen.de> NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Trace: main.gmane.org 1056634364 17033 80.91.224.249 (26 Jun 2003 13:32:44 GMT) X-Complaints-To: usenet@main.gmane.org NNTP-Posting-Date: Thu, 26 Jun 2003 13:32:44 +0000 (UTC) Cc: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+emacs-devel=quimby.gnus.org@gnu.org Thu Jun 26 15:32:42 2003 Return-path: Original-Received: from quimby.gnus.org ([80.91.224.244]) by main.gmane.org with esmtp (Exim 3.35 #1 (Debian)) id 19VWqT-0004JB-00 for ; Thu, 26 Jun 2003 15:31:25 +0200 Original-Received: from monty-python.gnu.org ([199.232.76.173]) by quimby.gnus.org with esmtp (Exim 3.12 #1 (Debian)) id 19VWv0-0002jN-00 for ; Thu, 26 Jun 2003 15:36:06 +0200 Original-Received: from localhost ([127.0.0.1] helo=monty-python.gnu.org) by monty-python.gnu.org with esmtp (Exim 4.20) id 19VWow-0003EM-MH for emacs-devel@quimby.gnus.org; Thu, 26 Jun 2003 09:29:50 -0400 Original-Received: from list by monty-python.gnu.org with tmda-scanned (Exim 4.20) id 19VWhA-0007g9-7D for emacs-devel@gnu.org; Thu, 26 Jun 2003 09:21:48 -0400 Original-Received: from mail by monty-python.gnu.org with spam-scanned (Exim 4.20) id 19VWg8-0007Kh-D4 for emacs-devel@gnu.org; Thu, 26 Jun 2003 09:20:46 -0400 Original-Received: from tfkp07.physik.uni-erlangen.de ([131.188.164.207]) by monty-python.gnu.org with esmtp (Exim 4.20) id 19VWeF-0006Ya-C8 for emacs-devel@gnu.org; Thu, 26 Jun 2003 09:18:47 -0400 Original-Received: by tfkp07.physik.uni-erlangen.de (Postfix, from userid 500) id A11BA52CD; Thu, 26 Jun 2003 15:17:42 +0200 (CEST) Original-To: "Stefan Monnier" In-Reply-To: X-Mailer: VM 6.96 under Emacs 21.2.1 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1b5 Precedence: list List-Id: Emacs development discussions. List-Help: List-Post: List-Subscribe: , List-Archive: List-Unsubscribe: , Errors-To: emacs-devel-bounces+emacs-devel=quimby.gnus.org@gnu.org Xref: main.gmane.org gmane.emacs.devel:15273 X-Report-Spam: http://spam.gmane.org/gmane.emacs.devel:15273 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