all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Leo <sdl.web@gmail.com>
To: Stefan Monnier <monnier@iro.umontreal.ca>
Cc: Drew Adams <drew.adams@oracle.com>, emacs-devel@gnu.org
Subject: Re: Any objection to adding completing-read-function?
Date: Thu, 02 Jun 2011 03:03:18 +0800	[thread overview]
Message-ID: <m14o494bnt.fsf@gmail.com> (raw)
In-Reply-To: <jwvr57erhtu.fsf-monnier+emacs@gnu.org> (Stefan Monnier's message of "Tue, 31 May 2011 12:51:36 -0300")

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

On 2011-05-31 23:51 +0800, Stefan Monnier wrote:
>> 2. I would also prefer it if the code for `completing-read-function' and its
>> treatment were in Lisp, not C.
>
> Full agreement.  I'd like to turn the `initial' arg into a callback
> (which can do initialization in a similar way to
> minibuffer-with-setup-hook, but more robust) but doing it in C is
> more painful.

Will look into this later on.

>> No, I won't be submitting a patch. ;-)  Dunno
>
> Damn!

Preliminary patch attached that moves completing-read-function and
completing-read-default to elisp. Comments welcome.

Since completing-read-default in the patch calls read-from-minibuffer,
what to do with this note:

,----[ read-from-minibuffer ]
| *Note* that this behavior differs from the way such arguments are used
| in `completing-read' and some related functions, which use
| zero-indexing for POSITION.
`----


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

=== modified file 'lisp/minibuffer.el'
--- lisp/minibuffer.el	2011-06-01 15:34:41 +0000
+++ lisp/minibuffer.el	2011-06-01 18:48:10 +0000
@@ -2699,7 +2699,30 @@
   (let ((newstr (completion-initials-expand string table pred)))
     (when newstr
       (completion-pcm-try-completion newstr table pred (length newstr)))))
+\f
+(defvar completing-read-function 'completing-read-default
+  "The function called by `completing-read' to do its work.
+It should accept the same arguments as `completing-read'.")
 
+(defun completing-read-default (prompt collection &optional predicate require-match
+                                       initial-input hist def inherit-input-method)
+  "Default method for reading from the minibuffer with completion.
+See `completing-read' for the meaning of the arguments."
+  (let* ((minibuffer-completion-table collection)
+         (minibuffer-completion-predicate predicate)
+         (minibuffer-completion-confirm (not require-match))
+         (keymap (if require-match
+                     (if minibuffer-completing-file-name
+                         minibuffer-local-filename-must-match-map
+                       minibuffer-local-must-match-map)
+                   (if minibuffer-completing-file-name
+                       minibuffer-local-filename-completion-map
+                     minibuffer-local-completion-map)))
+         (result (read-from-minibuffer prompt initial-input keymap
+                                       nil hist def inherit-input-method)))
+    (when (and (equal result "") def)
+      (setq result (if (consp def) (car def) def)))
+    result))
 \f
 ;; Miscellaneous
 

=== modified file 'src/minibuf.c'
--- src/minibuf.c	2011-06-01 15:34:41 +0000
+++ src/minibuf.c	2011-06-01 18:51:33 +0000
@@ -72,7 +72,6 @@
 static Lisp_Object Qminibuffer_completion_table;
 static Lisp_Object Qminibuffer_completion_predicate;
 static Lisp_Object Qminibuffer_completion_confirm;
-static Lisp_Object Qcompleting_read_default;
 static Lisp_Object Quser_variable_p;
 
 static Lisp_Object Qminibuffer_default;
@@ -1686,7 +1685,7 @@
   (Lisp_Object prompt, Lisp_Object collection, Lisp_Object predicate, Lisp_Object require_match, Lisp_Object initial_input, Lisp_Object hist, Lisp_Object def, Lisp_Object inherit_input_method)
 {
   Lisp_Object args[9];
-  args[0] = Vcompleting_read_function;
+  args[0] = Fsymbol_value (intern ("completing-read-function"));
   args[1] = prompt;
   args[2] = collection;
   args[3] = predicate;
@@ -1697,76 +1696,6 @@
   args[8] = inherit_input_method;
   return Ffuncall (9, args);
 }
-
-DEFUN ("completing-read-default", Fcompleting_read_default, Scompleting_read_default, 2, 8, 0,
-       doc: /* Default method for reading from the minibuffer with completion.
-See `completing-read' for the meaning of the arguments.  */)
-  (Lisp_Object prompt, Lisp_Object collection, Lisp_Object predicate, Lisp_Object require_match, Lisp_Object initial_input, Lisp_Object hist, Lisp_Object def, Lisp_Object inherit_input_method)
-{
-  Lisp_Object val, histvar, histpos, position;
-  Lisp_Object init;
-  int pos = 0;
-  int count = SPECPDL_INDEX ();
-  struct gcpro gcpro1;
-
-  init = initial_input;
-  GCPRO1 (def);
-
-  specbind (Qminibuffer_completion_table, collection);
-  specbind (Qminibuffer_completion_predicate, predicate);
-  specbind (Qminibuffer_completion_confirm,
-	    EQ (require_match, Qt) ? Qnil : require_match);
-
-  position = Qnil;
-  if (!NILP (init))
-    {
-      if (CONSP (init))
-	{
-	  position = Fcdr (init);
-	  init = Fcar (init);
-	}
-      CHECK_STRING (init);
-      if (!NILP (position))
-	{
-	  CHECK_NUMBER (position);
-	  /* Convert to distance from end of input.  */
-	  pos = XINT (position) - SCHARS (init);
-	}
-    }
-
-  if (SYMBOLP (hist))
-    {
-      histvar = hist;
-      histpos = Qnil;
-    }
-  else
-    {
-      histvar = Fcar_safe (hist);
-      histpos = Fcdr_safe (hist);
-    }
-  if (NILP (histvar))
-    histvar = Qminibuffer_history;
-  if (NILP (histpos))
-    XSETFASTINT (histpos, 0);
-
-  val = read_minibuf (NILP (require_match)
-		      ? (NILP (Vminibuffer_completing_file_name)
-			 || EQ (Vminibuffer_completing_file_name, Qlambda)
-			 ? Vminibuffer_local_completion_map
-			 : Vminibuffer_local_filename_completion_map)
-		      : (NILP (Vminibuffer_completing_file_name)
-			 || EQ (Vminibuffer_completing_file_name, Qlambda)
-			 ? Vminibuffer_local_must_match_map
-			 : Vminibuffer_local_filename_must_match_map),
-		      init, prompt, make_number (pos), 0,
-		      histvar, histpos, def, 0,
-		      !NILP (inherit_input_method));
-
-  if (STRINGP (val) && SCHARS (val) == 0 && ! NILP (def))
-    val = CONSP (def) ? XCAR (def) : def;
-
-  RETURN_UNGCPRO (unbind_to (count, val));
-}
 \f
 Lisp_Object Fassoc_string (register Lisp_Object key, Lisp_Object list, Lisp_Object case_fold);
 
@@ -2005,7 +1934,6 @@
   minibuf_save_list = Qnil;
   staticpro (&minibuf_save_list);
 
-  DEFSYM (Qcompleting_read_default, "completing-read-default");
   DEFSYM (Qcompletion_ignore_case, "completion-ignore-case");
   DEFSYM (Qread_file_name_internal, "read-file-name-internal");
   DEFSYM (Qminibuffer_default, "minibuffer-default");
@@ -2124,12 +2052,6 @@
 	       doc: /* Non-nil means completing file names.  */);
   Vminibuffer_completing_file_name = Qnil;
 
-  DEFVAR_LISP ("completing-read-function",
-	       Vcompleting_read_function,
-	       doc: /* The function called by `completing-read' to do the work.
-It should accept the same arguments as `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;
@@ -2205,5 +2127,4 @@
   defsubr (&Stest_completion);
   defsubr (&Sassoc_string);
   defsubr (&Scompleting_read);
-  defsubr (&Scompleting_read_default);
 }


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


Leo

  reply	other threads:[~2011-06-01 19:03 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=m14o494bnt.fsf@gmail.com \
    --to=sdl.web@gmail.com \
    --cc=drew.adams@oracle.com \
    --cc=emacs-devel@gnu.org \
    --cc=monnier@iro.umontreal.ca \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.