From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Leo Newsgroups: gmane.emacs.devel Subject: Re: Any objection to adding completing-read-function? Date: Tue, 28 Dec 2010 19:02:31 +0000 Message-ID: References: NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: dough.gmane.org 1293562998 3075 80.91.229.12 (28 Dec 2010 19:03:18 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Tue, 28 Dec 2010 19:03:18 +0000 (UTC) Cc: emacs-devel@gnu.org To: Stefan Monnier Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Tue Dec 28 20:03:14 2010 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.69) (envelope-from ) id 1PXepF-0003Lf-JH for ged-emacs-devel@m.gmane.org; Tue, 28 Dec 2010 20:03:14 +0100 Original-Received: from localhost ([127.0.0.1]:36886 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PXepF-0006VG-4U for ged-emacs-devel@m.gmane.org; Tue, 28 Dec 2010 14:03:13 -0500 Original-Received: from [140.186.70.92] (port=45058 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PXeos-0006UJ-KB for emacs-devel@gnu.org; Tue, 28 Dec 2010 14:03:09 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PXeoe-0002yE-UN for emacs-devel@gnu.org; Tue, 28 Dec 2010 14:02:50 -0500 Original-Received: from mail-wy0-f169.google.com ([74.125.82.169]:35452) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PXeoe-0002y8-GC for emacs-devel@gnu.org; Tue, 28 Dec 2010 14:02:36 -0500 Original-Received: by wyj26 with SMTP id 26so9883593wyj.0 for ; Tue, 28 Dec 2010 11:02:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:from:to:cc:subject:references :date:message-id:user-agent:mime-version:content-type; bh=GMJkxxUWdAtrW7EE9V+Wr3rLt9mlCzPHjRLq25u0KCY=; b=V8wFmDCY0FVIb/ts9USzu4mDGPaXff4olKq/8MvKSGJ9bzR5GVm+RGQze9u3XZlIGM S/S+OJzx5kG2mjwtvzAbY07J5lDI94Ki0UJyfBY9sxBnprJBqrB12xdGBDquBvAFUwY2 5uQNc+ZWAJBCSjzVILggAVXAO58B8utScsQD4= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=from:to:cc:subject:references:date:message-id:user-agent :mime-version:content-type; b=Z3qHMeMEhSC2tyws9qQh0N86aAyxqr65q9+xG7jdPckuIBYVdJGGQe30D1OhZhzOUu wppyuXpw1jjDd0dfr18/JXRUHAiTVDqf1DCZL/5FmyLlBk4mCE+ihH8BdQSNhglfnGp+ nvUnz7921rmy7r9rFJIpN7IYvE4U7ULv/0WwY= Original-Received: by 10.216.145.90 with SMTP id o68mr9002941wej.8.1293562955401; Tue, 28 Dec 2010 11:02:35 -0800 (PST) Original-Received: from Victoria.local (cpc1-cmbg13-0-0-cust596.5-4.cable.virginmedia.com [86.9.122.85]) by mx.google.com with ESMTPS id x3sm6675623wes.22.2010.12.28.11.02.33 (version=TLSv1/SSLv3 cipher=RC4-MD5); Tue, 28 Dec 2010 11:02:34 -0800 (PST) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.2.91 (Mac OS X 10.6.5) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2) 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:134010 Archived-At: --=-=-= On 2010-12-28 14:34 +0000, Stefan Monnier wrote: >> So I wonder if there is any objection to adding a new variable >> completing-read-function that when set replaces completing-read? Let me >> know if I should submit it to the bug tracker. > > There's been such requests in the past, which I've usually resisted. > But I guess it's OK to do such a thing. > A few points to note, tho: OK. I'll submit it to the bug tracker later. >> Here are some screenshots: >> I switching to a bookmark: > [...] >> Switching to a branch in magit: > [...] >> Loading lisp systems in slime: > [...] > > You can get similar results with M-x icomplete-mode, possibly combined > with changing completion-styles (e.g. to add substring matching). > > Generally, I'd much rather see the default completion improved than > side-stepped. I agree. > One other thing: a variable completing-read-function should not allow > a nil value, instead its default value should be > `completing-read-default' which is the current completing-read, so you > can always funcall completing-read-function without checking if it's > nil. I have modified the patch to be like this. Since there are quite a few libraries both in emacs and 3rd party calling completing-read directly, in the patch the old completing-read is now completing-read-default and the new completing-read calls completing-read-function, which defaults to completing-read-default. Is this OK? Thanks. > > Stefan Leo --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=crf.diff Content-Description: crf.diff diff --git a/lisp/ido.el b/lisp/ido.el index e52a753..0f464d3 100644 --- a/lisp/ido.el +++ b/lisp/ido.el @@ -2011,7 +2011,7 @@ (setq ido-exit nil) (setq ido-final-text (catch 'ido - (completing-read + (completing-read-default (ido-make-prompt item prompt) '(("dummy" . 1)) nil nil ; table predicate require-match (prog1 ido-text-init (setq ido-text-init nil)) ;initial-contents @@ -4835,7 +4835,7 @@ See `read-directory-name' for additional parameters." (concat ido-current-directory filename))))) ;;;###autoload -(defun ido-completing-read (prompt choices &optional predicate require-match initial-input hist def) +(defun ido-completing-read (prompt choices &optional predicate require-match initial-input hist def inherit-input-method) "Ido replacement for the built-in `completing-read'. Read a string in the minibuffer with ido-style completion. PROMPT is a string to prompt with; normally it ends in a colon and a space. diff --git a/src/minibuf.c b/src/minibuf.c index 564346f..6e7e18b 100644 --- a/src/minibuf.c +++ b/src/minibuf.c @@ -132,6 +132,7 @@ Lisp_Object Vminibuffer_completion_table, Qminibuffer_completion_table; Lisp_Object Vminibuffer_completion_predicate, Qminibuffer_completion_predicate; Lisp_Object Vminibuffer_completion_confirm, Qminibuffer_completion_confirm; Lisp_Object Vminibuffer_completing_file_name; +Lisp_Object Qcompleting_read_default, Vcompleting_read_function; Lisp_Object Quser_variable_p; @@ -1721,6 +1722,27 @@ with a space are ignored unless STRING itself starts with a space. */) DEFUN ("completing-read", Fcompleting_read, Scompleting_read, 2, 8, 0, doc: /* Read a string in the minibuffer, with completion. +This function calls `completing-read-function' to do the work, which +defaults to `completing-read-default' (which see). */) + (prompt, collection, predicate, require_match, initial_input, hist, def, inherit_input_method) + Lisp_Object prompt, collection, predicate, require_match, initial_input; + Lisp_Object hist, def, inherit_input_method; +{ + Lisp_Object args[9]; + args[0] = Vcompleting_read_function; + args[1] = prompt; + args[2] = collection; + args[3] = predicate; + args[4] = require_match; + args[5] = initial_input; + args[6] = hist; + args[7] = def; + args[8] = inherit_input_method; + return Ffuncall (9, args); +} + +DEFUN ("completing-read-default", Fcompleting_read_default, Scompleting_read_default, 2, 8, 0, + doc: /* Default function for `completing-read-function'. PROMPT is a string to prompt with; normally it ends in a colon and a space. COLLECTION can be a list of strings, an alist, an obarray or a hash table. COLLECTION can also be a function to do the completion itself. @@ -1741,9 +1763,9 @@ REQUIRE-MATCH can take the following values: - anything else behaves like t except that typing RET does not exit if it does non-null completion. -If the input is null, `completing-read' returns DEF, or the first element -of the list of default values, or an empty string if DEF is nil, -regardless of the value of REQUIRE-MATCH. +If the input is null, `completing-read-default' returns DEF, or the +first element of the list of default values, or an empty string if DEF +is nil, regardless of the value of REQUIRE-MATCH. If INITIAL-INPUT is non-nil, insert it in the minibuffer initially, with point positioned at the end. @@ -2077,6 +2099,9 @@ syms_of_minibuf () minibuf_save_list = Qnil; staticpro (&minibuf_save_list); + Qcompleting_read_default = intern_c_string ("completing-read-default"); + staticpro (&Qcompleting_read_default); + Qcompletion_ignore_case = intern_c_string ("completion-ignore-case"); staticpro (&Qcompletion_ignore_case); @@ -2216,6 +2241,11 @@ If the value is `confirm-after-completion', the user may exit with an doc: /* Non-nil means completing file names. */); Vminibuffer_completing_file_name = Qnil; + DEFVAR_LISP ("completing-read-function", + &Vcompleting_read_function, + doc: /* The function to be called by `completing-read'. */); + Vcompleting_read_function = Qcompleting_read_default; + DEFVAR_LISP ("minibuffer-help-form", &Vminibuffer_help_form, doc: /* Value that `help-form' takes on inside the minibuffer. */); Vminibuffer_help_form = Qnil; @@ -2291,6 +2321,7 @@ properties. */); defsubr (&Stest_completion); defsubr (&Sassoc_string); defsubr (&Scompleting_read); + defsubr (&Scompleting_read_default); } /* arch-tag: 8f69b601-fba3-484c-a6dd-ceaee54a7a73 --=-=-=--