[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Any objection to adding completing-read-function?

From: Leo
Subject: Re: Any objection to adding completing-read-function?
Date: Tue, 28 Dec 2010 19:02:31 +0000
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.2.91 (Mac OS X 10.6.5)

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

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)) 
@@ -4835,7 +4835,7 @@ See `read-directory-name' for additional parameters."
          (concat ido-current-directory filename)))))
-(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, 
 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, 
+     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

reply via email to

[Prev in Thread] Current Thread [Next in Thread]