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: Wed, 22 Jun 2011 12:15:38 +0800 Message-ID: References: <21E601B384E14788A5CDF8AD49535D75@us.oracle.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: dough.gmane.org 1308716195 18432 80.91.229.12 (22 Jun 2011 04:16:35 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Wed, 22 Jun 2011 04:16:35 +0000 (UTC) Cc: Drew Adams , emacs-devel@gnu.org To: Stefan Monnier Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Wed Jun 22 06:16:26 2011 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([140.186.70.17]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1QZEra-0003oB-80 for ged-emacs-devel@m.gmane.org; Wed, 22 Jun 2011 06:16:26 +0200 Original-Received: from localhost ([::1]:53570 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QZErZ-0004K1-EY for ged-emacs-devel@m.gmane.org; Wed, 22 Jun 2011 00:16:25 -0400 Original-Received: from eggs.gnu.org ([140.186.70.92]:33459) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QZErG-0004Hv-5z for emacs-devel@gnu.org; Wed, 22 Jun 2011 00:16:10 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1QZErB-0004Vo-Op for emacs-devel@gnu.org; Wed, 22 Jun 2011 00:16:06 -0400 Original-Received: from mail-iw0-f169.google.com ([209.85.214.169]:41658) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QZErB-0004Vj-Ar for emacs-devel@gnu.org; Wed, 22 Jun 2011 00:16:01 -0400 Original-Received: by iwn8 with SMTP id 8so483824iwn.0 for ; Tue, 21 Jun 2011 21:16:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:from:to:cc:subject:references:date:in-reply-to :message-id:user-agent:mime-version:content-type; bh=akZ3t6fXM337pOI2caYDkNa4vJUJcFzYA2Y9/oUM7u0=; b=qNgM1/urm7MwIhlm6vGhO4Otv96rbjnMy/RjQJFJM9bz+45JcQfpyf5eQdole4jPfG oHx28CxwGifK8izuiUQF1CM4R2V6HGL5E5awClXMjcJev0DMIkqN0lTM0+i9Vt0K4TtQ Rzt+5cuvXA/vOXhUB0y+z0d+GiRlGo0CSx2bE= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=from:to:cc:subject:references:date:in-reply-to:message-id :user-agent:mime-version:content-type; b=sPiWqGxmAkBnER0IdhSxM96PPBLxGrHSdiWR/Wn2Rbpki3VRovOdCPESsJ6lWNSZ39 KZBh/Kj93Qd9H8y3t7RSOcgYtK4mCN535lUK/ugPb5ovUpmMPOWigCZe3PZRc3Y2bIJQ k7iY9RERivQtLthTqZ4970hpNKCEQIgya3+Pc= Original-Received: by 10.42.243.9 with SMTP id lk9mr266468icb.207.1308716160317; Tue, 21 Jun 2011 21:16:00 -0700 (PDT) Original-Received: from th041141.ip.tsinghua.edu.cn ([114.247.10.72]) by mx.google.com with ESMTPS id v16sm108405ibe.51.2011.06.21.21.15.49 (version=TLSv1/SSLv3 cipher=OTHER); Tue, 21 Jun 2011 21:15:59 -0700 (PDT) In-Reply-To: (Stefan Monnier's message of "Tue, 21 Jun 2011 21:50:22 -0400") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.3.50 (Mac OS X 10.6.7) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2) X-Received-From: 209.85.214.169 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:140826 Archived-At: --=-=-= Content-Type: text/plain On 2011-06-22 09:50 +0800, Stefan Monnier wrote: >> +(defun completing-read-default (prompt collection &optional predicate require-match >> + initial-input hist def inherit-input-method) > > Please stay within 80 columns. Done. >> + "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)) > > This `not' doesn't preserve the behavior when `confirm' is not t. Fixed. >> + (keymap (if require-match >> + (if minibuffer-completing-file-name > > The C code checks (memq minibuffer-completing-file-name '(nil > lambda)) instead. Are you sure your code is correct, and if so why? The value 'lambda is not documented anywhere. What's its meaning? >> + (result (read-from-minibuffer prompt initial-input keymap >> + nil hist def inherit-input-method))) > > The C code does some funny dance with the initial-input before passing > it to read_minibuf, which read-from-minibuffer (and your code) doesn't > do, so I suspect that your code does not preserve the > corresponding behavior. > > > Stefan Please review the attached updated patch. Thanks very much. Leo --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=crf.diff Content-Description: crf.diff === modified file 'lisp/ChangeLog' --- lisp/ChangeLog 2011-06-21 22:55:52 +0000 +++ lisp/ChangeLog 2011-06-22 04:04:32 +0000 @@ -1,3 +1,8 @@ +2011-06-22 Leo Liu + + * minibuffer.el (completing-read-function): + (completing-read-default): Move from minibuf.c + 2011-06-21 Lars Magne Ingebrigtsen * mail/smtpmail.el (smtpmail-via-smtp): Set === modified file 'lisp/minibuffer.el' --- lisp/minibuffer.el 2011-06-20 20:16:20 +0000 +++ lisp/minibuffer.el 2011-06-22 04:11:40 +0000 @@ -2710,7 +2710,40 @@ (let ((newstr (completion-initials-expand string table pred))) (when newstr (completion-pcm-try-completion newstr table pred (length newstr))))) + +(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." + + (when (consp initial-input) + (setq initial-input + (cons (car initial-input) + ;; `completing-read' uses 0-based index while + ;; `read-from-minibuffer' uses 1-based index. + (1+ (cdr initial-input))))) + (let* ((minibuffer-completion-table collection) + (minibuffer-completion-predicate predicate) + (minibuffer-completion-confirm (unless (eq require-match t) + require-match)) + (keymap (if require-match + (if (memq minibuffer-completing-file-name '(nil lambda)) + minibuffer-local-must-match-map + minibuffer-local-filename-must-match-map) + (if (memq minibuffer-completing-file-name '(nil lambda)) + minibuffer-local-completion-map + minibuffer-local-filename-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)) ;; Miscellaneous === modified file 'src/ChangeLog' --- src/ChangeLog 2011-06-21 16:47:56 +0000 +++ src/ChangeLog 2011-06-22 04:05:59 +0000 @@ -1,3 +1,8 @@ +2011-06-22 Leo Liu + + * minibuf.c (Fcompleting_read_default): + (Vcompleting_read_function): Move to minibuffer.el. + 2011-06-21 Paul Eggert Port to Sun C. === modified file 'src/minibuf.c' --- src/minibuf.c 2011-06-10 20:05:21 +0000 +++ src/minibuf.c 2011-06-22 04:02:48 +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; @@ -1694,7 +1693,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; @@ -1705,76 +1704,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)); -} Lisp_Object Fassoc_string (register Lisp_Object key, Lisp_Object list, Lisp_Object case_fold); @@ -2013,7 +1942,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"); @@ -2132,12 +2060,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; @@ -2214,5 +2136,4 @@ defsubr (&Stest_completion); defsubr (&Sassoc_string); defsubr (&Scompleting_read); - defsubr (&Scompleting_read_default); } --=-=-=--