From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: "Drew Adams" Newsgroups: gmane.emacs.devel Subject: RE: how to determine the current table (really) being used for minibuffer completion? Date: Sat, 26 Sep 2009 17:02:24 -0700 Message-ID: <622F55DCAB0343E9827BF3FD038C3361@us.oracle.com> References: <137402B99D584CEE9AF2E4B23116527A@us.oracle.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Trace: ger.gmane.org 1254009763 30204 80.91.229.12 (27 Sep 2009 00:02:43 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sun, 27 Sep 2009 00:02:43 +0000 (UTC) Cc: emacs-devel@gnu.org To: "'Stefan Monnier'" Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Sun Sep 27 02:02:36 2009 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1MrhDn-0004KT-K5 for ged-emacs-devel@m.gmane.org; Sun, 27 Sep 2009 02:02:36 +0200 Original-Received: from localhost ([127.0.0.1]:41037 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MrhDn-0001NT-8t for ged-emacs-devel@m.gmane.org; Sat, 26 Sep 2009 20:02:35 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1MrhDg-0001NO-S8 for emacs-devel@gnu.org; Sat, 26 Sep 2009 20:02:28 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1MrhDb-0001Ke-Ig for emacs-devel@gnu.org; Sat, 26 Sep 2009 20:02:27 -0400 Original-Received: from [199.232.76.173] (port=53053 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MrhDb-0001KY-7u for emacs-devel@gnu.org; Sat, 26 Sep 2009 20:02:23 -0400 Original-Received: from rcsinet11.oracle.com ([148.87.113.123]:33300 helo=rgminet11.oracle.com) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1MrhDa-0002hJ-M6 for emacs-devel@gnu.org; Sat, 26 Sep 2009 20:02:22 -0400 Original-Received: from acsinet15.oracle.com (acsinet15.oracle.com [141.146.126.227]) by rgminet11.oracle.com (Switch-3.3.1/Switch-3.3.1) with ESMTP id n8R03GiA026957 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Sun, 27 Sep 2009 00:03:17 GMT Original-Received: from abhmt003.oracle.com (abhmt003.oracle.com [141.146.116.12]) by acsinet15.oracle.com (Switch-3.3.1/Switch-3.3.1) with ESMTP id n8R02r4U003426; Sun, 27 Sep 2009 00:02:53 GMT Original-Received: from dradamslap1 (/24.5.190.74) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Sat, 26 Sep 2009 17:02:16 -0700 X-Mailer: Microsoft Office Outlook 11 Thread-Index: Aco+8BKug40Dt/5SRpGhplQVoLZvLAAAYHNA In-Reply-To: X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.5579 X-Source-IP: abhmt003.oracle.com [141.146.116.12] X-Auth-Type: Internal IP X-CT-RefId: str=0001.0A090201.4ABEAB89.0227:SCFSTAT5015188,ss=1,fgs=0 X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6 (newer, 1) X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:115679 Archived-At: > > Hypothetical example that might make the request clearer: > > (completion-all-completions > > STRING 'read-file-name-internal nil (length STRING)) > > > The result returned might be a list of relative file names, or it > > might be a list of env vars. A result such as ("CATACOMBS" > > "CATAPHILE" "CATASTROPHE" . 4) could be either. > > > I would like (via Lisp) to know which kind of completion > > was in fact used successfully: file-name completion per se > > or env var completion. > > In which form? Do you want a symbol like `file' vs `envvar', > or do you want a completion-table (which can then be a > has-table, an obarray, an alist, a list, a symbol-function, > or a lambda expression)? The second might be doable in many > cases (actually more so in Emacs-23 than in Emacs-22, since > most functional completion tables now get composed using > primitives like complete-with-action or completion-table-*, > so we could add a 5th method (additionally to the original 3, > try-completions, all-completions, and test-completion, plus > the new completion-boundaries) a bit more easily), but I'm > not sure it would be easy to use. As you recognize, it is better to test a known symbol (e.g. `envvar') than a completion table (function or list or hash table or obarray...). What I suggest is this: Use a data structure (an alist), to have a standard list of symbols (the keys of the alist) that can be tested. @ In the case of completion styles (determining which style performed the completion), just reuse `completion-styles-alist': be able to test the alist key - `basic', `emacs22', `emacs21', or `partial-completion'. (But using whatever real alist entries are in `completion-styles-alist' at the time of testing.) This will provide a knowable and unambiguous set of symbols to test. @ In the case of env-var and file-name completion: Do the same thing. Implement something similar to `completion-styles-alist'. It would be good to use an alist here anyway, for flexibility of use and ease of maintenance. After successful completion, set a global variable to the symbol that represents the completion style. This is simply additional information to be, in effect, returned by the completion function. We already return the set of completions, and you've hacked that list to also carry the base size in its last cdr. This third piece of info about the completion state can be returned in a global variable. (It can be at least as important as the base size, IMO.) Your code comments acknowledge the hackiness of how base-size is returned, and they point to possibly also returning a `completion-extra-size' and `completion-no-auto-exit' in the future. The point is that completion is a complex process, and it can return more useful info than simply the list of completions. -- Also, it is somewhat inconvenient to have `completion-styles-alist' as a defvar, not a defcustom. It is the real fulcrum for all of the code. It is baked once by Emacs development, and then it is used as the basis for the rest. User customization of `completion-styles' is limited to choosing among predefined styles. It would be better to have a single option that lets users both (a) choose the styles to use and (b) define new styles (their names and their defining completion functions). IOW, combine `completion-styles-alist' with `completion-styles' as a single option that users can customize. That way, the code would still automatically adjust to the possible set of completion styles, but those styles would not be limited to choices from a predefined list. Users could still just as easily add or remove predefined styles, but they could also more easily add their own. > > Emacs should be able to tell me directly what the last completion > > table/function used was. It should be easy to make this info > > available somehow, e.g. in a global variable. > > It might be easy in 99% of the cases, depending on exactly what > you want. See above.