all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Any objection to adding completing-read-function?
@ 2010-12-28  8:03 Leo
  2010-12-28 14:34 ` Stefan Monnier
  2010-12-28 16:17 ` Drew Adams
  0 siblings, 2 replies; 28+ messages in thread
From: Leo @ 2010-12-28  8:03 UTC (permalink / raw)
  To: emacs-devel

[-- Attachment #1: Type: text/plain, Size: 1181 bytes --]

Hello all,

I have been locally using a variable like that to replace
completing-read with ido-completing-read and it appears to me to improve
efficiency in many places.

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.

After applying the attached patch, one may customise it like this:

(setq completing-read-function 'ido-completing-read*)
(defun ido-completing-read* (prompt choices &optional predicate require-match
                                    initial-input hist def inherit-input-method)
  (if (and (listp choices) (not (functionp choices)))
      (ido-completing-read prompt (if (listp (car choices))
                                      (mapcar 'car choices)
                                    choices)
                           predicate require-match initial-input hist def inherit-input-method)
    (let ((completing-read-function nil))
      (completing-read prompt choices predicate require-match
                       initial-input hist def inherit-input-method))))

Here are some screenshots:

I switching to a bookmark:

[-- Attachment #2: bookmark.png --]
[-- Type: image/png, Size: 18926 bytes --]

[-- Attachment #3: Type: text/plain, Size: 33 bytes --]


Switching to a branch in magit:

[-- Attachment #4: emacs.png --]
[-- Type: image/png, Size: 18752 bytes --]

[-- Attachment #5: Type: text/plain, Size: 32 bytes --]


Loading lisp systems in slime:

[-- Attachment #6: slime.png --]
[-- Type: image/png, Size: 18975 bytes --]

[-- Attachment #7: Type: text/plain, Size: 8 bytes --]


Patch:

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #8: crf.diff --]
[-- Type: text/x-diff, Size: 3807 bytes --]

diff --git a/lisp/ido.el b/lisp/ido.el
index e52a753..de12c8a 100644
--- a/lisp/ido.el
+++ b/lisp/ido.el
@@ -2011,11 +2011,12 @@ If INITIAL is non-nil, it specifies the initial input string."
 	(setq ido-exit nil)
 	(setq ido-final-text
 	      (catch 'ido
-		(completing-read
-		 (ido-make-prompt item prompt)
-		 '(("dummy" . 1)) nil nil ; table predicate require-match
-		 (prog1 ido-text-init (setq ido-text-init nil))	;initial-contents
-		 history))))
+		(let ((completing-read-function nil))
+		  (completing-read
+		   (ido-make-prompt item prompt)
+		   '(("dummy" . 1)) nil nil ; table predicate require-match
+		   (prog1 ido-text-init (setq ido-text-init nil)) ;initial-contents
+		   history)))))
       (ido-trace "completing-read" ido-final-text)
       (if (get-buffer ido-completion-buffer)
 	  (kill-buffer ido-completion-buffer))
@@ -4835,7 +4836,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..930d50f 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 Vcompleting_read_function;
 
 Lisp_Object Quser_variable_p;
 
@@ -1721,6 +1722,9 @@ with a space are ignored unless STRING itself starts with a space.  */)
 \f
 DEFUN ("completing-read", Fcompleting_read, Scompleting_read, 2, 8, 0,
        doc: /* Read a string in the minibuffer, with completion.
+If `completing-read-function' is non-nil, call it with all arguments passed
+to `completing-read'.
+
 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.
@@ -1779,9 +1783,25 @@ Completion ignores case if the ambient value of
      Lisp_Object hist, def, inherit_input_method;
 {
   Lisp_Object val, histvar, histpos, position;
+  Lisp_Object args[9];
   Lisp_Object init;
   int pos = 0;
   int count = SPECPDL_INDEX ();
+
+  if (! NILP (Vcompleting_read_function))
+    {
+      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);
+    }
+
   struct gcpro gcpro1;
 
   init = initial_input;
@@ -2216,6 +2236,12 @@ 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: /* Non-nil means `completing-read' does its work by calling this function.
+The function will receive all arguments passed to `completing-read'.  */);
+  Vcompleting_read_function = Qnil;
+
   DEFVAR_LISP ("minibuffer-help-form", &Vminibuffer_help_form,
 	       doc: /* Value that `help-form' takes on inside the minibuffer.  */);
   Vminibuffer_help_form = Qnil;

[-- Attachment #9: Type: text/plain, Size: 13 bytes --]


Cheers,
Leo

^ permalink raw reply related	[flat|nested] 28+ messages in thread

end of thread, other threads:[~2011-06-23  3:42 UTC | newest]

Thread overview: 28+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-12-28  8:03 Any objection to adding completing-read-function? Leo
2010-12-28 14:34 ` Stefan Monnier
2010-12-28 16:17   ` Drew Adams
2010-12-28 19:39     ` Stefan Monnier
2010-12-28 19:45       ` Drew Adams
2010-12-28 22:03         ` Stefan Monnier
2010-12-28 23:27           ` Leo
2010-12-29  2:51             ` Stefan Monnier
2010-12-29  8:16               ` Leo
2010-12-29 15:39                 ` Stefan Monnier
2010-12-29 16:12                   ` Leo
2011-03-20 13:07                   ` Leo
2011-03-21 14:22                     ` Stefan Monnier
2011-03-21 15:01                       ` Leo
2010-12-28 19:02   ` Leo
2010-12-28 19:45     ` Stefan Monnier
2011-05-31 15:27       ` Drew Adams
2011-05-31 15:51         ` Stefan Monnier
2011-06-01 19:03           ` Leo
2011-06-09 11:53             ` Leo
2011-06-09 15:16               ` Stefan Monnier
2011-06-21  9:11                 ` Leo
2011-06-22  1:50             ` Stefan Monnier
2011-06-22  4:15               ` Leo
2011-06-22 21:19                 ` Stefan Monnier
2011-06-23  3:42                   ` Leo
2010-12-28 16:17 ` Drew Adams
2010-12-28 19:07   ` Leo

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.